diff options
author | David Hook <dgh@cryptoworkshop.com> | 2022-08-21 21:29:15 +1000 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2022-08-21 21:29:15 +1000 |
commit | 7c4f853a74012cfbf0d233a3ad57e416ae5d98a3 (patch) | |
tree | 1cf3bb1f8a7443d482d46451ee3b91c36aa075a6 /crypto/test | |
parent | added key size restrictions (diff) | |
download | BouncyCastle.NET-ed25519-7c4f853a74012cfbf0d233a3ad57e416ae5d98a3.tar.xz |
added key size restrictions
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/pqc/crypto/test/CmceVectorTest.cs | 12 | ||||
-rw-r--r-- | crypto/test/src/pqc/crypto/test/FrodoVectorTest.cs | 16 |
2 files changed, 16 insertions, 12 deletions
diff --git a/crypto/test/src/pqc/crypto/test/CmceVectorTest.cs b/crypto/test/src/pqc/crypto/test/CmceVectorTest.cs index 821bd5a77..4bf7605e9 100644 --- a/crypto/test/src/pqc/crypto/test/CmceVectorTest.cs +++ b/crypto/test/src/pqc/crypto/test/CmceVectorTest.cs @@ -80,6 +80,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests CmceParameters.mceliece8192128fr3 }; + TestSampler sampler = new TestSampler(); for (int fileIndex = 0; fileIndex != files.Length; fileIndex++) { string name = files[fileIndex]; @@ -100,7 +101,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests } if (line.Length == 0) { - if (buf.Count > 0) + if (buf.Count > 0 && !sampler.SkipTest(buf["count"])) { string count = buf["count"]; if (!"0".Equals(count)) @@ -137,18 +138,19 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests // KEM Enc CmceKemGenerator CmceEncCipher = new CmceKemGenerator(random); - ISecretWithEncapsulation secWenc = CmceEncCipher.GenerateEncapsulated(pubParams, 256); + ISecretWithEncapsulation secWenc = CmceEncCipher.GenerateEncapsulated(pubParams); byte[] generated_cipher_text = secWenc.GetEncapsulation(); Assert.True(Arrays.AreEqual(ct, generated_cipher_text), name + " " + count + ": kem_enc cipher text"); byte[] secret = secWenc.GetSecret(); - Assert.True(Arrays.AreEqual(ss, secret), name + " " + count + ": kem_enc key"); + Assert.True(Arrays.AreEqual(ss, 0, secret.Length, secret, 0, secret.Length), name + " " + count + ": kem_enc key"); // KEM Dec CmceKemExtractor CmceDecCipher = new CmceKemExtractor(privParams); - byte[] dec_key = CmceDecCipher.ExtractSecret(generated_cipher_text, 256); + byte[] dec_key = CmceDecCipher.ExtractSecret(generated_cipher_text); - Assert.True(Arrays.AreEqual(dec_key, ss), name + " " + count + ": kem_dec ss"); + Assert.True(Cmceparameters.DefaultKeySize == dec_key.Length * 8); + Assert.True(Arrays.AreEqual(dec_key, 0, dec_key.Length, ss, 0, dec_key.Length), name + " " + count + ": kem_dec ss"); Assert.True(Arrays.AreEqual(dec_key, secret), name + " " + count + ": kem_dec key"); } buf.Clear(); diff --git a/crypto/test/src/pqc/crypto/test/FrodoVectorTest.cs b/crypto/test/src/pqc/crypto/test/FrodoVectorTest.cs index 90498ae7f..311a5cd3a 100644 --- a/crypto/test/src/pqc/crypto/test/FrodoVectorTest.cs +++ b/crypto/test/src/pqc/crypto/test/FrodoVectorTest.cs @@ -28,12 +28,12 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests FrodoParameters.frodokem43088shaker3 }; - Assert.AreEqual(64, FrodoParameters.frodokem19888r3.DefaultKeySize); - Assert.AreEqual(64, FrodoParameters.frodokem19888shaker3.DefaultKeySize); - Assert.AreEqual(96, FrodoParameters.frodokem31296r3.DefaultKeySize); - Assert.AreEqual(96, FrodoParameters.frodokem31296shaker3.DefaultKeySize); - Assert.AreEqual(128, FrodoParameters.frodokem43088r3.DefaultKeySize); - Assert.AreEqual(128, FrodoParameters.frodokem43088shaker3.DefaultKeySize); + Assert.AreEqual(128, FrodoParameters.frodokem19888r3.DefaultKeySize); + Assert.AreEqual(128, FrodoParameters.frodokem19888shaker3.DefaultKeySize); + Assert.AreEqual(192, FrodoParameters.frodokem31296r3.DefaultKeySize); + Assert.AreEqual(192, FrodoParameters.frodokem31296shaker3.DefaultKeySize); + Assert.AreEqual(256, FrodoParameters.frodokem43088r3.DefaultKeySize); + Assert.AreEqual(256, FrodoParameters.frodokem43088shaker3.DefaultKeySize); } [Test] @@ -76,6 +76,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests FrodoParameters.frodokem19888shaker3, }; } + TestSampler sampler = new TestSampler(); for (int fileIndex = 0; fileIndex != files.Length; fileIndex++) { String name = files[fileIndex]; @@ -95,7 +96,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests } if (line.Length == 0) { - if (buf.Count > 0) + if (buf.Count > 0 && !sampler.SkipTest(buf["count"])) { String count = buf["count"]; if (!"0".Equals(count)) @@ -144,6 +145,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests byte[] dec_key = frodoDecCipher.ExtractSecret(generated_cipher_text); + Assert.True(frodoParameters.DefaultKeySize == dec_key.Length * 8); Assert.True(Arrays.AreEqual(dec_key, ss), $"{name} {count}: kem_dec ss"); Assert.True(Arrays.AreEqual(dec_key, secret),$"{name} {count}: kem_dec key"); } |