ParagonIE_Sodium_Compat::add

Advertisement

Summery Summery

Add two numbers (little-endian unsigned), storing the value in the first parameter.

Syntax Syntax

ParagonIE_Sodium_Compat::add( string $val, string $addv )

Description Description

This mutates $val.

Parameters Parameters

$val

(string) (Required)

$addv

(string) (Required)

Return Return

(void)

Source Source

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

    public static function add(&$val, $addv)
    {
        $val_len = ParagonIE_Sodium_Core_Util::strlen($val);
        $addv_len = ParagonIE_Sodium_Core_Util::strlen($addv);
        if ($val_len !== $addv_len) {
            throw new SodiumException('values must have the same length');
        }
        $A = ParagonIE_Sodium_Core_Util::stringToIntArray($val);
        $B = ParagonIE_Sodium_Core_Util::stringToIntArray($addv);

        $c = 0;
        for ($i = 0; $i < $val_len; $i++) {
            $c += ($A[$i] + $B[$i]);
            $A[$i] = ($c & 0xff);
            $c >>= 8;
        }
        $val = ParagonIE_Sodium_Core_Util::intArrayToString($A);
    }

Advertisement

Advertisement

Leave a Reply

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