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

@@ -1,47 +1,18 @@
using System;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Macs;
using Org.BouncyCastle.Crypto.Parameters;
namespace ModernKeePassLib.Cryptography.Hash
{
public class HMACSHA256: IDisposable
public class HMACSHA256: HMAC
{
private readonly HMac _hmac;
public byte[] Hash
{
get
{
byte[] resBuf = new byte[_hmac.GetMacSize()];
_hmac.DoFinal(resBuf, 0);
return resBuf;
}
}
public HMACSHA256(byte[] key)
{
_hmac = new HMac(new Sha256Digest());
_hmac.Init(new KeyParameter(key));
}
public byte[] ComputeHash(byte[] value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
byte[] resBuf = new byte[_hmac.GetMacSize()];
_hmac.BlockUpdate(value, 0, value.Length);
_hmac.DoFinal(resBuf, 0);
return resBuf;
}
public void Dispose()
{
_hmac.Reset();
}
internal void TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset )
/*internal void TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
_hmac.BlockUpdate(inputBuffer, inputOffset, inputCount);
}
@@ -54,6 +25,6 @@ namespace ModernKeePassLib.Cryptography.Hash
internal void Initialize()
{
_hmac.Reset();
}
}*/
}
}