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

            Debug.Assert(error == 0);
        }
Ejemplo n.º 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());
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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_;
        }
Ejemplo n.º 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_;
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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_;
        }
Ejemplo n.º 19
0
 internal abstract bool FinalizeAndVerifyCore(
     ref IncrementalHashState state,
     ReadOnlySpan <byte> hash);
Ejemplo n.º 20
0
 internal abstract void FinalizeCore(
     ref IncrementalHashState state,
     Span <byte> hash);
Ejemplo n.º 21
0
 internal abstract void InitializeCore(
     out IncrementalHashState state);
Ejemplo n.º 22
0
 internal abstract void UpdateCore(
     ref IncrementalHashState state,
     ReadOnlySpan <byte> data);