summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-01-13 17:51:37 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-01-13 17:51:37 +0700
commit93253fe1a15f534ac53f9d665fd019d919ce01cf (patch)
treec0a17b4635916fcb6647c477929121ef6665014e
parentUpdate IsMasterKey (diff)
downloadBouncyCastle.NET-ed25519-93253fe1a15f534ac53f9d665fd019d919ce01cf.tar.xz
Avoid stateful processing in Camellia engines
-rw-r--r--crypto/src/crypto/engines/CamelliaEngine.cs12
-rw-r--r--crypto/src/crypto/engines/CamelliaLightEngine.cs12
2 files changed, 14 insertions, 10 deletions
diff --git a/crypto/src/crypto/engines/CamelliaEngine.cs b/crypto/src/crypto/engines/CamelliaEngine.cs

index 71bd1b0dc..2222e4b7c 100644 --- a/crypto/src/crypto/engines/CamelliaEngine.cs +++ b/crypto/src/crypto/engines/CamelliaEngine.cs
@@ -18,7 +18,6 @@ namespace Org.BouncyCastle.Crypto.Engines private uint[] subkey = new uint[24 * 4]; private uint[] kw = new uint[4 * 2]; // for whitening private uint[] ke = new uint[6 * 2]; // for FL and FL^(-1) - private uint[] state = new uint[4]; // for encryption and decryption private static readonly uint[] SIGMA = new uint[]{ 0xa09e667f, 0x3bcc908b, @@ -540,10 +539,11 @@ namespace Org.BouncyCastle.Crypto.Engines private int processBlock128(byte[] input, int inOff, byte[] output, int outOff) { + uint[] state = new uint[4]; + for (int i = 0; i < 4; i++) { - state[i] = bytes2uint(input, inOff + (i * 4)); - state[i] ^= kw[i]; + state[i] = bytes2uint(input, inOff + (i * 4)) ^ kw[i]; } camelliaF2(state, subkey, 0); @@ -573,10 +573,11 @@ namespace Org.BouncyCastle.Crypto.Engines private int processBlock192or256(byte[] input, int inOff, byte[] output, int outOff) { + uint[] state = new uint[4]; + for (int i = 0; i < 4; i++) { - state[i] = bytes2uint(input, inOff + (i * 4)); - state[i] ^= kw[i]; + state[i] = bytes2uint(input, inOff + (i * 4)) ^ kw[i]; } camelliaF2(state, subkey, 0); @@ -604,6 +605,7 @@ namespace Org.BouncyCastle.Crypto.Engines uint2bytes(state[3], output, outOff + 4); uint2bytes(state[0], output, outOff + 8); uint2bytes(state[1], output, outOff + 12); + return BLOCK_SIZE; } diff --git a/crypto/src/crypto/engines/CamelliaLightEngine.cs b/crypto/src/crypto/engines/CamelliaLightEngine.cs
index a132227c5..daf0316e2 100644 --- a/crypto/src/crypto/engines/CamelliaLightEngine.cs +++ b/crypto/src/crypto/engines/CamelliaLightEngine.cs
@@ -18,7 +18,6 @@ namespace Org.BouncyCastle.Crypto.Engines private uint[] subkey = new uint[24 * 4]; private uint[] kw = new uint[4 * 2]; // for whitening private uint[] ke = new uint[6 * 2]; // for FL and FL^(-1) - private uint[] state = new uint[4]; // for encryption and decryption private static readonly uint[] SIGMA = { 0xa09e667f, 0x3bcc908b, @@ -452,10 +451,11 @@ namespace Org.BouncyCastle.Crypto.Engines private int processBlock128(byte[] input, int inOff, byte[] output, int outOff) { + uint[] state = new uint[4]; + for (int i = 0; i < 4; i++) { - state[i] = bytes2uint(input, inOff + (i * 4)); - state[i] ^= kw[i]; + state[i] = bytes2uint(input, inOff + (i * 4)) ^ kw[i]; } camelliaF2(state, subkey, 0); @@ -485,10 +485,11 @@ namespace Org.BouncyCastle.Crypto.Engines private int processBlock192or256(byte[] input, int inOff, byte[] output, int outOff) { + uint[] state = new uint[4]; + for (int i = 0; i < 4; i++) { - state[i] = bytes2uint(input, inOff + (i * 4)); - state[i] ^= kw[i]; + state[i] = bytes2uint(input, inOff + (i * 4)) ^ kw[i]; } camelliaF2(state, subkey, 0); @@ -516,6 +517,7 @@ namespace Org.BouncyCastle.Crypto.Engines uint2bytes(state[3], output, outOff + 4); uint2bytes(state[0], output, outOff + 8); uint2bytes(state[1], output, outOff + 12); + return BLOCK_SIZE; }