diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-10-24 10:12:56 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2018-10-24 10:12:56 +0700 |
commit | 2a70b6dc400133a21df391a1cd4b57630f533cf2 (patch) | |
tree | 36911c0c577e11948f2aa2155f625931a7cd6397 | |
parent | Use Edwards internals for X25519/X448 public key calculations (diff) | |
download | BouncyCastle.NET-ed25519-2a70b6dc400133a21df391a1cd4b57630f533cf2.tar.xz |
Reverted short nonce on decryption change
-rw-r--r-- | crypto/src/crypto/modes/CcmBlockCipher.cs | 2 | ||||
-rw-r--r-- | crypto/test/src/crypto/test/CCMTest.cs | 40 |
2 files changed, 4 insertions, 38 deletions
diff --git a/crypto/src/crypto/modes/CcmBlockCipher.cs b/crypto/src/crypto/modes/CcmBlockCipher.cs index 0a28a288f..fa97ec840 100644 --- a/crypto/src/crypto/modes/CcmBlockCipher.cs +++ b/crypto/src/crypto/modes/CcmBlockCipher.cs @@ -91,7 +91,7 @@ namespace Org.BouncyCastle.Crypto.Modes keyParam = cipherParameters; } - if (nonce == null || (forEncryption && (nonce.Length < 7 || nonce.Length > 13))) + if (nonce == null || nonce.Length < 7 || nonce.Length > 13) throw new ArgumentException("nonce must have length from 7 to 13 octets"); Reset(); diff --git a/crypto/test/src/crypto/test/CCMTest.cs b/crypto/test/src/crypto/test/CCMTest.cs index 5d40cea53..cf5f31f4f 100644 --- a/crypto/test/src/crypto/test/CCMTest.cs +++ b/crypto/test/src/crypto/test/CCMTest.cs @@ -55,45 +55,11 @@ namespace Org.BouncyCastle.Crypto.Tests private static readonly byte[] C5 = Hex.Decode("49b17d8d3ea4e6174a48e2b65e6d8b417ac0dd3f8ee46ce4a4a2a509661cef52528c1cd9805333a5cfd482fa3f095a3c2fdd1cc47771c5e55fddd60b5c8d6d3fa5c8dd79d08b16242b6642106e7c0c28bd1064b31e6d7c9800c8397dbc3fa8071e6a38278b386c18d65d39c6ad1ef9501a5c8f68d38eb6474799f3cc898b4b9b97e87f9c95ce5c51bc9d758f17119586663a5684e0a0daf6520ec572b87473eb141d10471e4799ded9e607655402eca5176bbf792ef39dd135ac8d710da8e9e854fd3b95c681023f36b5ebe2fb213d0b62dd6e9e3cfe190b792ccb20c53423b2dca128f861a61d306910e1af418839467e466f0ec361d2539eedd99d4724f1b51c07beb40e875a87491ec8b27cd1"); private static readonly byte[] T5 = Hex.Decode("5c768856796b627b13ec8641581b"); - // - // short nonce decryption - // - private static readonly byte[] K6 = Hex.Decode("404142434445464748494a4b4c4d4e4f"); - private static readonly byte[] C6 = Hex.Decode("d5fd123ca49dca7040f3843d"); - private static readonly byte[] A6 = Hex.Decode("0001020304050607"); - private static readonly byte[] P6 = Hex.Decode("20212223"); - private static readonly byte[] N6 = Hex.Decode("1011121314"); - private static readonly byte[] T6 = Hex.Decode("6fb0180f3bbd3add"); - - public override void PerformTest() + public override void PerformTest() { CcmBlockCipher ccm = new CcmBlockCipher(new AesEngine()); - KeyParameter keyParam = new KeyParameter(K6); - - ccm.Init(false, new AeadParameters(keyParam, 64, N6, A6)); - - byte[] enc = new byte[P6.Length]; - - int len = ccm.ProcessBytes(C6, 0, C6.Length, enc, 0); - - len += ccm.DoFinal(enc, len); - - IsTrue(Arrays.AreEqual(T6, ccm.GetMac())); - - try - { - ccm.Init(true, new AeadParameters(keyParam, 64, N6, A6)); - Fail("no exception"); - } - catch (ArgumentException e) - { - IsEquals("nonce must have length from 7 to 13 octets", e.Message); - } - - ccm = new CcmBlockCipher(new AesEngine()); - - checkVectors(0, ccm, K1, 32, N1, A1, P1, T1, C1); + checkVectors(0, ccm, K1, 32, N1, A1, P1, T1, C1); checkVectors(1, ccm, K2, 48, N2, A2, P2, T2, C2); checkVectors(2, ccm, K3, 64, N3, A3, P3, T3, C3); @@ -124,7 +90,7 @@ namespace Org.BouncyCastle.Crypto.Tests Array.Copy(C2, 0, inBuf, 10, C2.Length); - len = ccm.ProcessPacket(inBuf, 10, C2.Length, outBuf, 10); + int len = ccm.ProcessPacket(inBuf, 10, C2.Length, outBuf, 10); byte[] output = ccm.ProcessPacket(C2, 0, C2.Length); if (len != output.Length || !isEqual(output, outBuf, 10)) |