11package 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 );
0 commit comments