@@ -88,8 +88,8 @@ private enum State
8888
8989 public ElephantEngine (ElephantParameters parameters )
9090 {
91- CRYPTO_KEYBYTES = 16 ;
92- CRYPTO_NPUBBYTES = 12 ;
91+ KEY_SIZE = 16 ;
92+ IV_SIZE = 12 ;
9393 switch (parameters )
9494 {
9595 case elephant160 :
@@ -98,7 +98,7 @@ public ElephantEngine(ElephantParameters parameters)
9898 nSBox = 20 ;
9999 nRounds = 80 ;
100100 lfsrIV = 0x75 ;
101- CRYPTO_ABYTES = 8 ;
101+ MAC_SIZE = 8 ;
102102 algorithmName = "Elephant 160 AEAD" ;
103103 break ;
104104 case elephant176 :
@@ -108,13 +108,13 @@ public ElephantEngine(ElephantParameters parameters)
108108 nRounds = 90 ;
109109 lfsrIV = 0x45 ;
110110 algorithmName = "Elephant 176 AEAD" ;
111- CRYPTO_ABYTES = 8 ;
111+ MAC_SIZE = 8 ;
112112 break ;
113113 case elephant200 :
114114 BLOCK_SIZE = 25 ;
115115 nRounds = 18 ;
116116 algorithmName = "Elephant 200 AEAD" ;
117- CRYPTO_ABYTES = 16 ;
117+ MAC_SIZE = 16 ;
118118 break ;
119119 default :
120120 throw new IllegalArgumentException ("Invalid parameter settings for Elephant" );
@@ -285,11 +285,11 @@ public void init(boolean forEncryption, CipherParameters params)
285285 npub = keyiv [1 ];
286286 // Storage for the expanded key L
287287 expanded_key = new byte [BLOCK_SIZE ];
288- System .arraycopy (k , 0 , expanded_key , 0 , CRYPTO_KEYBYTES );
288+ System .arraycopy (k , 0 , expanded_key , 0 , KEY_SIZE );
289289 permutation (expanded_key );
290290 initialised = true ;
291291 m_state = forEncryption ? State .EncInit : State .DecInit ;
292- inputMessage = new byte [BLOCK_SIZE * 2 + (forEncryption ? 0 : CRYPTO_ABYTES )];
292+ inputMessage = new byte [BLOCK_SIZE * 2 + (forEncryption ? 0 : MAC_SIZE )];
293293 reset (false );
294294 }
295295
@@ -318,13 +318,13 @@ public int processBytes(byte[] input, int inOff, int len, byte[] output, int out
318318 throw new DataLengthException ("input buffer too short" );
319319 }
320320
321- if (inputOff + len - (forEncryption ? 0 : CRYPTO_ABYTES ) >= BLOCK_SIZE )
321+ if (inputOff + len - (forEncryption ? 0 : MAC_SIZE ) >= BLOCK_SIZE )
322322 {
323- int mlen = inputOff + len - (forEncryption ? 0 : CRYPTO_ABYTES );
323+ int mlen = inputOff + len - (forEncryption ? 0 : MAC_SIZE );
324324 int adlen = processAADBytes ();
325325 int nblocks_c = 1 + mlen / BLOCK_SIZE ;
326326 int nblocks_m = ((mlen % BLOCK_SIZE ) != 0 ? nblocks_c : nblocks_c - 1 );
327- int nblocks_ad = 1 + (CRYPTO_NPUBBYTES + adlen ) / BLOCK_SIZE ;
327+ int nblocks_ad = 1 + (IV_SIZE + adlen ) / BLOCK_SIZE ;
328328 int nb_it = Math .max (nblocks_c + 1 , nblocks_ad - 1 );
329329 byte [] tempInput = new byte [Math .max (nblocks_c , 1 ) * BLOCK_SIZE ];
330330 System .arraycopy (inputMessage , 0 , tempInput , 0 , inputOff );
@@ -361,33 +361,33 @@ public int doFinal(byte[] output, int outOff)
361361 throw new IllegalArgumentException (algorithmName + " needs call init function before doFinal" );
362362 }
363363 int len = inputOff ;
364- if ((forEncryption && len + outOff + CRYPTO_ABYTES > output .length ) ||
365- (!forEncryption && len + outOff - CRYPTO_ABYTES > output .length ))
364+ if ((forEncryption && len + outOff + MAC_SIZE > output .length ) ||
365+ (!forEncryption && len + outOff - MAC_SIZE > output .length ))
366366 {
367367 throw new OutputLengthException ("output buffer is too short" );
368368 }
369- int mlen = len + messageLen - (forEncryption ? 0 : CRYPTO_ABYTES );
369+ int mlen = len + messageLen - (forEncryption ? 0 : MAC_SIZE );
370370 int rv = mlen - messageLen ;
371371 int adlen = processAADBytes ();
372372 int nblocks_c = 1 + mlen / BLOCK_SIZE ;
373373 int nblocks_m = (mlen % BLOCK_SIZE ) != 0 ? nblocks_c : nblocks_c - 1 ;
374- int nblocks_ad = 1 + (CRYPTO_NPUBBYTES + adlen ) / BLOCK_SIZE ;
374+ int nblocks_ad = 1 + (IV_SIZE + adlen ) / BLOCK_SIZE ;
375375 int nb_it = Math .max (nblocks_c + 1 , nblocks_ad - 1 );
376376 outOff += processBytes (inputMessage , output , outOff , nb_it , nblocks_m , nblocks_c , mlen , nblocks_ad , true );
377- mac = new byte [CRYPTO_ABYTES ];
377+ mac = new byte [MAC_SIZE ];
378378 xor_block (tag_buffer , expanded_key , 0 , BLOCK_SIZE );
379379 permutation (tag_buffer );
380380 xor_block (tag_buffer , expanded_key , 0 , BLOCK_SIZE );
381381 if (forEncryption )
382382 {
383- System .arraycopy (tag_buffer , 0 , mac , 0 , CRYPTO_ABYTES );
383+ System .arraycopy (tag_buffer , 0 , mac , 0 , MAC_SIZE );
384384 System .arraycopy (mac , 0 , output , outOff , mac .length );
385- rv += CRYPTO_ABYTES ;
385+ rv += MAC_SIZE ;
386386 }
387387 else
388388 {
389- inputOff -= CRYPTO_ABYTES ;
390- for (int i = 0 ; i < CRYPTO_ABYTES ; ++i )
389+ inputOff -= MAC_SIZE ;
390+ for (int i = 0 ; i < MAC_SIZE ; ++i )
391391 {
392392 if (tag_buffer [i ] != inputMessage [inputOff + i ])
393393 {
@@ -420,11 +420,11 @@ public int getUpdateOutputSize(int len)
420420 case DecData :
421421 case DecInit :
422422 {
423- int total = Math .max (0 , inputOff + len - CRYPTO_ABYTES );
423+ int total = Math .max (0 , inputOff + len - MAC_SIZE );
424424 return total - total % BLOCK_SIZE ;
425425 }
426426 }
427- return Math .max (0 , len + inputOff - CRYPTO_ABYTES );
427+ return Math .max (0 , len + inputOff - MAC_SIZE );
428428 }
429429
430430 @ Override
@@ -440,9 +440,9 @@ public int getOutputSize(int len)
440440 case EncAad :
441441 case EncData :
442442 case EncInit :
443- return len + inputOff + CRYPTO_ABYTES ;
443+ return len + inputOff + MAC_SIZE ;
444444 }
445- return Math .max (0 , len + inputOff - CRYPTO_ABYTES );
445+ return Math .max (0 , len + inputOff - MAC_SIZE );
446446 }
447447
448448 private int processAADBytes ()
@@ -505,14 +505,14 @@ private void processAADBytes(byte[] output)
505505 {
506506 case DecInit :
507507 System .arraycopy (expanded_key , 0 , current_mask , 0 , BLOCK_SIZE );
508- System .arraycopy (npub , 0 , output , 0 , CRYPTO_NPUBBYTES );
509- len += CRYPTO_NPUBBYTES ;
508+ System .arraycopy (npub , 0 , output , 0 , IV_SIZE );
509+ len += IV_SIZE ;
510510 m_state = State .DecAad ;
511511 break ;
512512 case EncInit :
513513 System .arraycopy (expanded_key , 0 , current_mask , 0 , BLOCK_SIZE );
514- System .arraycopy (npub , 0 , output , 0 , CRYPTO_NPUBBYTES );
515- len += CRYPTO_NPUBBYTES ;
514+ System .arraycopy (npub , 0 , output , 0 , IV_SIZE );
515+ len += IV_SIZE ;
516516 m_state = State .EncAad ;
517517 break ;
518518 case DecAad :
@@ -579,8 +579,8 @@ private int processBytes(byte[] m, byte[] output, int outOff, int nb_it, int nbl
579579 if (i < nblocks_m )
580580 {
581581 // Compute ciphertext block
582- System .arraycopy (npub , 0 , buffer , 0 , CRYPTO_NPUBBYTES );
583- Arrays .fill (buffer , CRYPTO_NPUBBYTES , BLOCK_SIZE , (byte )0 );
582+ System .arraycopy (npub , 0 , buffer , 0 , IV_SIZE );
583+ Arrays .fill (buffer , IV_SIZE , BLOCK_SIZE , (byte )0 );
584584 xor_block (buffer , current_mask , 0 , BLOCK_SIZE );
585585 xor_block (buffer , next_mask , 0 , BLOCK_SIZE );
586586 permutation (buffer );
0 commit comments