diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-11-03 16:45:48 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-11-03 16:45:48 +0700 |
commit | 240e9d212a05c11f38b12184fd2a504e6061e651 (patch) | |
tree | 932a53775c86ee04d9141fd340d3d96eb827f06c /crypto/src | |
parent | Improve performance of AES key schedule (diff) | |
download | BouncyCastle.NET-ed25519-240e9d212a05c11f38b12184fd2a504e6061e651.tar.xz |
Perform counter increment without branches
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/crypto/modes/GCMBlockCipher.cs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/crypto/src/crypto/modes/GCMBlockCipher.cs b/crypto/src/crypto/modes/GCMBlockCipher.cs index 8e6120eef..ecebc3de9 100644 --- a/crypto/src/crypto/modes/GCMBlockCipher.cs +++ b/crypto/src/crypto/modes/GCMBlockCipher.cs @@ -513,10 +513,11 @@ namespace Org.BouncyCastle.Crypto.Modes private byte[] GetNextCounterBlock() { - for (int i = 15; i >= 12; --i) - { - if (++counter[i] != 0) break; - } + uint c = 1; + c += counter[15]; counter[15] = (byte)c; c >>= 8; + c += counter[14]; counter[14] = (byte)c; c >>= 8; + c += counter[13]; counter[13] = (byte)c; c >>= 8; + c += counter[12]; counter[12] = (byte)c; byte[] tmp = new byte[BlockSize]; // TODO Sure would be nice if ciphers could operate on int[] |