summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/genpkey.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/genpkey.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/genpkey.c')
-rw-r--r--src/usr.bin/openssl/genpkey.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/usr.bin/openssl/genpkey.c b/src/usr.bin/openssl/genpkey.c
index ce266f404c..e2445c1433 100644
--- a/src/usr.bin/openssl/genpkey.c
+++ b/src/usr.bin/openssl/genpkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: genpkey.c,v 1.15 2023/03/05 13:12:53 tb Exp $ */ 1/* $OpenBSD: genpkey.c,v 1.16 2023/03/06 14:32:06 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006 3 * project 2006
4 */ 4 */
@@ -76,13 +76,13 @@ static struct {
76 int outformat; 76 int outformat;
77 char *passarg; 77 char *passarg;
78 int text; 78 int text;
79} genpkey_config; 79} cfg;
80 80
81static int 81static int
82genpkey_opt_algorithm(char *arg) 82genpkey_opt_algorithm(char *arg)
83{ 83{
84 if (!init_gen_str(bio_err, genpkey_config.ctx, arg, 84 if (!init_gen_str(bio_err, cfg.ctx, arg,
85 genpkey_config.do_param)) 85 cfg.do_param))
86 return (1); 86 return (1);
87 87
88 return (0); 88 return (0);
@@ -96,16 +96,16 @@ genpkey_opt_cipher(int argc, char **argv, int *argsused)
96 if (*name++ != '-') 96 if (*name++ != '-')
97 return (1); 97 return (1);
98 98
99 if (genpkey_config.do_param == 1) 99 if (cfg.do_param == 1)
100 return (1); 100 return (1);
101 101
102 if (strcmp(name, "none") == 0) { 102 if (strcmp(name, "none") == 0) {
103 genpkey_config.cipher = NULL; 103 cfg.cipher = NULL;
104 *argsused = 1; 104 *argsused = 1;
105 return (0); 105 return (0);
106 } 106 }
107 107
108 if ((genpkey_config.cipher = EVP_get_cipherbyname(name)) != NULL) { 108 if ((cfg.cipher = EVP_get_cipherbyname(name)) != NULL) {
109 *argsused = 1; 109 *argsused = 1;
110 return (0); 110 return (0);
111 } 111 }
@@ -116,9 +116,9 @@ genpkey_opt_cipher(int argc, char **argv, int *argsused)
116static int 116static int
117genpkey_opt_paramfile(char *arg) 117genpkey_opt_paramfile(char *arg)
118{ 118{
119 if (genpkey_config.do_param == 1) 119 if (cfg.do_param == 1)
120 return (1); 120 return (1);
121 if (!init_keygen_file(bio_err, genpkey_config.ctx, arg)) 121 if (!init_keygen_file(bio_err, cfg.ctx, arg))
122 return (1); 122 return (1);
123 123
124 return (0); 124 return (0);
@@ -127,12 +127,12 @@ genpkey_opt_paramfile(char *arg)
127static int 127static int
128genpkey_opt_pkeyopt(char *arg) 128genpkey_opt_pkeyopt(char *arg)
129{ 129{
130 if (*genpkey_config.ctx == NULL) { 130 if (*cfg.ctx == NULL) {
131 BIO_puts(bio_err, "No keytype specified\n"); 131 BIO_puts(bio_err, "No keytype specified\n");
132 return (1); 132 return (1);
133 } 133 }
134 134
135 if (pkey_ctrl_string(*genpkey_config.ctx, arg) <= 0) { 135 if (pkey_ctrl_string(*cfg.ctx, arg) <= 0) {
136 BIO_puts(bio_err, "parameter setting error\n"); 136 BIO_puts(bio_err, "parameter setting error\n");
137 ERR_print_errors(bio_err); 137 ERR_print_errors(bio_err);
138 return (1); 138 return (1);
@@ -153,21 +153,21 @@ static const struct option genpkey_options[] = {
153 .name = "genparam", 153 .name = "genparam",
154 .desc = "Generate a set of parameters instead of a private key", 154 .desc = "Generate a set of parameters instead of a private key",
155 .type = OPTION_FLAG, 155 .type = OPTION_FLAG,
156 .opt.flag = &genpkey_config.do_param, 156 .opt.flag = &cfg.do_param,
157 }, 157 },
158 { 158 {
159 .name = "out", 159 .name = "out",
160 .argname = "file", 160 .argname = "file",
161 .desc = "Output file to write to (default stdout)", 161 .desc = "Output file to write to (default stdout)",
162 .type = OPTION_ARG, 162 .type = OPTION_ARG,
163 .opt.arg = &genpkey_config.outfile, 163 .opt.arg = &cfg.outfile,
164 }, 164 },
165 { 165 {
166 .name = "outform", 166 .name = "outform",
167 .argname = "format", 167 .argname = "format",
168 .desc = "Output format (DER or PEM)", 168 .desc = "Output format (DER or PEM)",
169 .type = OPTION_ARG_FORMAT, 169 .type = OPTION_ARG_FORMAT,
170 .opt.value = &genpkey_config.outformat, 170 .opt.value = &cfg.outformat,
171 }, 171 },
172 { 172 {
173 .name = "paramfile", 173 .name = "paramfile",
@@ -182,7 +182,7 @@ static const struct option genpkey_options[] = {
182 .argname = "arg", 182 .argname = "arg",
183 .desc = "Output file password source", 183 .desc = "Output file password source",
184 .type = OPTION_ARG, 184 .type = OPTION_ARG,
185 .opt.arg = &genpkey_config.passarg, 185 .opt.arg = &cfg.passarg,
186 }, 186 },
187 { 187 {
188 .name = "pkeyopt", 188 .name = "pkeyopt",
@@ -195,7 +195,7 @@ static const struct option genpkey_options[] = {
195 .name = "text", 195 .name = "text",
196 .desc = "Print the private/public key in human readable form", 196 .desc = "Print the private/public key in human readable form",
197 .type = OPTION_FLAG, 197 .type = OPTION_FLAG,
198 .opt.flag = &genpkey_config.text, 198 .opt.flag = &cfg.text,
199 }, 199 },
200 { 200 {
201 .name = NULL, 201 .name = NULL,
@@ -229,9 +229,9 @@ genpkey_main(int argc, char **argv)
229 exit(1); 229 exit(1);
230 } 230 }
231 231
232 memset(&genpkey_config, 0, sizeof(genpkey_config)); 232 memset(&cfg, 0, sizeof(cfg));
233 genpkey_config.ctx = &ctx; 233 cfg.ctx = &ctx;
234 genpkey_config.outformat = FORMAT_PEM; 234 cfg.outformat = FORMAT_PEM;
235 235
236 if (options_parse(argc, argv, genpkey_options, NULL, NULL) != 0) { 236 if (options_parse(argc, argv, genpkey_options, NULL, NULL) != 0) {
237 genpkey_usage(); 237 genpkey_usage();
@@ -243,15 +243,15 @@ genpkey_main(int argc, char **argv)
243 goto end; 243 goto end;
244 } 244 }
245 245
246 if (!app_passwd(bio_err, genpkey_config.passarg, NULL, &pass, NULL)) { 246 if (!app_passwd(bio_err, cfg.passarg, NULL, &pass, NULL)) {
247 BIO_puts(bio_err, "Error getting password\n"); 247 BIO_puts(bio_err, "Error getting password\n");
248 goto end; 248 goto end;
249 } 249 }
250 if (genpkey_config.outfile != NULL) { 250 if (cfg.outfile != NULL) {
251 if ((out = BIO_new_file(genpkey_config.outfile, "wb")) == 251 if ((out = BIO_new_file(cfg.outfile, "wb")) ==
252 NULL) { 252 NULL) {
253 BIO_printf(bio_err, "Can't open output file %s\n", 253 BIO_printf(bio_err, "Can't open output file %s\n",
254 genpkey_config.outfile); 254 cfg.outfile);
255 goto end; 255 goto end;
256 } 256 }
257 } else { 257 } else {
@@ -261,7 +261,7 @@ genpkey_main(int argc, char **argv)
261 EVP_PKEY_CTX_set_cb(ctx, genpkey_cb); 261 EVP_PKEY_CTX_set_cb(ctx, genpkey_cb);
262 EVP_PKEY_CTX_set_app_data(ctx, bio_err); 262 EVP_PKEY_CTX_set_app_data(ctx, bio_err);
263 263
264 if (genpkey_config.do_param) { 264 if (cfg.do_param) {
265 if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) { 265 if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) {
266 BIO_puts(bio_err, "Error generating parameters\n"); 266 BIO_puts(bio_err, "Error generating parameters\n");
267 ERR_print_errors(bio_err); 267 ERR_print_errors(bio_err);
@@ -275,12 +275,12 @@ genpkey_main(int argc, char **argv)
275 } 275 }
276 } 276 }
277 277
278 if (genpkey_config.do_param) 278 if (cfg.do_param)
279 rv = PEM_write_bio_Parameters(out, pkey); 279 rv = PEM_write_bio_Parameters(out, pkey);
280 else if (genpkey_config.outformat == FORMAT_PEM) 280 else if (cfg.outformat == FORMAT_PEM)
281 rv = PEM_write_bio_PrivateKey(out, pkey, genpkey_config.cipher, 281 rv = PEM_write_bio_PrivateKey(out, pkey, cfg.cipher,
282 NULL, 0, NULL, pass); 282 NULL, 0, NULL, pass);
283 else if (genpkey_config.outformat == FORMAT_ASN1) 283 else if (cfg.outformat == FORMAT_ASN1)
284 rv = i2d_PrivateKey_bio(out, pkey); 284 rv = i2d_PrivateKey_bio(out, pkey);
285 else { 285 else {
286 BIO_printf(bio_err, "Bad format specified for key\n"); 286 BIO_printf(bio_err, "Bad format specified for key\n");
@@ -291,8 +291,8 @@ genpkey_main(int argc, char **argv)
291 BIO_puts(bio_err, "Error writing key\n"); 291 BIO_puts(bio_err, "Error writing key\n");
292 ERR_print_errors(bio_err); 292 ERR_print_errors(bio_err);
293 } 293 }
294 if (genpkey_config.text) { 294 if (cfg.text) {
295 if (genpkey_config.do_param) 295 if (cfg.do_param)
296 rv = EVP_PKEY_print_params(out, pkey, 0, NULL); 296 rv = EVP_PKEY_print_params(out, pkey, 0, NULL);
297 else 297 else
298 rv = EVP_PKEY_print_private(out, pkey, 0, NULL); 298 rv = EVP_PKEY_print_private(out, pkey, 0, NULL);