Skip to content

Commit c2b0ed7

Browse files
author
gefeili
committed
Remove some unnecessary code
1 parent a52c46a commit c2b0ed7

File tree

5 files changed

+16
-39
lines changed

5 files changed

+16
-39
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ public class AsconAEAD128
2121
{
2222
public AsconAEAD128()
2323
{
24-
KEY_SIZE = 16;
25-
IV_SIZE = 16;
26-
MAC_SIZE = 16;
27-
AADBufferSize = BlockSize = 16;
24+
KEY_SIZE = IV_SIZE = MAC_SIZE = AADBufferSize = BlockSize = 16;
2825
ASCON_IV = 0x00001000808c0001L;
2926
algorithmName = "Ascon-AEAD128";
3027
nr = 8;
31-
m_bufferSizeDecrypt = BlockSize + MAC_SIZE;
32-
m_buf = new byte[m_bufferSizeDecrypt];
33-
m_aad = new byte[BlockSize];
3428
dsep = -9223372036854775808L; //0x80L << 56
3529
setInnerMembers(ProcessingBufferType.Immediate, AADOperatorType.Default, DataOperatorType.Default);
3630
}
@@ -65,7 +59,7 @@ protected void ascon_aeadinit()
6559
p.x4 ^= K1;
6660
}
6761

68-
protected void processFinalAadBlock()
62+
protected void processFinalAAD()
6963
{
7064
if (m_aadPos == BlockSize)
7165
{
@@ -164,5 +158,4 @@ public String getAlgorithmVersion()
164158
{
165159
return "v1.3";
166160
}
167-
}
168-
161+
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected void finishAAD(State nextState, boolean isDofinal)
2727
{
2828
case DecAad:
2929
case EncAad:
30-
processFinalAadBlock();
30+
this.processFinalAAD();
3131
p.p(nr);
3232
break;
3333
default:
@@ -39,13 +39,10 @@ protected void finishAAD(State nextState, boolean isDofinal)
3939
m_state = nextState;
4040
}
4141

42-
protected abstract void processFinalAadBlock();
43-
4442
protected abstract void processFinalDecrypt(byte[] input, int inLen, byte[] output, int outOff);
4543

4644
protected abstract void processFinalEncrypt(byte[] input, int inLen, byte[] output, int outOff);
4745

48-
4946
protected void processBufferAAD(byte[] buffer, int inOff)
5047
{
5148
p.x0 ^= loadBytes(buffer, inOff);
@@ -56,12 +53,6 @@ protected void processBufferAAD(byte[] buffer, int inOff)
5653
p.p(nr);
5754
}
5855

59-
protected void processFinalAAD()
60-
{
61-
processFinalAadBlock();
62-
p.p(nr);
63-
}
64-
6556
@Override
6657
protected void processFinalBlock(byte[] output, int outOff)
6758
{

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public enum AsconParameters
3636
public AsconEngine(AsconParameters asconParameters)
3737
{
3838
this.asconParameters = asconParameters;
39-
IV_SIZE = 16;
40-
MAC_SIZE = 16;
39+
IV_SIZE = MAC_SIZE = 16;
4140
switch (asconParameters)
4241
{
4342
case ascon80pq:
@@ -63,9 +62,7 @@ public AsconEngine(AsconParameters asconParameters)
6362
}
6463
nr = (BlockSize == 8) ? 6 : 8;
6564
m_bufferSizeDecrypt = BlockSize + MAC_SIZE;
66-
m_buf = new byte[m_bufferSizeDecrypt];
6765
AADBufferSize = BlockSize;
68-
m_aad = new byte[BlockSize];
6966
dsep = 1L;
7067
setInnerMembers(asconParameters == AsconParameters.ascon128a ? ProcessingBufferType.Immediate : ProcessingBufferType.ImmediateLargeMac, AADOperatorType.Default, DataOperatorType.Default);
7168
}
@@ -108,7 +105,7 @@ protected void ascon_aeadinit()
108105
p.x4 ^= K2;
109106
}
110107

111-
protected void processFinalAadBlock()
108+
protected void processFinalAAD()
112109
{
113110
m_aad[m_aadPos] = (byte)0x80;
114111
if (m_aadPos >= 8) // ASCON_AEAD_RATE == 16 is implied
@@ -244,4 +241,4 @@ public String getAlgorithmVersion()
244241
{
245242
return "v1.2";
246243
}
247-
}
244+
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ public enum IsapType
2626

2727
public ISAPEngine(IsapType isapType)
2828
{
29-
KEY_SIZE = 16;
30-
IV_SIZE = 16;
31-
MAC_SIZE = 16;
29+
KEY_SIZE = IV_SIZE = MAC_SIZE = 16;
3230
switch (isapType)
3331
{
3432
case ISAP_A_128A:
@@ -53,7 +51,7 @@ public ISAPEngine(IsapType isapType)
5351
ProcessingBufferType.ImmediateLargeMac, AADOperatorType.Default, DataOperatorType.Default);
5452
}
5553

56-
final int ISAP_STATE_SZ = 40;
54+
private static final int ISAP_STATE_SZ = 40;
5755
private byte[] k;
5856
private byte[] npub;
5957
private int ISAP_rH;
@@ -740,15 +738,14 @@ protected void processBufferDecrypt(byte[] input, int inOff, byte[] output, int
740738
protected void processFinalBlock(byte[] output, int outOff)
741739
{
742740
processFinalAAD();
743-
int len = m_bufPos;
744741
ISAPAEAD.processEncFinalBlock(output, outOff);
745742
if (forEncryption)
746743
{
747-
ISAPAEAD.processMACFinal(output, outOff, len, mac);
744+
ISAPAEAD.processMACFinal(output, outOff, m_bufPos, mac);
748745
}
749746
else
750747
{
751-
ISAPAEAD.processMACFinal(m_buf, 0, len, mac);
748+
ISAPAEAD.processMACFinal(m_buf, 0, m_bufPos, mac);
752749
}
753750
}
754751

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public enum RomulusParameters
2222

2323
private byte[] k;
2424
private byte[] npub;
25-
private final int AD_BLK_LEN_HALF = 16;
25+
private static final int AD_BLK_LEN_HALF = 16;
2626
private Instance instance;
2727
private final byte[] CNT;
2828

@@ -120,11 +120,11 @@ private interface Instance
120120
private class RomulusM
121121
implements Instance
122122
{
123-
byte[] mac_s = new byte[16];
124-
byte[] mac_CNT = new byte[7];
123+
private final byte[] mac_s = new byte[16];
124+
private final byte[] mac_CNT = new byte[7];
125125

126-
byte[] s = new byte[16];
127-
byte[] CNT = new byte[7];
126+
private final byte[] s = new byte[16];
127+
private final byte[] CNT = new byte[7];
128128
int offset;
129129
boolean twist = true;
130130

@@ -626,7 +626,6 @@ public void reset()
626626
Arrays.clear(h);
627627
Arrays.clear(g);
628628
Arrays.clear(LR);
629-
Arrays.clear(CNT_Z);
630629
Arrays.clear(T);
631630
Arrays.clear(S);
632631
reset_lfsr_gf56(CNT);

0 commit comments

Comments
 (0)