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.c82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/usr.bin/openssl/dhparam.c b/src/usr.bin/openssl/dhparam.c
index 8a487cb918..0542464d7b 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.16 2023/03/05 13:12:53 tb Exp $ */ 1/* $OpenBSD: dhparam.c,v 1.17 2023/03/06 14:32:06 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 *
@@ -142,7 +142,7 @@ static struct {
142 char *outfile; 142 char *outfile;
143 int outformat; 143 int outformat;
144 int text; 144 int text;
145} dhparam_config; 145} cfg;
146 146
147static const struct option dhparam_options[] = { 147static const struct option dhparam_options[] = {
148 { 148 {
@@ -150,73 +150,73 @@ static const struct option dhparam_options[] = {
150 .desc = "Generate DH parameters with a generator value of 2 " 150 .desc = "Generate DH parameters with a generator value of 2 "
151 "(default)", 151 "(default)",
152 .type = OPTION_VALUE, 152 .type = OPTION_VALUE,
153 .opt.value = &dhparam_config.g, 153 .opt.value = &cfg.g,
154 .value = 2, 154 .value = 2,
155 }, 155 },
156 { 156 {
157 .name = "5", 157 .name = "5",
158 .desc = "Generate DH parameters with a generator value of 5", 158 .desc = "Generate DH parameters with a generator value of 5",
159 .type = OPTION_VALUE, 159 .type = OPTION_VALUE,
160 .opt.value = &dhparam_config.g, 160 .opt.value = &cfg.g,
161 .value = 5, 161 .value = 5,
162 }, 162 },
163 { 163 {
164 .name = "C", 164 .name = "C",
165 .desc = "Convert DH parameters into C code", 165 .desc = "Convert DH parameters into C code",
166 .type = OPTION_FLAG, 166 .type = OPTION_FLAG,
167 .opt.flag = &dhparam_config.C, 167 .opt.flag = &cfg.C,
168 }, 168 },
169 { 169 {
170 .name = "check", 170 .name = "check",
171 .desc = "Check the DH parameters", 171 .desc = "Check the DH parameters",
172 .type = OPTION_FLAG, 172 .type = OPTION_FLAG,
173 .opt.flag = &dhparam_config.check, 173 .opt.flag = &cfg.check,
174 }, 174 },
175 { 175 {
176 .name = "dsaparam", 176 .name = "dsaparam",
177 .desc = "Read or generate DSA parameters and convert to DH", 177 .desc = "Read or generate DSA parameters and convert to DH",
178 .type = OPTION_FLAG, 178 .type = OPTION_FLAG,
179 .opt.flag = &dhparam_config.dsaparam, 179 .opt.flag = &cfg.dsaparam,
180 }, 180 },
181 { 181 {
182 .name = "in", 182 .name = "in",
183 .argname = "file", 183 .argname = "file",
184 .desc = "Input file (default stdin)", 184 .desc = "Input file (default stdin)",
185 .type = OPTION_ARG, 185 .type = OPTION_ARG,
186 .opt.arg = &dhparam_config.infile, 186 .opt.arg = &cfg.infile,
187 }, 187 },
188 { 188 {
189 .name = "inform", 189 .name = "inform",
190 .argname = "format", 190 .argname = "format",
191 .desc = "Input format (DER or PEM (default))", 191 .desc = "Input format (DER or PEM (default))",
192 .type = OPTION_ARG_FORMAT, 192 .type = OPTION_ARG_FORMAT,
193 .opt.value = &dhparam_config.informat, 193 .opt.value = &cfg.informat,
194 }, 194 },
195 { 195 {
196 .name = "noout", 196 .name = "noout",
197 .desc = "Do not output encoded version of DH parameters", 197 .desc = "Do not output encoded version of DH parameters",
198 .type = OPTION_FLAG, 198 .type = OPTION_FLAG,
199 .opt.flag = &dhparam_config.noout, 199 .opt.flag = &cfg.noout,
200 }, 200 },
201 { 201 {
202 .name = "out", 202 .name = "out",
203 .argname = "file", 203 .argname = "file",
204 .desc = "Output file (default stdout)", 204 .desc = "Output file (default stdout)",
205 .type = OPTION_ARG, 205 .type = OPTION_ARG,
206 .opt.arg = &dhparam_config.outfile, 206 .opt.arg = &cfg.outfile,
207 }, 207 },
208 { 208 {
209 .name = "outform", 209 .name = "outform",
210 .argname = "format", 210 .argname = "format",
211 .desc = "Output format (DER or PEM (default))", 211 .desc = "Output format (DER or PEM (default))",
212 .type = OPTION_ARG_FORMAT, 212 .type = OPTION_ARG_FORMAT,
213 .opt.value = &dhparam_config.outformat, 213 .opt.value = &cfg.outformat,
214 }, 214 },
215 { 215 {
216 .name = "text", 216 .name = "text",
217 .desc = "Print DH parameters in plain text", 217 .desc = "Print DH parameters in plain text",
218 .type = OPTION_FLAG, 218 .type = OPTION_FLAG,
219 .opt.flag = &dhparam_config.text, 219 .opt.flag = &cfg.text,
220 }, 220 },
221 { NULL }, 221 { NULL },
222}; 222};
@@ -249,10 +249,10 @@ dhparam_main(int argc, char **argv)
249 exit(1); 249 exit(1);
250 } 250 }
251 251
252 memset(&dhparam_config, 0, sizeof(dhparam_config)); 252 memset(&cfg, 0, sizeof(cfg));
253 253
254 dhparam_config.informat = FORMAT_PEM; 254 cfg.informat = FORMAT_PEM;
255 dhparam_config.outformat = FORMAT_PEM; 255 cfg.outformat = FORMAT_PEM;
256 256
257 if (options_parse(argc, argv, dhparam_options, &num_bits, NULL) != 0) { 257 if (options_parse(argc, argv, dhparam_options, &num_bits, NULL) != 0) {
258 dhparam_usage(); 258 dhparam_usage();
@@ -267,18 +267,18 @@ dhparam_main(int argc, char **argv)
267 } 267 }
268 } 268 }
269 269
270 if (dhparam_config.g && !num) 270 if (cfg.g && !num)
271 num = DEFBITS; 271 num = DEFBITS;
272 272
273 if (dhparam_config.dsaparam) { 273 if (cfg.dsaparam) {
274 if (dhparam_config.g) { 274 if (cfg.g) {
275 BIO_printf(bio_err, "generator may not be chosen for DSA parameters\n"); 275 BIO_printf(bio_err, "generator may not be chosen for DSA parameters\n");
276 goto end; 276 goto end;
277 } 277 }
278 } else { 278 } else {
279 /* DH parameters */ 279 /* DH parameters */
280 if (num && !dhparam_config.g) 280 if (num && !cfg.g)
281 dhparam_config.g = 2; 281 cfg.g = 2;
282 } 282 }
283 283
284 if (num) { 284 if (num) {
@@ -289,7 +289,7 @@ dhparam_main(int argc, char **argv)
289 } 289 }
290 290
291 BN_GENCB_set(cb, dh_cb, bio_err); 291 BN_GENCB_set(cb, dh_cb, bio_err);
292 if (dhparam_config.dsaparam) { 292 if (cfg.dsaparam) {
293 DSA *dsa = DSA_new(); 293 DSA *dsa = DSA_new();
294 294
295 BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num); 295 BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num);
@@ -307,9 +307,9 @@ dhparam_main(int argc, char **argv)
307 } 307 }
308 } else { 308 } else {
309 dh = DH_new(); 309 dh = DH_new();
310 BIO_printf(bio_err, "Generating DH parameters, %d bit long safe prime, generator %d\n", num, dhparam_config.g); 310 BIO_printf(bio_err, "Generating DH parameters, %d bit long safe prime, generator %d\n", num, cfg.g);
311 BIO_printf(bio_err, "This is going to take a long time\n"); 311 BIO_printf(bio_err, "This is going to take a long time\n");
312 if (!dh || !DH_generate_parameters_ex(dh, num, dhparam_config.g, cb)) { 312 if (!dh || !DH_generate_parameters_ex(dh, num, cfg.g, cb)) {
313 ERR_print_errors(bio_err); 313 ERR_print_errors(bio_err);
314 goto end; 314 goto end;
315 } 315 }
@@ -321,24 +321,24 @@ dhparam_main(int argc, char **argv)
321 ERR_print_errors(bio_err); 321 ERR_print_errors(bio_err);
322 goto end; 322 goto end;
323 } 323 }
324 if (dhparam_config.infile == NULL) 324 if (cfg.infile == NULL)
325 BIO_set_fp(in, stdin, BIO_NOCLOSE); 325 BIO_set_fp(in, stdin, BIO_NOCLOSE);
326 else { 326 else {
327 if (BIO_read_filename(in, dhparam_config.infile) <= 0) { 327 if (BIO_read_filename(in, cfg.infile) <= 0) {
328 perror(dhparam_config.infile); 328 perror(cfg.infile);
329 goto end; 329 goto end;
330 } 330 }
331 } 331 }
332 332
333 if (dhparam_config.informat != FORMAT_ASN1 && 333 if (cfg.informat != FORMAT_ASN1 &&
334 dhparam_config.informat != FORMAT_PEM) { 334 cfg.informat != FORMAT_PEM) {
335 BIO_printf(bio_err, "bad input format specified\n"); 335 BIO_printf(bio_err, "bad input format specified\n");
336 goto end; 336 goto end;
337 } 337 }
338 if (dhparam_config.dsaparam) { 338 if (cfg.dsaparam) {
339 DSA *dsa; 339 DSA *dsa;
340 340
341 if (dhparam_config.informat == FORMAT_ASN1) 341 if (cfg.informat == FORMAT_ASN1)
342 dsa = d2i_DSAparams_bio(in, NULL); 342 dsa = d2i_DSAparams_bio(in, NULL);
343 else /* informat == FORMAT_PEM */ 343 else /* informat == FORMAT_PEM */
344 dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL); 344 dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL);
@@ -356,7 +356,7 @@ dhparam_main(int argc, char **argv)
356 } 356 }
357 } else 357 } else
358 { 358 {
359 if (dhparam_config.informat == FORMAT_ASN1) 359 if (cfg.informat == FORMAT_ASN1)
360 dh = d2i_DHparams_bio(in, NULL); 360 dh = d2i_DHparams_bio(in, NULL);
361 else /* informat == FORMAT_PEM */ 361 else /* informat == FORMAT_PEM */
362 dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL); 362 dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
@@ -376,20 +376,20 @@ dhparam_main(int argc, char **argv)
376 ERR_print_errors(bio_err); 376 ERR_print_errors(bio_err);
377 goto end; 377 goto end;
378 } 378 }
379 if (dhparam_config.outfile == NULL) { 379 if (cfg.outfile == NULL) {
380 BIO_set_fp(out, stdout, BIO_NOCLOSE); 380 BIO_set_fp(out, stdout, BIO_NOCLOSE);
381 } else { 381 } else {
382 if (BIO_write_filename(out, dhparam_config.outfile) <= 0) { 382 if (BIO_write_filename(out, cfg.outfile) <= 0) {
383 perror(dhparam_config.outfile); 383 perror(cfg.outfile);
384 goto end; 384 goto end;
385 } 385 }
386 } 386 }
387 387
388 388
389 if (dhparam_config.text) { 389 if (cfg.text) {
390 DHparams_print(out, dh); 390 DHparams_print(out, dh);
391 } 391 }
392 if (dhparam_config.check) { 392 if (cfg.check) {
393 if (!DH_check(dh, &i)) { 393 if (!DH_check(dh, &i)) {
394 ERR_print_errors(bio_err); 394 ERR_print_errors(bio_err);
395 goto end; 395 goto end;
@@ -405,7 +405,7 @@ dhparam_main(int argc, char **argv)
405 if (i == 0) 405 if (i == 0)
406 printf("DH parameters appear to be ok.\n"); 406 printf("DH parameters appear to be ok.\n");
407 } 407 }
408 if (dhparam_config.C) { 408 if (cfg.C) {
409 unsigned char *data; 409 unsigned char *data;
410 int len, l, bits; 410 int len, l, bits;
411 411
@@ -454,10 +454,10 @@ dhparam_main(int argc, char **argv)
454 printf("\treturn(dh);\n\t}\n"); 454 printf("\treturn(dh);\n\t}\n");
455 free(data); 455 free(data);
456 } 456 }
457 if (!dhparam_config.noout) { 457 if (!cfg.noout) {
458 if (dhparam_config.outformat == FORMAT_ASN1) 458 if (cfg.outformat == FORMAT_ASN1)
459 i = i2d_DHparams_bio(out, dh); 459 i = i2d_DHparams_bio(out, dh);
460 else if (dhparam_config.outformat == FORMAT_PEM) 460 else if (cfg.outformat == FORMAT_PEM)
461 i = PEM_write_bio_DHparams(out, dh); 461 i = PEM_write_bio_DHparams(out, dh);
462 else { 462 else {
463 BIO_printf(bio_err, "bad output format specified for outfile\n"); 463 BIO_printf(bio_err, "bad output format specified for outfile\n");