bc-csharp
bc-csharp copied to clipboard
GCMBlockCipher dup nonce check should use Array.Copy.
https://github.com/bcgit/bc-csharp/blob/master/crypto/src/crypto/modes/GCMBlockCipher.cs
if (forEncryption)
{
if (nonce != null && Arrays.AreEqual(nonce, newNonce))
{
if (keyParam == null)
{
throw new ArgumentException("cannot reuse nonce for GCM encryption");
}
if (lastKey != null && Arrays.AreEqual(lastKey, keyParam.GetKey()))
{
throw new ArgumentException("cannot reuse nonce for GCM encryption");
}
}
}
nonce = newNonce; //<--here, a deep copy will be better.
👍
This should be implemented as Arrays.AreEqual checks reference equality as well. If IV buffer is reused by the user, an exception will be thrown, which happened in my case.
@peterdettman