summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/dsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/openssl/dsa.c')
-rw-r--r--src/usr.bin/openssl/dsa.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/src/usr.bin/openssl/dsa.c b/src/usr.bin/openssl/dsa.c
index 0a3772dff7..f1de78cf4d 100644
--- a/src/usr.bin/openssl/dsa.c
+++ b/src/usr.bin/openssl/dsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa.c,v 1.17 2022/11/11 17:07:38 joshua Exp $ */ 1/* $OpenBSD: dsa.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 *
@@ -87,7 +87,7 @@ static struct {
87 int pubout; 87 int pubout;
88 int pvk_encr; 88 int pvk_encr;
89 int text; 89 int text;
90} dsa_config; 90} cfg;
91 91
92static int 92static int
93dsa_opt_enc(int argc, char **argv, int *argsused) 93dsa_opt_enc(int argc, char **argv, int *argsused)
@@ -97,7 +97,7 @@ dsa_opt_enc(int argc, char **argv, int *argsused)
97 if (*name++ != '-') 97 if (*name++ != '-')
98 return (1); 98 return (1);
99 99
100 if ((dsa_config.enc = EVP_get_cipherbyname(name)) != NULL) { 100 if ((cfg.enc = EVP_get_cipherbyname(name)) != NULL) {
101 *argsused = 1; 101 *argsused = 1;
102 return (0); 102 return (0);
103 } 103 }
@@ -111,7 +111,7 @@ static const struct option dsa_options[] = {
111 .argname = "file", 111 .argname = "file",
112 .desc = "Input file (default stdin)", 112 .desc = "Input file (default stdin)",
113 .type = OPTION_ARG, 113 .type = OPTION_ARG,
114 .opt.arg = &dsa_config.infile, 114 .opt.arg = &cfg.infile,
115 }, 115 },
116 { 116 {
117 .name = "inform", 117 .name = "inform",
@@ -119,87 +119,87 @@ static const struct option dsa_options[] = {
119 .desc = "Input format (PEM (default) or any other supported" 119 .desc = "Input format (PEM (default) or any other supported"
120 " format)", 120 " format)",
121 .type = OPTION_ARG_FORMAT, 121 .type = OPTION_ARG_FORMAT,
122 .opt.value = &dsa_config.informat, 122 .opt.value = &cfg.informat,
123 }, 123 },
124 { 124 {
125 .name = "modulus", 125 .name = "modulus",
126 .desc = "Print the DSA public value", 126 .desc = "Print the DSA public value",
127 .type = OPTION_FLAG, 127 .type = OPTION_FLAG,
128 .opt.flag = &dsa_config.modulus, 128 .opt.flag = &cfg.modulus,
129 }, 129 },
130 { 130 {
131 .name = "noout", 131 .name = "noout",
132 .desc = "No output", 132 .desc = "No output",
133 .type = OPTION_FLAG, 133 .type = OPTION_FLAG,
134 .opt.flag = &dsa_config.noout, 134 .opt.flag = &cfg.noout,
135 }, 135 },
136 { 136 {
137 .name = "out", 137 .name = "out",
138 .argname = "file", 138 .argname = "file",
139 .desc = "Output file (default stdout)", 139 .desc = "Output file (default stdout)",
140 .type = OPTION_ARG, 140 .type = OPTION_ARG,
141 .opt.arg = &dsa_config.outfile, 141 .opt.arg = &cfg.outfile,
142 }, 142 },
143 { 143 {
144 .name = "outform", 144 .name = "outform",
145 .argname = "format", 145 .argname = "format",
146 .desc = "Output format (DER, MSBLOB, PEM (default) or PVK)", 146 .desc = "Output format (DER, MSBLOB, PEM (default) or PVK)",
147 .type = OPTION_ARG_FORMAT, 147 .type = OPTION_ARG_FORMAT,
148 .opt.value = &dsa_config.outformat, 148 .opt.value = &cfg.outformat,
149 }, 149 },
150 { 150 {
151 .name = "passin", 151 .name = "passin",
152 .argname = "source", 152 .argname = "source",
153 .desc = "Input file passphrase source", 153 .desc = "Input file passphrase source",
154 .type = OPTION_ARG, 154 .type = OPTION_ARG,
155 .opt.arg = &dsa_config.passargin, 155 .opt.arg = &cfg.passargin,
156 }, 156 },
157 { 157 {
158 .name = "passout", 158 .name = "passout",
159 .argname = "source", 159 .argname = "source",
160 .desc = "Output file passphrase source", 160 .desc = "Output file passphrase source",
161 .type = OPTION_ARG, 161 .type = OPTION_ARG,
162 .opt.arg = &dsa_config.passargout, 162 .opt.arg = &cfg.passargout,
163 }, 163 },
164 { 164 {
165 .name = "pubin", 165 .name = "pubin",
166 .desc = "Read a public key from the input file instead of" 166 .desc = "Read a public key from the input file instead of"
167 " private key", 167 " private key",
168 .type = OPTION_FLAG, 168 .type = OPTION_FLAG,
169 .opt.flag = &dsa_config.pubin, 169 .opt.flag = &cfg.pubin,
170 }, 170 },
171 { 171 {
172 .name = "pubout", 172 .name = "pubout",
173 .desc = "Output a public key instead of private key", 173 .desc = "Output a public key instead of private key",
174 .type = OPTION_FLAG, 174 .type = OPTION_FLAG,
175 .opt.flag = &dsa_config.pubout, 175 .opt.flag = &cfg.pubout,
176 }, 176 },
177 { 177 {
178 .name = "pvk-none", 178 .name = "pvk-none",
179 .desc = "PVK encryption level", 179 .desc = "PVK encryption level",
180 .type = OPTION_VALUE, 180 .type = OPTION_VALUE,
181 .value = 0, 181 .value = 0,
182 .opt.value = &dsa_config.pvk_encr, 182 .opt.value = &cfg.pvk_encr,
183 }, 183 },
184 { 184 {
185 .name = "pvk-strong", 185 .name = "pvk-strong",
186 .desc = "PVK encryption level (default)", 186 .desc = "PVK encryption level (default)",
187 .type = OPTION_VALUE, 187 .type = OPTION_VALUE,
188 .value = 2, 188 .value = 2,
189 .opt.value = &dsa_config.pvk_encr, 189 .opt.value = &cfg.pvk_encr,
190 }, 190 },
191 { 191 {
192 .name = "pvk-weak", 192 .name = "pvk-weak",
193 .desc = "PVK encryption level", 193 .desc = "PVK encryption level",
194 .type = OPTION_VALUE, 194 .type = OPTION_VALUE,
195 .value = 1, 195 .value = 1,
196 .opt.value = &dsa_config.pvk_encr, 196 .opt.value = &cfg.pvk_encr,
197 }, 197 },
198 { 198 {
199 .name = "text", 199 .name = "text",
200 .desc = "Print the key in text form", 200 .desc = "Print the key in text form",
201 .type = OPTION_FLAG, 201 .type = OPTION_FLAG,
202 .opt.flag = &dsa_config.text, 202 .opt.flag = &cfg.text,
203 }, 203 },
204 { 204 {
205 .name = NULL, 205 .name = NULL,
@@ -241,18 +241,18 @@ dsa_main(int argc, char **argv)
241 exit(1); 241 exit(1);
242 } 242 }
243 243
244 memset(&dsa_config, 0, sizeof(dsa_config)); 244 memset(&cfg, 0, sizeof(cfg));
245 245
246 dsa_config.pvk_encr = 2; 246 cfg.pvk_encr = 2;
247 dsa_config.informat = FORMAT_PEM; 247 cfg.informat = FORMAT_PEM;
248 dsa_config.outformat = FORMAT_PEM; 248 cfg.outformat = FORMAT_PEM;
249 249
250 if (options_parse(argc, argv, dsa_options, NULL, NULL) != 0) { 250 if (options_parse(argc, argv, dsa_options, NULL, NULL) != 0) {
251 dsa_usage(); 251 dsa_usage();
252 goto end; 252 goto end;
253 } 253 }
254 254
255 if (!app_passwd(bio_err, dsa_config.passargin, dsa_config.passargout, 255 if (!app_passwd(bio_err, cfg.passargin, cfg.passargout,
256 &passin, &passout)) { 256 &passin, &passout)) {
257 BIO_printf(bio_err, "Error getting passwords\n"); 257 BIO_printf(bio_err, "Error getting passwords\n");
258 goto end; 258 goto end;
@@ -264,11 +264,11 @@ dsa_main(int argc, char **argv)
264 ERR_print_errors(bio_err); 264 ERR_print_errors(bio_err);
265 goto end; 265 goto end;
266 } 266 }
267 if (dsa_config.infile == NULL) 267 if (cfg.infile == NULL)
268 BIO_set_fp(in, stdin, BIO_NOCLOSE); 268 BIO_set_fp(in, stdin, BIO_NOCLOSE);
269 else { 269 else {
270 if (BIO_read_filename(in, dsa_config.infile) <= 0) { 270 if (BIO_read_filename(in, cfg.infile) <= 0) {
271 perror(dsa_config.infile); 271 perror(cfg.infile);
272 goto end; 272 goto end;
273 } 273 }
274 } 274 }
@@ -278,12 +278,12 @@ dsa_main(int argc, char **argv)
278 { 278 {
279 EVP_PKEY *pkey; 279 EVP_PKEY *pkey;
280 280
281 if (dsa_config.pubin) 281 if (cfg.pubin)
282 pkey = load_pubkey(bio_err, dsa_config.infile, 282 pkey = load_pubkey(bio_err, cfg.infile,
283 dsa_config.informat, 1, passin, "Public Key"); 283 cfg.informat, 1, passin, "Public Key");
284 else 284 else
285 pkey = load_key(bio_err, dsa_config.infile, 285 pkey = load_key(bio_err, cfg.infile,
286 dsa_config.informat, 1, passin, "Private Key"); 286 cfg.informat, 1, passin, "Private Key");
287 287
288 if (pkey) { 288 if (pkey) {
289 dsa = EVP_PKEY_get1_DSA(pkey); 289 dsa = EVP_PKEY_get1_DSA(pkey);
@@ -295,51 +295,51 @@ dsa_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 (dsa_config.outfile == NULL) { 298 if (cfg.outfile == NULL) {
299 BIO_set_fp(out, stdout, BIO_NOCLOSE); 299 BIO_set_fp(out, stdout, BIO_NOCLOSE);
300 } else { 300 } else {
301 if (BIO_write_filename(out, dsa_config.outfile) <= 0) { 301 if (BIO_write_filename(out, cfg.outfile) <= 0) {
302 perror(dsa_config.outfile); 302 perror(cfg.outfile);
303 goto end; 303 goto end;
304 } 304 }
305 } 305 }
306 306
307 if (dsa_config.text) { 307 if (cfg.text) {
308 if (!DSA_print(out, dsa, 0)) { 308 if (!DSA_print(out, dsa, 0)) {
309 perror(dsa_config.outfile); 309 perror(cfg.outfile);
310 ERR_print_errors(bio_err); 310 ERR_print_errors(bio_err);
311 goto end; 311 goto end;
312 } 312 }
313 } 313 }
314 if (dsa_config.modulus) { 314 if (cfg.modulus) {
315 fprintf(stdout, "Public Key="); 315 fprintf(stdout, "Public Key=");
316 BN_print(out, DSA_get0_pub_key(dsa)); 316 BN_print(out, DSA_get0_pub_key(dsa));
317 fprintf(stdout, "\n"); 317 fprintf(stdout, "\n");
318 } 318 }
319 if (dsa_config.noout) 319 if (cfg.noout)
320 goto end; 320 goto end;
321 BIO_printf(bio_err, "writing DSA key\n"); 321 BIO_printf(bio_err, "writing DSA key\n");
322 if (dsa_config.outformat == FORMAT_ASN1) { 322 if (cfg.outformat == FORMAT_ASN1) {
323 if (dsa_config.pubin || dsa_config.pubout) 323 if (cfg.pubin || cfg.pubout)
324 i = i2d_DSA_PUBKEY_bio(out, dsa); 324 i = i2d_DSA_PUBKEY_bio(out, dsa);
325 else 325 else
326 i = i2d_DSAPrivateKey_bio(out, dsa); 326 i = i2d_DSAPrivateKey_bio(out, dsa);
327 } else if (dsa_config.outformat == FORMAT_PEM) { 327 } else if (cfg.outformat == FORMAT_PEM) {
328 if (dsa_config.pubin || dsa_config.pubout) 328 if (cfg.pubin || cfg.pubout)
329 i = PEM_write_bio_DSA_PUBKEY(out, dsa); 329 i = PEM_write_bio_DSA_PUBKEY(out, dsa);
330 else 330 else
331 i = PEM_write_bio_DSAPrivateKey(out, dsa, dsa_config.enc, 331 i = PEM_write_bio_DSAPrivateKey(out, dsa, cfg.enc,
332 NULL, 0, NULL, passout); 332 NULL, 0, NULL, passout);
333#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4) 333#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4)
334 } else if (dsa_config.outformat == FORMAT_MSBLOB || 334 } else if (cfg.outformat == FORMAT_MSBLOB ||
335 dsa_config.outformat == FORMAT_PVK) { 335 cfg.outformat == FORMAT_PVK) {
336 EVP_PKEY *pk; 336 EVP_PKEY *pk;
337 pk = EVP_PKEY_new(); 337 pk = EVP_PKEY_new();
338 EVP_PKEY_set1_DSA(pk, dsa); 338 EVP_PKEY_set1_DSA(pk, dsa);
339 if (dsa_config.outformat == FORMAT_PVK) 339 if (cfg.outformat == FORMAT_PVK)
340 i = i2b_PVK_bio(out, pk, dsa_config.pvk_encr, 0, 340 i = i2b_PVK_bio(out, pk, cfg.pvk_encr, 0,
341 passout); 341 passout);
342 else if (dsa_config.pubin || dsa_config.pubout) 342 else if (cfg.pubin || cfg.pubout)
343 i = i2b_PublicKey_bio(out, pk); 343 i = i2b_PublicKey_bio(out, pk);
344 else 344 else
345 i = i2b_PrivateKey_bio(out, pk); 345 i = i2b_PrivateKey_bio(out, pk);