diff options
author | David Hook <dgh@cryptoworkshop.com> | 2014-06-18 14:07:39 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2014-06-18 14:07:39 +0400 |
commit | 8d1c852a9079fcbbf982e8d28994cc57dc90e95e (patch) | |
tree | d5b2032ae35aa213cf71e9e7cdba7f1804bba471 /core/src/main/java/org/bouncycastle/crypto | |
parent | 62c21fdf342a27dc2c6a7d2c01ecc8986abcc3fe (diff) |
further tweaking.
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/macs/CMac.java | 41 | ||||
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java | 6 |
2 files changed, 23 insertions, 24 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java b/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java index 3db85e38..0492ae69 100644 --- a/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java +++ b/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java @@ -133,36 +133,29 @@ public class CMac implements Mac public void init(CipherParameters params) { - if (params instanceof KeyParameter) - { - cipher.init(true, params); - - //initializes the L, Lu, Lu2 numbers - L = new byte[ZEROES.length]; - cipher.processBlock(ZEROES, 0, L, 0); - Lu = doubleLu(L); - Lu2 = doubleLu(Lu); - } - else if (params != null) - { - if (this instanceof CMacWithIV) - { - cipher.init(true, params); + validate(params); - //initializes the L, Lu, Lu2 numbers - L = new byte[ZEROES.length]; - cipher.processBlock(ZEROES, 0, L, 0); - Lu = doubleLu(L); - Lu2 = doubleLu(Lu); - } - else + cipher.init(true, params); + + //initializes the L, Lu, Lu2 numbers + L = new byte[ZEROES.length]; + cipher.processBlock(ZEROES, 0, L, 0); + Lu = doubleLu(L); + Lu2 = doubleLu(Lu); + + reset(); + } + + void validate(CipherParameters params) + { + if (params != null) + { + if (!(params instanceof KeyParameter)) { // CMAC mode does not permit IV to underlying CBC mode throw new IllegalArgumentException("CMac mode only permits key to be set."); } } - - reset(); } public int getMacSize() diff --git a/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java b/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java index 19a8521a..a0371d95 100644 --- a/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java +++ b/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java @@ -1,6 +1,7 @@ package org.bouncycastle.crypto.macs; import org.bouncycastle.crypto.BlockCipher; +import org.bouncycastle.crypto.CipherParameters; /** * A non-NIST variant which allows passing of an IV to the underlying CBC cipher. @@ -18,4 +19,9 @@ public class CMacWithIV { super(cipher, macSizeInBits); } + + void validate(CipherParameters params) + { + // accept all + } } |