X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=apps%2Fdhparam.c;h=9d5705f8bfb27a93fd32d1a19807bd805cedee5b;hb=ec5add8784a2ffacd3391daae7937e04225da9da;hp=b401789a1bc0bed47b0ce895782a42a87392dcd9;hpb=41918458c0617911fd5eb44df9abb2d8dacde48f;p=openssl.git diff --git a/apps/dhparam.c b/apps/dhparam.c index b401789a1b..9d5705f8bf 100644 --- a/apps/dhparam.c +++ b/apps/dhparam.c @@ -121,6 +121,7 @@ #include #include #include +#include #ifndef NO_DSA #include @@ -148,6 +149,7 @@ int MAIN(int, char **); int MAIN(int argc, char **argv) { + ENGINE *e = NULL; DH *dh=NULL; int i,badops=0,text=0; #ifndef NO_DSA @@ -156,7 +158,7 @@ int MAIN(int argc, char **argv) BIO *in=NULL,*out=NULL; int informat,outformat,check=0,noout=0,C=0,ret=1; char *infile,*outfile,*prog; - char *inrand=NULL; + char *inrand=NULL,*engine=NULL; int num = 0, g = 0; apps_startup(); @@ -195,6 +197,11 @@ int MAIN(int argc, char **argv) if (--argc < 1) goto bad; outfile= *(++argv); } + else if (strcmp(*argv,"-engine") == 0) + { + if (--argc < 1) goto bad; + engine= *(++argv); + } else if (strcmp(*argv,"-check") == 0) check=1; else if (strcmp(*argv,"-text") == 0) @@ -240,6 +247,7 @@ bad: BIO_printf(bio_err," -2 generate parameters using 2 as the generator value\n"); BIO_printf(bio_err," -5 generate parameters using 5 as the generator value\n"); BIO_printf(bio_err," numbits number of bits in to generate (default 512)\n"); + BIO_printf(bio_err," -engine e use engine e, possibly a hardware device.\n"); BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); BIO_printf(bio_err," the random number generator\n"); @@ -249,6 +257,24 @@ bad: ERR_load_crypto_strings(); + if (engine != NULL) + { + if((e = ENGINE_by_id(engine)) == NULL) + { + BIO_printf(bio_err,"invalid engine \"%s\"\n", + engine); + goto end; + } + if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) + { + BIO_printf(bio_err,"can't use that engine\n"); + goto end; + } + BIO_printf(bio_err,"engine \"%s\" set.\n", engine); + /* Free our "structural" reference. */ + ENGINE_free(e); + } + if (g && !num) num = DEFBITS; @@ -285,7 +311,7 @@ bad: DSA *dsa; BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num); - dsa = DSA_generate_parameters(num, NULL, 0, NULL, NULL, dh_cb, bio_err); + dsa = DSA_generate_parameters(num, NULL, 0, NULL, NULL, dh_cb, bio_err); if (dsa == NULL) { ERR_print_errors(bio_err); @@ -391,7 +417,15 @@ bad: goto end; } if (outfile == NULL) + { BIO_set_fp(out,stdout,BIO_NOCLOSE); +#ifdef VMS + { + BIO *tmpbio = BIO_new(BIO_f_linebuffer()); + out = BIO_push(tmpbio, out); + } +#endif + } else { if (BIO_write_filename(out,outfile) <= 0) @@ -432,31 +466,35 @@ bad: len=BN_num_bytes(dh->p); bits=BN_num_bits(dh->p); - data=(unsigned char *)Malloc(len); + data=(unsigned char *)OPENSSL_malloc(len); if (data == NULL) { - perror("Malloc"); + perror("OPENSSL_malloc"); goto end; } + printf("#ifndef HEADER_DH_H\n" + "#include \n" + "#endif\n"); + printf("DH *get_dh%d()\n\t{\n",bits); + l=BN_bn2bin(dh->p,data); - printf("static unsigned char dh%d_p[]={",bits); + printf("\tstatic unsigned char dh%d_p[]={",bits); for (i=0; ig,data); - printf("static unsigned char dh%d_g[]={",bits); + printf("\tstatic unsigned char dh%d_g[]={",bits); for (i=0; ip=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\n", @@ -464,11 +502,11 @@ bad: printf("\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\n", bits,bits); printf("\tif ((dh->p == NULL) || (dh->g == NULL))\n"); - printf("\t\treturn(NULL);\n"); + printf("\t\t{ DH_free(dh); return(NULL); }\n"); if (dh->length) - printf("\tdh->length = %d\n", dh->length); + printf("\tdh->length = %d;\n", dh->length); printf("\treturn(dh);\n\t}\n"); - Free(data); + OPENSSL_free(data); } @@ -492,7 +530,7 @@ bad: ret=0; end: if (in != NULL) BIO_free(in); - if (out != NULL) BIO_free(out); + if (out != NULL) BIO_free_all(out); if (dh != NULL) DH_free(dh); EXIT(ret); }