diff options
author | David Hook <dgh@cryptoworkshop.com> | 2014-06-23 15:53:59 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2014-06-23 15:53:59 +0400 |
commit | 147293c4a6c913c2ddb42a52c636ead5c9c78c6e (patch) | |
tree | a4236ad18d7cd728ba19c53d98129062399a9bd6 /core/src/main/java/org/bouncycastle | |
parent | 4b4fa1c3a4de45edc6fc25d68a9176bccf9c336e (diff) |
fixed decrement counter.
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java b/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java index 42f909bd..5dd47ae6 100644 --- a/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java +++ b/core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java @@ -117,10 +117,28 @@ public class SICBlockCipher private void decrementCounter() { - // increment counter by 1. - for (int i = counter.length - 1; i >= 0 && --counter[i] == Integer.MIN_VALUE; i--) + if (counter[0] == 0) { - ; // do nothing - pre-increment and test for 0 in counter does the job. + boolean nonZero = false; + + for (int i = counter.length - 1; i > 0; i--) + { + if (counter[i] != 0) + { + nonZero = true; + } + } + + if (!nonZero) + { + throw new IllegalStateException("attempt to reduce counter past zero."); + } + } + + // decrement counter by 1. + for (int i = counter.length - 1; i >= 0 && --counter[i] == -1; i--) + { + ; } } |