From: Ben Laurie Date: Sat, 3 Apr 2004 20:05:33 +0000 (+0000) Subject: SigGen test. X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=16d5c926deda88fc3f5471cbc2c48b515956b531;p=oweals%2Fopenssl.git SigGen test. --- diff --git a/fips/dsa/Makefile b/fips/dsa/Makefile index f3287d6bdf..ea18a9574b 100644 --- a/fips/dsa/Makefile +++ b/fips/dsa/Makefile @@ -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 diff --git a/fips/dsa/fips_dssvs.c b/fips/dsa/fips_dssvs.c index 594797f3f4..7252f41b3a 100644 --- a/fips/dsa/fips_dssvs.c +++ b/fips/dsa/fips_dssvs.c @@ -2,6 +2,7 @@ #include #include #include +#include #include 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