Skip to content

Commit

Permalink
SigGen test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Laurie committed Apr 3, 2004
1 parent f27846c commit 16d5c92
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
3 changes: 2 additions & 1 deletion fips/dsa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 46 additions & 3 deletions fips/dsa/fips_dssvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#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)
{
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';
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 16d5c92

Please sign in to comment.