ParagonIE_Sodium_Compat::runtime_speed_test

Advertisement

Summery Summery

Runtime testing method for 32-bit platforms.

Syntax Syntax

ParagonIE_Sodium_Compat::runtime_speed_test( int $iterations, int $maxTimeout )

Description Description

Usage: If runtime_speed_test() returns FALSE, then our 32-bit implementation is to slow to use safely without risking timeouts. If this happens, install sodium from PECL to get acceptable performance.

Parameters Parameters

$iterations

(int) (Required) Number of multiplications to attempt

$maxTimeout

(int) (Required) Milliseconds

Return Return

(bool) TRUE if we're fast enough, FALSE is not

Source Source

File: wp-includes/sodium_compat/src/Compat.php

    public static function runtime_speed_test($iterations, $maxTimeout)
    {
        if (self::polyfill_is_fast()) {
            return true;
        }
        /** @var float $end */
        $end = 0.0;
        /** @var float $start */
        $start = microtime(true);
        /** @var ParagonIE_Sodium_Core32_Int64 $a */
        $a = ParagonIE_Sodium_Core32_Int64::fromInt(random_int(3, 1 << 16));
        for ($i = 0; $i < $iterations; ++$i) {
            /** @var ParagonIE_Sodium_Core32_Int64 $b */
            $b = ParagonIE_Sodium_Core32_Int64::fromInt(random_int(3, 1 << 16));
            $a->mulInt64($b);
        }
        /** @var float $end */
        $end = microtime(true);
        /** @var int $diff */
        $diff = (int) ceil(($end - $start) * 1000);
        return $diff < $maxTimeout;
    }

Advertisement

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.