Skip to content

Commit 44ed712

Browse files
author
gefeili
committed
Fix the bug in PhotonBeetleEngine
1 parent 3135e29 commit 44ed712

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

core/src/main/java/org/bouncycastle/crypto/engines/PhotonBeetleEngine.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,20 @@ public int processBytes(byte[] input, int inOff, int len, byte[] output, int out
162162
int rv = 0;
163163

164164
int originalInOff = inOff;
165+
if (!forEncryption && bufferOff >= RATE_INBYTES)
166+
{
167+
PHOTON_Permutation();
168+
rhoohr(output, outOff, buffer, 0, RATE_INBYTES);
169+
rv += RATE_INBYTES;
170+
System.arraycopy(buffer, RATE_INBYTES, buffer, 0, bufferOff - RATE_INBYTES);
171+
bufferOff -= RATE_INBYTES;
172+
blockLen -= RATE_INBYTES;
173+
outOff += RATE_INBYTES;
174+
}
165175
if (blockLen >= RATE_INBYTES)
166176
{
167177
tmp = Math.max(RATE_INBYTES - bufferOff, 0);
168178
System.arraycopy(input, inOff, buffer, bufferOff, tmp);
169-
170179
PHOTON_Permutation();
171180
rhoohr(output, outOff, buffer, 0, RATE_INBYTES);
172181
inOff += tmp;

core/src/test/java/org/bouncycastle/crypto/test/PhotonBeetleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public void performTest()
4444
testExceptions(new PhotonBeetleDigest(), 32);
4545
CipherTest.checkAEADParemeter(this, 16, 16, 16, 16, new PhotonBeetleEngine(PhotonBeetleEngine.PhotonBeetleParameters.pb128));
4646
CipherTest.checkAEADParemeter(this, 16, 16, 16, 16, new PhotonBeetleEngine(PhotonBeetleEngine.PhotonBeetleParameters.pb32));
47-
//CipherTest.checkAEADCipherOutputSize(this, 16, 16, 16, 16, new PhotonBeetleEngine(PhotonBeetleEngine.PhotonBeetleParameters.pb128));
48-
//CipherTest.checkAEADCipherOutputSize(this, 16, 16, 4, 16, new PhotonBeetleEngine(PhotonBeetleEngine.PhotonBeetleParameters.pb32));
47+
CipherTest.checkAEADCipherOutputSize(this, 16, 16, 16, 16, new PhotonBeetleEngine(PhotonBeetleEngine.PhotonBeetleParameters.pb128));
48+
CipherTest.checkAEADCipherOutputSize(this, 16, 16, 4, 16, new PhotonBeetleEngine(PhotonBeetleEngine.PhotonBeetleParameters.pb32));
4949
}
5050

5151
private void testVectorsHash()

0 commit comments

Comments
 (0)