SigGen test.
authorBen Laurie <ben@openssl.org>
Sat, 3 Apr 2004 20:05:33 +0000 (20:05 +0000)
committerBen Laurie <ben@openssl.org>
Sat, 3 Apr 2004 20:05:33 +0000 (20:05 +0000)
fips/dsa/Makefile
fips/dsa/fips_dssvs.c

index f3287d6bdf89733b25b8315b33df2189effdaaf0..ea18a9574b29c74028ae43a995a4f46d0361c77a 100644 (file)
@@ -80,7 +80,8 @@ fips_test: top_fips_dssvs
        -rm -rf $A
        mkdir $A
 #      ./fips_dssvs pqg < $Q/PQGGen.req > $A/PQGGen.rsp
-       ./fips_dssvs keypair < $Q/KeyPair.req > $A/KeyPair.rsp
+#      ./fips_dssvs keypair < $Q/KeyPair.req > $A/KeyPair.rsp
+       ./fips_dssvs siggen < $Q/SigGen.req > $A/SigGen.rsp
 
 lint:
        lint -DLINT $(INCLUDES) $(SRC)>fluff
index 594797f3f4abfdc94a659ddb560638e8ea56041c..7252f41b3a6d88afaea94ccbfc257e6b9ceac5b0 100644 (file)
@@ -2,6 +2,7 @@
 #include <openssl/dsa.h>
 #include <openssl/fips.h>
 #include <openssl/err.h>
+#include <openssl/sha.h>
 #include <string.h>
 
 int hex2bin(const char *in, unsigned char *out)
@@ -9,7 +10,7 @@ int hex2bin(const char *in, unsigned char *out)
     int n1, n2;
     unsigned char ch;
 
-    for (n1=0,n2=0 ; in[n1] ; )
+    for (n1=0,n2=0 ; in[n1] && in[n1] != '\n' ; )
        { /* first byte */
        if ((in[n1] >= '0') && (in[n1] <= '9'))
            ch = in[n1++] - '0';
@@ -64,9 +65,8 @@ int bin2hex(const unsigned char *in,int len,char *out)
 void pv(const char *tag,const unsigned char *val,int len)
     {
     char obuf[2048];
-    int olen;
 
-    olen=bin2hex(val,len,obuf);
+    bin2hex(val,len,obuf);
     printf("%s = %s\n",tag,obuf);
     }
 
@@ -165,6 +165,47 @@ void keypair()
        }
     }
 
+void siggen()
+    {
+    char buf[1024];
+    int nmod=0;
+    DSA *dsa=NULL;
+
+    while(fgets(buf,sizeof buf,stdin) != NULL)
+       {
+       if(!strncmp(buf,"[mod = ",7))
+           {
+           nmod=atoi(buf+7);
+           printf("[mod = %d]\n\n",nmod);
+
+           dsa=DSA_generate_parameters(nmod,NULL,0,NULL,NULL,NULL,NULL);
+           pbn("P",dsa->p);
+           pbn("Q",dsa->q);
+           pbn("G",dsa->g);
+           putc('\n',stdout);
+           }
+       else if(!strncmp(buf,"Msg = ",6))
+           {
+           unsigned char msg[1024];
+           unsigned char hash[20];
+           int n;
+           DSA_SIG *sig;
+
+           n=hex2bin(buf+6,msg);
+           pv("Msg",msg,n);
+
+           DSA_generate_key(dsa);
+           pbn("Y",dsa->pub_key);
+
+           SHA1(msg,n,hash);
+           sig=DSA_do_sign(hash,sizeof hash,dsa);
+           pbn("R",sig->r);
+           pbn("S",sig->s);
+           putc('\n',stdout);
+           }
+       }
+    }
+
 int main(int argc,char **argv)
     {
     if(argc != 2)
@@ -184,6 +225,8 @@ int main(int argc,char **argv)
        pqg();
     else if(!strcmp(argv[1],"keypair"))
        keypair();
+    else if(!strcmp(argv[1],"siggen"))
+       siggen();
     //    else if(!strcmp(argv[1],"versig"))
     // versig();
     else