summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorinoguchi <>2019-06-19 01:51:14 +0000
committerinoguchi <>2019-06-19 01:51:14 +0000
commit50816412f7417865d20b1e64b8aeb42910b83d70 (patch)
treefe2b300b977e6b920506cabcd2fb60a80db08dae /src
parenta58a6d90c7fa6ece9183c620ed89abddbd00699d (diff)
downloadopenbsd-50816412f7417865d20b1e64b8aeb42910b83d70.tar.gz
openbsd-50816412f7417865d20b1e64b8aeb42910b83d70.tar.bz2
openbsd-50816412f7417865d20b1e64b8aeb42910b83d70.zip
Move variables into struct in openssl(1) genrsa
- Move local variables in genrsa_main() to struct genrsa_config - Leave long lines more than 80, still ok bcook@
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/openssl/genrsa.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/src/usr.bin/openssl/genrsa.c b/src/usr.bin/openssl/genrsa.c
index 3b643ab5f5..3ed2835631 100644
--- a/src/usr.bin/openssl/genrsa.c
+++ b/src/usr.bin/openssl/genrsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: genrsa.c,v 1.12 2018/12/09 19:30:34 tobias Exp $ */ 1/* $OpenBSD: genrsa.c,v 1.13 2019/06/19 01:51:14 inoguchi 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 *
@@ -85,6 +85,13 @@
85 85
86static int genrsa_cb(int p, int n, BN_GENCB * cb); 86static int genrsa_cb(int p, int n, BN_GENCB * cb);
87 87
88static struct {
89 const EVP_CIPHER *enc;
90 unsigned long f4;
91 char *outfile;
92 char *passargout;
93} genrsa_config;
94
88int 95int
89genrsa_main(int argc, char **argv) 96genrsa_main(int argc, char **argv)
90{ 97{
@@ -92,10 +99,7 @@ genrsa_main(int argc, char **argv)
92 int ret = 1; 99 int ret = 1;
93 int i, num = DEFBITS; 100 int i, num = DEFBITS;
94 long l; 101 long l;
95 const EVP_CIPHER *enc = NULL; 102 char *passout = NULL;
96 unsigned long f4 = RSA_F4;
97 char *outfile = NULL;
98 char *passargout = NULL, *passout = NULL;
99 BIO *out = NULL; 103 BIO *out = NULL;
100 BIGNUM *bn = BN_new(); 104 BIGNUM *bn = BN_new();
101 RSA *rsa = NULL; 105 RSA *rsa = NULL;
@@ -116,6 +120,10 @@ genrsa_main(int argc, char **argv)
116 BIO_printf(bio_err, "unable to create BIO for output\n"); 120 BIO_printf(bio_err, "unable to create BIO for output\n");
117 goto err; 121 goto err;
118 } 122 }
123
124 memset(&genrsa_config, 0, sizeof(genrsa_config));
125 genrsa_config.f4 = RSA_F4;
126
119 argv++; 127 argv++;
120 argc--; 128 argc--;
121 for (;;) { 129 for (;;) {
@@ -124,41 +132,41 @@ genrsa_main(int argc, char **argv)
124 if (strcmp(*argv, "-out") == 0) { 132 if (strcmp(*argv, "-out") == 0) {
125 if (--argc < 1) 133 if (--argc < 1)
126 goto bad; 134 goto bad;
127 outfile = *(++argv); 135 genrsa_config.outfile = *(++argv);
128 } else if (strcmp(*argv, "-3") == 0) 136 } else if (strcmp(*argv, "-3") == 0)
129 f4 = 3; 137 genrsa_config.f4 = 3;
130 else if (strcmp(*argv, "-F4") == 0 || strcmp(*argv, "-f4") == 0) 138 else if (strcmp(*argv, "-F4") == 0 || strcmp(*argv, "-f4") == 0)
131 f4 = RSA_F4; 139 genrsa_config.f4 = RSA_F4;
132#ifndef OPENSSL_NO_DES 140#ifndef OPENSSL_NO_DES
133 else if (strcmp(*argv, "-des") == 0) 141 else if (strcmp(*argv, "-des") == 0)
134 enc = EVP_des_cbc(); 142 genrsa_config.enc = EVP_des_cbc();
135 else if (strcmp(*argv, "-des3") == 0) 143 else if (strcmp(*argv, "-des3") == 0)
136 enc = EVP_des_ede3_cbc(); 144 genrsa_config.enc = EVP_des_ede3_cbc();
137#endif 145#endif
138#ifndef OPENSSL_NO_IDEA 146#ifndef OPENSSL_NO_IDEA
139 else if (strcmp(*argv, "-idea") == 0) 147 else if (strcmp(*argv, "-idea") == 0)
140 enc = EVP_idea_cbc(); 148 genrsa_config.enc = EVP_idea_cbc();
141#endif 149#endif
142#ifndef OPENSSL_NO_AES 150#ifndef OPENSSL_NO_AES
143 else if (strcmp(*argv, "-aes128") == 0) 151 else if (strcmp(*argv, "-aes128") == 0)
144 enc = EVP_aes_128_cbc(); 152 genrsa_config.enc = EVP_aes_128_cbc();
145 else if (strcmp(*argv, "-aes192") == 0) 153 else if (strcmp(*argv, "-aes192") == 0)
146 enc = EVP_aes_192_cbc(); 154 genrsa_config.enc = EVP_aes_192_cbc();
147 else if (strcmp(*argv, "-aes256") == 0) 155 else if (strcmp(*argv, "-aes256") == 0)
148 enc = EVP_aes_256_cbc(); 156 genrsa_config.enc = EVP_aes_256_cbc();
149#endif 157#endif
150#ifndef OPENSSL_NO_CAMELLIA 158#ifndef OPENSSL_NO_CAMELLIA
151 else if (strcmp(*argv, "-camellia128") == 0) 159 else if (strcmp(*argv, "-camellia128") == 0)
152 enc = EVP_camellia_128_cbc(); 160 genrsa_config.enc = EVP_camellia_128_cbc();
153 else if (strcmp(*argv, "-camellia192") == 0) 161 else if (strcmp(*argv, "-camellia192") == 0)
154 enc = EVP_camellia_192_cbc(); 162 genrsa_config.enc = EVP_camellia_192_cbc();
155 else if (strcmp(*argv, "-camellia256") == 0) 163 else if (strcmp(*argv, "-camellia256") == 0)
156 enc = EVP_camellia_256_cbc(); 164 genrsa_config.enc = EVP_camellia_256_cbc();
157#endif 165#endif
158 else if (strcmp(*argv, "-passout") == 0) { 166 else if (strcmp(*argv, "-passout") == 0) {
159 if (--argc < 1) 167 if (--argc < 1)
160 goto bad; 168 goto bad;
161 passargout = *(++argv); 169 genrsa_config.passargout = *(++argv);
162 } else 170 } else
163 break; 171 break;
164 argv++; 172 argv++;
@@ -189,16 +197,16 @@ genrsa_main(int argc, char **argv)
189 goto err; 197 goto err;
190 } 198 }
191 199
192 if (!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { 200 if (!app_passwd(bio_err, NULL, genrsa_config.passargout, NULL, &passout)) {
193 BIO_printf(bio_err, "Error getting password\n"); 201 BIO_printf(bio_err, "Error getting password\n");
194 goto err; 202 goto err;
195 } 203 }
196 204
197 if (outfile == NULL) { 205 if (genrsa_config.outfile == NULL) {
198 BIO_set_fp(out, stdout, BIO_NOCLOSE); 206 BIO_set_fp(out, stdout, BIO_NOCLOSE);
199 } else { 207 } else {
200 if (BIO_write_filename(out, outfile) <= 0) { 208 if (BIO_write_filename(out, genrsa_config.outfile) <= 0) {
201 perror(outfile); 209 perror(genrsa_config.outfile);
202 goto err; 210 goto err;
203 } 211 }
204 } 212 }
@@ -209,7 +217,7 @@ genrsa_main(int argc, char **argv)
209 if (!rsa) 217 if (!rsa)
210 goto err; 218 goto err;
211 219
212 if (!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb)) 220 if (!BN_set_word(bn, genrsa_config.f4) || !RSA_generate_key_ex(rsa, num, bn, &cb))
213 goto err; 221 goto err;
214 222
215 /* 223 /*
@@ -228,8 +236,8 @@ genrsa_main(int argc, char **argv)
228 { 236 {
229 PW_CB_DATA cb_data; 237 PW_CB_DATA cb_data;
230 cb_data.password = passout; 238 cb_data.password = passout;
231 cb_data.prompt_info = outfile; 239 cb_data.prompt_info = genrsa_config.outfile;
232 if (!PEM_write_bio_RSAPrivateKey(out, rsa, enc, NULL, 0, 240 if (!PEM_write_bio_RSAPrivateKey(out, rsa, genrsa_config.enc, NULL, 0,
233 password_callback, &cb_data)) 241 password_callback, &cb_data))
234 goto err; 242 goto err;
235 } 243 }