Fixed CamelliaEngine so encrypt/decrypt threadsafe
private int[] subkey = new int[24 * 4];
private int[] kw = new int[4 * 2]; // for whitening
private int[] ke = new int[6 * 2]; // for FL and FL^(-1)
- private int[] state = new int[4]; // for encryption and decryption
private static final int SIGMA[] = {
0xa09e667f, 0x3bcc908b,
@@ -550,10 +549,11 @@ private void setKey(boolean forEncryption, byte[] key)
private int processBlock128(byte[] in, int inOff,
byte[] out, int outOff)
{
+ int[] state = new int[4];
+
for (int i = 0; i < 4; i++)
{
- state[i] = bytes2int(in, inOff + (i * 4));
- state[i] ^= kw[i];
+ state[i] = bytes2int(in, inOff + (i * 4)) ^ kw[i];
}
camelliaF2(state, subkey, 0);
@@ -584,10 +584,11 @@ private int processBlock128(byte[] in, int inOff,
private int processBlock192or256(byte[] in, int inOff,
byte[] out, int outOff)
{
+ int[] state = new int[4];
+
for (int i = 0; i < 4; i++)
{
- state[i] = bytes2int(in, inOff + (i * 4));
- state[i] ^= kw[i];
+ state[i] = bytes2int(in, inOff + (i * 4)) ^ kw[i];
}
camelliaF2(state, subkey, 0);
@@ -615,6 +616,7 @@ private int processBlock192or256(byte[] in, int inOff,
int2bytes(state[3], out, outOff + 4);
int2bytes(state[0], out, outOff + 8);
int2bytes(state[1], out, outOff + 12);
+
return BLOCK_SIZE;
}
