internal unsafe override bool FinalizeAndVerifyCore( ref IncrementalHashState state, ReadOnlySpan <byte> hash) { Debug.Assert(hash.Length >= crypto_generichash_blake2b_BYTES_MIN); Debug.Assert(hash.Length <= crypto_generichash_blake2b_BYTES_MAX); byte *buffer = stackalloc byte[63 + Unsafe.SizeOf <crypto_generichash_blake2b_state>()]; crypto_generichash_blake2b_state *state_ = Align64(buffer); *state_ = state.blake2b; byte *temp = stackalloc byte[hash.Length]; int error = crypto_generichash_blake2b_final( state_, temp, (UIntPtr)hash.Length); Debug.Assert(error == 0); state.blake2b = *state_; fixed(byte * @out = hash) { return(CryptographicOperations.FixedTimeEquals(temp, @out, hash.Length)); } }
internal unsafe override void InitializeCore( ReadOnlySpan <byte> key, out IncrementalMacState state) { Debug.Assert(key.Length >= crypto_generichash_blake2b_KEYBYTES_MIN); Debug.Assert(key.Length <= crypto_generichash_blake2b_KEYBYTES_MAX); Debug.Assert(MacSize >= crypto_generichash_blake2b_BYTES_MIN); Debug.Assert(MacSize <= crypto_generichash_blake2b_BYTES_MAX); byte *buffer = stackalloc byte[63 + Unsafe.SizeOf <crypto_generichash_blake2b_state>()]; crypto_generichash_blake2b_state *state_ = Align64(buffer); fixed(byte *k = key) { int error = crypto_generichash_blake2b_init( state_, k, (UIntPtr)key.Length, (UIntPtr)MacSize); Debug.Assert(error == 0); } state.blake2b = *state_; }
internal unsafe override void InitializeCore( out IncrementalHashState state) { Debug.Assert(HashSize >= crypto_generichash_blake2b_BYTES_MIN); Debug.Assert(HashSize <= crypto_generichash_blake2b_BYTES_MAX); byte *buffer = stackalloc byte[63 + Unsafe.SizeOf <crypto_generichash_blake2b_state>()]; crypto_generichash_blake2b_state *state_ = Align64(buffer); int error = crypto_generichash_blake2b_init( state_, null, UIntPtr.Zero, (UIntPtr)HashSize); Debug.Assert(error == 0); state.blake2b = *state_; }
internal unsafe override void UpdateCore( ref IncrementalHashState state, ReadOnlySpan <byte> data) { byte *buffer = stackalloc byte[63 + Unsafe.SizeOf <crypto_generichash_blake2b_state>()]; crypto_generichash_blake2b_state *state_ = Align64(buffer); *state_ = state.blake2b; fixed(byte * @in = data) { int error = crypto_generichash_blake2b_update( state_, @in, (ulong)data.Length); Debug.Assert(error == 0); } state.blake2b = *state_; }
internal unsafe override void FinalizeCore( ref IncrementalHashState state, Span <byte> hash) { Debug.Assert(hash.Length >= crypto_generichash_blake2b_BYTES_MIN); Debug.Assert(hash.Length <= crypto_generichash_blake2b_BYTES_MAX); byte *buffer = stackalloc byte[63 + Unsafe.SizeOf <crypto_generichash_blake2b_state>()]; crypto_generichash_blake2b_state *state_ = Align64(buffer); *state_ = state.blake2b; fixed(byte * @out = hash) { int error = crypto_generichash_blake2b_final( state_, @out, (UIntPtr)hash.Length); Debug.Assert(error == 0); } state.blake2b = *state_; }
internal static unsafe extern int crypto_generichash_blake2b_update( crypto_generichash_blake2b_state *state, byte * @in, ulong inlen);
internal static unsafe extern int crypto_generichash_blake2b_init( crypto_generichash_blake2b_state *state, byte *key, UIntPtr keylen, UIntPtr outlen);
internal static unsafe extern int crypto_generichash_blake2b_final( crypto_generichash_blake2b_state *state, byte * @out, UIntPtr outlen);
internal static unsafe extern int crypto_generichash_blake2b_init( crypto_generichash_blake2b_state *state, SecureMemoryHandle key, UIntPtr keylen, UIntPtr outlen);