Correct implementation of SHA512 with WinRT in KeepassLib

This commit is contained in:
2017-10-23 10:29:07 +02:00
committed by BONNEVILLE Geoffroy
parent e95e62f184
commit a11d209280
15 changed files with 101 additions and 120 deletions

View File

@@ -52,15 +52,16 @@ namespace ModernKeePassLib.Cryptography
byte[] pbHash;
/*#if ModernKeePassLib
var h = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256).CreateHash();
CryptographicBuffer.CopyToByteArray(h.GetValueAndReset(), out pbHash);
#else*/
#if ModernKeePassLib
var h = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256)
.HashData(CryptographicBuffer.CreateFromByteArray(pbData));
CryptographicBuffer.CopyToByteArray(h, out pbHash);
#else
using(SHA256Managed h = new SHA256Managed())
{
pbHash = h.ComputeHash(pbData, iOffset, cbCount);
}
//#endif
#endif
#if DEBUG
// Ensure the data has not been modified
@@ -90,15 +91,16 @@ namespace ModernKeePassLib.Cryptography
if(cbOut <= 32) pbHash = HashSha256(pbIn, iInOffset, cbIn);
else
{
/*#if ModernKeePassLib
var h = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512).CreateHash();
CryptographicBuffer.CopyToByteArray(h.GetValueAndReset(), out pbHash);
#else*/
#if ModernKeePassLib
var h = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512)
.HashData(CryptographicBuffer.CreateFromByteArray(pbIn));
CryptographicBuffer.CopyToByteArray(h, out pbHash);
#else
using(SHA512Managed h = new SHA512Managed())
{
pbHash = h.ComputeHash(pbIn, iInOffset, cbIn);
}
//#endif
#endif
}
if(cbOut == pbHash.Length) return pbHash;