crypto_generichash_update example

if (!is_callable('\\Sodium\\crypto_generichash_update')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_generichash_update() * @param string|null $ctx * @param string $message * @return void * @throws \SodiumException * @throws \TypeError */
    function crypto_generichash_update(&$ctx$message = '')
    {
        ParagonIE_Sodium_Compat::crypto_generichash_update($ctx$message);
    }
}
if (!is_callable('\\Sodium\\crypto_kx')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_kx() * @param string $my_secret * @param string $their_public * @param string $client_public * @param string $server_public * @return string * @throws \SodiumException * @throws \TypeError */
throw new SodiumException('Could not open input file for reading');
        }
        $ctx = ParagonIE_Sodium_Compat::crypto_generichash_init($key$outputLength);
        while ($size > 0) {
            $blockSize = $size > 64
                ? 64
                : $size;
            $read = fread($fp$blockSize);
            if (!is_string($read)) {
                throw new SodiumException('Could not read input file');
            }
            ParagonIE_Sodium_Compat::crypto_generichash_update($ctx$read);
            $size -= $blockSize;
        }

        fclose($fp);
        return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx$outputLength);
    }

    /** * Encrypt a file (rather than a string). Uses less memory than * ParagonIE_Sodium_Compat::crypto_secretbox(), but produces * the same result. * * @param string $inputFile Absolute path to a file on the filesystem * @param string $outputFile Absolute path to a file on the filesystem * @param string $nonce Number to be used only once * @param string $key Encryption key * * @return bool * @throws SodiumException * @throws TypeError */
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_KX_KEYPAIRBYTES) {
            throw new SodiumException('keypair should be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes');
        }
        if (ParagonIE_Sodium_Core_Util::strlen($serverPublicKey) !== self::CRYPTO_KX_PUBLICKEYBYTES) {
            throw new SodiumException('public keys must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes');
        }

        $sk = self::crypto_kx_secretkey($keypair);
        $pk = self::crypto_kx_publickey($keypair);
        $h = self::crypto_generichash_init(null, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
        self::crypto_generichash_update($h, self::crypto_scalarmult($sk$serverPublicKey));
        self::crypto_generichash_update($h$pk);
        self::crypto_generichash_update($h$serverPublicKey);
        $sessionKeys = self::crypto_generichash_final($h, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
        return array(
            ParagonIE_Sodium_Core_Util::substr(
                $sessionKeys,
                0,
                self::CRYPTO_KX_SESSIONKEYBYTES
            ),
            ParagonIE_Sodium_Core_Util::substr(
                $sessionKeys,
                
if (!is_callable('sodium_crypto_generichash_update')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_generichash_update() * @param string|null $state * @param string $message * @return void * @throws SodiumException * @throws TypeError */
    function sodium_crypto_generichash_update(&$state$message = '')
    {
        ParagonIE_Sodium_Compat::crypto_generichash_update($state$message);
    }
}
if (!is_callable('sodium_crypto_kdf_keygen')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_kdf_keygen() * @return string * @throws Exception */
    function sodium_crypto_kdf_keygen()
    {
        return ParagonIE_Sodium_Compat::crypto_kdf_keygen();
    }
Home | Imprint | This part of the site doesn't use cookies.