WordPress at Your Fingertips
function is not described

ParagonIE_Sodium_Core_Ristretto255::h2c_string_to_hash_sha256() protected WP 1.0

{} It's a method of the class: ParagonIE_Sodium_Core_Ristretto255{}

No Hooks.

Return

String.

Usage

$result = ParagonIE_Sodium_Core_Ristretto255::h2c_string_to_hash_sha256( $hLen, $ctx, $msg );
$hLen(int) (required)
-
$ctx(?string) (required)
-
$msg(string) (required)
-

Code of ParagonIE_Sodium_Core_Ristretto255::h2c_string_to_hash_sha256() WP 5.8.2

protected static function h2c_string_to_hash_sha256($hLen, $ctx, $msg)
{
    $h = array_fill(0, $hLen, 0);
    $ctx_len = !is_null($ctx) ? self::strlen($ctx) : 0;
    if ($hLen > 0xff) {
        throw new SodiumException('Hash must be less than 256 bytes');
    }

    if ($ctx_len > 0xff) {
        $st = hash_init('sha256');
        self::hash_update($st, "H2C-OVERSIZE-DST-");
        self::hash_update($st, $ctx);
        $ctx = hash_final($st, true);
        $ctx_len = 32;
    }
    $t = array(0, $hLen, 0);
    $ux = str_repeat("\0", 64);
    $st = hash_init('sha256');
    self::hash_update($st, $ux);
    self::hash_update($st, $msg);
    self::hash_update($st, self::intArrayToString($t));
    self::hash_update($st, $ctx);
    self::hash_update($st, self::intToChr($ctx_len));
    $u0 = hash_final($st, true);

    for ($i = 0; $i < $hLen; $i += 64) {
        $ux = self::xorStrings($ux, $u0);
        ++$t[2];
        $st = hash_init('sha256');
        self::hash_update($st, $ux);
        self::hash_update($st, self::intToChr($t[2]));
        self::hash_update($st, $ctx);
        self::hash_update($st, self::intToChr($ctx_len));
        $ux = hash_final($st, true);
        $amount = min($hLen - $i, 64);
        for ($j = 0; $j < $amount; ++$j) {
            $h[$i + $j] = self::chrToInt($ux[$i]);
        }
    }
    return self::intArrayToString(array_slice($h, 0, $hLen));
}