diff options
author | tb <> | 2023-03-06 14:32:06 +0000 |
---|---|---|
committer | tb <> | 2023-03-06 14:32:06 +0000 |
commit | 6c965e26b1a93da63948edae6b68564be1ded507 (patch) | |
tree | bbe07d6e06b695cebe22802551f2db0a61354d7c /src/usr.bin/openssl/ecparam.c | |
parent | 48e828ea26ee91710242131cd75cd9d1d20b773c (diff) | |
download | openbsd-6c965e26b1a93da63948edae6b68564be1ded507.tar.gz openbsd-6c965e26b1a93da63948edae6b68564be1ded507.tar.bz2 openbsd-6c965e26b1a93da63948edae6b68564be1ded507.zip |
Rename struct ${app}_config to plain cfg
All the structs are static and we need to reach into them many times.
Having a shorter name is more concise and results in less visual clutter.
It also avoids many overlong lines and we will be able to get rid of some
unfortunate line wrapping down the road.
Discussed with jsing
Diffstat (limited to 'src/usr.bin/openssl/ecparam.c')
-rw-r--r-- | src/usr.bin/openssl/ecparam.c | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/src/usr.bin/openssl/ecparam.c b/src/usr.bin/openssl/ecparam.c index 52ccc491fc..933cd3eb69 100644 --- a/src/usr.bin/openssl/ecparam.c +++ b/src/usr.bin/openssl/ecparam.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecparam.c,v 1.22 2022/11/11 17:07:38 joshua Exp $ */ | 1 | /* $OpenBSD: ecparam.c,v 1.23 2023/03/06 14:32:06 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -107,21 +107,21 @@ static struct { | |||
107 | char *outfile; | 107 | char *outfile; |
108 | int outformat; | 108 | int outformat; |
109 | int text; | 109 | int text; |
110 | } ecparam_config; | 110 | } cfg; |
111 | 111 | ||
112 | static int | 112 | static int |
113 | ecparam_opt_form(char *arg) | 113 | ecparam_opt_form(char *arg) |
114 | { | 114 | { |
115 | if (strcmp(arg, "compressed") == 0) | 115 | if (strcmp(arg, "compressed") == 0) |
116 | ecparam_config.form = POINT_CONVERSION_COMPRESSED; | 116 | cfg.form = POINT_CONVERSION_COMPRESSED; |
117 | else if (strcmp(arg, "uncompressed") == 0) | 117 | else if (strcmp(arg, "uncompressed") == 0) |
118 | ecparam_config.form = POINT_CONVERSION_UNCOMPRESSED; | 118 | cfg.form = POINT_CONVERSION_UNCOMPRESSED; |
119 | else if (strcmp(arg, "hybrid") == 0) | 119 | else if (strcmp(arg, "hybrid") == 0) |
120 | ecparam_config.form = POINT_CONVERSION_HYBRID; | 120 | cfg.form = POINT_CONVERSION_HYBRID; |
121 | else | 121 | else |
122 | return (1); | 122 | return (1); |
123 | 123 | ||
124 | ecparam_config.new_form = 1; | 124 | cfg.new_form = 1; |
125 | return (0); | 125 | return (0); |
126 | } | 126 | } |
127 | 127 | ||
@@ -129,13 +129,13 @@ static int | |||
129 | ecparam_opt_enctype(char *arg) | 129 | ecparam_opt_enctype(char *arg) |
130 | { | 130 | { |
131 | if (strcmp(arg, "explicit") == 0) | 131 | if (strcmp(arg, "explicit") == 0) |
132 | ecparam_config.asn1_flag = 0; | 132 | cfg.asn1_flag = 0; |
133 | else if (strcmp(arg, "named_curve") == 0) | 133 | else if (strcmp(arg, "named_curve") == 0) |
134 | ecparam_config.asn1_flag = OPENSSL_EC_NAMED_CURVE; | 134 | cfg.asn1_flag = OPENSSL_EC_NAMED_CURVE; |
135 | else | 135 | else |
136 | return (1); | 136 | return (1); |
137 | 137 | ||
138 | ecparam_config.new_asn1_flag = 1; | 138 | cfg.new_asn1_flag = 1; |
139 | return (0); | 139 | return (0); |
140 | } | 140 | } |
141 | 141 | ||
@@ -144,13 +144,13 @@ static const struct option ecparam_options[] = { | |||
144 | .name = "C", | 144 | .name = "C", |
145 | .desc = "Convert the EC parameters into C code", | 145 | .desc = "Convert the EC parameters into C code", |
146 | .type = OPTION_FLAG, | 146 | .type = OPTION_FLAG, |
147 | .opt.flag = &ecparam_config.C, | 147 | .opt.flag = &cfg.C, |
148 | }, | 148 | }, |
149 | { | 149 | { |
150 | .name = "check", | 150 | .name = "check", |
151 | .desc = "Validate the elliptic curve parameters", | 151 | .desc = "Validate the elliptic curve parameters", |
152 | .type = OPTION_FLAG, | 152 | .type = OPTION_FLAG, |
153 | .opt.flag = &ecparam_config.check, | 153 | .opt.flag = &cfg.check, |
154 | }, | 154 | }, |
155 | { | 155 | { |
156 | .name = "conv_form", | 156 | .name = "conv_form", |
@@ -165,61 +165,61 @@ static const struct option ecparam_options[] = { | |||
165 | .desc = "Generate an EC private key using the specified " | 165 | .desc = "Generate an EC private key using the specified " |
166 | "parameters", | 166 | "parameters", |
167 | .type = OPTION_FLAG, | 167 | .type = OPTION_FLAG, |
168 | .opt.flag = &ecparam_config.genkey, | 168 | .opt.flag = &cfg.genkey, |
169 | }, | 169 | }, |
170 | { | 170 | { |
171 | .name = "in", | 171 | .name = "in", |
172 | .argname = "file", | 172 | .argname = "file", |
173 | .desc = "Input file to read parameters from (default stdin)", | 173 | .desc = "Input file to read parameters from (default stdin)", |
174 | .type = OPTION_ARG, | 174 | .type = OPTION_ARG, |
175 | .opt.arg = &ecparam_config.infile, | 175 | .opt.arg = &cfg.infile, |
176 | }, | 176 | }, |
177 | { | 177 | { |
178 | .name = "inform", | 178 | .name = "inform", |
179 | .argname = "format", | 179 | .argname = "format", |
180 | .desc = "Input format (DER or PEM)", | 180 | .desc = "Input format (DER or PEM)", |
181 | .type = OPTION_ARG_FORMAT, | 181 | .type = OPTION_ARG_FORMAT, |
182 | .opt.value = &ecparam_config.informat, | 182 | .opt.value = &cfg.informat, |
183 | }, | 183 | }, |
184 | { | 184 | { |
185 | .name = "list_curves", | 185 | .name = "list_curves", |
186 | .desc = "Print list of all currently implemented EC " | 186 | .desc = "Print list of all currently implemented EC " |
187 | "parameter names", | 187 | "parameter names", |
188 | .type = OPTION_FLAG, | 188 | .type = OPTION_FLAG, |
189 | .opt.flag = &ecparam_config.list_curves, | 189 | .opt.flag = &cfg.list_curves, |
190 | }, | 190 | }, |
191 | { | 191 | { |
192 | .name = "name", | 192 | .name = "name", |
193 | .argname = "curve", | 193 | .argname = "curve", |
194 | .desc = "Use the EC parameters with the specified name", | 194 | .desc = "Use the EC parameters with the specified name", |
195 | .type = OPTION_ARG, | 195 | .type = OPTION_ARG, |
196 | .opt.arg = &ecparam_config.curve_name, | 196 | .opt.arg = &cfg.curve_name, |
197 | }, | 197 | }, |
198 | { | 198 | { |
199 | .name = "no_seed", | 199 | .name = "no_seed", |
200 | .desc = "Do not output seed with explicit parameter encoding", | 200 | .desc = "Do not output seed with explicit parameter encoding", |
201 | .type = OPTION_FLAG, | 201 | .type = OPTION_FLAG, |
202 | .opt.flag = &ecparam_config.no_seed, | 202 | .opt.flag = &cfg.no_seed, |
203 | }, | 203 | }, |
204 | { | 204 | { |
205 | .name = "noout", | 205 | .name = "noout", |
206 | .desc = "Do not output encoded version of EC parameters", | 206 | .desc = "Do not output encoded version of EC parameters", |
207 | .type = OPTION_FLAG, | 207 | .type = OPTION_FLAG, |
208 | .opt.flag = &ecparam_config.noout, | 208 | .opt.flag = &cfg.noout, |
209 | }, | 209 | }, |
210 | { | 210 | { |
211 | .name = "out", | 211 | .name = "out", |
212 | .argname = "file", | 212 | .argname = "file", |
213 | .desc = "Output file to write parameters to (default stdout)", | 213 | .desc = "Output file to write parameters to (default stdout)", |
214 | .type = OPTION_ARG, | 214 | .type = OPTION_ARG, |
215 | .opt.arg = &ecparam_config.outfile, | 215 | .opt.arg = &cfg.outfile, |
216 | }, | 216 | }, |
217 | { | 217 | { |
218 | .name = "outform", | 218 | .name = "outform", |
219 | .argname = "format", | 219 | .argname = "format", |
220 | .desc = "Output format (DER or PEM)", | 220 | .desc = "Output format (DER or PEM)", |
221 | .type = OPTION_ARG_FORMAT, | 221 | .type = OPTION_ARG_FORMAT, |
222 | .opt.value = &ecparam_config.outformat, | 222 | .opt.value = &cfg.outformat, |
223 | }, | 223 | }, |
224 | { | 224 | { |
225 | .name = "param_enc", | 225 | .name = "param_enc", |
@@ -233,7 +233,7 @@ static const struct option ecparam_options[] = { | |||
233 | .name = "text", | 233 | .name = "text", |
234 | .desc = "Print out the EC parameters in human readable form", | 234 | .desc = "Print out the EC parameters in human readable form", |
235 | .type = OPTION_FLAG, | 235 | .type = OPTION_FLAG, |
236 | .opt.flag = &ecparam_config.text, | 236 | .opt.flag = &cfg.text, |
237 | }, | 237 | }, |
238 | {NULL}, | 238 | {NULL}, |
239 | }; | 239 | }; |
@@ -264,11 +264,11 @@ ecparam_main(int argc, char **argv) | |||
264 | exit(1); | 264 | exit(1); |
265 | } | 265 | } |
266 | 266 | ||
267 | memset(&ecparam_config, 0, sizeof(ecparam_config)); | 267 | memset(&cfg, 0, sizeof(cfg)); |
268 | ecparam_config.asn1_flag = OPENSSL_EC_NAMED_CURVE; | 268 | cfg.asn1_flag = OPENSSL_EC_NAMED_CURVE; |
269 | ecparam_config.form = POINT_CONVERSION_UNCOMPRESSED; | 269 | cfg.form = POINT_CONVERSION_UNCOMPRESSED; |
270 | ecparam_config.informat = FORMAT_PEM; | 270 | cfg.informat = FORMAT_PEM; |
271 | ecparam_config.outformat = FORMAT_PEM; | 271 | cfg.outformat = FORMAT_PEM; |
272 | 272 | ||
273 | if (options_parse(argc, argv, ecparam_options, NULL, NULL) != 0) { | 273 | if (options_parse(argc, argv, ecparam_options, NULL, NULL) != 0) { |
274 | ecparam_usage(); | 274 | ecparam_usage(); |
@@ -281,24 +281,24 @@ ecparam_main(int argc, char **argv) | |||
281 | ERR_print_errors(bio_err); | 281 | ERR_print_errors(bio_err); |
282 | goto end; | 282 | goto end; |
283 | } | 283 | } |
284 | if (ecparam_config.infile == NULL) | 284 | if (cfg.infile == NULL) |
285 | BIO_set_fp(in, stdin, BIO_NOCLOSE); | 285 | BIO_set_fp(in, stdin, BIO_NOCLOSE); |
286 | else { | 286 | else { |
287 | if (BIO_read_filename(in, ecparam_config.infile) <= 0) { | 287 | if (BIO_read_filename(in, cfg.infile) <= 0) { |
288 | perror(ecparam_config.infile); | 288 | perror(cfg.infile); |
289 | goto end; | 289 | goto end; |
290 | } | 290 | } |
291 | } | 291 | } |
292 | if (ecparam_config.outfile == NULL) { | 292 | if (cfg.outfile == NULL) { |
293 | BIO_set_fp(out, stdout, BIO_NOCLOSE); | 293 | BIO_set_fp(out, stdout, BIO_NOCLOSE); |
294 | } else { | 294 | } else { |
295 | if (BIO_write_filename(out, ecparam_config.outfile) <= 0) { | 295 | if (BIO_write_filename(out, cfg.outfile) <= 0) { |
296 | perror(ecparam_config.outfile); | 296 | perror(cfg.outfile); |
297 | goto end; | 297 | goto end; |
298 | } | 298 | } |
299 | } | 299 | } |
300 | 300 | ||
301 | if (ecparam_config.list_curves) { | 301 | if (cfg.list_curves) { |
302 | EC_builtin_curve *curves = NULL; | 302 | EC_builtin_curve *curves = NULL; |
303 | size_t crv_len = 0; | 303 | size_t crv_len = 0; |
304 | size_t n = 0; | 304 | size_t n = 0; |
@@ -331,7 +331,7 @@ ecparam_main(int argc, char **argv) | |||
331 | ret = 0; | 331 | ret = 0; |
332 | goto end; | 332 | goto end; |
333 | } | 333 | } |
334 | if (ecparam_config.curve_name != NULL) { | 334 | if (cfg.curve_name != NULL) { |
335 | int nid; | 335 | int nid; |
336 | 336 | ||
337 | /* | 337 | /* |
@@ -339,36 +339,36 @@ ecparam_main(int argc, char **argv) | |||
339 | * secp256r1 (which are the same as the curves prime192v1 and | 339 | * secp256r1 (which are the same as the curves prime192v1 and |
340 | * prime256v1 defined in X9.62) | 340 | * prime256v1 defined in X9.62) |
341 | */ | 341 | */ |
342 | if (!strcmp(ecparam_config.curve_name, "secp192r1")) { | 342 | if (!strcmp(cfg.curve_name, "secp192r1")) { |
343 | BIO_printf(bio_err, "using curve name prime192v1 " | 343 | BIO_printf(bio_err, "using curve name prime192v1 " |
344 | "instead of secp192r1\n"); | 344 | "instead of secp192r1\n"); |
345 | nid = NID_X9_62_prime192v1; | 345 | nid = NID_X9_62_prime192v1; |
346 | } else if (!strcmp(ecparam_config.curve_name, "secp256r1")) { | 346 | } else if (!strcmp(cfg.curve_name, "secp256r1")) { |
347 | BIO_printf(bio_err, "using curve name prime256v1 " | 347 | BIO_printf(bio_err, "using curve name prime256v1 " |
348 | "instead of secp256r1\n"); | 348 | "instead of secp256r1\n"); |
349 | nid = NID_X9_62_prime256v1; | 349 | nid = NID_X9_62_prime256v1; |
350 | } else | 350 | } else |
351 | nid = OBJ_sn2nid(ecparam_config.curve_name); | 351 | nid = OBJ_sn2nid(cfg.curve_name); |
352 | 352 | ||
353 | if (nid == 0) | 353 | if (nid == 0) |
354 | nid = EC_curve_nist2nid(ecparam_config.curve_name); | 354 | nid = EC_curve_nist2nid(cfg.curve_name); |
355 | 355 | ||
356 | if (nid == 0) { | 356 | if (nid == 0) { |
357 | BIO_printf(bio_err, "unknown curve name (%s)\n", | 357 | BIO_printf(bio_err, "unknown curve name (%s)\n", |
358 | ecparam_config.curve_name); | 358 | cfg.curve_name); |
359 | goto end; | 359 | goto end; |
360 | } | 360 | } |
361 | group = EC_GROUP_new_by_curve_name(nid); | 361 | group = EC_GROUP_new_by_curve_name(nid); |
362 | if (group == NULL) { | 362 | if (group == NULL) { |
363 | BIO_printf(bio_err, "unable to create curve (%s)\n", | 363 | BIO_printf(bio_err, "unable to create curve (%s)\n", |
364 | ecparam_config.curve_name); | 364 | cfg.curve_name); |
365 | goto end; | 365 | goto end; |
366 | } | 366 | } |
367 | EC_GROUP_set_asn1_flag(group, ecparam_config.asn1_flag); | 367 | EC_GROUP_set_asn1_flag(group, cfg.asn1_flag); |
368 | EC_GROUP_set_point_conversion_form(group, ecparam_config.form); | 368 | EC_GROUP_set_point_conversion_form(group, cfg.form); |
369 | } else if (ecparam_config.informat == FORMAT_ASN1) { | 369 | } else if (cfg.informat == FORMAT_ASN1) { |
370 | group = d2i_ECPKParameters_bio(in, NULL); | 370 | group = d2i_ECPKParameters_bio(in, NULL); |
371 | } else if (ecparam_config.informat == FORMAT_PEM) { | 371 | } else if (cfg.informat == FORMAT_PEM) { |
372 | group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL); | 372 | group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL); |
373 | } else { | 373 | } else { |
374 | BIO_printf(bio_err, "bad input format specified\n"); | 374 | BIO_printf(bio_err, "bad input format specified\n"); |
@@ -381,20 +381,20 @@ ecparam_main(int argc, char **argv) | |||
381 | ERR_print_errors(bio_err); | 381 | ERR_print_errors(bio_err); |
382 | goto end; | 382 | goto end; |
383 | } | 383 | } |
384 | if (ecparam_config.new_form) | 384 | if (cfg.new_form) |
385 | EC_GROUP_set_point_conversion_form(group, ecparam_config.form); | 385 | EC_GROUP_set_point_conversion_form(group, cfg.form); |
386 | 386 | ||
387 | if (ecparam_config.new_asn1_flag) | 387 | if (cfg.new_asn1_flag) |
388 | EC_GROUP_set_asn1_flag(group, ecparam_config.asn1_flag); | 388 | EC_GROUP_set_asn1_flag(group, cfg.asn1_flag); |
389 | 389 | ||
390 | if (ecparam_config.no_seed) | 390 | if (cfg.no_seed) |
391 | EC_GROUP_set_seed(group, NULL, 0); | 391 | EC_GROUP_set_seed(group, NULL, 0); |
392 | 392 | ||
393 | if (ecparam_config.text) { | 393 | if (cfg.text) { |
394 | if (!ECPKParameters_print(out, group, 0)) | 394 | if (!ECPKParameters_print(out, group, 0)) |
395 | goto end; | 395 | goto end; |
396 | } | 396 | } |
397 | if (ecparam_config.check) { | 397 | if (cfg.check) { |
398 | BIO_printf(bio_err, "checking elliptic curve parameters: "); | 398 | BIO_printf(bio_err, "checking elliptic curve parameters: "); |
399 | if (!EC_GROUP_check(group, NULL)) { | 399 | if (!EC_GROUP_check(group, NULL)) { |
400 | BIO_printf(bio_err, "failed\n"); | 400 | BIO_printf(bio_err, "failed\n"); |
@@ -403,7 +403,7 @@ ecparam_main(int argc, char **argv) | |||
403 | BIO_printf(bio_err, "ok\n"); | 403 | BIO_printf(bio_err, "ok\n"); |
404 | 404 | ||
405 | } | 405 | } |
406 | if (ecparam_config.C) { | 406 | if (cfg.C) { |
407 | size_t buf_len = 0, tmp_len = 0; | 407 | size_t buf_len = 0, tmp_len = 0; |
408 | const EC_POINT *point; | 408 | const EC_POINT *point; |
409 | int is_prime, len = 0; | 409 | int is_prime, len = 0; |
@@ -516,10 +516,10 @@ ecparam_main(int argc, char **argv) | |||
516 | BIO_printf(out, "\t\t}\n"); | 516 | BIO_printf(out, "\t\t}\n"); |
517 | BIO_printf(out, "\treturn(group);\n\t}\n"); | 517 | BIO_printf(out, "\treturn(group);\n\t}\n"); |
518 | } | 518 | } |
519 | if (!ecparam_config.noout) { | 519 | if (!cfg.noout) { |
520 | if (ecparam_config.outformat == FORMAT_ASN1) | 520 | if (cfg.outformat == FORMAT_ASN1) |
521 | i = i2d_ECPKParameters_bio(out, group); | 521 | i = i2d_ECPKParameters_bio(out, group); |
522 | else if (ecparam_config.outformat == FORMAT_PEM) | 522 | else if (cfg.outformat == FORMAT_PEM) |
523 | i = PEM_write_bio_ECPKParameters(out, group); | 523 | i = PEM_write_bio_ECPKParameters(out, group); |
524 | else { | 524 | else { |
525 | BIO_printf(bio_err, "bad output format specified for" | 525 | BIO_printf(bio_err, "bad output format specified for" |
@@ -533,7 +533,7 @@ ecparam_main(int argc, char **argv) | |||
533 | goto end; | 533 | goto end; |
534 | } | 534 | } |
535 | } | 535 | } |
536 | if (ecparam_config.genkey) { | 536 | if (cfg.genkey) { |
537 | EC_KEY *eckey = EC_KEY_new(); | 537 | EC_KEY *eckey = EC_KEY_new(); |
538 | 538 | ||
539 | if (eckey == NULL) | 539 | if (eckey == NULL) |
@@ -548,9 +548,9 @@ ecparam_main(int argc, char **argv) | |||
548 | EC_KEY_free(eckey); | 548 | EC_KEY_free(eckey); |
549 | goto end; | 549 | goto end; |
550 | } | 550 | } |
551 | if (ecparam_config.outformat == FORMAT_ASN1) | 551 | if (cfg.outformat == FORMAT_ASN1) |
552 | i = i2d_ECPrivateKey_bio(out, eckey); | 552 | i = i2d_ECPrivateKey_bio(out, eckey); |
553 | else if (ecparam_config.outformat == FORMAT_PEM) | 553 | else if (cfg.outformat == FORMAT_PEM) |
554 | i = PEM_write_bio_ECPrivateKey(out, eckey, NULL, | 554 | i = PEM_write_bio_ECPrivateKey(out, eckey, NULL, |
555 | NULL, 0, NULL, NULL); | 555 | NULL, 0, NULL, NULL); |
556 | else { | 556 | else { |