diff options
author | David Hook <dgh@cryptoworkshop.com> | 2014-06-18 11:25:59 +0400 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2014-06-18 11:25:59 +0400 |
commit | 15a171201743d869960d3d0ba82a3502af4c4aa4 (patch) | |
tree | 6c60022377c3855414a852af975c10732f19a87a /core/src/main/java/org/bouncycastle/crypto | |
parent | 22b5b860d84c19121e4e0c4b4a3234ec36e687ee (diff) |
added CMacWithIV class for "backwards" compatibility.
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/macs/CMac.java | 3 | ||||
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java | 43 |
2 files changed, 45 insertions, 1 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 64294e08..e4b2d7f3 100644 --- a/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java +++ b/core/src/main/java/org/bouncycastle/crypto/macs/CMac.java @@ -142,7 +142,8 @@ public class CMac implements Mac cipher.processBlock(ZEROES, 0, L, 0); Lu = doubleLu(L); Lu2 = doubleLu(Lu); - } else if (params != null) + } + 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."); diff --git a/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java b/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java new file mode 100644 index 00000000..8361eea0 --- /dev/null +++ b/core/src/main/java/org/bouncycastle/crypto/macs/CMacWithIV.java @@ -0,0 +1,43 @@ +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. + * <p>Note: there isn't really a good reason to use an IV here, use the regular CMac where possible.</p> + */ +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); + } + } +} |