Skip to content

Commit 788a212

Browse files
author
gefeili
committed
Set DataOperatorType as Counter for PhotonBeetleEngine
1 parent e3979e5 commit 788a212

File tree

4 files changed

+5
-19
lines changed

4 files changed

+5
-19
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ public void reset()
382382
}
383383
}
384384

385-
protected class StreamDataOperator
385+
protected static class StreamDataOperator
386386
implements DataOperator
387387
{
388-
private ErasableOutputStream stream = new ErasableOutputStream();
388+
private final ErasableOutputStream stream = new ErasableOutputStream();
389389

390390
@Override
391391
public int processBytes(byte[] input, int inOff, int len, byte[] output, int outOff)

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.bouncycastle.crypto.engines;
22

3-
import org.bouncycastle.crypto.DataLengthException;
4-
53
/**
64
* Photon-Beetle, <a href="https://www.isical.ac.in/~lightweight/beetle/"></a>
75
* https://csrc.nist.gov/CSRC/media/Projects/lightweight-cryptography/documents/finalist-round/updated-spec-doc/photon-beetle-spec-final.pdf
@@ -24,7 +22,6 @@ public enum PhotonBeetleParameters
2422
private byte[] N;
2523
private byte[] state;
2624
private byte[][] state_2d;
27-
private int messageLen;
2825
private final int RATE_INBYTES_HALF;
2926
private final int STATE_INBYTES;
3027
private final int LAST_THREE_BITS_OFFSET;
@@ -77,7 +74,7 @@ public PhotonBeetleEngine(PhotonBeetleParameters pbp)
7774
LAST_THREE_BITS_OFFSET = (STATE_INBITS - ((STATE_INBYTES - 1) << 3) - 3);
7875
algorithmName = "Photon-Beetle AEAD";
7976
setInnerMembers(pbp == PhotonBeetleParameters.pb128 ? ProcessingBufferType.Buffered : ProcessingBufferType.BufferedLargeMac,
80-
AADOperatorType.Counter, DataOperatorType.Default);
77+
AADOperatorType.Counter, DataOperatorType.Counter);
8178
}
8279

8380
@Override
@@ -116,7 +113,7 @@ public void processFinalAAD()
116113
state[m_aadPos] ^= 0x01; // ozs
117114
}
118115
}
119-
state[STATE_INBYTES - 1] ^= select(messageLen - (forEncryption ? 0 : MAC_SIZE) > 0,
116+
state[STATE_INBYTES - 1] ^= select(dataOperator.getLen() - (forEncryption ? 0 : MAC_SIZE) > 0,
120117
((aadLen % BlockSize) == 0), (byte)3, (byte)4) << LAST_THREE_BITS_OFFSET;
121118
}
122119
m_aadPos = 0;
@@ -138,18 +135,10 @@ protected void processBufferDecrypt(byte[] input, int inOff, byte[] output, int
138135
XOR(output, outOff, BlockSize);
139136
}
140137

141-
@Override
142-
public int processBytes(byte[] input, int inOff, int len, byte[] output, int outOff)
143-
throws DataLengthException
144-
{
145-
messageLen += len;
146-
return super.processBytes(input, inOff, len, output, outOff);
147-
}
148-
149138
@Override
150139
protected void processFinalBlock(byte[] output, int outOff)
151140
{
152-
int len = messageLen - (forEncryption ? 0 : MAC_SIZE);
141+
int len = dataOperator.getLen() - (forEncryption ? 0 : MAC_SIZE);
153142
int bufferLen = m_bufPos;// - (forEncryption ? 0 : MAC_SIZE);
154143
int aadLen = aadOperator.getLen();
155144
if (aadLen != 0 || len != 0)
@@ -194,7 +183,6 @@ protected void reset(boolean clearMac)
194183
bufferReset();
195184
input_empty = true;
196185
aadFinished = false;
197-
messageLen = 0;
198186
System.arraycopy(K, 0, state, 0, K.length);
199187
System.arraycopy(N, 0, state, K.length, N.length);
200188
super.reset(clearMac);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.bouncycastle.util.Arrays;
44

5-
65
/**
76
* Romulus v1.3, based on the current round 3 submission, https://romulusae.github.io/romulus/
87
* Reference C implementation: https://github.com/romulusae/romulus

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.bouncycastle.crypto.DataLengthException;
1111
import org.bouncycastle.crypto.InvalidCipherTextException;
1212
import org.bouncycastle.crypto.engines.ElephantEngine;
13-
import org.bouncycastle.crypto.engines.GiftCofbEngine;
1413
import org.bouncycastle.crypto.modes.AEADCipher;
1514
import org.bouncycastle.crypto.params.KeyParameter;
1615
import org.bouncycastle.crypto.params.ParametersWithIV;

0 commit comments

Comments
 (0)