diff options
Diffstat (limited to 'src/lib/libssl/src/apps/gendsa.c')
-rw-r--r-- | src/lib/libssl/src/apps/gendsa.c | 237 |
1 files changed, 116 insertions, 121 deletions
diff --git a/src/lib/libssl/src/apps/gendsa.c b/src/lib/libssl/src/apps/gendsa.c index 5c9ec7d24b..17dbd9d6d3 100644 --- a/src/lib/libssl/src/apps/gendsa.c +++ b/src/lib/libssl/src/apps/gendsa.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -76,204 +76,199 @@ | |||
76 | 76 | ||
77 | int MAIN(int, char **); | 77 | int MAIN(int, char **); |
78 | 78 | ||
79 | int MAIN(int argc, char **argv) | 79 | int |
80 | { | 80 | MAIN(int argc, char **argv) |
81 | DSA *dsa=NULL; | 81 | { |
82 | int ret=1; | 82 | DSA *dsa = NULL; |
83 | char *outfile=NULL; | 83 | int ret = 1; |
84 | char *inrand=NULL,*dsaparams=NULL; | 84 | char *outfile = NULL; |
85 | char *inrand = NULL, *dsaparams = NULL; | ||
85 | char *passargout = NULL, *passout = NULL; | 86 | char *passargout = NULL, *passout = NULL; |
86 | BIO *out=NULL,*in=NULL; | 87 | BIO *out = NULL, *in = NULL; |
87 | const EVP_CIPHER *enc=NULL; | 88 | const EVP_CIPHER *enc = NULL; |
88 | #ifndef OPENSSL_NO_ENGINE | 89 | #ifndef OPENSSL_NO_ENGINE |
89 | char *engine=NULL; | 90 | char *engine = NULL; |
90 | #endif | 91 | #endif |
91 | 92 | ||
92 | apps_startup(); | 93 | apps_startup(); |
93 | 94 | ||
94 | if (bio_err == NULL) | 95 | if (bio_err == NULL) |
95 | if ((bio_err=BIO_new(BIO_s_file())) != NULL) | 96 | if ((bio_err = BIO_new(BIO_s_file())) != NULL) |
96 | BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); | 97 | BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); |
97 | 98 | ||
98 | if (!load_config(bio_err, NULL)) | 99 | if (!load_config(bio_err, NULL)) |
99 | goto end; | 100 | goto end; |
100 | 101 | ||
101 | argv++; | 102 | argv++; |
102 | argc--; | 103 | argc--; |
103 | for (;;) | 104 | for (;;) { |
104 | { | 105 | if (argc <= 0) |
105 | if (argc <= 0) break; | 106 | break; |
106 | if (strcmp(*argv,"-out") == 0) | 107 | if (strcmp(*argv, "-out") == 0) { |
107 | { | 108 | if (--argc < 1) |
108 | if (--argc < 1) goto bad; | 109 | goto bad; |
109 | outfile= *(++argv); | 110 | outfile= *(++argv); |
110 | } | 111 | } else if (strcmp(*argv, "-passout") == 0) { |
111 | else if (strcmp(*argv,"-passout") == 0) | 112 | if (--argc < 1) |
112 | { | 113 | goto bad; |
113 | if (--argc < 1) goto bad; | ||
114 | passargout= *(++argv); | 114 | passargout= *(++argv); |
115 | } | 115 | } |
116 | #ifndef OPENSSL_NO_ENGINE | 116 | #ifndef OPENSSL_NO_ENGINE |
117 | else if (strcmp(*argv,"-engine") == 0) | 117 | else if (strcmp(*argv, "-engine") == 0) { |
118 | { | 118 | if (--argc < 1) |
119 | if (--argc < 1) goto bad; | 119 | goto bad; |
120 | engine= *(++argv); | 120 | engine= *(++argv); |
121 | } | 121 | } |
122 | #endif | 122 | #endif |
123 | else if (strcmp(*argv,"-rand") == 0) | 123 | else if (strcmp(*argv, "-rand") == 0) { |
124 | { | 124 | if (--argc < 1) |
125 | if (--argc < 1) goto bad; | 125 | goto bad; |
126 | inrand= *(++argv); | 126 | inrand= *(++argv); |
127 | } | 127 | } else if (strcmp(*argv, "-") == 0) |
128 | else if (strcmp(*argv,"-") == 0) | ||
129 | goto bad; | 128 | goto bad; |
130 | #ifndef OPENSSL_NO_DES | 129 | #ifndef OPENSSL_NO_DES |
131 | else if (strcmp(*argv,"-des") == 0) | 130 | else if (strcmp(*argv, "-des") == 0) |
132 | enc=EVP_des_cbc(); | 131 | enc = EVP_des_cbc(); |
133 | else if (strcmp(*argv,"-des3") == 0) | 132 | else if (strcmp(*argv, "-des3") == 0) |
134 | enc=EVP_des_ede3_cbc(); | 133 | enc = EVP_des_ede3_cbc(); |
135 | #endif | 134 | #endif |
136 | #ifndef OPENSSL_NO_IDEA | 135 | #ifndef OPENSSL_NO_IDEA |
137 | else if (strcmp(*argv,"-idea") == 0) | 136 | else if (strcmp(*argv, "-idea") == 0) |
138 | enc=EVP_idea_cbc(); | 137 | enc = EVP_idea_cbc(); |
139 | #endif | 138 | #endif |
140 | #ifndef OPENSSL_NO_SEED | 139 | #ifndef OPENSSL_NO_SEED |
141 | else if (strcmp(*argv,"-seed") == 0) | 140 | else if (strcmp(*argv, "-seed") == 0) |
142 | enc=EVP_seed_cbc(); | 141 | enc = EVP_seed_cbc(); |
143 | #endif | 142 | #endif |
144 | #ifndef OPENSSL_NO_AES | 143 | #ifndef OPENSSL_NO_AES |
145 | else if (strcmp(*argv,"-aes128") == 0) | 144 | else if (strcmp(*argv, "-aes128") == 0) |
146 | enc=EVP_aes_128_cbc(); | 145 | enc = EVP_aes_128_cbc(); |
147 | else if (strcmp(*argv,"-aes192") == 0) | 146 | else if (strcmp(*argv, "-aes192") == 0) |
148 | enc=EVP_aes_192_cbc(); | 147 | enc = EVP_aes_192_cbc(); |
149 | else if (strcmp(*argv,"-aes256") == 0) | 148 | else if (strcmp(*argv, "-aes256") == 0) |
150 | enc=EVP_aes_256_cbc(); | 149 | enc = EVP_aes_256_cbc(); |
151 | #endif | 150 | #endif |
152 | #ifndef OPENSSL_NO_CAMELLIA | 151 | #ifndef OPENSSL_NO_CAMELLIA |
153 | else if (strcmp(*argv,"-camellia128") == 0) | 152 | else if (strcmp(*argv, "-camellia128") == 0) |
154 | enc=EVP_camellia_128_cbc(); | 153 | enc = EVP_camellia_128_cbc(); |
155 | else if (strcmp(*argv,"-camellia192") == 0) | 154 | else if (strcmp(*argv, "-camellia192") == 0) |
156 | enc=EVP_camellia_192_cbc(); | 155 | enc = EVP_camellia_192_cbc(); |
157 | else if (strcmp(*argv,"-camellia256") == 0) | 156 | else if (strcmp(*argv, "-camellia256") == 0) |
158 | enc=EVP_camellia_256_cbc(); | 157 | enc = EVP_camellia_256_cbc(); |
159 | #endif | 158 | #endif |
160 | else if (**argv != '-' && dsaparams == NULL) | 159 | else if (**argv != '-' && dsaparams == NULL) { |
161 | { | ||
162 | dsaparams = *argv; | 160 | dsaparams = *argv; |
163 | } | 161 | } else |
164 | else | ||
165 | goto bad; | 162 | goto bad; |
166 | argv++; | 163 | argv++; |
167 | argc--; | 164 | argc--; |
168 | } | 165 | } |
169 | 166 | ||
170 | if (dsaparams == NULL) | 167 | if (dsaparams == NULL) { |
171 | { | ||
172 | bad: | 168 | bad: |
173 | BIO_printf(bio_err,"usage: gendsa [args] dsaparam-file\n"); | 169 | BIO_printf(bio_err, "usage: gendsa [args] dsaparam-file\n"); |
174 | BIO_printf(bio_err," -out file - output the key to 'file'\n"); | 170 | BIO_printf(bio_err, " -out file - output the key to 'file'\n"); |
175 | #ifndef OPENSSL_NO_DES | 171 | #ifndef OPENSSL_NO_DES |
176 | BIO_printf(bio_err," -des - encrypt the generated key with DES in cbc mode\n"); | 172 | BIO_printf(bio_err, " -des - encrypt the generated key with DES in cbc mode\n"); |
177 | BIO_printf(bio_err," -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); | 173 | BIO_printf(bio_err, " -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); |
178 | #endif | 174 | #endif |
179 | #ifndef OPENSSL_NO_IDEA | 175 | #ifndef OPENSSL_NO_IDEA |
180 | BIO_printf(bio_err," -idea - encrypt the generated key with IDEA in cbc mode\n"); | 176 | BIO_printf(bio_err, " -idea - encrypt the generated key with IDEA in cbc mode\n"); |
181 | #endif | 177 | #endif |
182 | #ifndef OPENSSL_NO_SEED | 178 | #ifndef OPENSSL_NO_SEED |
183 | BIO_printf(bio_err," -seed\n"); | 179 | BIO_printf(bio_err, " -seed\n"); |
184 | BIO_printf(bio_err," encrypt PEM output with cbc seed\n"); | 180 | BIO_printf(bio_err, " encrypt PEM output with cbc seed\n"); |
185 | #endif | 181 | #endif |
186 | #ifndef OPENSSL_NO_AES | 182 | #ifndef OPENSSL_NO_AES |
187 | BIO_printf(bio_err," -aes128, -aes192, -aes256\n"); | 183 | BIO_printf(bio_err, " -aes128, -aes192, -aes256\n"); |
188 | BIO_printf(bio_err," encrypt PEM output with cbc aes\n"); | 184 | BIO_printf(bio_err, " encrypt PEM output with cbc aes\n"); |
189 | #endif | 185 | #endif |
190 | #ifndef OPENSSL_NO_CAMELLIA | 186 | #ifndef OPENSSL_NO_CAMELLIA |
191 | BIO_printf(bio_err," -camellia128, -camellia192, -camellia256\n"); | 187 | BIO_printf(bio_err, " -camellia128, -camellia192, -camellia256\n"); |
192 | BIO_printf(bio_err," encrypt PEM output with cbc camellia\n"); | 188 | BIO_printf(bio_err, " encrypt PEM output with cbc camellia\n"); |
193 | #endif | 189 | #endif |
194 | #ifndef OPENSSL_NO_ENGINE | 190 | #ifndef OPENSSL_NO_ENGINE |
195 | BIO_printf(bio_err," -engine e - use engine e, possibly a hardware device.\n"); | 191 | BIO_printf(bio_err, " -engine e - use engine e, possibly a hardware device.\n"); |
196 | #endif | 192 | #endif |
197 | BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); | 193 | BIO_printf(bio_err, " -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); |
198 | BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); | 194 | BIO_printf(bio_err, " - load the file (or the files in the directory) into\n"); |
199 | BIO_printf(bio_err," the random number generator\n"); | 195 | BIO_printf(bio_err, " the random number generator\n"); |
200 | BIO_printf(bio_err," dsaparam-file\n"); | 196 | BIO_printf(bio_err, " dsaparam-file\n"); |
201 | BIO_printf(bio_err," - a DSA parameter file as generated by the dsaparam command\n"); | 197 | BIO_printf(bio_err, " - a DSA parameter file as generated by the dsaparam command\n"); |
202 | goto end; | 198 | goto end; |
203 | } | 199 | } |
204 | 200 | ||
205 | #ifndef OPENSSL_NO_ENGINE | 201 | #ifndef OPENSSL_NO_ENGINE |
206 | setup_engine(bio_err, engine, 0); | 202 | setup_engine(bio_err, engine, 0); |
207 | #endif | 203 | #endif |
208 | 204 | ||
209 | if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { | 205 | if (!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { |
210 | BIO_printf(bio_err, "Error getting password\n"); | 206 | BIO_printf(bio_err, "Error getting password\n"); |
211 | goto end; | 207 | goto end; |
212 | } | 208 | } |
213 | 209 | ||
214 | 210 | ||
215 | in=BIO_new(BIO_s_file()); | 211 | in = BIO_new(BIO_s_file()); |
216 | if (!(BIO_read_filename(in,dsaparams))) | 212 | if (!(BIO_read_filename(in, dsaparams))) { |
217 | { | ||
218 | perror(dsaparams); | 213 | perror(dsaparams); |
219 | goto end; | 214 | goto end; |
220 | } | 215 | } |
221 | 216 | ||
222 | if ((dsa=PEM_read_bio_DSAparams(in,NULL,NULL,NULL)) == NULL) | 217 | if ((dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL)) == NULL) { |
223 | { | 218 | BIO_printf(bio_err, "unable to load DSA parameter file\n"); |
224 | BIO_printf(bio_err,"unable to load DSA parameter file\n"); | ||
225 | goto end; | 219 | goto end; |
226 | } | 220 | } |
227 | BIO_free(in); | 221 | BIO_free(in); |
228 | in = NULL; | 222 | in = NULL; |
229 | |||
230 | out=BIO_new(BIO_s_file()); | ||
231 | if (out == NULL) goto end; | ||
232 | 223 | ||
233 | if (outfile == NULL) | 224 | out = BIO_new(BIO_s_file()); |
234 | { | 225 | if (out == NULL) |
235 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | 226 | goto end; |
236 | } | 227 | |
237 | else | 228 | if (outfile == NULL) { |
238 | { | 229 | BIO_set_fp(out, stdout, BIO_NOCLOSE); |
239 | if (BIO_write_filename(out,outfile) <= 0) | 230 | } else { |
240 | { | 231 | if (BIO_write_filename(out, outfile) <= 0) { |
241 | perror(outfile); | 232 | perror(outfile); |
242 | goto end; | 233 | goto end; |
243 | } | ||
244 | } | 234 | } |
235 | } | ||
245 | 236 | ||
246 | if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) | 237 | if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { |
247 | { | 238 | BIO_printf(bio_err, "warning, not much extra random data, consider using the -rand option\n"); |
248 | BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); | 239 | } |
249 | } | ||
250 | if (inrand != NULL) | 240 | if (inrand != NULL) |
251 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | 241 | BIO_printf(bio_err, "%ld semi-random bytes loaded\n", |
252 | app_RAND_load_files(inrand)); | 242 | app_RAND_load_files(inrand)); |
253 | 243 | ||
254 | BIO_printf(bio_err,"Generating DSA key, %d bits\n", | 244 | BIO_printf(bio_err, "Generating DSA key, %d bits\n", |
255 | BN_num_bits(dsa->p)); | 245 | BN_num_bits(dsa->p)); |
256 | if (!DSA_generate_key(dsa)) goto end; | 246 | if (!DSA_generate_key(dsa)) |
247 | goto end; | ||
257 | 248 | ||
258 | app_RAND_write_file(NULL, bio_err); | 249 | app_RAND_write_file(NULL, bio_err); |
259 | 250 | ||
260 | if (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL, passout)) | 251 | if (!PEM_write_bio_DSAPrivateKey(out, dsa, enc, NULL, 0, NULL, passout)) |
261 | goto end; | 252 | goto end; |
262 | ret=0; | 253 | ret = 0; |
263 | end: | 254 | end: |
264 | if (ret != 0) | 255 | if (ret != 0) |
265 | ERR_print_errors(bio_err); | 256 | ERR_print_errors(bio_err); |
266 | if (in != NULL) BIO_free(in); | 257 | if (in != NULL) |
267 | if (out != NULL) BIO_free_all(out); | 258 | BIO_free(in); |
268 | if (dsa != NULL) DSA_free(dsa); | 259 | if (out != NULL) |
269 | if(passout) free(passout); | 260 | BIO_free_all(out); |
261 | if (dsa != NULL) | ||
262 | DSA_free(dsa); | ||
263 | if (passout) | ||
264 | free(passout); | ||
270 | apps_shutdown(); | 265 | apps_shutdown(); |
271 | OPENSSL_EXIT(ret); | 266 | OPENSSL_EXIT(ret); |
272 | } | 267 | } |
273 | #else /* !OPENSSL_NO_DSA */ | 268 | #else /* !OPENSSL_NO_DSA */ |
274 | 269 | ||
275 | # if PEDANTIC | 270 | # if PEDANTIC |
276 | static void *dummy=&dummy; | 271 | static void *dummy = &dummy; |
277 | # endif | 272 | # endif |
278 | 273 | ||
279 | #endif | 274 | #endif |