diff options
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java')
-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--) + { + ; } } |