113 #ifndef OPENSSL_NO_DH
126 #ifndef OPENSSL_NO_DSA
131 #define PROG dhparam_main
148 int MAIN(
int,
char **);
150 int MAIN(
int argc,
char **argv)
153 int i,badops=0,
text=0;
154 #ifndef OPENSSL_NO_DSA
158 int informat,outformat,check=0,noout=0,C=0,ret=1;
159 char *infile,*outfile,*prog;
161 #ifndef OPENSSL_NO_ENGINE
185 if (strcmp(*argv,
"-inform") == 0)
187 if (--argc < 1)
goto bad;
190 else if (strcmp(*argv,
"-outform") == 0)
192 if (--argc < 1)
goto bad;
195 else if (strcmp(*argv,
"-in") == 0)
197 if (--argc < 1)
goto bad;
200 else if (strcmp(*argv,
"-out") == 0)
202 if (--argc < 1)
goto bad;
205 #ifndef OPENSSL_NO_ENGINE
206 else if (strcmp(*argv,
"-engine") == 0)
208 if (--argc < 1)
goto bad;
212 else if (strcmp(*argv,
"-check") == 0)
214 else if (strcmp(*argv,
"-text") == 0)
216 #ifndef OPENSSL_NO_DSA
217 else if (strcmp(*argv,
"-dsaparam") == 0)
220 else if (strcmp(*argv,
"-C") == 0)
222 else if (strcmp(*argv,
"-noout") == 0)
224 else if (strcmp(*argv,
"-2") == 0)
226 else if (strcmp(*argv,
"-5") == 0)
228 else if (strcmp(*argv,
"-rand") == 0)
230 if (--argc < 1)
goto bad;
233 else if (((sscanf(*argv,
"%d",&num) == 0) || (num <= 0)))
248 #ifndef OPENSSL_NO_DSA
249 BIO_printf(
bio_err,
" -dsaparam read or generate DSA parameters, convert to DH\n");
257 #ifndef OPENSSL_NO_ENGINE
269 #ifndef OPENSSL_NO_ENGINE
276 #ifndef OPENSSL_NO_DSA
299 BIO_printf(
bio_err,
"warning, not much extra random data, consider using the -rand option\n");
305 #ifndef OPENSSL_NO_DSA
312 NULL, 0, NULL, NULL, &cb))
331 BIO_printf(
bio_err,
"Generating DH parameters, %d bit long safe prime, generator %d\n",num,g);
367 #ifndef OPENSSL_NO_DSA
375 dsa=PEM_read_bio_DSAparams(in,NULL,NULL,NULL);
398 dh=PEM_read_bio_DHparams(in,NULL,NULL,NULL);
420 #ifdef OPENSSL_SYS_VMS
450 printf(
"p value is not prime\n");
452 printf(
"p value is not a safe prime\n");
454 printf(
"unable to check the generator value\n");
456 printf(
"the g value is not a generator\n");
458 printf(
"DH parameters appear to be ok.\n");
470 perror(
"OPENSSL_malloc");
473 printf(
"#ifndef HEADER_DH_H\n"
474 "#include <openssl/dh.h>\n"
476 printf(
"DH *get_dh%d()\n\t{\n",bits);
479 printf(
"\tstatic unsigned char dh%d_p[]={",bits);
482 if ((i%12) == 0) printf(
"\n\t\t");
483 printf(
"0x%02X,",data[i]);
485 printf(
"\n\t\t};\n");
488 printf(
"\tstatic unsigned char dh%d_g[]={",bits);
491 if ((i%12) == 0) printf(
"\n\t\t");
492 printf(
"0x%02X,",data[i]);
494 printf(
"\n\t\t};\n");
496 printf(
"\tDH *dh;\n\n");
497 printf(
"\tif ((dh=DH_new()) == NULL) return(NULL);\n");
498 printf(
"\tdh->p=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\n",
500 printf(
"\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\n",
502 printf(
"\tif ((dh->p == NULL) || (dh->g == NULL))\n");
503 printf(
"\t\t{ DH_free(dh); return(NULL); }\n");
505 printf(
"\tdh->length = %ld;\n", dh->
length);
506 printf(
"\treturn(dh);\n\t}\n");
516 i=PEM_write_bio_DHparams(out,dh);
557 static void *dummy=&dummy;