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/test/java | |
parent | 15a171201743d869960d3d0ba82a3502af4c4aa4 (diff) |
fixed CMacWithIV class (sigh...)
Diffstat (limited to 'core/src/test/java')
-rw-r--r-- | core/src/test/java/org/bouncycastle/crypto/test/CMacTest.java | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/core/src/test/java/org/bouncycastle/crypto/test/CMacTest.java b/core/src/test/java/org/bouncycastle/crypto/test/CMacTest.java index d1241e2c..5db0779d 100644 --- a/core/src/test/java/org/bouncycastle/crypto/test/CMacTest.java +++ b/core/src/test/java/org/bouncycastle/crypto/test/CMacTest.java @@ -5,6 +5,7 @@ import org.bouncycastle.crypto.Mac; import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.engines.AESFastEngine; import org.bouncycastle.crypto.macs.CMac; +import org.bouncycastle.crypto.macs.CMacWithIV; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.params.ParametersWithIV; import org.bouncycastle.util.encoders.Hex; @@ -250,7 +251,49 @@ public class CMacTest fail("Failed - expected " + new String(Hex.encode(output_k256_m64)) + " got " + new String(Hex.encode(out))); } - + + // CMAC with IV + // 16 bytes message - 256 bytes key + mac = new CMacWithIV(new AESFastEngine()); + + mac.init(key); + + mac.update(input16, 0, input16.length); + + out = new byte[16]; + + mac.doFinal(out, 0); + + if (!areEqual(out, output_k256_m16)) + { + fail("Failed - expected " + new String(Hex.encode(output_k256_m16)) + + " got " + new String(Hex.encode(out))); + } + + // CMAC with IV + // 16 bytes message - 256 bytes key + mac = new CMacWithIV(new AESFastEngine()); + + mac.init(new ParametersWithIV(key, Hex.decode("000102030405060708090a0b0c0d0e0f"))); + + mac.update(input16, 0, input16.length); + + out = new byte[16]; + + mac.doFinal(out, 0); + + if (areEqual(out, output_k256_m16)) + { + fail("Failed - expected " + new String(Hex.encode(output_k256_m16)) + + " got " + new String(Hex.encode(out))); + } + + if (!areEqual(out, Hex.decode("9347a60c64061b9ff2a92522ca8e08fc"))) + { + fail("Failed - expected " + "9347a60c64061b9ff2a92522ca8e08fc" + + " got " + new String(Hex.encode(out))); + } + testExceptions(); } |