summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorroyb <roy.basmacier@primekey.com>2022-09-29 18:30:54 -0400
committerroyb <roy.basmacier@primekey.com>2022-09-29 18:30:54 -0400
commite079a4d5b24a1daece4abf8807670da7442fded2 (patch)
tree17e610253993704f30af7b65253ea5ae6a200e49 /crypto/test
parentAdded Kyber AES support (diff)
downloadBouncyCastle.NET-ed25519-e079a4d5b24a1daece4abf8807670da7442fded2.tar.xz
Added ASN.1 key encoding/decoding for Kyber, Dilithium, and Falcon.
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/pqc/crypto/test/FalconTest.cs55
1 files changed, 7 insertions, 48 deletions
diff --git a/crypto/test/src/pqc/crypto/test/FalconTest.cs b/crypto/test/src/pqc/crypto/test/FalconTest.cs
index bcda32669..4ede0803d 100644
--- a/crypto/test/src/pqc/crypto/test/FalconTest.cs
+++ b/crypto/test/src/pqc/crypto/test/FalconTest.cs
@@ -63,11 +63,14 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests
                             AsymmetricCipherKeyPair ackp = kpg.GenerateKeyPair();
                             byte[] respk = ((FalconPublicKeyParameters) ackp.Public).GetEncoded();
                             byte[] ressk = ((FalconPrivateKeyParameters) ackp.Private).GetEncoded();
+                            
+                            //keygen
+                            Assert.True(Arrays.AreEqual(respk, 0, respk.Length, pk, 1, pk.Length), name + " " + count + " public key");
+                            Assert.True(Arrays.AreEqual(ressk, 0, ressk.Length, sk, 1, sk.Length), name + " " + count + " private key");
 
                             // sign
                             FalconSigner signer = new FalconSigner();
-                            FalconPrivateKeyParameters skparam = new FalconPrivateKeyParameters(parameters[fileIndex], sk);
-                            ParametersWithRandom skwrand = new ParametersWithRandom(skparam, random);
+                            ParametersWithRandom skwrand = new ParametersWithRandom(ackp.Private, random);
                             signer.Init(true, skwrand);
                             byte[] sig = signer.GenerateSignature(msg);
                             byte[] ressm = new byte[2 + msg.Length + sig.Length - 1];
@@ -79,7 +82,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests
 
                             // verify
                             FalconSigner verifier = new FalconSigner();
-                            FalconPublicKeyParameters pkparam = new FalconPublicKeyParameters(parameters[fileIndex], pk);
+                            FalconPublicKeyParameters pkparam = (FalconPublicKeyParameters)ackp.Public;
                             verifier.Init(false, pkparam);
                             byte[] noncesig = new byte[sm_len - m_len - 2 + 1];
                             noncesig[0] = (byte)(0x30 + parameters[fileIndex].LogN);
@@ -88,51 +91,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests
                             bool vrfyrespass = verifier.VerifySignature(msg, noncesig);
                             noncesig[42]++; // changing the signature by 1 byte should cause it to fail
                             bool vrfyresfail = verifier.VerifySignature(msg, noncesig);
-
-                            // print results
-                            /*
-                            System.out.println("--Keygen");
-                            bool kgenpass = true;
-                            if (!Arrays.areEqual(respk, pk)) {
-                                System.out.println("  == Keygen: pk do not match");
-                                kgenpass = false;
-                            }
-                            if (!Arrays.areEqual(ressk, sk)) {
-                                System.out.println("  == Keygen: sk do not match");
-                                kgenpass = false;
-                            }
-                            if (kgenpass) {
-                                System.out.println("  ++ Keygen pass");
-                            } else {
-                                System.out.println("  == Keygen failed");
-                                return;
-                            }
-
-                            System.out.println("--Sign");
-                            bool spass = true;
-                            if (!Arrays.areEqual(ressm, sm)) {
-                                System.out.println("  == Sign: signature do not match");
-                                spass = false;
-                            }
-                            if (spass) {
-                                System.out.println("  ++ Sign pass");
-                            } else {
-                                System.out.println("  == Sign failed");
-                                return;
-                            }
-
-                            System.out.println("--Verify");
-                            if (vrfyrespass && !vrfyresfail) {
-                                System.out.println("  ++ Verify pass");
-                            } else {
-                                System.out.println("  == Verify failed");
-                                return;
-                            }
-                            */
-                            // Assert.True
-                            //keygen
-                            Assert.True(Arrays.AreEqual(respk, pk), name + " " + count + " public key");
-                            Assert.True(Arrays.AreEqual(ressk, sk), name + " " + count + " private key");
+                            
                             //sign
                             Assert.True(Arrays.AreEqual(ressm, sm), name + " " + count + " signature");
                             //verify