X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=apps%2Fdhparam.c;h=e794dacd1d6f40ddc5f71eae0a7f7d0f491148dd;hb=6b9686e694d602640a565e8cbbe80857db832571;hp=e842ca5f20ed5cb5a99a5addba2ca1cbe9a5afac;hpb=7e1b7485706c2b11091b5fa897fe496a2faa56cc;p=oweals%2Fopenssl.git diff --git a/apps/dhparam.c b/apps/dhparam.c index e842ca5f20..e794dacd1d 100644 --- a/apps/dhparam.c +++ b/apps/dhparam.c @@ -153,12 +153,12 @@ OPTIONS dhparam_options[] = { {"C", OPT_C, '-', "Print C code"}, {"2", OPT_2, '-', "Generate parameters using 2 as the generator value"}, {"5", OPT_5, '-', "Generate parameters using 5 as the generator value"}, -# ifndef OPENSSL_NO_ENGINE - {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"}, -# endif # ifndef OPENSSL_NO_DSA {"dsaparam", OPT_DSAPARAM, '-', "Read or generate DSA parameters, convert to DH"}, +# endif +# ifndef OPENSSL_NO_ENGINE + {"engine", OPT_ENGINE, 's', "Use engine e, possibly a hardware device"}, # endif {NULL} }; @@ -167,8 +167,7 @@ int dhparam_main(int argc, char **argv) { BIO *in = NULL, *out = NULL; DH *dh = NULL; - char *engine = NULL, *infile = NULL, *outfile = NULL, *prog, *inrand = - NULL; + char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL; int dsaparam = 0, i, text = 0, C = 0, ret = 1, num = 0, g = 0; int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0; OPTION_CHOICE o; @@ -200,7 +199,7 @@ int dhparam_main(int argc, char **argv) outfile = opt_arg(); break; case OPT_ENGINE: - engine = opt_arg(); + (void)setup_engine(opt_arg(), 0); break; case OPT_CHECK: check = 1; @@ -234,10 +233,6 @@ int dhparam_main(int argc, char **argv) if (argv[0] && (!opt_int(argv[0], &num) || num <= 0)) goto end; -# ifndef OPENSSL_NO_ENGINE - setup_engine(engine, 0); -# endif - if (g && !num) num = DEFBITS; @@ -256,7 +251,7 @@ int dhparam_main(int argc, char **argv) BN_GENCB *cb; cb = BN_GENCB_new(); - if (!cb) { + if (cb == NULL) { ERR_print_errors(bio_err); goto end; } @@ -276,7 +271,7 @@ int dhparam_main(int argc, char **argv) BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num); - if (!dsa + if (dsa == NULL || !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL, cb)) { DSA_free(dsa); @@ -300,7 +295,7 @@ int dhparam_main(int argc, char **argv) "Generating DH parameters, %d bit long safe prime, generator %d\n", num, g); BIO_printf(bio_err, "This is going to take a long time\n"); - if (!dh || !DH_generate_parameters_ex(dh, num, g, cb)) { + if (dh == NULL || !DH_generate_parameters_ex(dh, num, g, cb)) { BN_GENCB_free(cb); ERR_print_errors(bio_err); goto end; @@ -311,7 +306,7 @@ int dhparam_main(int argc, char **argv) app_RAND_write_file(NULL); } else { - in = bio_open_default(infile, RB(informat)); + in = bio_open_default(infile, 'r', informat); if (in == NULL) goto end; @@ -354,7 +349,7 @@ int dhparam_main(int argc, char **argv) /* dh != NULL */ } - out = bio_open_default(outfile, "w"); + out = bio_open_default(outfile, 'w', outformat); if (out == NULL) goto end; @@ -384,11 +379,7 @@ int dhparam_main(int argc, char **argv) len = BN_num_bytes(dh->p); bits = BN_num_bits(dh->p); - data = (unsigned char *)OPENSSL_malloc(len); - if (data == NULL) { - perror("OPENSSL_malloc"); - goto end; - } + data = app_malloc(len, "print a BN"); BIO_printf(out, "#ifndef HEADER_DH_H\n" "# include \n" "#endif\n"