Example #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));
            }
        }
Example #2
0
        internal override void InitializeCore(
            out IncrementalHashState state)
        {
            int error = crypto_hash_sha512_init(
                out state.sha512);

            Debug.Assert(error == 0);
        }
Example #3
0
        internal 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);

            Span <byte> buffer = stackalloc byte[63 + Unsafe.SizeOf <crypto_generichash_blake2b_state>()];
            ref crypto_generichash_blake2b_state state_ = ref AlignPinnedReference(ref buffer.GetPinnableReference());
Example #4
0
        internal override void InitializeCore(
            int hashSize,
            out IncrementalHashState state)
        {
            Debug.Assert(hashSize == crypto_hash_sha256_BYTES);

            int error = crypto_hash_sha256_init(
                out state.sha256);

            Debug.Assert(error == 0);
        }
Example #5
0
        internal override void UpdateCore(
            ref IncrementalHashState state,
            ReadOnlySpan <byte> data)
        {
            int error = crypto_hash_sha512_update(
                ref state.sha512,
                in data.GetPinnableReference(),
                (ulong)data.Length);

            Debug.Assert(error == 0);
        }
Example #6
0
        internal unsafe override void InitializeCore(
            out IncrementalHashState state)
        {
            fixed(crypto_hash_sha256_state *state_ = &state.sha256)
            {
                int error = crypto_hash_sha256_init(
                    state_);

                Debug.Assert(error == 0);
            }
        }
Example #7
0
        internal override void FinalizeCore(
            ref IncrementalHashState state,
            Span <byte> hash)
        {
            Debug.Assert(hash.Length == crypto_hash_sha256_BYTES);

            int error = crypto_hash_sha256_final(
                ref state.sha256,
                ref hash.GetPinnableReference());

            Debug.Assert(error == 0);
        }
Example #8
0
        internal unsafe override void UpdateCore(
            ref IncrementalHashState state,
            ReadOnlySpan <byte> data)
        {
            fixed(crypto_generichash_blake2b_state *state_ = &state.blake2b)
            fixed(byte * @in = data)
            {
                int error = crypto_generichash_blake2b_update(
                    state_,
                    @in,
                    (ulong)data.Length);

                Debug.Assert(error == 0);
            }
        }
Example #9
0
        internal override bool FinalizeAndVerifyCore(
            ref IncrementalHashState state,
            ReadOnlySpan <byte> hash)
        {
            Debug.Assert(hash.Length <= crypto_hash_sha512_BYTES);

            Span <byte> temp = stackalloc byte[crypto_hash_sha512_BYTES];

            int error = crypto_hash_sha512_final(
                ref state.sha512,
                ref temp.GetPinnableReference());

            Debug.Assert(error == 0);

            return(CryptographicOperations.FixedTimeEquals(temp.Slice(0, hash.Length), hash));
        }
Example #10
0
        internal override void FinalizeCore(
            ref IncrementalHashState state,
            Span <byte> hash)
        {
            Debug.Assert(hash.Length <= crypto_hash_sha512_BYTES);

            Span <byte> temp = stackalloc byte[crypto_hash_sha512_BYTES];

            int error = crypto_hash_sha512_final(
                ref state.sha512,
                ref temp.GetPinnableReference());

            Debug.Assert(error == 0);

            temp.Slice(0, hash.Length).CopyTo(hash);
        }
Example #11
0
        internal unsafe override void FinalizeCore(
            ref IncrementalHashState state,
            Span <byte> hash)
        {
            Debug.Assert(hash.Length == crypto_hash_sha256_BYTES);

            fixed(crypto_hash_sha256_state *state_ = &state.sha256)
            fixed(byte * @out = hash)
            {
                int error = crypto_hash_sha256_final(
                    state_,
                    @out);

                Debug.Assert(error == 0);
            }
        }
Example #12
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);

            fixed(crypto_generichash_blake2b_state *state_ = &state.blake2b)
            {
                int error = crypto_generichash_blake2b_init(
                    state_,
                    IntPtr.Zero,
                    UIntPtr.Zero,
                    (UIntPtr)HashSize);

                Debug.Assert(error == 0);
            }
        }
Example #13
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);

            fixed(crypto_generichash_blake2b_state *state_ = &state.blake2b)
            fixed(byte * @out = hash)
            {
                int error = crypto_generichash_blake2b_final(
                    state_,
                    @out,
                    (UIntPtr)hash.Length);

                Debug.Assert(error == 0);
            }
        }
Example #14
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_;
        }
Example #15
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_;
        }
Example #16
0
        internal unsafe override void FinalizeCore(
            ref IncrementalHashState state,
            Span <byte> hash)
        {
            Debug.Assert(hash.Length <= crypto_hash_sha512_BYTES);

            byte *temp = stackalloc byte[crypto_hash_sha512_BYTES];

            fixed(crypto_hash_sha512_state *state_ = &state.sha512)
            {
                int error = crypto_hash_sha512_final(
                    state_,
                    temp);

                Debug.Assert(error == 0);
            }

            fixed(byte * @out = hash)
            {
                Unsafe.CopyBlockUnaligned(@out, temp, (uint)hash.Length);
            }
        }
Example #17
0
        internal unsafe override bool FinalizeAndVerifyCore(
            ref IncrementalHashState state,
            ReadOnlySpan <byte> hash)
        {
            Debug.Assert(hash.Length == crypto_hash_sha256_BYTES);

            byte *temp = stackalloc byte[crypto_hash_sha256_BYTES];

            fixed(crypto_hash_sha256_state *state_ = &state.sha256)
            {
                int error = crypto_hash_sha256_final(
                    state_,
                    temp);

                Debug.Assert(error == 0);
            }

            fixed(byte * @out = hash)
            {
                return(CryptographicOperations.FixedTimeEquals(temp, @out, hash.Length));
            }
        }
Example #18
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_;
        }
Example #19
0
 internal abstract bool FinalizeAndVerifyCore(
     ref IncrementalHashState state,
     ReadOnlySpan <byte> hash);
Example #20
0
 internal abstract void FinalizeCore(
     ref IncrementalHashState state,
     Span <byte> hash);
Example #21
0
 internal abstract void InitializeCore(
     out IncrementalHashState state);
Example #22
0
 internal abstract void UpdateCore(
     ref IncrementalHashState state,
     ReadOnlySpan <byte> data);