diff options
author | tb <> | 2021-11-20 18:10:48 +0000 |
---|---|---|
committer | tb <> | 2021-11-20 18:10:48 +0000 |
commit | ddffb653bb836ef8741e0b2e002c1ea1c0a17dc8 (patch) | |
tree | 3b802e89fdcb5de312935cb76899b338d6c0999d /src/usr.bin/openssl/gendh.c | |
parent | 105c69b5d010aec960fdbf571dd0598e0436e293 (diff) | |
download | openbsd-ddffb653bb836ef8741e0b2e002c1ea1c0a17dc8.tar.gz openbsd-ddffb653bb836ef8741e0b2e002c1ea1c0a17dc8.tar.bz2 openbsd-ddffb653bb836ef8741e0b2e002c1ea1c0a17dc8.zip |
Convert openssl(1) to using BN_GENCB on the heap
This is three times the same thing while genrsa needs some extra steps
to deal with opaque BIGNUMs. We can also garbage collect some Win 3.1
contortions and use the conversion routines directly instead of doing
them manually.
ok jsing
Diffstat (limited to 'src/usr.bin/openssl/gendh.c')
-rw-r--r-- | src/usr.bin/openssl/gendh.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/usr.bin/openssl/gendh.c b/src/usr.bin/openssl/gendh.c index facc9248f3..c6564e047b 100644 --- a/src/usr.bin/openssl/gendh.c +++ b/src/usr.bin/openssl/gendh.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: gendh.c,v 1.11 2019/07/14 03:30:45 guenther Exp $ */ | 1 | /* $OpenBSD: gendh.c,v 1.12 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 | * |
@@ -84,7 +84,7 @@ | |||
84 | 84 | ||
85 | #define DEFBITS 512 | 85 | #define DEFBITS 512 |
86 | 86 | ||
87 | static int dh_cb(int p, int n, BN_GENCB * cb); | 87 | static int dh_cb(int p, int n, BN_GENCB *cb); |
88 | 88 | ||
89 | static struct { | 89 | static struct { |
90 | int g; | 90 | int g; |
@@ -128,7 +128,7 @@ gendh_usage(void) | |||
128 | int | 128 | int |
129 | gendh_main(int argc, char **argv) | 129 | gendh_main(int argc, char **argv) |
130 | { | 130 | { |
131 | BN_GENCB cb; | 131 | BN_GENCB *cb = NULL; |
132 | DH *dh = NULL; | 132 | DH *dh = NULL; |
133 | int ret = 1, numbits = DEFBITS; | 133 | int ret = 1, numbits = DEFBITS; |
134 | BIO *out = NULL; | 134 | BIO *out = NULL; |
@@ -141,7 +141,12 @@ gendh_main(int argc, char **argv) | |||
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | BN_GENCB_set(&cb, dh_cb, bio_err); | 144 | if ((cb = BN_GENCB_new()) == NULL) { |
145 | BIO_printf(bio_err, "Error allocating BN_GENCB object\n"); | ||
146 | goto end; | ||
147 | } | ||
148 | |||
149 | BN_GENCB_set(cb, dh_cb, bio_err); | ||
145 | 150 | ||
146 | memset(&gendh_config, 0, sizeof(gendh_config)); | 151 | memset(&gendh_config, 0, sizeof(gendh_config)); |
147 | 152 | ||
@@ -180,7 +185,7 @@ gendh_main(int argc, char **argv) | |||
180 | BIO_printf(bio_err, "This is going to take a long time\n"); | 185 | BIO_printf(bio_err, "This is going to take a long time\n"); |
181 | 186 | ||
182 | if (((dh = DH_new()) == NULL) || | 187 | if (((dh = DH_new()) == NULL) || |
183 | !DH_generate_parameters_ex(dh, numbits, gendh_config.g, &cb)) | 188 | !DH_generate_parameters_ex(dh, numbits, gendh_config.g, cb)) |
184 | goto end; | 189 | goto end; |
185 | 190 | ||
186 | if (!PEM_write_bio_DHparams(out, dh)) | 191 | if (!PEM_write_bio_DHparams(out, dh)) |
@@ -190,13 +195,14 @@ gendh_main(int argc, char **argv) | |||
190 | if (ret != 0) | 195 | if (ret != 0) |
191 | ERR_print_errors(bio_err); | 196 | ERR_print_errors(bio_err); |
192 | BIO_free_all(out); | 197 | BIO_free_all(out); |
198 | BN_GENCB_free(cb); | ||
193 | DH_free(dh); | 199 | DH_free(dh); |
194 | 200 | ||
195 | return (ret); | 201 | return (ret); |
196 | } | 202 | } |
197 | 203 | ||
198 | static int | 204 | static int |
199 | dh_cb(int p, int n, BN_GENCB * cb) | 205 | dh_cb(int p, int n, BN_GENCB *cb) |
200 | { | 206 | { |
201 | char c = '*'; | 207 | char c = '*'; |
202 | 208 | ||
@@ -208,8 +214,8 @@ dh_cb(int p, int n, BN_GENCB * cb) | |||
208 | c = '*'; | 214 | c = '*'; |
209 | if (p == 3) | 215 | if (p == 3) |
210 | c = '\n'; | 216 | c = '\n'; |
211 | BIO_write(cb->arg, &c, 1); | 217 | BIO_write(BN_GENCB_get_arg(cb), &c, 1); |
212 | (void) BIO_flush(cb->arg); | 218 | (void) BIO_flush(BN_GENCB_get_arg(cb)); |
213 | return 1; | 219 | return 1; |
214 | } | 220 | } |
215 | #endif | 221 | #endif |