Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2014-06-23 15:53:59 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-06-23 15:53:59 +0400
commit147293c4a6c913c2ddb42a52c636ead5c9c78c6e (patch)
treea4236ad18d7cd728ba19c53d98129062399a9bd6 /core
parent4b4fa1c3a4de45edc6fc25d68a9176bccf9c336e (diff)
fixed decrement counter.
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/modes/SICBlockCipher.java24
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--)
+ {
+ ;
}
}