Exemple #1
0
        // 'pbExpectedDigest' must point to a '_hmacAlgorithmDigestLengthInBytes'-length buffer
        private bool ValidateHash(BCryptHashHandle hashHandle, byte *pbInput, uint cbInput, byte *pbExpectedDigest)
        {
            byte *pbActualDigest = stackalloc byte[checked ((int)_hmacAlgorithmDigestLengthInBytes)];

            hashHandle.HashData(pbInput, cbInput, pbActualDigest, _hmacAlgorithmDigestLengthInBytes);
            return(CryptoUtil.TimeConstantBuffersAreEqual(pbExpectedDigest, pbActualDigest, _hmacAlgorithmDigestLengthInBytes));
        }
    internal static extern int BCryptDuplicateHash(
#endif
        BCryptHashHandle hHash,
        out BCryptHashHandle phNewHash,
        IntPtr pbHashObject,
        uint cbHashObject,
        uint dwFlags);
 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa375383(v=vs.85).aspx
 internal static extern int BCryptCreateHash(
     [In] BCryptAlgorithmHandle hAlgorithm,
     [Out] out BCryptHashHandle phHash,
     [In] IntPtr pbHashObject,
     [In] uint cbHashObject,
     [In] byte *pbSecret,
     [In] uint cbSecret,
     [In] uint dwFlags);
    internal static extern int BCryptCreateHash(
#endif
        BCryptAlgorithmHandle hAlgorithm,
        out BCryptHashHandle phHash,
        IntPtr pbHashObject,
        uint cbHashObject,
        byte *pbSecret,
        uint cbSecret,
        uint dwFlags);
 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa375468(v=vs.85).aspx
 internal static extern int BCryptHashData(
     [In] BCryptHashHandle hHash,
     [In] byte *pbInput,
     [In] uint cbInput,
     [In] uint dwFlags);
 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa375443(v=vs.85).aspx
 internal static extern int BCryptFinishHash(
     [In] BCryptHashHandle hHash,
     [In] byte *pbOutput,
     [In] uint cbOutput,
     [In] uint dwFlags);
 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa375413(v=vs.85).aspx
 internal static extern int BCryptDuplicateHash(
     [In] BCryptHashHandle hHash,
     [Out] out BCryptHashHandle phNewHash,
     [In] IntPtr pbHashObject,
     [In] uint cbHashObject,
     [In] uint dwFlags);
    internal static extern int BCryptHashData(
#endif
        BCryptHashHandle hHash,
        byte *pbInput,
        uint cbInput,
        uint dwFlags);
    internal static extern int BCryptFinishHash(
#endif
        BCryptHashHandle hHash,
        byte *pbOutput,
        uint cbOutput,
        uint dwFlags);
 public Win7SP800_108_CTR_HMACSHA512Provider(byte *pbKdk, uint cbKdk)
 {
     _hashHandle = CachedAlgorithmHandles.HMAC_SHA512.CreateHmac(pbKdk, cbKdk);
 }