public override void Dispose(bool disposing) { if (disposing && _hmacCtx != null) { _hmacCtx.Dispose(); _hmacCtx = null !; } }
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); }
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); }
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); } }
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); }
private static partial int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len);
internal static partial int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len);
internal extern static unsafe int HmacFinal(SafeHmacCtxHandle ctx, byte *data, ref int len);
internal extern static unsafe int HmacUpdate(SafeHmacCtxHandle ctx, byte *data, int len);
internal extern static int HmacReset(SafeHmacCtxHandle ctx);
internal extern static int HmacFinal(SafeHmacCtxHandle ctx, ref byte data, ref int len);
private static extern int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len);
internal static extern int HmacReset(SafeHmacCtxHandle ctx);
internal static partial int HmacReset(SafeHmacCtxHandle ctx);
internal static extern SafeHmacCtxHandle HmacCopy(SafeHmacCtxHandle ctx);
internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len) => HmacUpdate(ctx, ref MemoryMarshal.GetReference(data), len);
internal static partial int HmacFinal(SafeHmacCtxHandle ctx, ref byte data, ref int len);
internal static extern int HmacCurrent(SafeHmacCtxHandle ctx, ref byte data, ref int len);
internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan <byte> data, int len) => HmacUpdate(ctx, ref data.DangerousGetPinnableReference(), len);