diff options
Diffstat (limited to 'src/usr.bin/openssl/prime.c')
-rw-r--r-- | src/usr.bin/openssl/prime.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/usr.bin/openssl/prime.c b/src/usr.bin/openssl/prime.c index 64b1953e33..d704d882fc 100644 --- a/src/usr.bin/openssl/prime.c +++ b/src/usr.bin/openssl/prime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: prime.c,v 1.16 2023/03/05 13:12:53 tb Exp $ */ | 1 | /* $OpenBSD: prime.c,v 1.17 2023/03/06 14:32:06 tb Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -62,7 +62,7 @@ static struct { | |||
62 | int generate; | 62 | int generate; |
63 | int hex; | 63 | int hex; |
64 | int safe; | 64 | int safe; |
65 | } prime_config; | 65 | } cfg; |
66 | 66 | ||
67 | static const struct option prime_options[] = { | 67 | static const struct option prime_options[] = { |
68 | { | 68 | { |
@@ -70,32 +70,32 @@ static const struct option prime_options[] = { | |||
70 | .argname = "n", | 70 | .argname = "n", |
71 | .desc = "Number of bits in the generated prime number", | 71 | .desc = "Number of bits in the generated prime number", |
72 | .type = OPTION_ARG_INT, | 72 | .type = OPTION_ARG_INT, |
73 | .opt.value = &prime_config.bits, | 73 | .opt.value = &cfg.bits, |
74 | }, | 74 | }, |
75 | { | 75 | { |
76 | .name = "checks", | 76 | .name = "checks", |
77 | .argname = "n", | 77 | .argname = "n", |
78 | .desc = "Miller-Rabin probabilistic primality test iterations", | 78 | .desc = "Miller-Rabin probabilistic primality test iterations", |
79 | .type = OPTION_ARG_INT, | 79 | .type = OPTION_ARG_INT, |
80 | .opt.value = &prime_config.checks, | 80 | .opt.value = &cfg.checks, |
81 | }, | 81 | }, |
82 | { | 82 | { |
83 | .name = "generate", | 83 | .name = "generate", |
84 | .desc = "Generate a pseudo-random prime number", | 84 | .desc = "Generate a pseudo-random prime number", |
85 | .type = OPTION_FLAG, | 85 | .type = OPTION_FLAG, |
86 | .opt.flag = &prime_config.generate, | 86 | .opt.flag = &cfg.generate, |
87 | }, | 87 | }, |
88 | { | 88 | { |
89 | .name = "hex", | 89 | .name = "hex", |
90 | .desc = "Hexadecimal prime numbers", | 90 | .desc = "Hexadecimal prime numbers", |
91 | .type = OPTION_FLAG, | 91 | .type = OPTION_FLAG, |
92 | .opt.flag = &prime_config.hex, | 92 | .opt.flag = &cfg.hex, |
93 | }, | 93 | }, |
94 | { | 94 | { |
95 | .name = "safe", | 95 | .name = "safe", |
96 | .desc = "Generate only \"safe\" prime numbers", | 96 | .desc = "Generate only \"safe\" prime numbers", |
97 | .type = OPTION_FLAG, | 97 | .type = OPTION_FLAG, |
98 | .opt.flag = &prime_config.safe, | 98 | .opt.flag = &cfg.safe, |
99 | }, | 99 | }, |
100 | {NULL}, | 100 | {NULL}, |
101 | }; | 101 | }; |
@@ -123,17 +123,17 @@ prime_main(int argc, char **argv) | |||
123 | exit(1); | 123 | exit(1); |
124 | } | 124 | } |
125 | 125 | ||
126 | memset(&prime_config, 0, sizeof(prime_config)); | 126 | memset(&cfg, 0, sizeof(cfg)); |
127 | 127 | ||
128 | /* Default iterations for Miller-Rabin probabilistic primality test. */ | 128 | /* Default iterations for Miller-Rabin probabilistic primality test. */ |
129 | prime_config.checks = 20; | 129 | cfg.checks = 20; |
130 | 130 | ||
131 | if (options_parse(argc, argv, prime_options, &prime, NULL) != 0) { | 131 | if (options_parse(argc, argv, prime_options, &prime, NULL) != 0) { |
132 | prime_usage(); | 132 | prime_usage(); |
133 | return (1); | 133 | return (1); |
134 | } | 134 | } |
135 | 135 | ||
136 | if (prime == NULL && prime_config.generate == 0) { | 136 | if (prime == NULL && cfg.generate == 0) { |
137 | BIO_printf(bio_err, "No prime specified.\n"); | 137 | BIO_printf(bio_err, "No prime specified.\n"); |
138 | prime_usage(); | 138 | prime_usage(); |
139 | return (1); | 139 | return (1); |
@@ -145,8 +145,8 @@ prime_main(int argc, char **argv) | |||
145 | } | 145 | } |
146 | BIO_set_fp(bio_out, stdout, BIO_NOCLOSE); | 146 | BIO_set_fp(bio_out, stdout, BIO_NOCLOSE); |
147 | 147 | ||
148 | if (prime_config.generate != 0) { | 148 | if (cfg.generate != 0) { |
149 | if (prime_config.bits == 0) { | 149 | if (cfg.bits == 0) { |
150 | BIO_printf(bio_err, "Specify the number of bits.\n"); | 150 | BIO_printf(bio_err, "Specify the number of bits.\n"); |
151 | goto end; | 151 | goto end; |
152 | } | 152 | } |
@@ -155,12 +155,12 @@ prime_main(int argc, char **argv) | |||
155 | BIO_printf(bio_err, "Out of memory.\n"); | 155 | BIO_printf(bio_err, "Out of memory.\n"); |
156 | goto end; | 156 | goto end; |
157 | } | 157 | } |
158 | if (!BN_generate_prime_ex(bn, prime_config.bits, | 158 | if (!BN_generate_prime_ex(bn, cfg.bits, |
159 | prime_config.safe, NULL, NULL, NULL)) { | 159 | cfg.safe, NULL, NULL, NULL)) { |
160 | BIO_printf(bio_err, "Prime generation error.\n"); | 160 | BIO_printf(bio_err, "Prime generation error.\n"); |
161 | goto end; | 161 | goto end; |
162 | } | 162 | } |
163 | s = prime_config.hex ? BN_bn2hex(bn) : BN_bn2dec(bn); | 163 | s = cfg.hex ? BN_bn2hex(bn) : BN_bn2dec(bn); |
164 | if (s == NULL) { | 164 | if (s == NULL) { |
165 | BIO_printf(bio_err, "Out of memory.\n"); | 165 | BIO_printf(bio_err, "Out of memory.\n"); |
166 | goto end; | 166 | goto end; |
@@ -168,7 +168,7 @@ prime_main(int argc, char **argv) | |||
168 | BIO_printf(bio_out, "%s\n", s); | 168 | BIO_printf(bio_out, "%s\n", s); |
169 | free(s); | 169 | free(s); |
170 | } else { | 170 | } else { |
171 | if (prime_config.hex) { | 171 | if (cfg.hex) { |
172 | if (!BN_hex2bn(&bn, prime)) { | 172 | if (!BN_hex2bn(&bn, prime)) { |
173 | BIO_printf(bio_err, "%s is an invalid hex " | 173 | BIO_printf(bio_err, "%s is an invalid hex " |
174 | "value.\n", prime); | 174 | "value.\n", prime); |
@@ -182,7 +182,7 @@ prime_main(int argc, char **argv) | |||
182 | } | 182 | } |
183 | } | 183 | } |
184 | 184 | ||
185 | is_prime = BN_is_prime_ex(bn, prime_config.checks, NULL, NULL); | 185 | is_prime = BN_is_prime_ex(bn, cfg.checks, NULL, NULL); |
186 | if (is_prime < 0) { | 186 | if (is_prime < 0) { |
187 | BIO_printf(bio_err, "BN_is_prime_ex failed.\n"); | 187 | BIO_printf(bio_err, "BN_is_prime_ex failed.\n"); |
188 | goto end; | 188 | goto end; |