internal static unsafe int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan <byte> d, int cnt) { fixed(byte *dPtr = &d.DangerousGetPinnableReference()) { return(EvpDigestUpdate(ctx, dPtr, cnt)); } }
public EvpHashProvider(IntPtr algorithmEvp) { _algorithmEvp = algorithmEvp; Debug.Assert(algorithmEvp != IntPtr.Zero); _hashSize = Interop.Crypto.EvpMdSize(_algorithmEvp); if (_hashSize <= 0 || _hashSize > Interop.Crypto.EVP_MAX_MD_SIZE) { throw new CryptographicException(); } _ctx = Interop.Crypto.EvpMdCtxCreate(_algorithmEvp); Interop.Crypto.CheckValidOpenSslHandle(_ctx); }
internal LiteHash(IntPtr algorithm) { Debug.Assert(algorithm != IntPtr.Zero); _algorithm = algorithm; _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.EvpMdCtxCreate(algorithm); Interop.Crypto.CheckValidOpenSslHandle(_ctx); }
public EvpHashProvider(IntPtr algorithmEvp) { _algorithmEvp = algorithmEvp; Debug.Assert(algorithmEvp != IntPtr.Zero); _hashSize = Interop.libcrypto.EVP_MD_size(algorithmEvp); if (_hashSize <= 0 || _hashSize > Interop.libcrypto.EVP_MAX_MD_SIZE) { throw new CryptographicException(); } _ctx = Interop.libcrypto.EVP_MD_CTX_create(); Interop.libcrypto.CheckValidOpenSslHandle(_ctx); Check(Interop.libcrypto.EVP_DigestInit_ex(_ctx, algorithmEvp, IntPtr.Zero)); }
public override bool TryGetCurrentHash(Span <byte> destination, out int bytesWritten) { if (destination.Length < _hashSize) { bytesWritten = 0; return(false); } SafeEvpMdCtxHandle copy = Interop.Crypto.EvpMdCtxCopyEx(_ctx); Interop.Crypto.CheckValidOpenSslHandle(copy); uint length = (uint)destination.Length; Check(Interop.Crypto.EvpDigestFinalEx(copy, ref MemoryMarshal.GetReference(destination), ref length)); Debug.Assert(length == _hashSize); bytesWritten = (int)length; // Destroy the copy copy.Close(); return(true); }
internal static partial int EvpDigestReset(SafeEvpMdCtxHandle ctx, IntPtr type);
private static extern int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ref byte d, int cnt);
internal static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan <byte> d, int cnt) => EvpDigestUpdate(ctx, ref MemoryMarshal.GetReference(d), cnt);
internal extern static unsafe int EvpDigestFinalEx(SafeEvpMdCtxHandle ctx, byte *md, ref uint s);
internal extern static int EvpDigestFinalEx(SafeEvpMdCtxHandle ctx, ref byte md, ref uint s);
internal static partial int EvpDigestCurrent(SafeEvpMdCtxHandle ctx, ref byte md, ref uint s);
internal static extern SafeEvpMdCtxHandle EvpMdCtxCopyEx(SafeEvpMdCtxHandle ctx);
private static partial int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ref byte d, int cnt);
internal extern static int EvpDigestInitEx(SafeEvpMdCtxHandle ctx, IntPtr type, IntPtr impl);
internal extern static unsafe int EVP_DigestUpdate(SafeEvpMdCtxHandle ctx, byte *d, size_t cnt);
internal static partial int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan <byte> d, int cnt);
internal static partial int EvpDigestFinalEx(SafeEvpMdCtxHandle ctx, ref byte md, ref uint s);
internal extern static int EvpDigestReset(SafeEvpMdCtxHandle ctx, IntPtr type);
internal extern static unsafe int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, byte *d, int cnt);
internal static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan <byte> d, int cnt) => EvpDigestUpdate(ctx, ref d.DangerousGetPinnableReference(), cnt);