Skip to content

Commit 4bb29fd

Browse files
author
gefeili
committed
move new byte array of mac to AsconBufferBaseEngine
1 parent 17176fc commit 4bb29fd

File tree

11 files changed

+8
-24
lines changed

11 files changed

+8
-24
lines changed

core/src/main/java/org/bouncycastle/crypto/digests/ISAPDigest.java

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

33
import org.bouncycastle.crypto.engines.AsconPermutationFriend;
4+
import org.bouncycastle.util.Longs;
45
import org.bouncycastle.util.Pack;
56

67
/**
@@ -43,15 +44,10 @@ public ISAPDigest()
4344
reset();
4445
}
4546

46-
private long ROTR(long x, long n)
47-
{
48-
return (x >>> n) | (x << (64 - n));
49-
}
50-
5147
protected long U64BIG(long x)
5248
{
53-
return ((ROTR(x, 8) & (0xFF000000FF000000L)) | (ROTR(x, 24) & (0x00FF000000FF0000L)) |
54-
(ROTR(x, 40) & (0x0000FF000000FF00L)) | (ROTR(x, 56) & (0x000000FF000000FFL)));
49+
return ((Longs.rotateRight(x, 8) & (0xFF000000FF000000L)) | (Longs.rotateRight(x, 24) & (0x00FF000000FF0000L)) |
50+
(Longs.rotateRight(x, 40) & (0x0000FF000000FF00L)) | (Longs.rotateRight(x, 56) & (0x000000FF000000FFL)));
5551
}
5652

5753
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ public int doFinal(byte[] output, int outOff)
663663
{
664664
throw new OutputLengthException("output buffer too short");
665665
}
666+
mac = new byte[MAC_SIZE];
666667
processFinalBlock(output, outOff);
667668
if (forEncryption)
668669
{
@@ -767,7 +768,6 @@ protected boolean checkData(boolean isDoFinal)
767768
}
768769
}
769770

770-
//TODO: override this for aadFinished
771771
protected void finishAAD(State nextState, boolean isDoFinal)
772772
{
773773
// State indicates whether we ever received AAD

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.bouncycastle.crypto.engines;
22

3-
import org.bouncycastle.crypto.digests.ISAPDigest;
43
import org.bouncycastle.util.Arrays;
54
import org.bouncycastle.util.Pack;
65

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ protected void processFinalBlock(byte[] output, int outOff)
7373
{
7474
processFinalDecrypt(m_buf, m_bufPos, output, outOff);
7575
}
76-
mac = new byte[MAC_SIZE];
7776
setBytes(p.x3, mac, 0);
7877
setBytes(p.x4, mac, 8);
7978
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ protected void processFinalBlock(byte[] output, int outOff)
389389
int nblocks_ad = 1 + (IV_SIZE + adlen) / BlockSize;
390390
int nb_it = Math.max(nblocks_c + 1, nblocks_ad - 1);
391391
processBytes(m_buf, output, outOff, nb_it, nblocks_m, nblocks_c, mlen, nblocks_ad);
392-
mac = new byte[MAC_SIZE];
393392
Bytes.xorTo(BlockSize, expanded_key, tag_buffer);
394393
instance.permutation(tag_buffer);
395394
Bytes.xorTo(BlockSize, expanded_key, tag_buffer);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ protected void processFinalBlock(byte[] output, int outOff)
288288
/* T = E(X[m+a]) */
289289
giftb128(input, k, Y);
290290
}
291-
mac = new byte[BlockSize];
292291
System.arraycopy(Y, 0, mac, 0, BlockSize);
293292
}
294293

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ protected void processFinalBlock(byte[] output, int outOff)
785785
{
786786
processFinalAAD();
787787
int len = m_bufPos;
788-
mac = new byte[MAC_SIZE];
789788
ISAPAEAD.processEncFinalBlock(output, outOff);
790789
ISAPAEAD.swapInternalState();
791790
if (forEncryption)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ protected void processFinalBlock(byte[] output, int outOff)
176176
state[STATE_INBYTES - 1] ^= 1 << LAST_THREE_BITS_OFFSET;
177177
}
178178
PhotonPermutation(state_2d, state);
179-
mac = new byte[MAC_SIZE];
180179
System.arraycopy(state, 0, mac, 0, MAC_SIZE);
181180
}
182181

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public enum RomulusParameters
3232
//12 13 14 15
3333

