示例#1
0
 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);
            }
示例#3
0
        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));
            }
示例#5
0
            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);
            }
示例#6
0
 internal static partial int EvpDigestReset(SafeEvpMdCtxHandle ctx, IntPtr type);
示例#7
0
 private static extern int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ref byte d, int cnt);
示例#8
0
 internal static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan <byte> d, int cnt) =>
 EvpDigestUpdate(ctx, ref MemoryMarshal.GetReference(d), cnt);
示例#9
0
 internal extern static unsafe int EvpDigestFinalEx(SafeEvpMdCtxHandle ctx, byte *md, ref uint s);
示例#10
0
 internal extern static int EvpDigestFinalEx(SafeEvpMdCtxHandle ctx, ref byte md, ref uint s);
示例#11
0
 internal static partial int EvpDigestCurrent(SafeEvpMdCtxHandle ctx, ref byte md, ref uint s);
示例#12
0
 internal static extern SafeEvpMdCtxHandle EvpMdCtxCopyEx(SafeEvpMdCtxHandle ctx);
示例#13
0
 private static partial int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ref byte d, int cnt);
示例#14
0
 internal extern static int EvpDigestInitEx(SafeEvpMdCtxHandle ctx, IntPtr type, IntPtr impl);
示例#15
0
 internal extern static unsafe int EVP_DigestUpdate(SafeEvpMdCtxHandle ctx, byte *d, size_t cnt);
示例#16
0
 internal static partial int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan <byte> d, int cnt);
示例#17
0
 internal static partial int EvpDigestFinalEx(SafeEvpMdCtxHandle ctx, ref byte md, ref uint s);
示例#18
0
 internal extern static int EvpDigestReset(SafeEvpMdCtxHandle ctx, IntPtr type);
示例#19
0
 internal extern static unsafe int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, byte *d, int cnt);
示例#20
0
 internal static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan <byte> d, int cnt) =>
 EvpDigestUpdate(ctx, ref d.DangerousGetPinnableReference(), cnt);