diff options
author | David Hook <dgh@cryptoworkshop.com> | 2014-06-18 13:12:31 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2014-06-18 13:12:31 +0400 |
commit | 554a46d8d1470beacb32c14d6d6c74e9248684b8 (patch) | |
tree | 4be37c8f7069644dbbcace6ab564380e567dcac4 /core/src/main/java/org/bouncycastle/crypto | |
parent | 15a171201743d869960d3d0ba82a3502af4c4aa4 (diff) |
fixed CMacWithIV class (sigh...)
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/macs/CMac.java | 17 | ||||
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java | 22 |
2 files changed, 15 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 e4b2d7f3..3db85e38 100644 --- a/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java +++ b/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java @@ -145,8 +145,21 @@ public class CMac implements Mac } else if (params != null) { - // CMAC mode does not permit IV to underlying CBC mode - throw new IllegalArgumentException("CMac mode only permits key to be set."); + if (this instanceof CMacWithIV) + { + 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 + { + // CMAC mode does not permit IV to underlying CBC mode + throw new IllegalArgumentException("CMac mode only permits key to be set."); + } } reset(); 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 8361eea0..19a8521a 100644 --- a/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java +++ b/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java @@ -1,8 +1,6 @@ package org.bouncycastle.crypto.macs; import org.bouncycastle.crypto.BlockCipher; -import org.bouncycastle.crypto.CipherParameters; -import org.bouncycastle.crypto.params.ParametersWithIV; /** * A non-NIST variant which allows passing of an IV to the underlying CBC cipher. @@ -11,33 +9,13 @@ import org.bouncycastle.crypto.params.ParametersWithIV; public class CMacWithIV extends CMac { - private BlockCipher cipher; - public CMacWithIV(BlockCipher cipher) { super(cipher); - this.cipher = cipher; } public CMacWithIV(BlockCipher cipher, int macSizeInBits) { super(cipher, macSizeInBits); - this.cipher = cipher; - } - - public void init(CipherParameters params) - { - if (params instanceof ParametersWithIV) - { - ParametersWithIV pWithIV = (ParametersWithIV)params; - - super.init(pWithIV.getParameters()); - - cipher.init(true, params); - } - else - { - super.init(params); - } } } |