summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/dhparam.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/openssl/dhparam.c')
-rw-r--r--src/usr.bin/openssl/dhparam.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/usr.bin/openssl/dhparam.c b/src/usr.bin/openssl/dhparam.c
index b0dd510949..55263274b6 100644
--- a/src/usr.bin/openssl/dhparam.c
+++ b/src/usr.bin/openssl/dhparam.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dhparam.c,v 1.12 2019/07/14 03:30:45 guenther Exp $ */ 1/* $OpenBSD: dhparam.c,v 1.13 2021/11/20 18:10:48 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -231,12 +231,13 @@ dhparam_usage()
231 options_usage(dhparam_options); 231 options_usage(dhparam_options);
232} 232}
233 233
234static int dh_cb(int p, int n, BN_GENCB * cb); 234static int dh_cb(int p, int n, BN_GENCB *cb);
235 235
236int 236int
237dhparam_main(int argc, char **argv) 237dhparam_main(int argc, char **argv)
238{ 238{
239 BIO *in = NULL, *out = NULL; 239 BIO *in = NULL, *out = NULL;
240 BN_GENCB *cb = NULL;
240 char *num_bits = NULL; 241 char *num_bits = NULL;
241 DH *dh = NULL; 242 DH *dh = NULL;
242 int num = 0; 243 int num = 0;
@@ -283,15 +284,19 @@ dhparam_main(int argc, char **argv)
283 } 284 }
284 285
285 if (num) { 286 if (num) {
287 if ((cb = BN_GENCB_new()) == NULL) {
288 BIO_printf(bio_err,
289 "Error allocating BN_GENCB object\n");
290 goto end;
291 }
286 292
287 BN_GENCB cb; 293 BN_GENCB_set(cb, dh_cb, bio_err);
288 BN_GENCB_set(&cb, dh_cb, bio_err);
289 if (dhparam_config.dsaparam) { 294 if (dhparam_config.dsaparam) {
290 DSA *dsa = DSA_new(); 295 DSA *dsa = DSA_new();
291 296
292 BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num); 297 BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num);
293 if (!dsa || !DSA_generate_parameters_ex(dsa, num, 298 if (!dsa || !DSA_generate_parameters_ex(dsa, num,
294 NULL, 0, NULL, NULL, &cb)) { 299 NULL, 0, NULL, NULL, cb)) {
295 DSA_free(dsa); 300 DSA_free(dsa);
296 ERR_print_errors(bio_err); 301 ERR_print_errors(bio_err);
297 goto end; 302 goto end;
@@ -306,7 +311,7 @@ dhparam_main(int argc, char **argv)
306 dh = DH_new(); 311 dh = DH_new();
307 BIO_printf(bio_err, "Generating DH parameters, %d bit long safe prime, generator %d\n", num, dhparam_config.g); 312 BIO_printf(bio_err, "Generating DH parameters, %d bit long safe prime, generator %d\n", num, dhparam_config.g);
308 BIO_printf(bio_err, "This is going to take a long time\n"); 313 BIO_printf(bio_err, "This is going to take a long time\n");
309 if (!dh || !DH_generate_parameters_ex(dh, num, dhparam_config.g, &cb)) { 314 if (!dh || !DH_generate_parameters_ex(dh, num, dhparam_config.g, cb)) {
310 ERR_print_errors(bio_err); 315 ERR_print_errors(bio_err);
311 goto end; 316 goto end;
312 } 317 }
@@ -469,6 +474,7 @@ dhparam_main(int argc, char **argv)
469 end: 474 end:
470 BIO_free(in); 475 BIO_free(in);
471 BIO_free_all(out); 476 BIO_free_all(out);
477 BN_GENCB_free(cb);
472 DH_free(dh); 478 DH_free(dh);
473 479
474 return (ret); 480 return (ret);
@@ -476,7 +482,7 @@ dhparam_main(int argc, char **argv)
476 482
477/* dh_cb is identical to dsa_cb in apps/dsaparam.c */ 483/* dh_cb is identical to dsa_cb in apps/dsaparam.c */
478static int 484static int
479dh_cb(int p, int n, BN_GENCB * cb) 485dh_cb(int p, int n, BN_GENCB *cb)
480{ 486{
481 char c = '*'; 487 char c = '*';
482 488
@@ -488,8 +494,8 @@ dh_cb(int p, int n, BN_GENCB * cb)
488 c = '*'; 494 c = '*';
489 if (p == 3) 495 if (p == 3)
490 c = '\n'; 496 c = '\n';
491 BIO_write(cb->arg, &c, 1); 497 BIO_write(BN_GENCB_get_arg(cb), &c, 1);
492 (void) BIO_flush(cb->arg); 498 (void) BIO_flush(BN_GENCB_get_arg(cb));
493 return 1; 499 return 1;
494} 500}
495 501