Skip to content

Commit 75260e3

Browse files
committed
Refactoring DESEdeWrapEngine
1 parent 8d2c9cd commit 75260e3

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ public byte[] wrap(byte[] in, int inOff, int inLen)
178178
System.arraycopy(this.iv, 0, TEMP2, 0, this.iv.length);
179179
System.arraycopy(TEMP1, 0, TEMP2, this.iv.length, TEMP1.length);
180180

181-
// Reverse the order of the octets in TEMP2 and call the result TEMP3.
182-
byte[] TEMP3 = reverse(TEMP2);
181+
// Reverse the order of the octets in TEMP2.
182+
Arrays.reverseInPlace(TEMP2);
183183

184184
// Encrypt TEMP3 in CBC mode using the KEK and an initialization vector
185185
// of 0x 4a dd a2 2c 79 e8 21 05. The resulting cipher text is the desired
@@ -188,12 +188,12 @@ public byte[] wrap(byte[] in, int inOff, int inLen)
188188

189189
this.engine.init(true, param2);
190190

191-
for (int currentBytePos = 0; currentBytePos != TEMP3.length; currentBytePos += blockSize)
191+
for (int currentBytePos = 0; currentBytePos != TEMP2.length; currentBytePos += blockSize)
192192
{
193-
engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
193+
engine.processBlock(TEMP2, currentBytePos, TEMP2, currentBytePos);
194194
}
195195

196-
return TEMP3;
196+
return TEMP2;
197197
}
198198

199199
/**
@@ -246,15 +246,15 @@ public byte[] unwrap(byte[] in, int inOff, int inLen)
246246

247247
this.engine.init(false, param2);
248248

249-
byte TEMP3[] = new byte[inLen];
249+
byte TEMP2[] = new byte[inLen];
250250

251251
for (int currentBytePos = 0; currentBytePos != inLen; currentBytePos += blockSize)
252252
{
253-
engine.processBlock(in, inOff + currentBytePos, TEMP3, currentBytePos);
253+
engine.processBlock(in, inOff + currentBytePos, TEMP2, currentBytePos);
254254
}
255255

256-
// Reverse the order of the octets in TEMP3 and call the result TEMP2.
257-
byte[] TEMP2 = reverse(TEMP3);
256+
// Reverse the order of the octets in TEMP2.
257+
Arrays.reverseInPlace(TEMP2);
258258

259259
// Decompose TEMP2 into IV, the first 8 octets, and TEMP1, the remaining octets.
260260
this.iv = new byte[8];
@@ -337,14 +337,4 @@ private boolean checkCMSKeyChecksum(
337337
{
338338
return Arrays.constantTimeAreEqual(calculateCMSKeyChecksum(key), checksum);
339339
}
340-
341-
private static byte[] reverse(byte[] bs)
342-
{
343-
byte[] result = new byte[bs.length];
344-
for (int i = 0; i < bs.length; i++)
345-
{
346-
result[i] = bs[bs.length - (i + 1)];
347-
}
348-
return result;
349-
}
350340
}

0 commit comments

Comments
 (0)