3434
// 8-bit Sbox
35-
private final byte[] sbox_8 =
35+
private static final byte[] sbox_8 =
3636
{
3737
(byte)0x65, (byte)0x4c, (byte)0x6a, (byte)0x42, (byte)0x4b, (byte)0x63, (byte)0x43, (byte)0x6b, (byte)0x55,
3838
(byte)0x75, (byte)0x5a, (byte)0x7a, (byte)0x53, (byte)0x73, (byte)0x5b, (byte)0x7b, (byte)0x35, (byte)0x8c,
@@ -66,10 +66,10 @@ public enum RomulusParameters
6666
};
6767

6868
// Tweakey permutation
69-
private final byte[] TWEAKEY_P = {9, 15, 8, 13, 10, 14, 12, 11, 0, 1, 2, 3, 4, 5, 6, 7};
69+
private static final byte[] TWEAKEY_P = {9, 15, 8, 13, 10, 14, 12, 11, 0, 1, 2, 3, 4, 5, 6, 7};
7070

7171
// round constants
72-
private final byte[] RC = {
72+
private static final byte[] RC = {
7373
0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3E, 0x3D, 0x3B, 0x37, 0x2F,
7474
0x1E, 0x3C, 0x39, 0x33, 0x27, 0x0E, 0x1D, 0x3A, 0x35, 0x2B,
7575
0x16, 0x2C, 0x18, 0x30, 0x21, 0x02, 0x05, 0x0B, 0x17, 0x2E,
@@ -138,7 +138,6 @@ public void processFinalBlock(byte[] output, int outOff)
138138
int adlen = aadOperator.getLen();
139139
int mlen = dataOperator.getLen() - (forEncryption ? 0 : MAC_SIZE);
140140
byte[] m = ((StreamDataOperator)dataOperator).getBytes();
141-
mac = new byte[MAC_SIZE];
142141
int xlen, mOff = 0, mauth = 0;
143142
xlen = mlen;
144143
if ((adlen & 31) == 0 && adlen != 0)
@@ -360,7 +359,6 @@ else if (m_bufPos != 0)
360359
lfsr_gf56(CNT);
361360
nonce_encryption(npub, CNT, s, k, m_bufPos == AD_BLK_LEN_HALF ? (byte)0x14 : (byte)0x15);
362361
}
363-
mac = new byte[MAC_SIZE];
364362
g8A(s, mac, 0);
365363
}
366364

@@ -540,7 +538,6 @@ else if (messegeLen > 0)
540538
System.arraycopy(g, 0, LR, 16, 16);
541539
Arrays.clear(CNT_Z);
542540
block_cipher(LR, k, LR, 16, CNT_Z, (byte)68);
543-
mac = new byte[MAC_SIZE];
544541
System.arraycopy(LR, 0, mac, 0, MAC_SIZE);
545542
}
546543

@@ -635,8 +632,7 @@ public void reset()
635632
}
636633
}
637634

638-
639-
private void skinny_128_384_plus_enc(byte[] input, byte[] userkey)
635+
private static void skinny_128_384_plus_enc(byte[] input, byte[] userkey)
640636
{
641637
byte[][] state = new byte[4][4];
642638
byte[][][] keyCells = new byte[3][4][4];

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ protected void processFinalBlock(byte[] output, int outOff)
184184
{
185185
state[RATE_WORDS + i] ^= k[i];
186186
}
187-
mac = new byte[MAC_SIZE];
188187
Pack.intToLittleEndian(state, RATE_WORDS, TAG_WORDS, mac, 0);
189188

190189
}

0 commit comments

Comments
 (0)