ModernKeePassLib implements HMAC correctly

Blake2b also implemented, but not tested
ModernKeePass app better implements focus on database password box (but still not working correctly)
This commit is contained in:
2017-10-26 12:38:34 +02:00
committed by BONNEVILLE Geoffroy
parent 5cf4ff3012
commit 1b439a4960
18 changed files with 317 additions and 213 deletions

View File

@@ -22,8 +22,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Text;
#if ModernKeePassLib
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using ModernKeePassLib.Cryptography.Hash;
#elif !KeePassUAP
using System.Security.Cryptography;
#endif
@@ -46,16 +45,10 @@ namespace ModernKeePassLib.Cryptography
{
byte[] pbText = MemUtil.UInt64ToBytes(uFactor);
Array.Reverse(pbText); // To big-endian
#if ModernKeePassLib
var hsha1 = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha1).CreateHash(CryptographicBuffer.CreateFromByteArray(pbSecret));
hsha1.Append(CryptographicBuffer.CreateFromByteArray(pbText));
byte[] pbHash;
CryptographicBuffer.CopyToByteArray(hsha1.GetValueAndReset(), out pbHash);
#else
HMACSHA1 hsha1 = new HMACSHA1(pbSecret);
byte[] pbHash = hsha1.ComputeHash(pbText);
#endif
uint uOffset = (uint)(pbHash[pbHash.Length - 1] & 0xF);
if((iTruncationOffset >= 0) && (iTruncationOffset < (pbHash.Length - 4)))
uOffset = (uint)iTruncationOffset;