diff options
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/crypto/test/AsconTest.cs | 337 |
1 files changed, 156 insertions, 181 deletions
diff --git a/crypto/test/src/crypto/test/AsconTest.cs b/crypto/test/src/crypto/test/AsconTest.cs index 837dc413b..eca949471 100644 --- a/crypto/test/src/crypto/test/AsconTest.cs +++ b/crypto/test/src/crypto/test/AsconTest.cs @@ -5,7 +5,6 @@ using System.IO; using NUnit.Framework; using Org.BouncyCastle.Crypto.Engines; -using Org.BouncyCastle.Crypto.Modes; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Encoders; @@ -14,87 +13,82 @@ using Org.BouncyCastle.Utilities.Test; namespace Org.BouncyCastle.Crypto.Tests { [TestFixture] - public class AsconTest : SimpleTest + public class AsconTest + : SimpleTest { - public override string Name - { - get { return "ASCON AEAD"; } - } + public override string Name => "ASCON AEAD"; [Test] public override void PerformTest() { - AsconEngine Ascon = new AsconEngine(AsconEngine.AsconParameters.ascon80pq); - testExceptions(Ascon, Ascon.GetKeyBytesSize(), Ascon.GetIVBytesSize(), Ascon.GetBlockSize()); - testParameters(Ascon, 20, 16, 16, 8); - Ascon = new AsconEngine(AsconEngine.AsconParameters.ascon128a); - testExceptions(Ascon, Ascon.GetKeyBytesSize(), Ascon.GetIVBytesSize(), Ascon.GetBlockSize()); - testParameters(Ascon, 16, 16, 16, 16); - Ascon = new AsconEngine(AsconEngine.AsconParameters.ascon128); - testExceptions(Ascon, Ascon.GetKeyBytesSize(), Ascon.GetIVBytesSize(), Ascon.GetBlockSize()); - testParameters(Ascon, 16, 16, 16, 8); - testVectors(AsconEngine.AsconParameters.ascon80pq, "160_128"); - testVectors(AsconEngine.AsconParameters.ascon128a, "128_128_a"); - testVectors(AsconEngine.AsconParameters.ascon128, "128_128"); + AsconEngine asconEngine = new AsconEngine(AsconEngine.AsconParameters.ascon80pq); + ImplTestExceptions(asconEngine); + ImplTestParameters(asconEngine, 20, 16, 16); + + asconEngine = new AsconEngine(AsconEngine.AsconParameters.ascon128a); + ImplTestExceptions(asconEngine); + ImplTestParameters(asconEngine, 16, 16, 16); + + asconEngine = new AsconEngine(AsconEngine.AsconParameters.ascon128); + ImplTestExceptions(asconEngine); + ImplTestParameters(asconEngine, 16, 16, 16); + + ImplTestVectors(AsconEngine.AsconParameters.ascon80pq, "160_128"); + ImplTestVectors(AsconEngine.AsconParameters.ascon128a, "128_128_a"); + ImplTestVectors(AsconEngine.AsconParameters.ascon128, "128_128"); } - private void testVectors(AsconEngine.AsconParameters asconParameters, string filename) + private void ImplTestVectors(AsconEngine.AsconParameters asconParameters, string filename) { + Random random = new Random(); AsconEngine Ascon = new AsconEngine(asconParameters); - ICipherParameters param; var buf = new Dictionary<string, string>(); //TestSampler sampler = new TestSampler(); using (var src = new StreamReader(SimpleTest.GetTestDataAsStream("crypto.ascon.LWC_AEAD_KAT_" + filename + ".txt"))) { - string line; - string[] data; - byte[] rv; Dictionary<string, string> map = new Dictionary<string, string>(); + string line; while ((line = src.ReadLine()) != null) { - data = line.Split(' '); + var data = line.Split(' '); if (data.Length == 1) { - //if (!map["Count"].Equals("265")) - //{ - // continue; - //} byte[] key = Hex.Decode(map["Key"]); byte[] nonce = Hex.Decode(map["Nonce"]); byte[] ad = Hex.Decode(map["AD"]); byte[] pt = Hex.Decode(map["PT"]); byte[] ct = Hex.Decode(map["CT"]); - param = new ParametersWithIV(new KeyParameter(key), nonce); - Ascon.Init(true, param); - Ascon.ProcessAadBytes(ad, 0, ad.Length); - rv = new byte[Ascon.GetOutputSize(pt.Length)]; - int len = Ascon.ProcessBytes(pt, 0, pt.Length, rv, 0); - //byte[] mac = new byte[16]; - Ascon.DoFinal(rv, len); - //foreach(byte b in Hex.Decode(map["CT"])) - //{ - // Console.Write(b.ToString("X2")); - //} - //Console.WriteLine(); - //foreach (byte b in Arrays.Concatenate(rv, mac)) - //{ - // Console.Write(b.ToString("X2")); - //} - //Console.WriteLine(); - Assert.True(Arrays.AreEqual(rv, ct)); - Ascon.Reset(); - Ascon.Init(false, param); - //Decrypt - Ascon.ProcessAadBytes(ad, 0, ad.Length); - rv = new byte[pt.Length + 16]; - len = Ascon.ProcessBytes(ct, 0, ct.Length, rv, 0); - Ascon.DoFinal(rv, len); - byte[] pt_recovered = new byte[pt.Length]; - Array.Copy(rv, 0, pt_recovered, 0, pt.Length); - Assert.True(Arrays.AreEqual(pt, pt_recovered)); - //Console.WriteLine(map["Count"] + " pass"); map.Clear(); + var param = new ParametersWithIV(new KeyParameter(key), nonce); + + // Encrypt + { + Ascon.Init(true, param); + + var rv = new byte[Ascon.GetOutputSize(pt.Length)]; + random.NextBytes(rv); // should overwrite any existing data + + Ascon.ProcessAadBytes(ad, 0, ad.Length); + int len = Ascon.ProcessBytes(pt, 0, pt.Length, rv, 0); + len += Ascon.DoFinal(rv, len); + + Assert.True(Arrays.AreEqual(rv, 0, len, ct, 0, ct.Length)); + } + + // Decrypt + { + Ascon.Init(false, param); + + var rv = new byte[Ascon.GetOutputSize(ct.Length)]; + random.NextBytes(rv); // should overwrite any existing data + + Ascon.ProcessAadBytes(ad, 0, ad.Length); + int len = Ascon.ProcessBytes(ct, 0, ct.Length, rv, 0); + len += Ascon.DoFinal(rv, len); + + Assert.True(Arrays.AreEqual(rv, 0, len, pt, 0, pt.Length)); + } } else { @@ -106,27 +100,23 @@ namespace Org.BouncyCastle.Crypto.Tests { map[data[0].Trim()] = ""; } - } } } - Console.WriteLine("Ascon AEAD pass"); } - - private void testExceptions(IAeadBlockCipher aeadBlockCipher, int keysize, int ivsize, int blocksize) - + private void ImplTestExceptions(AsconEngine asconEngine) { - ICipherParameters param; - byte[] k = new byte[keysize]; - byte[] iv = new byte[ivsize]; + int keySize = asconEngine.GetKeyBytesSize(), ivSize = asconEngine.GetIVBytesSize(); + byte[] k = new byte[keySize]; + byte[] iv = new byte[ivSize]; byte[] m = new byte[0]; - byte[] c1 = new byte[aeadBlockCipher.GetOutputSize(m.Length)]; - param = new ParametersWithIV(new KeyParameter(k), iv); + byte[] c1 = new byte[asconEngine.GetOutputSize(m.Length)]; + var param = new ParametersWithIV(new KeyParameter(k), iv); try { - aeadBlockCipher.ProcessBytes(m, 0, m.Length, c1, 0); - Assert.Fail(aeadBlockCipher.AlgorithmName + " need to be initialed before ProcessBytes"); + asconEngine.ProcessBytes(m, 0, m.Length, c1, 0); + Assert.Fail(asconEngine.AlgorithmName + " need to be initialed before ProcessBytes"); } catch (ArgumentException) { @@ -135,8 +125,8 @@ namespace Org.BouncyCastle.Crypto.Tests try { - aeadBlockCipher.ProcessByte((byte)0, c1, 0); - Assert.Fail(aeadBlockCipher.AlgorithmName + " need to be initialed before ProcessByte"); + asconEngine.ProcessByte((byte)0, c1, 0); + Assert.Fail(asconEngine.AlgorithmName + " need to be initialed before ProcessByte"); } catch (ArgumentException) { @@ -145,8 +135,8 @@ namespace Org.BouncyCastle.Crypto.Tests try { - aeadBlockCipher.Reset(); - Assert.Fail(aeadBlockCipher.AlgorithmName + " need to be initialed before reset"); + asconEngine.Reset(); + Assert.Fail(asconEngine.AlgorithmName + " need to be initialed before reset"); } catch (ArgumentException) { @@ -155,8 +145,8 @@ namespace Org.BouncyCastle.Crypto.Tests try { - aeadBlockCipher.DoFinal(c1, m.Length); - Assert.Fail(aeadBlockCipher.AlgorithmName + " need to be initialed before dofinal"); + asconEngine.DoFinal(c1, m.Length); + Assert.Fail(asconEngine.AlgorithmName + " need to be initialed before dofinal"); } catch (ArgumentException) { @@ -165,25 +155,26 @@ namespace Org.BouncyCastle.Crypto.Tests try { - aeadBlockCipher.GetMac(); - aeadBlockCipher.GetOutputSize(0); - aeadBlockCipher.GetUpdateOutputSize(0); + asconEngine.GetMac(); + asconEngine.GetOutputSize(0); + asconEngine.GetUpdateOutputSize(0); } catch (ArgumentException) { //expected - Assert.Fail(aeadBlockCipher.AlgorithmName + " functions can be called before initialisation"); + Assert.Fail(asconEngine.AlgorithmName + " functions can be called before initialisation"); } + Random rand = new Random(); int randomNum; - while ((randomNum = rand.Next(100)) == keysize) ; + while ((randomNum = rand.Next(100)) == keySize) ; byte[] k1 = new byte[randomNum]; - while ((randomNum = rand.Next(100)) == ivsize) ; + while ((randomNum = rand.Next(100)) == ivSize) ; byte[] iv1 = new byte[randomNum]; try { - aeadBlockCipher.Init(true, new ParametersWithIV(new KeyParameter(k1), iv)); - Assert.Fail(aeadBlockCipher.AlgorithmName + " k size does not match"); + asconEngine.Init(true, new ParametersWithIV(new KeyParameter(k1), iv)); + Assert.Fail(asconEngine.AlgorithmName + " k size does not match"); } catch (ArgumentException) { @@ -191,25 +182,24 @@ namespace Org.BouncyCastle.Crypto.Tests } try { - aeadBlockCipher.Init(true, new ParametersWithIV(new KeyParameter(k), iv1)); - Assert.Fail(aeadBlockCipher.AlgorithmName + "iv size does not match"); + asconEngine.Init(true, new ParametersWithIV(new KeyParameter(k), iv1)); + Assert.Fail(asconEngine.AlgorithmName + "iv size does not match"); } catch (ArgumentException) { //expected } - - aeadBlockCipher.Init(true, param); + asconEngine.Init(true, param); try { - aeadBlockCipher.DoFinal(c1, m.Length); + asconEngine.DoFinal(c1, m.Length); } catch (Exception) { - Assert.Fail(aeadBlockCipher.AlgorithmName + " allows no input for AAD and plaintext"); + Assert.Fail(asconEngine.AlgorithmName + " allows no input for AAD and plaintext"); } - byte[] mac2 = aeadBlockCipher.GetMac(); + byte[] mac2 = asconEngine.GetMac(); if (mac2 == null) { Assert.Fail("mac should not be empty after dofinal"); @@ -218,18 +208,18 @@ namespace Org.BouncyCastle.Crypto.Tests { Assert.Fail("mac should be equal when calling dofinal and getMac"); } - aeadBlockCipher.ProcessAadByte((byte)0); - byte[] mac1 = new byte[aeadBlockCipher.GetOutputSize(0)]; - aeadBlockCipher.DoFinal(mac1, 0); + asconEngine.ProcessAadByte((byte)0); + byte[] mac1 = new byte[asconEngine.GetOutputSize(0)]; + asconEngine.DoFinal(mac1, 0); if (Arrays.AreEqual(mac1, mac2)) { Assert.Fail("mac should not match"); } - aeadBlockCipher.Reset(); - aeadBlockCipher.ProcessBytes(new byte[16], 0, 16, new byte[16], 0); + asconEngine.Reset(); + asconEngine.ProcessBytes(new byte[16], 0, 16, new byte[16], 0); try { - aeadBlockCipher.ProcessAadByte((byte)0); + asconEngine.ProcessAadByte((byte)0); Assert.Fail("ProcessAadByte(s) cannot be called after encryption/decryption"); } catch (ArgumentException) @@ -238,7 +228,7 @@ namespace Org.BouncyCastle.Crypto.Tests } try { - aeadBlockCipher.ProcessAadBytes(new byte[] { 0 }, 0, 1); + asconEngine.ProcessAadBytes(new byte[] { 0 }, 0, 1); Assert.Fail("ProcessAadByte(s) cannot be called once only"); } catch (ArgumentException) @@ -246,10 +236,10 @@ namespace Org.BouncyCastle.Crypto.Tests //expected } - aeadBlockCipher.Reset(); + asconEngine.Reset(); try { - aeadBlockCipher.ProcessAadBytes(new byte[] { 0 }, 1, 1); + asconEngine.ProcessAadBytes(new byte[] { 0 }, 1, 1); Assert.Fail("input for ProcessAadBytes is too short"); } catch (DataLengthException) @@ -258,7 +248,7 @@ namespace Org.BouncyCastle.Crypto.Tests } try { - aeadBlockCipher.ProcessBytes(new byte[] { 0 }, 1, 1, c1, 0); + asconEngine.ProcessBytes(new byte[] { 0 }, 1, 1, c1, 0); Assert.Fail("input for ProcessBytes is too short"); } catch (DataLengthException) @@ -267,7 +257,7 @@ namespace Org.BouncyCastle.Crypto.Tests } try { - aeadBlockCipher.ProcessBytes(new byte[16], 0, 16, new byte[16], 8); + asconEngine.ProcessBytes(new byte[16], 0, 16, new byte[16], 8); Assert.Fail("output for ProcessBytes is too short"); } catch (OutputLengthException) @@ -276,7 +266,7 @@ namespace Org.BouncyCastle.Crypto.Tests } try { - aeadBlockCipher.DoFinal(new byte[2], 2); + asconEngine.DoFinal(new byte[2], 2); Assert.Fail("output for dofinal is too short"); } catch (DataLengthException) @@ -284,59 +274,58 @@ namespace Org.BouncyCastle.Crypto.Tests //expected } - mac1 = new byte[aeadBlockCipher.GetOutputSize(0)]; - mac2 = new byte[aeadBlockCipher.GetOutputSize(0)]; - aeadBlockCipher.Reset(); - aeadBlockCipher.ProcessAadBytes(new byte[] { 0, 0 }, 0, 2); - aeadBlockCipher.DoFinal(mac1, 0); - aeadBlockCipher.Reset(); - aeadBlockCipher.ProcessAadByte((byte)0); - aeadBlockCipher.ProcessAadByte((byte)0); - aeadBlockCipher.DoFinal(mac2, 0); + mac1 = new byte[asconEngine.GetOutputSize(0)]; + mac2 = new byte[asconEngine.GetOutputSize(0)]; + asconEngine.Reset(); + asconEngine.ProcessAadBytes(new byte[] { 0, 0 }, 0, 2); + asconEngine.DoFinal(mac1, 0); + asconEngine.Reset(); + asconEngine.ProcessAadByte((byte)0); + asconEngine.ProcessAadByte((byte)0); + asconEngine.DoFinal(mac2, 0); if (!Arrays.AreEqual(mac1, mac2)) { Assert.Fail("mac should match for the same AAD with different ways of inputing"); } - byte[] c2 = new byte[aeadBlockCipher.GetOutputSize(10)]; - byte[] c3 = new byte[aeadBlockCipher.GetOutputSize(10) + 2]; + byte[] c2 = new byte[asconEngine.GetOutputSize(10)]; + byte[] c3 = new byte[asconEngine.GetOutputSize(10) + 2]; byte[] aad2 = { 0, 1, 2, 3, 4 }; byte[] aad3 = { 0, 0, 1, 2, 3, 4, 5 }; byte[] m2 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; byte[] m3 = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; byte[] m4 = new byte[m2.Length]; - aeadBlockCipher.Reset(); - aeadBlockCipher.ProcessAadBytes(aad2, 0, aad2.Length); - int offset = aeadBlockCipher.ProcessBytes(m2, 0, m2.Length, c2, 0); - aeadBlockCipher.DoFinal(c2, offset); - aeadBlockCipher.Reset(); - aeadBlockCipher.ProcessAadBytes(aad3, 1, aad2.Length); - offset = aeadBlockCipher.ProcessBytes(m3, 1, m2.Length, c3, 1); - aeadBlockCipher.DoFinal(c3, offset + 1); + asconEngine.Reset(); + asconEngine.ProcessAadBytes(aad2, 0, aad2.Length); + int offset = asconEngine.ProcessBytes(m2, 0, m2.Length, c2, 0); + asconEngine.DoFinal(c2, offset); + asconEngine.Reset(); + asconEngine.ProcessAadBytes(aad3, 1, aad2.Length); + offset = asconEngine.ProcessBytes(m3, 1, m2.Length, c3, 1); + asconEngine.DoFinal(c3, offset + 1); byte[] c3_partial = new byte[c2.Length]; Array.Copy(c3, 1, c3_partial, 0, c2.Length); if (!Arrays.AreEqual(c2, c3_partial)) { Assert.Fail("mac should match for the same AAD and message with different offset for both input and output"); } - aeadBlockCipher.Reset(); - aeadBlockCipher.Init(false, param); - aeadBlockCipher.ProcessAadBytes(aad2, 0, aad2.Length); - offset = aeadBlockCipher.ProcessBytes(c2, 0, c2.Length, m4, 0); - aeadBlockCipher.DoFinal(m4, offset); + asconEngine.Reset(); + asconEngine.Init(false, param); + asconEngine.ProcessAadBytes(aad2, 0, aad2.Length); + offset = asconEngine.ProcessBytes(c2, 0, c2.Length, m4, 0); + asconEngine.DoFinal(m4, offset); if (!Arrays.AreEqual(m2, m4)) { Assert.Fail("The encryption and decryption does not recover the plaintext"); } - Console.WriteLine(aeadBlockCipher.AlgorithmName + " test Exceptions pass"); c2[c2.Length - 1] ^= 1; - aeadBlockCipher.Reset(); - aeadBlockCipher.Init(false, param); - aeadBlockCipher.ProcessAadBytes(aad2, 0, aad2.Length); - offset = aeadBlockCipher.ProcessBytes(c2, 0, c2.Length, m4, 0); + asconEngine.Reset(); + asconEngine.Init(false, param); + asconEngine.ProcessAadBytes(aad2, 0, aad2.Length); + offset = asconEngine.ProcessBytes(c2, 0, c2.Length, m4, 0); try { - aeadBlockCipher.DoFinal(m4, offset); + asconEngine.DoFinal(m4, offset); Assert.Fail("The decryption should fail"); } catch (ArgumentException) @@ -345,29 +334,26 @@ namespace Org.BouncyCastle.Crypto.Tests } c2[c2.Length - 1] ^= 1; - byte[] m7 = new byte[blocksize * 2]; - for (int i = 0; i < m7.Length; ++i) - { - m7[i] = (byte)rand.Next(); - } - byte[] c7 = new byte[aeadBlockCipher.GetOutputSize(m7.Length)]; + byte[] m7 = new byte[32 + rand.Next(16)]; + rand.NextBytes(m7); + + byte[] c7 = new byte[asconEngine.GetOutputSize(m7.Length)]; byte[] c8 = new byte[c7.Length]; byte[] c9 = new byte[c7.Length]; - aeadBlockCipher.Init(true, param); - aeadBlockCipher.ProcessAadBytes(aad2, 0, aad2.Length); - offset = aeadBlockCipher.ProcessBytes(m7, 0, m7.Length, c7, 0); - aeadBlockCipher.DoFinal(c7, offset); - aeadBlockCipher.Reset(); - aeadBlockCipher.ProcessAadBytes(aad2, 0, aad2.Length); - offset = aeadBlockCipher.ProcessBytes(m7, 0, blocksize, c8, 0); - offset += aeadBlockCipher.ProcessBytes(m7, blocksize, m7.Length - blocksize, c8, offset); - aeadBlockCipher.DoFinal(c8, offset); - aeadBlockCipher.Reset(); - int split = rand.Next(blocksize * 2); - aeadBlockCipher.ProcessAadBytes(aad2, 0, aad2.Length); - offset = aeadBlockCipher.ProcessBytes(m7, 0, split, c9, 0); - offset += aeadBlockCipher.ProcessBytes(m7, split, m7.Length - split, c9, offset); - aeadBlockCipher.DoFinal(c9, offset); + asconEngine.Init(true, param); + asconEngine.ProcessAadBytes(aad2, 0, aad2.Length); + offset = asconEngine.ProcessBytes(m7, 0, m7.Length, c7, 0); + asconEngine.DoFinal(c7, offset); + asconEngine.Reset(); + asconEngine.ProcessAadBytes(aad2, 0, aad2.Length); + offset = asconEngine.ProcessBytes(m7, 0, m7.Length, c8, 0); + offset += asconEngine.DoFinal(c8, offset); + asconEngine.Reset(); + int split = rand.Next(1, m7.Length); + asconEngine.ProcessAadBytes(aad2, 0, aad2.Length); + offset = asconEngine.ProcessBytes(m7, 0, split, c9, 0); + offset += asconEngine.ProcessBytes(m7, split, m7.Length - split, c9, offset); + asconEngine.DoFinal(c9, offset); if (!Arrays.AreEqual(c7, c8) || !Arrays.AreEqual(c7, c9)) { Assert.Fail("Splitting input of plaintext should output the same ciphertext"); @@ -379,10 +365,10 @@ namespace Org.BouncyCastle.Crypto.Tests Span<byte> c4_2 = new byte[c2.Length]; ReadOnlySpan<byte> m5 = new ReadOnlySpan<byte>(m2); ReadOnlySpan<byte> aad4 = new ReadOnlySpan<byte>(aad2); - aeadBlockCipher.Init(true, param); - aeadBlockCipher.ProcessAadBytes(aad4); - offset = aeadBlockCipher.ProcessBytes(m5, c4_1); - aeadBlockCipher.DoFinal(c4_2); + asconEngine.Init(true, param); + asconEngine.ProcessAadBytes(aad4); + offset = asconEngine.ProcessBytes(m5, c4_1); + asconEngine.DoFinal(c4_2); byte[] c5 = new byte[c2.Length]; Array.Copy(c4_1.ToArray(), 0, c5, 0, offset); Array.Copy(c4_2.ToArray(), 0, c5, offset, c5.Length - offset); @@ -390,14 +376,14 @@ namespace Org.BouncyCastle.Crypto.Tests { Assert.Fail("mac should match for the same AAD and message with different offset for both input and output"); } - aeadBlockCipher.Reset(); - aeadBlockCipher.Init(false, param); + asconEngine.Reset(); + asconEngine.Init(false, param); Span<byte> m6_1 = new byte[m2.Length]; Span<byte> m6_2 = new byte[m2.Length]; ReadOnlySpan<byte> c6 = new ReadOnlySpan<byte>(c2); - aeadBlockCipher.ProcessAadBytes(aad4); - offset = aeadBlockCipher.ProcessBytes(c6, m6_1); - aeadBlockCipher.DoFinal(m6_2); + asconEngine.ProcessAadBytes(aad4); + offset = asconEngine.ProcessBytes(c6, m6_1); + asconEngine.DoFinal(m6_2); byte[] m6 = new byte[m2.Length]; Array.Copy(m6_1.ToArray(), 0, m6, 0, offset); Array.Copy(m6_2.ToArray(), 0, m6, offset, m6.Length - offset); @@ -408,25 +394,14 @@ namespace Org.BouncyCastle.Crypto.Tests #endif } - private void testParameters(AsconEngine ascon, int keySize, int ivSize, int macSize, int blockSize) + private void ImplTestParameters(AsconEngine asconEngine, int keySize, int ivSize, int macSize) { - if (ascon.GetKeyBytesSize() != keySize) - { - Assert.Fail("key bytes of " + ascon.AlgorithmName + " is not correct"); - } - if (ascon.GetIVBytesSize() != ivSize) - { - Assert.Fail("iv bytes of " + ascon.AlgorithmName + " is not correct"); - } - if (ascon.GetOutputSize(0) != macSize) - { - Assert.Fail("mac bytes of " + ascon.AlgorithmName + " is not correct"); - } - if (ascon.GetBlockSize() != blockSize) - { - Assert.Fail("block size of " + ascon.AlgorithmName + " is not correct"); - } - Console.WriteLine(ascon.AlgorithmName + " test Parameters pass"); + Assert.AreEqual(keySize, asconEngine.GetKeyBytesSize(), + "key bytes of " + asconEngine.AlgorithmName + " is not correct"); + Assert.AreEqual(ivSize, asconEngine.GetIVBytesSize(), + "iv bytes of " + asconEngine.AlgorithmName + " is not correct"); + Assert.AreEqual(macSize, asconEngine.GetOutputSize(0), + "mac bytes of " + asconEngine.AlgorithmName + " is not correct"); } } -} \ No newline at end of file +} |