diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-29 20:34:11 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-29 20:34:11 +0700 |
commit | d5cf9239aca3f6f43fea68508b9b9d7585afb8c5 (patch) | |
tree | 86951586b83864443c15d8a74b8a35af53795065 | |
parent | Grain128Aead fixes (diff) | |
download | BouncyCastle.NET-ed25519-d5cf9239aca3f6f43fea68508b9b9d7585afb8c5.tar.xz |
Preserve mac after DoFinal
-rw-r--r-- | crypto/src/crypto/engines/Grain128AEADEngine.cs | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/crypto/src/crypto/engines/Grain128AEADEngine.cs b/crypto/src/crypto/engines/Grain128AEADEngine.cs index 8dca6a6d8..a571cb124 100644 --- a/crypto/src/crypto/engines/Grain128AEADEngine.cs +++ b/crypto/src/crypto/engines/Grain128AEADEngine.cs @@ -298,8 +298,16 @@ namespace Org.BouncyCastle.Crypto.Engines public void Reset() { + Reset(true); + } + + private void Reset(bool clearMac) + { this.isEven = true; - this.mac = null; + if (clearMac) + { + this.mac = null; + } this.aadData.SetLength(0); this.aadFinished = false; @@ -547,14 +555,9 @@ namespace Org.BouncyCastle.Crypto.Engines Array.Copy(mac, 0, output, outOff, mac.Length); - try - { - return mac.Length; - } - finally - { - Reset(); - } + Reset(false); + + return mac.Length; #endif } @@ -585,14 +588,9 @@ namespace Org.BouncyCastle.Crypto.Engines mac.CopyTo(output); - try - { - return mac.Length; - } - finally - { - Reset(); - } + Reset(false); + + return mac.Length; } #endif |