diff options
Diffstat (limited to '')
| -rw-r--r-- | src/usr.bin/openssl/ec.c | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/src/usr.bin/openssl/ec.c b/src/usr.bin/openssl/ec.c index 3dace88d6f..c6af1263d4 100644 --- a/src/usr.bin/openssl/ec.c +++ b/src/usr.bin/openssl/ec.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec.c,v 1.15 2022/11/11 17:07:38 joshua Exp $ */ | 1 | /* $OpenBSD: ec.c,v 1.16 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 | */ |
| @@ -88,7 +88,7 @@ static struct { | |||
| 88 | int pubin; | 88 | int pubin; |
| 89 | int pubout; | 89 | int pubout; |
| 90 | int text; | 90 | int text; |
| 91 | } ec_config; | 91 | } cfg; |
| 92 | 92 | ||
| 93 | static int | 93 | static int |
| 94 | ec_opt_enc(int argc, char **argv, int *argsused) | 94 | ec_opt_enc(int argc, char **argv, int *argsused) |
| @@ -98,7 +98,7 @@ ec_opt_enc(int argc, char **argv, int *argsused) | |||
| 98 | if (*name++ != '-') | 98 | if (*name++ != '-') |
| 99 | return (1); | 99 | return (1); |
| 100 | 100 | ||
| 101 | if ((ec_config.enc = EVP_get_cipherbyname(name)) != NULL) { | 101 | if ((cfg.enc = EVP_get_cipherbyname(name)) != NULL) { |
| 102 | *argsused = 1; | 102 | *argsused = 1; |
| 103 | return (0); | 103 | return (0); |
| 104 | } | 104 | } |
| @@ -110,17 +110,17 @@ static int | |||
| 110 | ec_opt_form(char *arg) | 110 | ec_opt_form(char *arg) |
| 111 | { | 111 | { |
| 112 | if (strcmp(arg, "compressed") == 0) | 112 | if (strcmp(arg, "compressed") == 0) |
| 113 | ec_config.form = POINT_CONVERSION_COMPRESSED; | 113 | cfg.form = POINT_CONVERSION_COMPRESSED; |
| 114 | else if (strcmp(arg, "uncompressed") == 0) | 114 | else if (strcmp(arg, "uncompressed") == 0) |
| 115 | ec_config.form = POINT_CONVERSION_UNCOMPRESSED; | 115 | cfg.form = POINT_CONVERSION_UNCOMPRESSED; |
| 116 | else if (strcmp(arg, "hybrid") == 0) | 116 | else if (strcmp(arg, "hybrid") == 0) |
| 117 | ec_config.form = POINT_CONVERSION_HYBRID; | 117 | cfg.form = POINT_CONVERSION_HYBRID; |
| 118 | else { | 118 | else { |
| 119 | fprintf(stderr, "Invalid point conversion: %s\n", arg); | 119 | fprintf(stderr, "Invalid point conversion: %s\n", arg); |
| 120 | return (1); | 120 | return (1); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | ec_config.new_form = 1; | 123 | cfg.new_form = 1; |
| 124 | return (0); | 124 | return (0); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| @@ -128,15 +128,15 @@ static int | |||
| 128 | ec_opt_named(char *arg) | 128 | ec_opt_named(char *arg) |
| 129 | { | 129 | { |
| 130 | if (strcmp(arg, "named_curve") == 0) | 130 | if (strcmp(arg, "named_curve") == 0) |
| 131 | ec_config.asn1_flag = OPENSSL_EC_NAMED_CURVE; | 131 | cfg.asn1_flag = OPENSSL_EC_NAMED_CURVE; |
| 132 | else if (strcmp(arg, "explicit") == 0) | 132 | else if (strcmp(arg, "explicit") == 0) |
| 133 | ec_config.asn1_flag = 0; | 133 | cfg.asn1_flag = 0; |
| 134 | else { | 134 | else { |
| 135 | fprintf(stderr, "Invalid curve type: %s\n", arg); | 135 | fprintf(stderr, "Invalid curve type: %s\n", arg); |
| 136 | return (1); | 136 | return (1); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | ec_config.new_asn1_flag = 1; | 139 | cfg.new_asn1_flag = 1; |
| 140 | return (0); | 140 | return (0); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| @@ -154,34 +154,34 @@ static const struct option ec_options[] = { | |||
| 154 | .argname = "file", | 154 | .argname = "file", |
| 155 | .desc = "Input file (default stdin)", | 155 | .desc = "Input file (default stdin)", |
| 156 | .type = OPTION_ARG, | 156 | .type = OPTION_ARG, |
| 157 | .opt.arg = &ec_config.infile, | 157 | .opt.arg = &cfg.infile, |
| 158 | }, | 158 | }, |
| 159 | { | 159 | { |
| 160 | .name = "inform", | 160 | .name = "inform", |
| 161 | .argname = "format", | 161 | .argname = "format", |
| 162 | .desc = "Input format (DER or PEM (default))", | 162 | .desc = "Input format (DER or PEM (default))", |
| 163 | .type = OPTION_ARG_FORMAT, | 163 | .type = OPTION_ARG_FORMAT, |
| 164 | .opt.value = &ec_config.informat, | 164 | .opt.value = &cfg.informat, |
| 165 | }, | 165 | }, |
| 166 | { | 166 | { |
| 167 | .name = "noout", | 167 | .name = "noout", |
| 168 | .desc = "No output", | 168 | .desc = "No output", |
| 169 | .type = OPTION_FLAG, | 169 | .type = OPTION_FLAG, |
| 170 | .opt.flag = &ec_config.noout, | 170 | .opt.flag = &cfg.noout, |
| 171 | }, | 171 | }, |
| 172 | { | 172 | { |
| 173 | .name = "out", | 173 | .name = "out", |
| 174 | .argname = "file", | 174 | .argname = "file", |
| 175 | .desc = "Output file (default stdout)", | 175 | .desc = "Output file (default stdout)", |
| 176 | .type = OPTION_ARG, | 176 | .type = OPTION_ARG, |
| 177 | .opt.arg = &ec_config.outfile, | 177 | .opt.arg = &cfg.outfile, |
| 178 | }, | 178 | }, |
| 179 | { | 179 | { |
| 180 | .name = "outform", | 180 | .name = "outform", |
| 181 | .argname = "format", | 181 | .argname = "format", |
| 182 | .desc = "Output format (DER or PEM (default))", | 182 | .desc = "Output format (DER or PEM (default))", |
| 183 | .type = OPTION_ARG_FORMAT, | 183 | .type = OPTION_ARG_FORMAT, |
| 184 | .opt.value = &ec_config.outformat, | 184 | .opt.value = &cfg.outformat, |
| 185 | }, | 185 | }, |
| 186 | { | 186 | { |
| 187 | .name = "param_enc", | 187 | .name = "param_enc", |
| @@ -195,39 +195,39 @@ static const struct option ec_options[] = { | |||
| 195 | .name = "param_out", | 195 | .name = "param_out", |
| 196 | .desc = "Print the elliptic curve parameters", | 196 | .desc = "Print the elliptic curve parameters", |
| 197 | .type = OPTION_FLAG, | 197 | .type = OPTION_FLAG, |
| 198 | .opt.flag = &ec_config.param_out, | 198 | .opt.flag = &cfg.param_out, |
| 199 | }, | 199 | }, |
| 200 | { | 200 | { |
| 201 | .name = "passin", | 201 | .name = "passin", |
| 202 | .argname = "source", | 202 | .argname = "source", |
| 203 | .desc = "Input file passphrase source", | 203 | .desc = "Input file passphrase source", |
| 204 | .type = OPTION_ARG, | 204 | .type = OPTION_ARG, |
| 205 | .opt.arg = &ec_config.passargin, | 205 | .opt.arg = &cfg.passargin, |
| 206 | }, | 206 | }, |
| 207 | { | 207 | { |
| 208 | .name = "passout", | 208 | .name = "passout", |
| 209 | .argname = "source", | 209 | .argname = "source", |
| 210 | .desc = "Output file passphrase source", | 210 | .desc = "Output file passphrase source", |
| 211 | .type = OPTION_ARG, | 211 | .type = OPTION_ARG, |
| 212 | .opt.arg = &ec_config.passargout, | 212 | .opt.arg = &cfg.passargout, |
| 213 | }, | 213 | }, |
| 214 | { | 214 | { |
| 215 | .name = "pubin", | 215 | .name = "pubin", |
| 216 | .desc = "Read public key instead of private key from input", | 216 | .desc = "Read public key instead of private key from input", |
| 217 | .type = OPTION_FLAG, | 217 | .type = OPTION_FLAG, |
| 218 | .opt.flag = &ec_config.pubin, | 218 | .opt.flag = &cfg.pubin, |
| 219 | }, | 219 | }, |
| 220 | { | 220 | { |
| 221 | .name = "pubout", | 221 | .name = "pubout", |
| 222 | .desc = "Output public key instead of private key in output", | 222 | .desc = "Output public key instead of private key in output", |
| 223 | .type = OPTION_FLAG, | 223 | .type = OPTION_FLAG, |
| 224 | .opt.flag = &ec_config.pubout, | 224 | .opt.flag = &cfg.pubout, |
| 225 | }, | 225 | }, |
| 226 | { | 226 | { |
| 227 | .name = "text", | 227 | .name = "text", |
| 228 | .desc = "Print the public/private key components and parameters", | 228 | .desc = "Print the public/private key components and parameters", |
| 229 | .type = OPTION_FLAG, | 229 | .type = OPTION_FLAG, |
| 230 | .opt.flag = &ec_config.text, | 230 | .opt.flag = &cfg.text, |
| 231 | }, | 231 | }, |
| 232 | { | 232 | { |
| 233 | .name = NULL, | 233 | .name = NULL, |
| @@ -272,19 +272,19 @@ ec_main(int argc, char **argv) | |||
| 272 | exit(1); | 272 | exit(1); |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | memset(&ec_config, 0, sizeof(ec_config)); | 275 | memset(&cfg, 0, sizeof(cfg)); |
| 276 | 276 | ||
| 277 | ec_config.asn1_flag = OPENSSL_EC_NAMED_CURVE; | 277 | cfg.asn1_flag = OPENSSL_EC_NAMED_CURVE; |
| 278 | ec_config.form = POINT_CONVERSION_UNCOMPRESSED; | 278 | cfg.form = POINT_CONVERSION_UNCOMPRESSED; |
| 279 | ec_config.informat = FORMAT_PEM; | 279 | cfg.informat = FORMAT_PEM; |
| 280 | ec_config.outformat = FORMAT_PEM; | 280 | cfg.outformat = FORMAT_PEM; |
| 281 | 281 | ||
| 282 | if (options_parse(argc, argv, ec_options, NULL, NULL) != 0) { | 282 | if (options_parse(argc, argv, ec_options, NULL, NULL) != 0) { |
| 283 | ec_usage(); | 283 | ec_usage(); |
| 284 | goto end; | 284 | goto end; |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | if (!app_passwd(bio_err, ec_config.passargin, ec_config.passargout, | 287 | if (!app_passwd(bio_err, cfg.passargin, cfg.passargout, |
| 288 | &passin, &passout)) { | 288 | &passin, &passout)) { |
| 289 | BIO_printf(bio_err, "Error getting passwords\n"); | 289 | BIO_printf(bio_err, "Error getting passwords\n"); |
| 290 | goto end; | 290 | goto end; |
| @@ -295,23 +295,23 @@ ec_main(int argc, char **argv) | |||
| 295 | ERR_print_errors(bio_err); | 295 | ERR_print_errors(bio_err); |
| 296 | goto end; | 296 | goto end; |
| 297 | } | 297 | } |
| 298 | if (ec_config.infile == NULL) | 298 | if (cfg.infile == NULL) |
| 299 | BIO_set_fp(in, stdin, BIO_NOCLOSE); | 299 | BIO_set_fp(in, stdin, BIO_NOCLOSE); |
| 300 | else { | 300 | else { |
| 301 | if (BIO_read_filename(in, ec_config.infile) <= 0) { | 301 | if (BIO_read_filename(in, cfg.infile) <= 0) { |
| 302 | perror(ec_config.infile); | 302 | perror(cfg.infile); |
| 303 | goto end; | 303 | goto end; |
| 304 | } | 304 | } |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | BIO_printf(bio_err, "read EC key\n"); | 307 | BIO_printf(bio_err, "read EC key\n"); |
| 308 | if (ec_config.informat == FORMAT_ASN1) { | 308 | if (cfg.informat == FORMAT_ASN1) { |
| 309 | if (ec_config.pubin) | 309 | if (cfg.pubin) |
| 310 | eckey = d2i_EC_PUBKEY_bio(in, NULL); | 310 | eckey = d2i_EC_PUBKEY_bio(in, NULL); |
| 311 | else | 311 | else |
| 312 | eckey = d2i_ECPrivateKey_bio(in, NULL); | 312 | eckey = d2i_ECPrivateKey_bio(in, NULL); |
| 313 | } else if (ec_config.informat == FORMAT_PEM) { | 313 | } else if (cfg.informat == FORMAT_PEM) { |
| 314 | if (ec_config.pubin) | 314 | if (cfg.pubin) |
| 315 | eckey = PEM_read_bio_EC_PUBKEY(in, NULL, NULL, | 315 | eckey = PEM_read_bio_EC_PUBKEY(in, NULL, NULL, |
| 316 | NULL); | 316 | NULL); |
| 317 | else | 317 | else |
| @@ -326,49 +326,49 @@ ec_main(int argc, char **argv) | |||
| 326 | ERR_print_errors(bio_err); | 326 | ERR_print_errors(bio_err); |
| 327 | goto end; | 327 | goto end; |
| 328 | } | 328 | } |
| 329 | if (ec_config.outfile == NULL) { | 329 | if (cfg.outfile == NULL) { |
| 330 | BIO_set_fp(out, stdout, BIO_NOCLOSE); | 330 | BIO_set_fp(out, stdout, BIO_NOCLOSE); |
| 331 | } else { | 331 | } else { |
| 332 | if (BIO_write_filename(out, ec_config.outfile) <= 0) { | 332 | if (BIO_write_filename(out, cfg.outfile) <= 0) { |
| 333 | perror(ec_config.outfile); | 333 | perror(cfg.outfile); |
| 334 | goto end; | 334 | goto end; |
| 335 | } | 335 | } |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | group = EC_KEY_get0_group(eckey); | 338 | group = EC_KEY_get0_group(eckey); |
| 339 | 339 | ||
| 340 | if (ec_config.new_form) | 340 | if (cfg.new_form) |
| 341 | EC_KEY_set_conv_form(eckey, ec_config.form); | 341 | EC_KEY_set_conv_form(eckey, cfg.form); |
| 342 | 342 | ||
| 343 | if (ec_config.new_asn1_flag) | 343 | if (cfg.new_asn1_flag) |
| 344 | EC_KEY_set_asn1_flag(eckey, ec_config.asn1_flag); | 344 | EC_KEY_set_asn1_flag(eckey, cfg.asn1_flag); |
| 345 | 345 | ||
| 346 | if (ec_config.text) | 346 | if (cfg.text) |
| 347 | if (!EC_KEY_print(out, eckey, 0)) { | 347 | if (!EC_KEY_print(out, eckey, 0)) { |
| 348 | perror(ec_config.outfile); | 348 | perror(cfg.outfile); |
| 349 | ERR_print_errors(bio_err); | 349 | ERR_print_errors(bio_err); |
| 350 | goto end; | 350 | goto end; |
| 351 | } | 351 | } |
| 352 | if (ec_config.noout) { | 352 | if (cfg.noout) { |
| 353 | ret = 0; | 353 | ret = 0; |
| 354 | goto end; | 354 | goto end; |
| 355 | } | 355 | } |
| 356 | BIO_printf(bio_err, "writing EC key\n"); | 356 | BIO_printf(bio_err, "writing EC key\n"); |
| 357 | if (ec_config.outformat == FORMAT_ASN1) { | 357 | if (cfg.outformat == FORMAT_ASN1) { |
| 358 | if (ec_config.param_out) | 358 | if (cfg.param_out) |
| 359 | i = i2d_ECPKParameters_bio(out, group); | 359 | i = i2d_ECPKParameters_bio(out, group); |
| 360 | else if (ec_config.pubin || ec_config.pubout) | 360 | else if (cfg.pubin || cfg.pubout) |
| 361 | i = i2d_EC_PUBKEY_bio(out, eckey); | 361 | i = i2d_EC_PUBKEY_bio(out, eckey); |
| 362 | else | 362 | else |
| 363 | i = i2d_ECPrivateKey_bio(out, eckey); | 363 | i = i2d_ECPrivateKey_bio(out, eckey); |
| 364 | } else if (ec_config.outformat == FORMAT_PEM) { | 364 | } else if (cfg.outformat == FORMAT_PEM) { |
| 365 | if (ec_config.param_out) | 365 | if (cfg.param_out) |
| 366 | i = PEM_write_bio_ECPKParameters(out, group); | 366 | i = PEM_write_bio_ECPKParameters(out, group); |
| 367 | else if (ec_config.pubin || ec_config.pubout) | 367 | else if (cfg.pubin || cfg.pubout) |
| 368 | i = PEM_write_bio_EC_PUBKEY(out, eckey); | 368 | i = PEM_write_bio_EC_PUBKEY(out, eckey); |
| 369 | else | 369 | else |
| 370 | i = PEM_write_bio_ECPrivateKey(out, eckey, | 370 | i = PEM_write_bio_ECPrivateKey(out, eckey, |
| 371 | ec_config.enc, NULL, 0, NULL, passout); | 371 | cfg.enc, NULL, 0, NULL, passout); |
| 372 | } else { | 372 | } else { |
| 373 | BIO_printf(bio_err, "bad output format specified for " | 373 | BIO_printf(bio_err, "bad output format specified for " |
| 374 | "outfile\n"); | 374 | "outfile\n"); |
