Пример #1
0
 public override void Dispose(bool disposing)
 {
     if (disposing && _hmacCtx != null)
     {
         _hmacCtx.Dispose();
         _hmacCtx = null !;
     }
 }
Пример #2
0
 public sealed override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_hmacCtx != null)
         {
             _hmacCtx.Dispose();
             _hmacCtx = null;
         }
     }
 }
Пример #3
0
            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);
            }
Пример #4
0
            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);
            }
Пример #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);
        }
Пример #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);
                }
            }
Пример #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);
            }
Пример #8
0
 private static partial int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len);
Пример #9
0
 internal static partial int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len);
Пример #10
0
 internal extern static unsafe int HmacFinal(SafeHmacCtxHandle ctx, byte *data, ref int len);
Пример #11
0
 internal extern static unsafe int HmacUpdate(SafeHmacCtxHandle ctx, byte *data, int len);
Пример #12
0
 internal extern static int HmacReset(SafeHmacCtxHandle ctx);
Пример #13
0
 internal extern static int HmacFinal(SafeHmacCtxHandle ctx, ref byte data, ref int len);
Пример #14
0
 private static extern int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len);
Пример #15
0
 internal static extern int HmacReset(SafeHmacCtxHandle ctx);
Пример #16
0
 internal static partial int HmacReset(SafeHmacCtxHandle ctx);
Пример #17
0
 internal static extern SafeHmacCtxHandle HmacCopy(SafeHmacCtxHandle ctx);
Пример #18
0
 internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len) =>
 HmacUpdate(ctx, ref MemoryMarshal.GetReference(data), len);
Пример #19
0
 internal static partial int HmacFinal(SafeHmacCtxHandle ctx, ref byte data, ref int len);
Пример #20
0
 internal static extern int HmacCurrent(SafeHmacCtxHandle ctx, ref byte data, ref int len);
Пример #21
0
 internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len) =>
 HmacUpdate(ctx, ref data.DangerousGetPinnableReference(), len);