diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-01-13 17:51:37 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-01-13 17:51:37 +0700 |
commit | 93253fe1a15f534ac53f9d665fd019d919ce01cf (patch) | |
tree | c0a17b4635916fcb6647c477929121ef6665014e /crypto/src | |
parent | Update IsMasterKey (diff) | |
download | BouncyCastle.NET-ed25519-93253fe1a15f534ac53f9d665fd019d919ce01cf.tar.xz |
Avoid stateful processing in Camellia engines
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/crypto/engines/CamelliaEngine.cs | 12 | ||||
-rw-r--r-- | crypto/src/crypto/engines/CamelliaLightEngine.cs | 12 |
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; } |