예제 #1
0
        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));
            }
        }
예제 #2
0
파일: Blake2bMac.cs 프로젝트: pdb0102/nsec
        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_;
        }
예제 #3
0
        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_;
        }
예제 #4
0
        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_;
        }
예제 #5
0
        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_;
        }
예제 #6
0
 internal static unsafe extern int crypto_generichash_blake2b_update(
     crypto_generichash_blake2b_state *state,
     byte * @in,
     ulong inlen);
예제 #7
0
 internal static unsafe extern int crypto_generichash_blake2b_init(
     crypto_generichash_blake2b_state *state,
     byte *key,
     UIntPtr keylen,
     UIntPtr outlen);
예제 #8
0
 internal static unsafe extern int crypto_generichash_blake2b_final(
     crypto_generichash_blake2b_state *state,
     byte * @out,
     UIntPtr outlen);
예제 #9
0
 internal static unsafe extern int crypto_generichash_blake2b_init(
     crypto_generichash_blake2b_state *state,
     SecureMemoryHandle key,
     UIntPtr keylen,
     UIntPtr outlen);