Explorar el Código

Testing gen pub -e -p -q.

Fixing public key generation, which segfaulted with the couple <p, q>, and
adding a small test to asssert it.
Moreover, changing #!/bin/bash to #!/bin/sh. Apparently using bash is almost
always wrong: may be outdated in new osx, not present in some linux, and
generally not really needed in comparaison with bash.
Michele Orrù hace 11 años
padre
commit
672a084cdc
Se han modificado 2 ficheros con 24 adiciones y 2 borrados
  1. 5 1
      src/apps/gen.c
  2. 19 1
      src/apps/tests/test_gen_pub.test

+ 5 - 1
src/apps/gen.c

@@ -39,12 +39,16 @@ pubkey_generation(RSA* rsa)
     exit(EXIT_FAILURE);
     }
 
-  if (!rsa->n)
+  if (!rsa->n) {
+    rsa->n = BN_new();
     BN_mul(rsa->n, rsa->p, rsa->q, ctx);
+  }
 
   PEM_write_RSAPublicKey(stdout, rsa);
 
   BN_CTX_free(ctx);
+  RSA_free(rsa);
+
   return EXIT_SUCCESS;
 }
 

+ 19 - 1
src/apps/tests/test_gen_pub.test

@@ -1,6 +1,24 @@
-#!/bin/bash
+#!/bin/sh
 
 # N = 11 * 13
 # e = 103
 # d = 7
 ./gen pub -N 143 -e 103 | grep -q PUBLIC
+if [ $? -ne 0 ]
+then
+    echo "should accept public exponent and public modulus."
+    exit 1
+fi
+
+
+# <http://cryptowars2011.forumfree.it/?t=58954862>
+p='5596931086554284281185296406554840964858720713572245165038844132225787390922\
+226340619345603534845283511495476913891096668345376424228245705523358529690689'
+q='5596931086554284281185296406554840964858720713572245165038844132225787390922\
+226340619345603534845283511495476913891096668345376424228245705523358529692809'
+./gen pub -p $p -q $q -e 29
+if [ $? -ne 0 ]
+then
+    echo "should accept the pair of primes <p, q> and the public exponent."
+    exit 1
+fi