Esempio n. 1
0
 public override void Dispose(bool disposing)
 {
     if (disposing && _hmacCtx != null)
     {
         _hmacCtx.Dispose();
         _hmacCtx = null !;
     }
 }
Esempio n. 2
0
 public sealed override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_hmacCtx != null)
         {
             _hmacCtx.Dispose();
             _hmacCtx = null;
         }
     }
 }
            public HmacHashProvider(IntPtr algorithmEvp, ReadOnlySpan <byte> key)
            {
                Debug.Assert(algorithmEvp != IntPtr.Zero);

                _hashSize = Interop.Crypto.EvpMdSize(algorithmEvp);
                if (_hashSize <= 0 || _hashSize > Interop.Crypto.EVP_MAX_MD_SIZE)
                {
                    throw new CryptographicException();
                }

                _hmacCtx = Interop.Crypto.HmacCreate(ref MemoryMarshal.GetReference(key), key.Length, algorithmEvp);
                Interop.Crypto.CheckValidOpenSslHandle(_hmacCtx);
            }
            public HmacHashProvider(IntPtr algorithmEvp, byte[] key)
            {
                Debug.Assert(algorithmEvp != IntPtr.Zero);
                Debug.Assert(key != null);

                _hashSize = Interop.Crypto.EvpMdSize(algorithmEvp);
                if (_hashSize <= 0 || _hashSize > Interop.Crypto.EVP_MAX_MD_SIZE)
                {
                    throw new CryptographicException();
                }

                _hmacCtx = Interop.Crypto.HmacCreate(ref new Span <byte>(key).DangerousGetPinnableReference(), key.Length, algorithmEvp);
                Interop.Crypto.CheckValidOpenSslHandle(_hmacCtx);
            }
Esempio n. 5
0
        internal LiteHmac(IntPtr algorithm, ReadOnlySpan <byte> key)
        {
            Debug.Assert(algorithm != IntPtr.Zero);
            _hashSizeInBytes = Interop.Crypto.EvpMdSize(algorithm);

            if (_hashSizeInBytes <= 0 || _hashSizeInBytes > Interop.Crypto.EVP_MAX_MD_SIZE)
            {
                Debug.Fail($"Unexpected hash '{_hashSizeInBytes}' size from {nameof(Interop.Crypto.EvpMdSize)}.");
                throw new CryptographicException();
            }

            _ctx = Interop.Crypto.HmacCreate(ref MemoryMarshal.GetReference(key), key.Length, algorithm);
            Interop.Crypto.CheckValidOpenSslHandle(_ctx);
        }
Esempio n. 6
0
            public unsafe HmacHashProvider(IntPtr algorithmEvp, byte[] key)
            {
                Debug.Assert(algorithmEvp != IntPtr.Zero);
                Debug.Assert(key != null);

                _hashSize = Interop.Crypto.EvpMdSize(algorithmEvp);
                if (_hashSize <= 0 || _hashSize > Interop.Crypto.EVP_MAX_MD_SIZE)
                {
                    throw new CryptographicException();
                }

                fixed(byte *keyPtr = key)
                {
                    _hmacCtx = Interop.Crypto.HmacCreate(keyPtr, key.Length, algorithmEvp);
                    Interop.libcrypto.CheckValidOpenSslHandle(_hmacCtx);
                }
            }
Esempio n. 7
0
            public override bool TryGetCurrentHash(Span <byte> destination, out int bytesWritten)
            {
                if (destination.Length < _hashSize)
                {
                    bytesWritten = 0;
                    return(false);
                }

                SafeHmacCtxHandle copy = Interop.Crypto.HmacCopy(_hmacCtx);

                Interop.Crypto.CheckValidOpenSslHandle(copy);

                int length = destination.Length;

                Check(Interop.Crypto.HmacFinal(copy, ref MemoryMarshal.GetReference(destination), ref length));
                Debug.Assert(length == _hashSize);
                bytesWritten = (int)length;

                // Destroy the copy
                copy.Close();

                return(true);
            }
Esempio n. 8
0
 private static partial int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len);
Esempio n. 9
0
 internal static partial int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len);
Esempio n. 10
0
 internal extern static unsafe int HmacFinal(SafeHmacCtxHandle ctx, byte *data, ref int len);
Esempio n. 11
0
 internal extern static unsafe int HmacUpdate(SafeHmacCtxHandle ctx, byte *data, int len);
Esempio n. 12
0
 internal extern static int HmacReset(SafeHmacCtxHandle ctx);
Esempio n. 13
0
 internal extern static int HmacFinal(SafeHmacCtxHandle ctx, ref byte data, ref int len);
Esempio n. 14
0
 private static extern int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len);
Esempio n. 15
0
 internal static extern int HmacReset(SafeHmacCtxHandle ctx);
Esempio n. 16
0
 internal static partial int HmacReset(SafeHmacCtxHandle ctx);
Esempio n. 17
0
 internal static extern SafeHmacCtxHandle HmacCopy(SafeHmacCtxHandle ctx);
Esempio n. 18
0
 internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len) =>
 HmacUpdate(ctx, ref MemoryMarshal.GetReference(data), len);
Esempio n. 19
0
 internal static partial int HmacFinal(SafeHmacCtxHandle ctx, ref byte data, ref int len);
Esempio n. 20
0
 internal static extern int HmacCurrent(SafeHmacCtxHandle ctx, ref byte data, ref int len);
Esempio n. 21
0
 internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len) =>
 HmacUpdate(ctx, ref data.DangerousGetPinnableReference(), len);