Skip to content

Commit 2c23d5c

Browse files
committed
Merged PR 874
Add LEAEngine Found test more test vectors added those. open-keychain#2
1 parent c853df5 commit 2c23d5c

File tree

3 files changed

+1747
-144
lines changed

3 files changed

+1747
-144
lines changed

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

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* LEA Cipher engine.
1212
*/
1313
public class LEAEngine
14-
implements BlockCipher
14+
implements BlockCipher
1515
{
1616
/**
1717
* Base number of rounds.
@@ -127,9 +127,9 @@ public class LEAEngine
127127
* Delta values.
128128
*/
129129
private static final int[] DELTA =
130-
{
130+
{
131131
0xc3efe9db, 0x44626b02, 0x79e27c8a, 0x78df30ec, 0x715ea49e, 0xc785da0a, 0xe04ef22a, 0xe5c40957
132-
};
132+
};
133133

134134
/**
135135
* The work buffer.
@@ -166,11 +166,11 @@ public void init(final boolean pEncrypt,
166166
if (!(pParams instanceof KeyParameter))
167167
{
168168
throw new IllegalArgumentException("Invalid parameter passed to LEA init - "
169-
+ pParams.getClass().getName());
169+
+ pParams.getClass().getName());
170170
}
171171

172172
/* Validate keyLength */
173-
final byte[] myKey = ((KeyParameter) pParams).getKey();
173+
final byte[] myKey = ((KeyParameter)pParams).getKey();
174174
final int myKeyLen = myKey.length;
175175
if ((((myKeyLen << 1) % BLOCKSIZE) != 0)
176176
|| myKeyLen < BLOCKSIZE
@@ -210,12 +210,13 @@ public int processBlock(final byte[] pInput,
210210

211211
/* Perform the encryption/decryption */
212212
return forEncryption
213-
? encryptBlock(pInput, pInOff, pOutput, pOutOff)
214-
: decryptBlock(pInput, pInOff, pOutput, pOutOff);
213+
? encryptBlock(pInput, pInOff, pOutput, pOutOff)
214+
: decryptBlock(pInput, pInOff, pOutput, pOutOff);
215215
}
216216

217217
/**
218218
* Obtain buffer length (allowing for null).
219+
*
219220
* @param pBuffer the buffer
220221
* @return the length
221222
*/
@@ -226,6 +227,7 @@ private static int bufLength(final byte[] pBuffer)
226227

227228
/**
228229
* Check buffer.
230+
*
229231
* @param pBuffer the buffer
230232
* @param pOffset the offset
231233
* @param pOutput is this an output buffer?
@@ -243,15 +245,16 @@ private static void checkBuffer(final byte[] pBuffer,
243245
if (badLen || myLast > myBufLen)
244246
{
245247
throw pOutput
246-
? new OutputLengthException("Output buffer too short.")
247-
: new DataLengthException("Input buffer too short.");
248+
? new OutputLengthException("Output buffer too short.")
249+
: new DataLengthException("Input buffer too short.");
248250
}
249251
}
250252

251253
/**
252254
* Encrypt a block.
253-
* @param pInput the input buffer
254-
* @param pInOff the input offset
255+
*
256+
* @param pInput the input buffer
257+
* @param pInOff the input offset
255258
* @param pOutput the output offset
256259
* @param pOutOff the output offset
257260
* @return the bytes processed
@@ -279,6 +282,7 @@ private int encryptBlock(final byte[] pInput,
279282

280283
/**
281284
* Encrypt a round.
285+
*
282286
* @param pRound the round#
283287
*/
284288
private void encryptRound(final int pRound)
@@ -297,6 +301,7 @@ private void encryptRound(final int pRound)
297301

298302
/**
299303
* Return the left of an index.
304+
*
300305
* @param pIndex the index
301306
* @return the left of an index
302307
*/
@@ -307,8 +312,9 @@ private static int leftIndex(final int pIndex)
307312

308313
/**
309314
* Decrypt a block.
310-
* @param pInput the input buffer
311-
* @param pInOff the input offset
315+
*
316+
* @param pInput the input buffer
317+
* @param pInOff the input offset
312318
* @param pOutput the output offset
313319
* @param pOutOff the output offset
314320
* @return the bytes processed
@@ -336,6 +342,7 @@ private int decryptBlock(final byte[] pInput,
336342

337343
/**
338344
* Decrypt a round.
345+
*
339346
* @param pRound the round#
340347
*/
341348
private void decryptRound(final int pRound)
@@ -354,6 +361,7 @@ private void decryptRound(final int pRound)
354361

355362
/**
356363
* Return the left of an index.
364+
*
357365
* @param pIndex the index
358366
* @return the left of an index
359367
*/
@@ -364,6 +372,7 @@ private static int rightIndex(final int pIndex)
364372

365373
/**
366374
* Generate the round keys.
375+
*
367376
* @param pKey the key
368377
*/
369378
private void generateRoundKeys(final byte[] pKey)
@@ -380,21 +389,22 @@ private void generateRoundKeys(final byte[] pKey)
380389
/* Switch on number of words in the key */
381390
switch (numWords)
382391
{
383-
case NUMWORDS128:
384-
generate128RoundKeys(myT);
385-
break;
386-
case NUMWORDS192:
387-
generate192RoundKeys(myT);
388-
break;
389-
case NUMWORDS256:
390-
default:
391-
generate256RoundKeys(myT);
392-
break;
392+
case NUMWORDS128:
393+
generate128RoundKeys(myT);
394+
break;
395+
case NUMWORDS192:
396+
generate192RoundKeys(myT);
397+
break;
398+
case NUMWORDS256:
399+
default:
400+
generate256RoundKeys(myT);
401+
break;
393402
}
394403
}
395404

396405
/**
397406
* Generate the round keys from 128-bit key.
407+
*
398408
* @param pWork the working keys
399409
*/
400410
private void generate128RoundKeys(final int[] pWork)
@@ -421,6 +431,7 @@ private void generate128RoundKeys(final int[] pWork)
421431

422432
/**
423433
* Generate the round keys from 192-bit key.
434+
*
424435
* @param pWork the working keys
425436
*/
426437
private void generate192RoundKeys(final int[] pWork)
@@ -442,6 +453,7 @@ private void generate192RoundKeys(final int[] pWork)
442453

443454
/**
444455
* Generate the round keys from 256-bit key.
456+
*
445457
* @param pWork the working keys
446458
*/
447459
private void generate256RoundKeys(final int[] pWork)
@@ -470,8 +482,9 @@ private void generate256RoundKeys(final int[] pWork)
470482

471483
/**
472484
* rotate left.
485+
*
473486
* @param pValue the value to rotate
474-
* @param pBits the # of bits to rotate
487+
* @param pBits the # of bits to rotate
475488
* @return the rotated value
476489
*/
477490
private static int rol32(final int pValue,
@@ -482,8 +495,9 @@ private static int rol32(final int pValue,
482495

483496
/**
484497
* rotate right.
498+
*
485499
* @param pValue the value to rotate
486-
* @param pBits the # of bits to rotate
500+
* @param pBits the # of bits to rotate
487501
* @return the rotated value
488502
*/
489503
private static int ror32(final int pValue,

0 commit comments

Comments
 (0)