ParagonIE_Sodium_Compat::crypto_generichash_final

Advertisement

Summery Summery

Get the final BLAKE2b hash output for a given context.

Syntax Syntax

ParagonIE_Sodium_Compat::crypto_generichash_final( string $ctx, int $length = self::CRYPTO_GENERICHASH_BYTES )

Parameters Parameters

$ctx

(Required) BLAKE2 hashing context. Generated by crypto_generichash_init().

$length

(Optional) Hash output size.

Default value: self::CRYPTO_GENERICHASH_BYTES

Return Return

(string) Final BLAKE2b hash.

Source Source

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

    public static function crypto_generichash_final(&$ctx, $length = self::CRYPTO_GENERICHASH_BYTES)
    {
        /* Type checks: */
        ParagonIE_Sodium_Core_Util::declareScalarType($ctx, 'string', 1);
        ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 2);

        if (self::useNewSodiumAPI()) {
            return sodium_crypto_generichash_final($ctx, $length);
        }
        if (self::use_fallback('crypto_generichash_final')) {
            $func = '\\Sodium\\crypto_generichash_final';
            return (string) $func($ctx, $length);
        }
        if ($length < 1) {
            try {
                self::memzero($ctx);
            } catch (SodiumException $ex) {
                unset($ctx);
            }
            return '';
        }
        if (PHP_INT_SIZE === 4) {
            $result = ParagonIE_Sodium_Crypto32::generichash_final($ctx, $length);
        } else {
            $result = ParagonIE_Sodium_Crypto::generichash_final($ctx, $length);
        }
        try {
            self::memzero($ctx);
        } catch (SodiumException $ex) {
            unset($ctx);
        }
        return $result;
    }

Advertisement

Advertisement

Leave a Reply