diff options
author | David Hook <dgh@cryptoworkshop.com> | 2022-08-21 21:04:09 +1000 |
---|---|---|
committer | David Hook <dgh@cryptoworkshop.com> | 2022-08-21 21:04:09 +1000 |
commit | 37fdb4543c83dc7f4accfde993fe7b32064b8de3 (patch) | |
tree | 501fa781b966dcccef17e3531ee9ab13c6500f5f /crypto/test | |
parent | Implement NextBytes(Span<byte) (diff) | |
download | BouncyCastle.NET-ed25519-37fdb4543c83dc7f4accfde993fe7b32064b8de3.tar.xz |
added key size restrictions
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs | 20 | ||||
-rw-r--r-- | crypto/test/src/pqc/crypto/test/SaberVectorTest.cs | 23 |
2 files changed, 23 insertions, 20 deletions
diff --git a/crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs b/crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs index dca3a0f45..178e05fc9 100644 --- a/crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs +++ b/crypto/test/src/pqc/crypto/test/NtruPrimeVectorTest.cs @@ -73,7 +73,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests { // Console.WriteLine("Zero"); } - + byte[] seed = Hex.Decode(buf["seed"]); byte[] pk = Hex.Decode(buf["pk"]); byte[] ct = Hex.Decode(buf["ct"]); @@ -108,14 +108,15 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests // Check secret byte[] secret = secWenc.GetSecret(); - Assert.True(Arrays.AreEqual(ss, secret), name + " " + count + ": kem_enc secret"); - + Assert.True(Arrays.AreEqual(ss, 0, secret.Length, secret, 0, secret.Length), name + " " + count + ": kem_enc secret"); + // Decapsulation NtruLPRimeKemExtractor ntruDecCipher = new NtruLPRimeKemExtractor(privParams); byte[] dec_key = ntruDecCipher.ExtractSecret(generatedCT); - + // Check decapsulation secret - Assert.True(Arrays.AreEqual(dec_key, ss), $"{name} {count}: kem_dec ss"); + Assert.True(ntruPParameters.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(); @@ -171,7 +172,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"]; @@ -214,15 +215,16 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests // Check secret byte[] secret = secWenc.GetSecret(); - Assert.True(Arrays.AreEqual(ss, secret), name + " " + count + ": kem_enc secret"); + Assert.True(Arrays.AreEqual(ss, 0, secret.Length, secret, 0, secret.Length), name + " " + count + ": kem_enc secret"); // Decapsulation SNtruPrimeKemExtractor ntruDecCipher = new SNtruPrimeKemExtractor(privParams); byte[] dec_key = ntruDecCipher.ExtractSecret(generatedCT); // Check decapsulation secret - Assert.True(Arrays.AreEqual(dec_key, ss), $"{name} {count}: kem_dec ss"); - Assert.True(Arrays.AreEqual(dec_key, secret), $"{name} {count}: kem_dec key"); + Assert.True(ntruPParameters.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, 0, dec_key.Length, secret, 0, secret.Length), $"{name} {count}: kem_dec key"); } buf.Clear(); diff --git a/crypto/test/src/pqc/crypto/test/SaberVectorTest.cs b/crypto/test/src/pqc/crypto/test/SaberVectorTest.cs index 73ad7c47d..bc519614f 100644 --- a/crypto/test/src/pqc/crypto/test/SaberVectorTest.cs +++ b/crypto/test/src/pqc/crypto/test/SaberVectorTest.cs @@ -31,15 +31,15 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests SABERParameters.firesaberkem256r3, }; - Assert.AreEqual(128, SABERParameters.lightsaberkem128r3.GetDefaultKeySize()); - Assert.AreEqual(128, SABERParameters.saberkem128r3.GetDefaultKeySize()); - Assert.AreEqual(128, SABERParameters.firesaberkem128r3.GetDefaultKeySize()); - Assert.AreEqual(192, SABERParameters.lightsaberkem192r3.GetDefaultKeySize()); - Assert.AreEqual(192, SABERParameters.saberkem192r3.GetDefaultKeySize()); - Assert.AreEqual(192, SABERParameters.firesaberkem192r3.GetDefaultKeySize()); - Assert.AreEqual(256, SABERParameters.lightsaberkem256r3.GetDefaultKeySize()); - Assert.AreEqual(256, SABERParameters.saberkem256r3.GetDefaultKeySize()); - Assert.AreEqual(256, SABERParameters.firesaberkem256r3.GetDefaultKeySize()); + Assert.AreEqual(128, SABERParameters.lightsaberkem128r3.DefaultKeySize); + Assert.AreEqual(128, SABERParameters.saberkem128r3.DefaultKeySize); + Assert.AreEqual(128, SABERParameters.firesaberkem128r3.DefaultKeySize); + Assert.AreEqual(192, SABERParameters.lightsaberkem192r3.DefaultKeySize); + Assert.AreEqual(192, SABERParameters.saberkem192r3.DefaultKeySize); + Assert.AreEqual(192, SABERParameters.firesaberkem192r3.DefaultKeySize); + Assert.AreEqual(256, SABERParameters.lightsaberkem256r3.DefaultKeySize); + Assert.AreEqual(256, SABERParameters.saberkem256r3.DefaultKeySize); + Assert.AreEqual(256, SABERParameters.firesaberkem256r3.DefaultKeySize); } [Test] @@ -119,14 +119,15 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests 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 SABERKEMExtractor SABERDecCipher = new SABERKEMExtractor(privParams); byte[] dec_key = SABERDecCipher.ExtractSecret(generated_cipher_text); - Assert.True(Arrays.AreEqual(dec_key, ss), name + " " + count + ": kem_dec ss"); + Assert.True(parameters.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"); } |