diff options
Diffstat (limited to 'src/usr.bin/openssl/dhparam.c')
| -rw-r--r-- | src/usr.bin/openssl/dhparam.c | 60 |
1 files changed, 2 insertions, 58 deletions
diff --git a/src/usr.bin/openssl/dhparam.c b/src/usr.bin/openssl/dhparam.c index 00bf697264..752f9ee01a 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.18 2023/07/23 11:39:29 tb Exp $ */ | 1 | /* $OpenBSD: dhparam.c,v 1.19 2025/01/19 10:24:17 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 | * |
| @@ -132,7 +132,6 @@ | |||
| 132 | #define DEFBITS 2048 | 132 | #define DEFBITS 2048 |
| 133 | 133 | ||
| 134 | static struct { | 134 | static struct { |
| 135 | int C; | ||
| 136 | int check; | 135 | int check; |
| 137 | int dsaparam; | 136 | int dsaparam; |
| 138 | int g; | 137 | int g; |
| @@ -161,12 +160,6 @@ static const struct option dhparam_options[] = { | |||
| 161 | .value = 5, | 160 | .value = 5, |
| 162 | }, | 161 | }, |
| 163 | { | 162 | { |
| 164 | .name = "C", | ||
| 165 | .desc = "Convert DH parameters into C code", | ||
| 166 | .type = OPTION_FLAG, | ||
| 167 | .opt.flag = &cfg.C, | ||
| 168 | }, | ||
| 169 | { | ||
| 170 | .name = "check", | 163 | .name = "check", |
| 171 | .desc = "Check the DH parameters", | 164 | .desc = "Check the DH parameters", |
| 172 | .type = OPTION_FLAG, | 165 | .type = OPTION_FLAG, |
| @@ -225,7 +218,7 @@ static void | |||
| 225 | dhparam_usage(void) | 218 | dhparam_usage(void) |
| 226 | { | 219 | { |
| 227 | fprintf(stderr, | 220 | fprintf(stderr, |
| 228 | "usage: dhparam [-2 | -5] [-C] [-check] [-dsaparam]\n" | 221 | "usage: dhparam [-2 | -5] [-check] [-dsaparam]\n" |
| 229 | " [-in file] [-inform DER | PEM] [-noout] [-out file]\n" | 222 | " [-in file] [-inform DER | PEM] [-noout] [-out file]\n" |
| 230 | " [-outform DER | PEM] [-text] [numbits]\n\n"); | 223 | " [-outform DER | PEM] [-text] [numbits]\n\n"); |
| 231 | options_usage(dhparam_options); | 224 | options_usage(dhparam_options); |
| @@ -405,55 +398,6 @@ dhparam_main(int argc, char **argv) | |||
| 405 | if (i == 0) | 398 | if (i == 0) |
| 406 | printf("DH parameters appear to be ok.\n"); | 399 | printf("DH parameters appear to be ok.\n"); |
| 407 | } | 400 | } |
| 408 | if (cfg.C) { | ||
| 409 | unsigned char *data; | ||
| 410 | int len, l, bits; | ||
| 411 | |||
| 412 | len = BN_num_bytes(DH_get0_p(dh)); | ||
| 413 | bits = BN_num_bits(DH_get0_p(dh)); | ||
| 414 | data = malloc(len); | ||
| 415 | if (data == NULL) { | ||
| 416 | perror("malloc"); | ||
| 417 | goto end; | ||
| 418 | } | ||
| 419 | printf("#ifndef HEADER_DH_H\n" | ||
| 420 | "#include <openssl/dh.h>\n" | ||
| 421 | "#endif\n"); | ||
| 422 | printf("DH *get_dh%d()\n\t{\n", bits); | ||
| 423 | |||
| 424 | l = BN_bn2bin(DH_get0_p(dh), data); | ||
| 425 | printf("\tstatic unsigned char dh%d_p[] = {", bits); | ||
| 426 | for (i = 0; i < l; i++) { | ||
| 427 | if ((i % 12) == 0) | ||
| 428 | printf("\n\t\t"); | ||
| 429 | printf("0x%02X, ", data[i]); | ||
| 430 | } | ||
| 431 | printf("\n\t\t};\n"); | ||
| 432 | |||
| 433 | l = BN_bn2bin(DH_get0_g(dh), data); | ||
| 434 | printf("\tstatic unsigned char dh%d_g[] = {", bits); | ||
| 435 | for (i = 0; i < l; i++) { | ||
| 436 | if ((i % 12) == 0) | ||
| 437 | printf("\n\t\t"); | ||
| 438 | printf("0x%02X, ", data[i]); | ||
| 439 | } | ||
| 440 | printf("\n\t\t};\n"); | ||
| 441 | |||
| 442 | printf("\tDH *dh;\n"); | ||
| 443 | printf("\tBIGNUM *p = NULL, *g = NULL;\n\n"); | ||
| 444 | printf("\tif ((dh = DH_new()) == NULL) return(NULL);\n"); | ||
| 445 | printf("\tp = BN_bin2bn(dh%d_p, sizeof(dh%d_p), NULL);\n", | ||
| 446 | bits, bits); | ||
| 447 | printf("\tg = BN_bin2bn(dh%d_g, sizeof(dh%d_g), NULL);\n", | ||
| 448 | bits, bits); | ||
| 449 | printf("\tif (p == NULL || g == NULL)\n"); | ||
| 450 | printf("\t\t{ BN_free(p); BN_free(g); DH_free(dh); return(NULL); }\n"); | ||
| 451 | printf("\tDH_set0_pqg(dh, p, NULL, g);\n"); | ||
| 452 | if (DH_get_length(dh) > 0) | ||
| 453 | printf("\tDH_set_length(dh, %ld);\n", DH_get_length(dh)); | ||
| 454 | printf("\treturn(dh);\n\t}\n"); | ||
| 455 | free(data); | ||
| 456 | } | ||
| 457 | if (!cfg.noout) { | 401 | if (!cfg.noout) { |
| 458 | if (cfg.outformat == FORMAT_ASN1) | 402 | if (cfg.outformat == FORMAT_ASN1) |
| 459 | i = i2d_DHparams_bio(out, dh); | 403 | i = i2d_DHparams_bio(out, dh); |
