summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/rsa.c
diff options
context:
space:
mode:
authortb <>2023-03-06 14:32:06 +0000
committertb <>2023-03-06 14:32:06 +0000
commit6c965e26b1a93da63948edae6b68564be1ded507 (patch)
treebbe07d6e06b695cebe22802551f2db0a61354d7c /src/usr.bin/openssl/rsa.c
parent48e828ea26ee91710242131cd75cd9d1d20b773c (diff)
downloadopenbsd-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/rsa.c')
-rw-r--r--src/usr.bin/openssl/rsa.c108
1 files changed, 54 insertions, 54 deletions
diff --git a/src/usr.bin/openssl/rsa.c b/src/usr.bin/openssl/rsa.c
index bdd263ce7c..953daaacf7 100644
--- a/src/usr.bin/openssl/rsa.c
+++ b/src/usr.bin/openssl/rsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa.c,v 1.17 2022/11/11 17:07:39 joshua Exp $ */ 1/* $OpenBSD: rsa.c,v 1.18 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 *
@@ -89,7 +89,7 @@ static struct {
89 int pubout; 89 int pubout;
90 int pvk_encr; 90 int pvk_encr;
91 int text; 91 int text;
92} rsa_config; 92} cfg;
93 93
94static int 94static int
95rsa_opt_cipher(int argc, char **argv, int *argsused) 95rsa_opt_cipher(int argc, char **argv, int *argsused)
@@ -99,7 +99,7 @@ rsa_opt_cipher(int argc, char **argv, int *argsused)
99 if (*name++ != '-') 99 if (*name++ != '-')
100 return (1); 100 return (1);
101 101
102 if ((rsa_config.enc = EVP_get_cipherbyname(name)) == NULL) { 102 if ((cfg.enc = EVP_get_cipherbyname(name)) == NULL) {
103 fprintf(stderr, "Invalid cipher '%s'\n", name); 103 fprintf(stderr, "Invalid cipher '%s'\n", name);
104 return (1); 104 return (1);
105 } 105 }
@@ -113,111 +113,111 @@ static const struct option rsa_options[] = {
113 .name = "check", 113 .name = "check",
114 .desc = "Check consistency of RSA private key", 114 .desc = "Check consistency of RSA private key",
115 .type = OPTION_FLAG, 115 .type = OPTION_FLAG,
116 .opt.flag = &rsa_config.check, 116 .opt.flag = &cfg.check,
117 }, 117 },
118 { 118 {
119 .name = "in", 119 .name = "in",
120 .argname = "file", 120 .argname = "file",
121 .desc = "Input file (default stdin)", 121 .desc = "Input file (default stdin)",
122 .type = OPTION_ARG, 122 .type = OPTION_ARG,
123 .opt.arg = &rsa_config.infile, 123 .opt.arg = &cfg.infile,
124 }, 124 },
125 { 125 {
126 .name = "inform", 126 .name = "inform",
127 .argname = "format", 127 .argname = "format",
128 .desc = "Input format (DER, NET or PEM (default))", 128 .desc = "Input format (DER, NET or PEM (default))",
129 .type = OPTION_ARG_FORMAT, 129 .type = OPTION_ARG_FORMAT,
130 .opt.value = &rsa_config.informat, 130 .opt.value = &cfg.informat,
131 }, 131 },
132 { 132 {
133 .name = "modulus", 133 .name = "modulus",
134 .desc = "Print the RSA key modulus", 134 .desc = "Print the RSA key modulus",
135 .type = OPTION_FLAG, 135 .type = OPTION_FLAG,
136 .opt.flag = &rsa_config.modulus, 136 .opt.flag = &cfg.modulus,
137 }, 137 },
138 { 138 {
139 .name = "noout", 139 .name = "noout",
140 .desc = "Do not print encoded version of the key", 140 .desc = "Do not print encoded version of the key",
141 .type = OPTION_FLAG, 141 .type = OPTION_FLAG,
142 .opt.flag = &rsa_config.noout, 142 .opt.flag = &cfg.noout,
143 }, 143 },
144 { 144 {
145 .name = "out", 145 .name = "out",
146 .argname = "file", 146 .argname = "file",
147 .desc = "Output file (default stdout)", 147 .desc = "Output file (default stdout)",
148 .type = OPTION_ARG, 148 .type = OPTION_ARG,
149 .opt.arg = &rsa_config.outfile, 149 .opt.arg = &cfg.outfile,
150 }, 150 },
151 { 151 {
152 .name = "outform", 152 .name = "outform",
153 .argname = "format", 153 .argname = "format",
154 .desc = "Output format (DER, NET or PEM (default PEM))", 154 .desc = "Output format (DER, NET or PEM (default PEM))",
155 .type = OPTION_ARG_FORMAT, 155 .type = OPTION_ARG_FORMAT,
156 .opt.value = &rsa_config.outformat, 156 .opt.value = &cfg.outformat,
157 }, 157 },
158 { 158 {
159 .name = "passin", 159 .name = "passin",
160 .argname = "src", 160 .argname = "src",
161 .desc = "Input file passphrase source", 161 .desc = "Input file passphrase source",
162 .type = OPTION_ARG, 162 .type = OPTION_ARG,
163 .opt.arg = &rsa_config.passargin, 163 .opt.arg = &cfg.passargin,
164 }, 164 },
165 { 165 {
166 .name = "passout", 166 .name = "passout",
167 .argname = "src", 167 .argname = "src",
168 .desc = "Output file passphrase source", 168 .desc = "Output file passphrase source",
169 .type = OPTION_ARG, 169 .type = OPTION_ARG,
170 .opt.arg = &rsa_config.passargout, 170 .opt.arg = &cfg.passargout,
171 }, 171 },
172 { 172 {
173 .name = "pubin", 173 .name = "pubin",
174 .desc = "Expect a public key (default private key)", 174 .desc = "Expect a public key (default private key)",
175 .type = OPTION_VALUE, 175 .type = OPTION_VALUE,
176 .value = 1, 176 .value = 1,
177 .opt.value = &rsa_config.pubin, 177 .opt.value = &cfg.pubin,
178 }, 178 },
179 { 179 {
180 .name = "pubout", 180 .name = "pubout",
181 .desc = "Output a public key (default private key)", 181 .desc = "Output a public key (default private key)",
182 .type = OPTION_VALUE, 182 .type = OPTION_VALUE,
183 .value = 1, 183 .value = 1,
184 .opt.value = &rsa_config.pubout, 184 .opt.value = &cfg.pubout,
185 }, 185 },
186 { 186 {
187 .name = "pvk-none", 187 .name = "pvk-none",
188 .type = OPTION_VALUE, 188 .type = OPTION_VALUE,
189 .value = 0, 189 .value = 0,
190 .opt.value = &rsa_config.pvk_encr, 190 .opt.value = &cfg.pvk_encr,
191 }, 191 },
192 { 192 {
193 .name = "pvk-strong", 193 .name = "pvk-strong",
194 .type = OPTION_VALUE, 194 .type = OPTION_VALUE,
195 .value = 2, 195 .value = 2,
196 .opt.value = &rsa_config.pvk_encr, 196 .opt.value = &cfg.pvk_encr,
197 }, 197 },
198 { 198 {
199 .name = "pvk-weak", 199 .name = "pvk-weak",
200 .type = OPTION_VALUE, 200 .type = OPTION_VALUE,
201 .value = 1, 201 .value = 1,
202 .opt.value = &rsa_config.pvk_encr, 202 .opt.value = &cfg.pvk_encr,
203 }, 203 },
204 { 204 {
205 .name = "RSAPublicKey_in", 205 .name = "RSAPublicKey_in",
206 .type = OPTION_VALUE, 206 .type = OPTION_VALUE,
207 .value = 2, 207 .value = 2,
208 .opt.value = &rsa_config.pubin, 208 .opt.value = &cfg.pubin,
209 }, 209 },
210 { 210 {
211 .name = "RSAPublicKey_out", 211 .name = "RSAPublicKey_out",
212 .type = OPTION_VALUE, 212 .type = OPTION_VALUE,
213 .value = 2, 213 .value = 2,
214 .opt.value = &rsa_config.pubout, 214 .opt.value = &cfg.pubout,
215 }, 215 },
216 { 216 {
217 .name = "text", 217 .name = "text",
218 .desc = "Print in plain text in addition to encoded", 218 .desc = "Print in plain text in addition to encoded",
219 .type = OPTION_FLAG, 219 .type = OPTION_FLAG,
220 .opt.flag = &rsa_config.text, 220 .opt.flag = &cfg.text,
221 }, 221 },
222 { 222 {
223 .name = NULL, 223 .name = NULL,
@@ -260,22 +260,22 @@ rsa_main(int argc, char **argv)
260 exit(1); 260 exit(1);
261 } 261 }
262 262
263 memset(&rsa_config, 0, sizeof(rsa_config)); 263 memset(&cfg, 0, sizeof(cfg));
264 rsa_config.pvk_encr = 2; 264 cfg.pvk_encr = 2;
265 rsa_config.informat = FORMAT_PEM; 265 cfg.informat = FORMAT_PEM;
266 rsa_config.outformat = FORMAT_PEM; 266 cfg.outformat = FORMAT_PEM;
267 267
268 if (options_parse(argc, argv, rsa_options, NULL, NULL) != 0) { 268 if (options_parse(argc, argv, rsa_options, NULL, NULL) != 0) {
269 rsa_usage(); 269 rsa_usage();
270 goto end; 270 goto end;
271 } 271 }
272 272
273 if (!app_passwd(bio_err, rsa_config.passargin, rsa_config.passargout, 273 if (!app_passwd(bio_err, cfg.passargin, cfg.passargout,
274 &passin, &passout)) { 274 &passin, &passout)) {
275 BIO_printf(bio_err, "Error getting passwords\n"); 275 BIO_printf(bio_err, "Error getting passwords\n");
276 goto end; 276 goto end;
277 } 277 }
278 if (rsa_config.check && rsa_config.pubin) { 278 if (cfg.check && cfg.pubin) {
279 BIO_printf(bio_err, "Only private keys can be checked\n"); 279 BIO_printf(bio_err, "Only private keys can be checked\n");
280 goto end; 280 goto end;
281 } 281 }
@@ -284,21 +284,21 @@ rsa_main(int argc, char **argv)
284 { 284 {
285 EVP_PKEY *pkey; 285 EVP_PKEY *pkey;
286 286
287 if (rsa_config.pubin) { 287 if (cfg.pubin) {
288 int tmpformat = -1; 288 int tmpformat = -1;
289 if (rsa_config.pubin == 2) { 289 if (cfg.pubin == 2) {
290 if (rsa_config.informat == FORMAT_PEM) 290 if (cfg.informat == FORMAT_PEM)
291 tmpformat = FORMAT_PEMRSA; 291 tmpformat = FORMAT_PEMRSA;
292 else if (rsa_config.informat == FORMAT_ASN1) 292 else if (cfg.informat == FORMAT_ASN1)
293 tmpformat = FORMAT_ASN1RSA; 293 tmpformat = FORMAT_ASN1RSA;
294 } else 294 } else
295 tmpformat = rsa_config.informat; 295 tmpformat = cfg.informat;
296 296
297 pkey = load_pubkey(bio_err, rsa_config.infile, 297 pkey = load_pubkey(bio_err, cfg.infile,
298 tmpformat, 1, passin, "Public Key"); 298 tmpformat, 1, passin, "Public Key");
299 } else 299 } else
300 pkey = load_key(bio_err, rsa_config.infile, 300 pkey = load_key(bio_err, cfg.infile,
301 rsa_config.informat, 1, passin, "Private Key"); 301 cfg.informat, 1, passin, "Private Key");
302 302
303 if (pkey != NULL) 303 if (pkey != NULL)
304 rsa = EVP_PKEY_get1_RSA(pkey); 304 rsa = EVP_PKEY_get1_RSA(pkey);
@@ -309,27 +309,27 @@ rsa_main(int argc, char **argv)
309 ERR_print_errors(bio_err); 309 ERR_print_errors(bio_err);
310 goto end; 310 goto end;
311 } 311 }
312 if (rsa_config.outfile == NULL) { 312 if (cfg.outfile == NULL) {
313 BIO_set_fp(out, stdout, BIO_NOCLOSE); 313 BIO_set_fp(out, stdout, BIO_NOCLOSE);
314 } else { 314 } else {
315 if (BIO_write_filename(out, rsa_config.outfile) <= 0) { 315 if (BIO_write_filename(out, cfg.outfile) <= 0) {
316 perror(rsa_config.outfile); 316 perror(cfg.outfile);
317 goto end; 317 goto end;
318 } 318 }
319 } 319 }
320 320
321 if (rsa_config.text) 321 if (cfg.text)
322 if (!RSA_print(out, rsa, 0)) { 322 if (!RSA_print(out, rsa, 0)) {
323 perror(rsa_config.outfile); 323 perror(cfg.outfile);
324 ERR_print_errors(bio_err); 324 ERR_print_errors(bio_err);
325 goto end; 325 goto end;
326 } 326 }
327 if (rsa_config.modulus) { 327 if (cfg.modulus) {
328 BIO_printf(out, "Modulus="); 328 BIO_printf(out, "Modulus=");
329 BN_print(out, RSA_get0_n(rsa)); 329 BN_print(out, RSA_get0_n(rsa));
330 BIO_printf(out, "\n"); 330 BIO_printf(out, "\n");
331 } 331 }
332 if (rsa_config.check) { 332 if (cfg.check) {
333 int r = RSA_check_key(rsa); 333 int r = RSA_check_key(rsa);
334 334
335 if (r == 1) 335 if (r == 1)
@@ -353,38 +353,38 @@ rsa_main(int argc, char **argv)
353 goto end; 353 goto end;
354 } 354 }
355 } 355 }
356 if (rsa_config.noout) { 356 if (cfg.noout) {
357 ret = 0; 357 ret = 0;
358 goto end; 358 goto end;
359 } 359 }
360 BIO_printf(bio_err, "writing RSA key\n"); 360 BIO_printf(bio_err, "writing RSA key\n");
361 if (rsa_config.outformat == FORMAT_ASN1) { 361 if (cfg.outformat == FORMAT_ASN1) {
362 if (rsa_config.pubout || rsa_config.pubin) { 362 if (cfg.pubout || cfg.pubin) {
363 if (rsa_config.pubout == 2) 363 if (cfg.pubout == 2)
364 i = i2d_RSAPublicKey_bio(out, rsa); 364 i = i2d_RSAPublicKey_bio(out, rsa);
365 else 365 else
366 i = i2d_RSA_PUBKEY_bio(out, rsa); 366 i = i2d_RSA_PUBKEY_bio(out, rsa);
367 } else 367 } else
368 i = i2d_RSAPrivateKey_bio(out, rsa); 368 i = i2d_RSAPrivateKey_bio(out, rsa);
369 } else if (rsa_config.outformat == FORMAT_PEM) { 369 } else if (cfg.outformat == FORMAT_PEM) {
370 if (rsa_config.pubout || rsa_config.pubin) { 370 if (cfg.pubout || cfg.pubin) {
371 if (rsa_config.pubout == 2) 371 if (cfg.pubout == 2)
372 i = PEM_write_bio_RSAPublicKey(out, rsa); 372 i = PEM_write_bio_RSAPublicKey(out, rsa);
373 else 373 else
374 i = PEM_write_bio_RSA_PUBKEY(out, rsa); 374 i = PEM_write_bio_RSA_PUBKEY(out, rsa);
375 } else 375 } else
376 i = PEM_write_bio_RSAPrivateKey(out, rsa, 376 i = PEM_write_bio_RSAPrivateKey(out, rsa,
377 rsa_config.enc, NULL, 0, NULL, passout); 377 cfg.enc, NULL, 0, NULL, passout);
378#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4) 378#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)
379 } else if (rsa_config.outformat == FORMAT_MSBLOB || 379 } else if (cfg.outformat == FORMAT_MSBLOB ||
380 rsa_config.outformat == FORMAT_PVK) { 380 cfg.outformat == FORMAT_PVK) {
381 EVP_PKEY *pk; 381 EVP_PKEY *pk;
382 pk = EVP_PKEY_new(); 382 pk = EVP_PKEY_new();
383 EVP_PKEY_set1_RSA(pk, rsa); 383 EVP_PKEY_set1_RSA(pk, rsa);
384 if (rsa_config.outformat == FORMAT_PVK) 384 if (cfg.outformat == FORMAT_PVK)
385 i = i2b_PVK_bio(out, pk, rsa_config.pvk_encr, 0, 385 i = i2b_PVK_bio(out, pk, cfg.pvk_encr, 0,
386 passout); 386 passout);
387 else if (rsa_config.pubin || rsa_config.pubout) 387 else if (cfg.pubin || cfg.pubout)
388 i = i2b_PublicKey_bio(out, pk); 388 i = i2b_PublicKey_bio(out, pk);
389 else 389 else
390 i = i2b_PrivateKey_bio(out, pk); 390 i = i2b_PrivateKey_bio(out, pk);