From 02bb35f614bf0f76ea5cc3728a23aa2bf898bd05 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 24 Aug 2022 21:28:07 +0700 Subject: Fix GcmSivBlockCipher processing --- crypto/src/crypto/modes/GcmSivBlockCipher.cs | 4 ++-- crypto/test/src/crypto/test/GcmSivTest.cs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crypto/src/crypto/modes/GcmSivBlockCipher.cs b/crypto/src/crypto/modes/GcmSivBlockCipher.cs index 2ea8eef1d..63808a53a 100644 --- a/crypto/src/crypto/modes/GcmSivBlockCipher.cs +++ b/crypto/src/crypto/modes/GcmSivBlockCipher.cs @@ -875,8 +875,8 @@ namespace Org.BouncyCastle.Crypto.Modes parent.gHASH(parent.theReverse); /* Adjust counters */ - numProcessed += mySpace; - myRemaining -= mySpace; + numProcessed += BUFLEN; + myRemaining -= BUFLEN; } /* If we have remaining data */ diff --git a/crypto/test/src/crypto/test/GcmSivTest.cs b/crypto/test/src/crypto/test/GcmSivTest.cs index 16e53abdf..47f824db6 100644 --- a/crypto/test/src/crypto/test/GcmSivTest.cs +++ b/crypto/test/src/crypto/test/GcmSivTest.cs @@ -74,6 +74,15 @@ namespace Org.BouncyCastle.Crypto.Tests pCipher.DoFinal(myOutput, 0); IsTrue("Encryption mismatch", Arrays.AreEqual(myExpected, myOutput)); + if (myData.Length >= 2) + { + /* Repeat processing checking processBytes with non-empty internal buffer */ + pCipher.ProcessByte(myData[0], null, 0); + pCipher.ProcessBytes(myData, 1, myData.Length - 1, null, 0); + pCipher.DoFinal(myOutput, 0); + IsTrue("Encryption mismatch", Arrays.AreEqual(myExpected, myOutput)); + } + /* Re-initialise the cipher */ pCipher.Init(false, myParams); pCipher.ProcessBytes(myOutput, 0, myOutput.Length, null, 0); -- cgit 1.4.1