Skip to content

Commit 54b8279

Browse files
author
gefeili
committed
Rename variables
1 parent b6111f5 commit 54b8279

File tree

10 files changed

+154
-152
lines changed

10 files changed

+154
-152
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ abstract class AEADBaseEngine
1414
{
1515
protected boolean forEncryption;
1616
protected String algorithmName;
17-
protected int CRYPTO_KEYBYTES;
18-
protected int CRYPTO_NPUBBYTES;
19-
protected int CRYPTO_ABYTES;
17+
protected int KEY_SIZE;
18+
protected int IV_SIZE;
19+
protected int MAC_SIZE;
2020
protected byte[] initialAssociatedText;
2121
protected byte[] mac;
2222

@@ -28,12 +28,12 @@ public String getAlgorithmName()
2828

2929
public int getKeyBytesSize()
3030
{
31-
return CRYPTO_KEYBYTES;
31+
return KEY_SIZE;
3232
}
3333

3434
public int getIVBytesSize()
3535
{
36-
return CRYPTO_NPUBBYTES;
36+
return IV_SIZE;
3737
}
3838

3939
public byte[] getMac()
@@ -67,7 +67,7 @@ protected byte[][] initialize(boolean forEncryption, CipherParameters params)
6767
initialAssociatedText = aeadParameters.getAssociatedText();
6868

6969
int macSizeBits = aeadParameters.getMacSize();
70-
if (macSizeBits != CRYPTO_ABYTES * 8)
70+
if (macSizeBits != MAC_SIZE * 8)
7171
{
7272
throw new IllegalArgumentException("Invalid value for MAC size: " + macSizeBits);
7373
}
@@ -88,15 +88,15 @@ else if (params instanceof ParametersWithIV)
8888
{
8989
throw new IllegalArgumentException(algorithmName + " Init parameters must include a key");
9090
}
91-
if (npub == null || npub.length != CRYPTO_NPUBBYTES)
91+
if (npub == null || npub.length != IV_SIZE)
9292
{
93-
throw new IllegalArgumentException(algorithmName + " requires exactly " + CRYPTO_NPUBBYTES + " bytes of IV");
93+
throw new IllegalArgumentException(algorithmName + " requires exactly " + IV_SIZE + " bytes of IV");
9494
}
9595

9696
k = key.getKey();
97-
if (k.length != CRYPTO_KEYBYTES)
97+
if (k.length != KEY_SIZE)
9898
{
99-
throw new IllegalArgumentException(algorithmName + " key must be " + CRYPTO_KEYBYTES + " bytes long");
99+
throw new IllegalArgumentException(algorithmName + " key must be " + KEY_SIZE + " bytes long");
100100
}
101101

102102
CryptoServicesRegistrar.checkConstraints(new DefaultServiceProperties(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public class AsconAEAD128
2121
{
2222
public AsconAEAD128()
2323
{
24-
CRYPTO_KEYBYTES = 16;
25-
CRYPTO_NPUBBYTES = 16;
26-
CRYPTO_ABYTES = 16;
24+
KEY_SIZE = 16;
25+
IV_SIZE = 16;
26+
MAC_SIZE = 16;
2727
ASCON_AEAD_RATE = 16;
2828
ASCON_IV = 0x00001000808c0001L;
2929
algorithmName = "Ascon-AEAD128";
3030
nr = 8;
31-
m_bufferSizeDecrypt = ASCON_AEAD_RATE + CRYPTO_ABYTES;
31+
m_bufferSizeDecrypt = ASCON_AEAD_RATE + MAC_SIZE;
3232
m_buf = new byte[m_bufferSizeDecrypt];
3333
dsep = -9223372036854775808L; //0x80L << 56
3434
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,25 +344,25 @@ public int doFinal(byte[] outBytes, int outOff)
344344
int resultLength;
345345
if (forEncryption)
346346
{
347-
resultLength = m_bufPos + CRYPTO_ABYTES;
347+
resultLength = m_bufPos + MAC_SIZE;
348348
if (outOff + resultLength > outBytes.length)
349349
{
350350
throw new OutputLengthException("output buffer too short");
351351
}
352352
processFinalEncrypt(m_buf, m_bufPos, outBytes, outOff);
353-
mac = new byte[CRYPTO_ABYTES];
353+
mac = new byte[MAC_SIZE];
354354
setBytes(x3, mac, 0);
355355
setBytes(x4, mac, 8);
356-
System.arraycopy(mac, 0, outBytes, outOff + m_bufPos, CRYPTO_ABYTES);
356+
System.arraycopy(mac, 0, outBytes, outOff + m_bufPos, MAC_SIZE);
357357
reset(false);
358358
}
359359
else
360360
{
361-
if (m_bufPos < CRYPTO_ABYTES)
361+
if (m_bufPos < MAC_SIZE)
362362
{
363363
throw new InvalidCipherTextException("data too short");
364364
}
365-
m_bufPos -= CRYPTO_ABYTES;
365+
m_bufPos -= MAC_SIZE;
366366
resultLength = m_bufPos;
367367
if (outOff + resultLength > outBytes.length)
368368
{
@@ -387,11 +387,11 @@ public int getUpdateOutputSize(int len)
387387
{
388388
case DecInit:
389389
case DecAad:
390-
total = Math.max(0, total - CRYPTO_ABYTES);
390+
total = Math.max(0, total - MAC_SIZE);
391391
break;
392392
case DecData:
393393
case DecFinal:
394-
total = Math.max(0, total + m_bufPos - CRYPTO_ABYTES);
394+
total = Math.max(0, total + m_bufPos - MAC_SIZE);
395395
break;
396396
case EncData:
397397
case EncFinal:
@@ -411,15 +411,15 @@ public int getOutputSize(int len)
411411
{
412412
case DecInit:
413413
case DecAad:
414-
return Math.max(0, total - CRYPTO_ABYTES);
414+
return Math.max(0, total - MAC_SIZE);
415415
case DecData:
416416
case DecFinal:
417-
return Math.max(0, total + m_bufPos - CRYPTO_ABYTES);
417+
return Math.max(0, total + m_bufPos - MAC_SIZE);
418418
case EncData:
419419
case EncFinal:
420-
return total + m_bufPos + CRYPTO_ABYTES;
420+
return total + m_bufPos + MAC_SIZE;
421421
default:
422-
return total + CRYPTO_ABYTES;
422+
return total + MAC_SIZE;
423423
}
424424
}
425425

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ public enum AsconParameters
3636
public AsconEngine(AsconParameters asconParameters)
3737
{
3838
this.asconParameters = asconParameters;
39-
CRYPTO_NPUBBYTES = 16;
40-
CRYPTO_ABYTES = 16;
39+
IV_SIZE = 16;
40+
MAC_SIZE = 16;
4141
switch (asconParameters)
4242
{
4343
case ascon80pq:
44-
CRYPTO_KEYBYTES = 20;
44+
KEY_SIZE = 20;
4545
ASCON_AEAD_RATE = 8;
4646
ASCON_IV = 0xa0400c0600000000L;
4747
algorithmName = "Ascon-80pq AEAD";
4848
break;
4949
case ascon128a:
50-
CRYPTO_KEYBYTES = 16;
50+
KEY_SIZE = 16;
5151
ASCON_AEAD_RATE = 16;
5252
ASCON_IV = 0x80800c0800000000L;
5353
algorithmName = "Ascon-128a AEAD";
5454
break;
5555
case ascon128:
56-
CRYPTO_KEYBYTES = 16;
56+
KEY_SIZE = 16;
5757
ASCON_AEAD_RATE = 8;
5858
ASCON_IV = 0x80400c0600000000L;
5959
algorithmName = "Ascon-128 AEAD";
@@ -62,7 +62,7 @@ public AsconEngine(AsconParameters asconParameters)
6262
throw new IllegalArgumentException("invalid parameter setting for ASCON AEAD");
6363
}
6464
nr = (ASCON_AEAD_RATE == 8) ? 6 : 8;
65-
m_bufferSizeDecrypt = ASCON_AEAD_RATE + CRYPTO_ABYTES;
65+
m_bufferSizeDecrypt = ASCON_AEAD_RATE + MAC_SIZE;
6666
m_buf = new byte[m_bufferSizeDecrypt];
6767
dsep = 1L;
6868
}
@@ -87,7 +87,7 @@ protected void ascon_aeadinit()
8787
{
8888
/* initialize */
8989
x0 = ASCON_IV;
90-
if (CRYPTO_KEYBYTES == 20)
90+
if (KEY_SIZE == 20)
9191
{
9292
x0 ^= K0;
9393
}
@@ -96,7 +96,7 @@ protected void ascon_aeadinit()
9696
x3 = N0;
9797
x4 = N1;
9898
p(12);
99-
if (CRYPTO_KEYBYTES == 20)
99+
if (KEY_SIZE == 20)
100100
{
101101
x2 ^= K0;
102102
}
@@ -216,12 +216,12 @@ public void init(boolean forEncryption, CipherParameters params)
216216

217217
N0 = Pack.bigEndianToLong(keyiv[1], 0);
218218
N1 = Pack.bigEndianToLong(keyiv[1], 8);
219-
if (CRYPTO_KEYBYTES == 16)
219+
if (KEY_SIZE == 16)
220220
{
221221
K1 = Pack.bigEndianToLong(keyiv[0], 0);
222222
K2 = Pack.bigEndianToLong(keyiv[0], 8);
223223
}
224-
else if (CRYPTO_KEYBYTES == 20)
224+
else if (KEY_SIZE == 20)
225225
{
226226
K0 = Pack.bigEndianToInt(keyiv[0], 0);
227227
K1 = Pack.bigEndianToLong(keyiv[0], 4);

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)