ParagonIE_Sodium_Core32_Int64::multiplyLong

Advertisement

Syntax Syntax

ParagonIE_Sodium_Core32_Int64::multiplyLong( $a,  $b, int $baseLog2 = 16 )

Parameters Parameters

(Required) int> $b

$baseLog2

(Optional)

Default value: 16

Return Return

(array<int,) int>

Source Source

File: wp-includes/sodium_compat/src/Core32/Int64.php

    public function multiplyLong(array $a, array $b, $baseLog2 = 16)
    {
        $a_l = count($a);
        $b_l = count($b);
        /** @var array<int, int> $r */
        $r = array_fill(0, $a_l + $b_l + 1, 0);
        $base = 1 << $baseLog2;
        for ($i = 0; $i < $a_l; ++$i) {
            $a_i = $a[$i];
            for ($j = 0; $j < $a_l; ++$j) {
                $b_j = $b[$j];
                $product = ($a_i * $b_j) + $r[$i + $j];
                $carry = ($product >> $baseLog2 & 0xffff);
                $r[$i + $j] = ($product - (int) ($carry * $base)) & 0xffff;
                $r[$i + $j + 1] += $carry;
            }
        }
        return array_slice($r, 0, 5);
    }

Advertisement

Advertisement

Leave a Reply