diff options
author | jsing <> | 2014-04-17 15:43:33 +0000 |
---|---|---|
committer | jsing <> | 2014-04-17 15:43:33 +0000 |
commit | 18c3f2b77b5cab0b6689479dee685aff2566defe (patch) | |
tree | 71edffe224ca9ec431966c835097a0ab8d2e9915 | |
parent | c967cb15537b403273b75572fc32e7dbf88e2533 (diff) | |
download | openbsd-18c3f2b77b5cab0b6689479dee685aff2566defe.tar.gz openbsd-18c3f2b77b5cab0b6689479dee685aff2566defe.tar.bz2 openbsd-18c3f2b77b5cab0b6689479dee685aff2566defe.zip |
Initial KNF.
-rw-r--r-- | src/lib/libssl/src/apps/gendh.c | 185 | ||||
-rw-r--r-- | src/lib/libssl/src/apps/gendsa.c | 237 | ||||
-rw-r--r-- | src/lib/libssl/src/apps/genpkey.c | 252 | ||||
-rw-r--r-- | src/lib/libssl/src/apps/genrsa.c | 287 |
4 files changed, 459 insertions, 502 deletions
diff --git a/src/lib/libssl/src/apps/gendh.c b/src/lib/libssl/src/apps/gendh.c index c80fc0c21c..00c31cf40d 100644 --- a/src/lib/libssl/src/apps/gendh.c +++ b/src/lib/libssl/src/apps/gendh.c | |||
@@ -6,21 +6,21 @@ | |||
6 | * This package is an SSL implementation written | 6 | * This package is an SSL implementation written |
7 | * by Eric Young (eay@cryptsoft.com). | 7 | * by Eric Young (eay@cryptsoft.com). |
8 | * The implementation was written so as to conform with Netscapes SSL. | 8 | * The implementation was written so as to conform with Netscapes SSL. |
9 | * | 9 | * |
10 | * This library is free for commercial and non-commercial use as long as | 10 | * This library is free for commercial and non-commercial use as long as |
11 | * the following conditions are aheared to. The following conditions | 11 | * the following conditions are aheared to. The following conditions |
12 | * apply to all code found in this distribution, be it the RC4, RSA, | 12 | * apply to all code found in this distribution, be it the RC4, RSA, |
13 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 13 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
14 | * included with this distribution is covered by the same copyright terms | 14 | * included with this distribution is covered by the same copyright terms |
15 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 15 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
16 | * | 16 | * |
17 | * Copyright remains Eric Young's, and as such any Copyright notices in | 17 | * Copyright remains Eric Young's, and as such any Copyright notices in |
18 | * the code are not to be removed. | 18 | * the code are not to be removed. |
19 | * If this package is used in a product, Eric Young should be given attribution | 19 | * If this package is used in a product, Eric Young should be given attribution |
20 | * as the author of the parts of the library used. | 20 | * as the author of the parts of the library used. |
21 | * This can be in the form of a textual message at program startup or | 21 | * This can be in the form of a textual message at program startup or |
22 | * in documentation (online or textual) provided with the package. | 22 | * in documentation (online or textual) provided with the package. |
23 | * | 23 | * |
24 | * Redistribution and use in source and binary forms, with or without | 24 | * Redistribution and use in source and binary forms, with or without |
25 | * modification, are permitted provided that the following conditions | 25 | * modification, are permitted provided that the following conditions |
26 | * are met: | 26 | * are met: |
@@ -35,10 +35,10 @@ | |||
35 | * Eric Young (eay@cryptsoft.com)" | 35 | * Eric Young (eay@cryptsoft.com)" |
36 | * The word 'cryptographic' can be left out if the rouines from the library | 36 | * The word 'cryptographic' can be left out if the rouines from the library |
37 | * being used are not cryptographic related :-). | 37 | * being used are not cryptographic related :-). |
38 | * 4. If you include any Windows specific code (or a derivative thereof) from | 38 | * 4. If you include any Windows specific code (or a derivative thereof) from |
39 | * the apps directory (application code) you must include an acknowledgement: | 39 | * the apps directory (application code) you must include an acknowledgement: |
40 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 40 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
41 | * | 41 | * |
42 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 42 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
43 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 43 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
44 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 44 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -50,7 +50,7 @@ | |||
50 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 50 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
51 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 51 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
52 | * SUCH DAMAGE. | 52 | * SUCH DAMAGE. |
53 | * | 53 | * |
54 | * The licence and distribution terms for any publically available version or | 54 | * The licence and distribution terms for any publically available version or |
55 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 55 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
56 | * copied and put under another distribution licence | 56 | * copied and put under another distribution licence |
@@ -86,150 +86,149 @@ static int dh_cb(int p, int n, BN_GENCB *cb); | |||
86 | 86 | ||
87 | int MAIN(int, char **); | 87 | int MAIN(int, char **); |
88 | 88 | ||
89 | int MAIN(int argc, char **argv) | 89 | int |
90 | { | 90 | MAIN(int argc, char **argv) |
91 | { | ||
91 | BN_GENCB cb; | 92 | BN_GENCB cb; |
92 | DH *dh=NULL; | 93 | DH *dh = NULL; |
93 | int ret=1,num=DEFBITS; | 94 | int ret = 1, num = DEFBITS; |
94 | int g=2; | 95 | int g = 2; |
95 | char *outfile=NULL; | 96 | char *outfile = NULL; |
96 | char *inrand=NULL; | 97 | char *inrand = NULL; |
97 | #ifndef OPENSSL_NO_ENGINE | 98 | #ifndef OPENSSL_NO_ENGINE |
98 | char *engine=NULL; | 99 | char *engine = NULL; |
99 | #endif | 100 | #endif |
100 | BIO *out=NULL; | 101 | BIO *out = NULL; |
101 | 102 | ||
102 | apps_startup(); | 103 | apps_startup(); |
103 | 104 | ||
104 | BN_GENCB_set(&cb, dh_cb, bio_err); | 105 | BN_GENCB_set(&cb, dh_cb, bio_err); |
105 | if (bio_err == NULL) | 106 | if (bio_err == NULL) |
106 | if ((bio_err=BIO_new(BIO_s_file())) != NULL) | 107 | if ((bio_err = BIO_new(BIO_s_file())) != NULL) |
107 | BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); | 108 | BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); |
108 | 109 | ||
109 | if (!load_config(bio_err, NULL)) | 110 | if (!load_config(bio_err, NULL)) |
110 | goto end; | 111 | goto end; |
111 | 112 | ||
112 | argv++; | 113 | argv++; |
113 | argc--; | 114 | argc--; |
114 | for (;;) | 115 | for (;;) { |
115 | { | 116 | if (argc <= 0) |
116 | if (argc <= 0) break; | 117 | break; |
117 | if (strcmp(*argv,"-out") == 0) | 118 | if (strcmp(*argv, "-out") == 0) { |
118 | { | 119 | if (--argc < 1) |
119 | if (--argc < 1) goto bad; | 120 | goto bad; |
120 | outfile= *(++argv); | 121 | outfile= *(++argv); |
121 | } | 122 | } else if (strcmp(*argv, "-2") == 0) |
122 | else if (strcmp(*argv,"-2") == 0) | 123 | g = 2; |
123 | g=2; | ||
124 | /* else if (strcmp(*argv,"-3") == 0) | 124 | /* else if (strcmp(*argv,"-3") == 0) |
125 | g=3; */ | 125 | g=3; */ |
126 | else if (strcmp(*argv,"-5") == 0) | 126 | else if (strcmp(*argv, "-5") == 0) |
127 | g=5; | 127 | g = 5; |
128 | #ifndef OPENSSL_NO_ENGINE | 128 | #ifndef OPENSSL_NO_ENGINE |
129 | else if (strcmp(*argv,"-engine") == 0) | 129 | else if (strcmp(*argv, "-engine") == 0) { |
130 | { | 130 | if (--argc < 1) |
131 | if (--argc < 1) goto bad; | 131 | goto bad; |
132 | engine= *(++argv); | 132 | engine= *(++argv); |
133 | } | 133 | } |
134 | #endif | 134 | #endif |
135 | else if (strcmp(*argv,"-rand") == 0) | 135 | else if (strcmp(*argv, "-rand") == 0) { |
136 | { | 136 | if (--argc < 1) |
137 | if (--argc < 1) goto bad; | 137 | goto bad; |
138 | inrand= *(++argv); | 138 | inrand= *(++argv); |
139 | } | 139 | } else |
140 | else | ||
141 | break; | 140 | break; |
142 | argv++; | 141 | argv++; |
143 | argc--; | 142 | argc--; |
144 | } | 143 | } |
145 | if ((argc >= 1) && ((sscanf(*argv,"%d",&num) == 0) || (num < 0))) | 144 | if ((argc >= 1) && ((sscanf(*argv, "%d",&num) == 0) || (num < 0))) { |
146 | { | ||
147 | bad: | 145 | bad: |
148 | BIO_printf(bio_err,"usage: gendh [args] [numbits]\n"); | 146 | BIO_printf(bio_err, "usage: gendh [args] [numbits]\n"); |
149 | BIO_printf(bio_err," -out file - output the key to 'file\n"); | 147 | BIO_printf(bio_err, " -out file - output the key to 'file\n"); |
150 | BIO_printf(bio_err," -2 - use 2 as the generator value\n"); | 148 | BIO_printf(bio_err, " -2 - use 2 as the generator value\n"); |
151 | /* BIO_printf(bio_err," -3 - use 3 as the generator value\n"); */ | 149 | /* BIO_printf(bio_err," -3 - use 3 as the generator value\n"); */ |
152 | BIO_printf(bio_err," -5 - use 5 as the generator value\n"); | 150 | BIO_printf(bio_err, " -5 - use 5 as the generator value\n"); |
153 | #ifndef OPENSSL_NO_ENGINE | 151 | #ifndef OPENSSL_NO_ENGINE |
154 | BIO_printf(bio_err," -engine e - use engine e, possibly a hardware device.\n"); | 152 | BIO_printf(bio_err, " -engine e - use engine e, possibly a hardware device.\n"); |
155 | #endif | 153 | #endif |
156 | BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); | 154 | BIO_printf(bio_err, " -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); |
157 | BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); | 155 | BIO_printf(bio_err, " - load the file (or the files in the directory) into\n"); |
158 | BIO_printf(bio_err," the random number generator\n"); | 156 | BIO_printf(bio_err, " the random number generator\n"); |
159 | goto end; | 157 | goto end; |
160 | } | 158 | } |
161 | 159 | ||
162 | #ifndef OPENSSL_NO_ENGINE | 160 | #ifndef OPENSSL_NO_ENGINE |
163 | setup_engine(bio_err, engine, 0); | 161 | setup_engine(bio_err, engine, 0); |
164 | #endif | 162 | #endif |
165 | 163 | ||
166 | out=BIO_new(BIO_s_file()); | 164 | out = BIO_new(BIO_s_file()); |
167 | if (out == NULL) | 165 | if (out == NULL) { |
168 | { | ||
169 | ERR_print_errors(bio_err); | 166 | ERR_print_errors(bio_err); |
170 | goto end; | 167 | goto end; |
171 | } | 168 | } |
172 | 169 | ||
173 | if (outfile == NULL) | 170 | if (outfile == NULL) { |
174 | { | 171 | BIO_set_fp(out, stdout, BIO_NOCLOSE); |
175 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | 172 | } else { |
176 | } | 173 | if (BIO_write_filename(out, outfile) <= 0) { |
177 | else | ||
178 | { | ||
179 | if (BIO_write_filename(out,outfile) <= 0) | ||
180 | { | ||
181 | perror(outfile); | 174 | perror(outfile); |
182 | goto end; | 175 | goto end; |
183 | } | ||
184 | } | 176 | } |
177 | } | ||
185 | 178 | ||
186 | if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) | 179 | if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { |
187 | { | 180 | BIO_printf(bio_err, "warning, not much extra random data, consider using the -rand option\n"); |
188 | BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); | 181 | } |
189 | } | ||
190 | if (inrand != NULL) | 182 | if (inrand != NULL) |
191 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | 183 | BIO_printf(bio_err, "%ld semi-random bytes loaded\n", |
192 | app_RAND_load_files(inrand)); | 184 | app_RAND_load_files(inrand)); |
193 | 185 | ||
194 | BIO_printf(bio_err,"Generating DH parameters, %d bit long safe prime, generator %d\n",num,g); | 186 | BIO_printf(bio_err, "Generating DH parameters, %d bit long safe prime, generator %d\n",num,g); |
195 | BIO_printf(bio_err,"This is going to take a long time\n"); | 187 | BIO_printf(bio_err, "This is going to take a long time\n"); |
196 | 188 | ||
197 | if(((dh = DH_new()) == NULL) || !DH_generate_parameters_ex(dh, num, g, &cb)) | 189 | if (((dh = DH_new()) == NULL) || !DH_generate_parameters_ex(dh, num, g, &cb)) |
198 | goto end; | 190 | goto end; |
199 | 191 | ||
200 | app_RAND_write_file(NULL, bio_err); | 192 | app_RAND_write_file(NULL, bio_err); |
201 | 193 | ||
202 | if (!PEM_write_bio_DHparams(out,dh)) | 194 | if (!PEM_write_bio_DHparams(out, dh)) |
203 | goto end; | 195 | goto end; |
204 | ret=0; | 196 | ret = 0; |
205 | end: | 197 | end: |
206 | if (ret != 0) | 198 | if (ret != 0) |
207 | ERR_print_errors(bio_err); | 199 | ERR_print_errors(bio_err); |
208 | if (out != NULL) BIO_free_all(out); | 200 | if (out != NULL) |
209 | if (dh != NULL) DH_free(dh); | 201 | BIO_free_all(out); |
202 | if (dh != NULL) | ||
203 | DH_free(dh); | ||
210 | apps_shutdown(); | 204 | apps_shutdown(); |
211 | OPENSSL_EXIT(ret); | 205 | OPENSSL_EXIT(ret); |
212 | } | 206 | } |
213 | 207 | ||
214 | static int dh_cb(int p, int n, BN_GENCB *cb) | 208 | static int |
215 | { | 209 | dh_cb(int p, int n, BN_GENCB *cb) |
216 | char c='*'; | 210 | { |
217 | 211 | char c = '*'; | |
218 | if (p == 0) c='.'; | 212 | |
219 | if (p == 1) c='+'; | 213 | if (p == 0) |
220 | if (p == 2) c='*'; | 214 | c = '.'; |
221 | if (p == 3) c='\n'; | 215 | if (p == 1) |
222 | BIO_write(cb->arg,&c,1); | 216 | c = '+'; |
217 | if (p == 2) | ||
218 | c = '*'; | ||
219 | if (p == 3) | ||
220 | c = '\n'; | ||
221 | BIO_write(cb->arg, &c, 1); | ||
223 | (void)BIO_flush(cb->arg); | 222 | (void)BIO_flush(cb->arg); |
224 | #ifdef LINT | 223 | #ifdef LINT |
225 | p=n; | 224 | p = n; |
226 | #endif | 225 | #endif |
227 | return 1; | 226 | return 1; |
228 | } | 227 | } |
229 | #else /* !OPENSSL_NO_DH */ | 228 | #else /* !OPENSSL_NO_DH */ |
230 | 229 | ||
231 | # if PEDANTIC | 230 | # if PEDANTIC |
232 | static void *dummy=&dummy; | 231 | static void *dummy = &dummy; |
233 | # endif | 232 | # endif |
234 | 233 | ||
235 | #endif | 234 | #endif |
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 |
diff --git a/src/lib/libssl/src/apps/genpkey.c b/src/lib/libssl/src/apps/genpkey.c index f6b23ac5a6..de375a571b 100644 --- a/src/lib/libssl/src/apps/genpkey.c +++ b/src/lib/libssl/src/apps/genpkey.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -65,16 +65,17 @@ | |||
65 | #include <openssl/engine.h> | 65 | #include <openssl/engine.h> |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, | 68 | static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, const char *file, |
69 | const char *file, ENGINE *e); | 69 | ENGINE *e); |
70 | static int genpkey_cb(EVP_PKEY_CTX *ctx); | 70 | static int genpkey_cb(EVP_PKEY_CTX *ctx); |
71 | 71 | ||
72 | #define PROG genpkey_main | 72 | #define PROG genpkey_main |
73 | 73 | ||
74 | int MAIN(int, char **); | 74 | int MAIN(int, char **); |
75 | 75 | ||
76 | int MAIN(int argc, char **argv) | 76 | int |
77 | { | 77 | MAIN(int argc, char **argv) |
78 | { | ||
78 | ENGINE *e = NULL; | 79 | ENGINE *e = NULL; |
79 | char **args, *outfile = NULL; | 80 | char **args, *outfile = NULL; |
80 | char *passarg = NULL; | 81 | char *passarg = NULL; |
@@ -82,7 +83,7 @@ int MAIN(int argc, char **argv) | |||
82 | const EVP_CIPHER *cipher = NULL; | 83 | const EVP_CIPHER *cipher = NULL; |
83 | int outformat; | 84 | int outformat; |
84 | int text = 0; | 85 | int text = 0; |
85 | EVP_PKEY *pkey=NULL; | 86 | EVP_PKEY *pkey = NULL; |
86 | EVP_PKEY_CTX *ctx = NULL; | 87 | EVP_PKEY_CTX *ctx = NULL; |
87 | char *pass = NULL; | 88 | char *pass = NULL; |
88 | int badarg = 0; | 89 | int badarg = 0; |
@@ -91,42 +92,36 @@ int MAIN(int argc, char **argv) | |||
91 | int do_param = 0; | 92 | int do_param = 0; |
92 | 93 | ||
93 | if (bio_err == NULL) | 94 | if (bio_err == NULL) |
94 | bio_err = BIO_new_fp (stderr, BIO_NOCLOSE); | 95 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); |
95 | 96 | ||
96 | if (!load_config(bio_err, NULL)) | 97 | if (!load_config(bio_err, NULL)) |
97 | goto end; | 98 | goto end; |
98 | 99 | ||
99 | outformat=FORMAT_PEM; | 100 | outformat = FORMAT_PEM; |
100 | 101 | ||
101 | ERR_load_crypto_strings(); | 102 | ERR_load_crypto_strings(); |
102 | OpenSSL_add_all_algorithms(); | 103 | OpenSSL_add_all_algorithms(); |
103 | args = argv + 1; | 104 | args = argv + 1; |
104 | while (!badarg && *args && *args[0] == '-') | 105 | while (!badarg && *args && *args[0] == '-') { |
105 | { | 106 | if (!strcmp(*args, "-outform")) { |
106 | if (!strcmp(*args,"-outform")) | 107 | if (args[1]) { |
107 | { | ||
108 | if (args[1]) | ||
109 | { | ||
110 | args++; | 108 | args++; |
111 | outformat=str2fmt(*args); | 109 | outformat = str2fmt(*args); |
112 | } | 110 | } else |
113 | else badarg = 1; | 111 | badarg = 1; |
114 | } | 112 | } else if (!strcmp(*args, "-pass")) { |
115 | else if (!strcmp(*args,"-pass")) | 113 | if (!args[1]) |
116 | { | 114 | goto bad; |
117 | if (!args[1]) goto bad; | ||
118 | passarg= *(++args); | 115 | passarg= *(++args); |
119 | } | 116 | } |
120 | #ifndef OPENSSL_NO_ENGINE | 117 | #ifndef OPENSSL_NO_ENGINE |
121 | else if (strcmp(*args,"-engine") == 0) | 118 | else if (strcmp(*args, "-engine") == 0) { |
122 | { | ||
123 | if (!args[1]) | 119 | if (!args[1]) |
124 | goto bad; | 120 | goto bad; |
125 | e = setup_engine(bio_err, *(++args), 0); | 121 | e = setup_engine(bio_err, *(++args), 0); |
126 | } | 122 | } |
127 | #endif | 123 | #endif |
128 | else if (!strcmp (*args, "-paramfile")) | 124 | else if (!strcmp (*args, "-paramfile")) { |
129 | { | ||
130 | if (!args[1]) | 125 | if (!args[1]) |
131 | goto bad; | 126 | goto bad; |
132 | args++; | 127 | args++; |
@@ -134,68 +129,52 @@ int MAIN(int argc, char **argv) | |||
134 | goto bad; | 129 | goto bad; |
135 | if (!init_keygen_file(bio_err, &ctx, *args, e)) | 130 | if (!init_keygen_file(bio_err, &ctx, *args, e)) |
136 | goto end; | 131 | goto end; |
137 | } | 132 | } else if (!strcmp (*args, "-out")) { |
138 | else if (!strcmp (*args, "-out")) | 133 | if (args[1]) { |
139 | { | ||
140 | if (args[1]) | ||
141 | { | ||
142 | args++; | 134 | args++; |
143 | outfile = *args; | 135 | outfile = *args; |
144 | } | 136 | } else |
145 | else badarg = 1; | 137 | badarg = 1; |
146 | } | 138 | } else if (strcmp(*args, "-algorithm") == 0) { |
147 | else if (strcmp(*args,"-algorithm") == 0) | ||
148 | { | ||
149 | if (!args[1]) | 139 | if (!args[1]) |
150 | goto bad; | 140 | goto bad; |
151 | if (!init_gen_str(bio_err, &ctx, *(++args),e, do_param)) | 141 | if (!init_gen_str(bio_err, &ctx, *(++args), e, do_param)) |
152 | goto end; | 142 | goto end; |
153 | } | 143 | } else if (strcmp(*args, "-pkeyopt") == 0) { |
154 | else if (strcmp(*args,"-pkeyopt") == 0) | ||
155 | { | ||
156 | if (!args[1]) | 144 | if (!args[1]) |
157 | goto bad; | 145 | goto bad; |
158 | if (!ctx) | 146 | if (!ctx) { |
159 | { | ||
160 | BIO_puts(bio_err, "No keytype specified\n"); | 147 | BIO_puts(bio_err, "No keytype specified\n"); |
161 | goto bad; | 148 | goto bad; |
162 | } | 149 | } else if (pkey_ctrl_string(ctx, *(++args)) <= 0) { |
163 | else if (pkey_ctrl_string(ctx, *(++args)) <= 0) | ||
164 | { | ||
165 | BIO_puts(bio_err, "parameter setting error\n"); | 150 | BIO_puts(bio_err, "parameter setting error\n"); |
166 | ERR_print_errors(bio_err); | 151 | ERR_print_errors(bio_err); |
167 | goto end; | 152 | goto end; |
168 | } | ||
169 | } | 153 | } |
170 | else if (strcmp(*args,"-genparam") == 0) | 154 | } else if (strcmp(*args, "-genparam") == 0) { |
171 | { | ||
172 | if (ctx) | 155 | if (ctx) |
173 | goto bad; | 156 | goto bad; |
174 | do_param = 1; | 157 | do_param = 1; |
175 | } | 158 | } else if (strcmp(*args, "-text") == 0) |
176 | else if (strcmp(*args,"-text") == 0) | 159 | text = 1; |
177 | text=1; | 160 | else { |
178 | else | ||
179 | { | ||
180 | cipher = EVP_get_cipherbyname(*args + 1); | 161 | cipher = EVP_get_cipherbyname(*args + 1); |
181 | if (!cipher) | 162 | if (!cipher) { |
182 | { | ||
183 | BIO_printf(bio_err, "Unknown cipher %s\n", | 163 | BIO_printf(bio_err, "Unknown cipher %s\n", |
184 | *args + 1); | 164 | *args + 1); |
185 | badarg = 1; | 165 | badarg = 1; |
186 | } | 166 | } |
187 | if (do_param == 1) | 167 | if (do_param == 1) |
188 | badarg = 1; | 168 | badarg = 1; |
189 | } | ||
190 | args++; | ||
191 | } | 169 | } |
170 | args++; | ||
171 | } | ||
192 | 172 | ||
193 | if (!ctx) | 173 | if (!ctx) |
194 | badarg = 1; | 174 | badarg = 1; |
195 | 175 | ||
196 | if (badarg) | 176 | if (badarg) { |
197 | { | 177 | bad: |
198 | bad: | ||
199 | BIO_printf(bio_err, "Usage: genpkey [options]\n"); | 178 | BIO_printf(bio_err, "Usage: genpkey [options]\n"); |
200 | BIO_printf(bio_err, "where options may be\n"); | 179 | BIO_printf(bio_err, "where options may be\n"); |
201 | BIO_printf(bio_err, "-out file output file\n"); | 180 | BIO_printf(bio_err, "-out file output file\n"); |
@@ -208,91 +187,77 @@ int MAIN(int argc, char **argv) | |||
208 | BIO_printf(bio_err, "-paramfile file parameters file\n"); | 187 | BIO_printf(bio_err, "-paramfile file parameters file\n"); |
209 | BIO_printf(bio_err, "-algorithm alg the public key algorithm\n"); | 188 | BIO_printf(bio_err, "-algorithm alg the public key algorithm\n"); |
210 | BIO_printf(bio_err, "-pkeyopt opt:value set the public key algorithm option <opt>\n" | 189 | BIO_printf(bio_err, "-pkeyopt opt:value set the public key algorithm option <opt>\n" |
211 | " to value <value>\n"); | 190 | " to value <value>\n"); |
212 | BIO_printf(bio_err, "-genparam generate parameters, not key\n"); | 191 | BIO_printf(bio_err, "-genparam generate parameters, not key\n"); |
213 | BIO_printf(bio_err, "-text print the in text\n"); | 192 | BIO_printf(bio_err, "-text print the in text\n"); |
214 | BIO_printf(bio_err, "NB: options order may be important! See the manual page.\n"); | 193 | BIO_printf(bio_err, "NB: options order may be important! See the manual page.\n"); |
215 | goto end; | 194 | goto end; |
216 | } | 195 | } |
217 | 196 | ||
218 | if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) | 197 | if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) { |
219 | { | ||
220 | BIO_puts(bio_err, "Error getting password\n"); | 198 | BIO_puts(bio_err, "Error getting password\n"); |
221 | goto end; | 199 | goto end; |
222 | } | 200 | } |
223 | 201 | ||
224 | if (outfile) | 202 | if (outfile) { |
225 | { | 203 | if (!(out = BIO_new_file (outfile, "wb"))) { |
226 | if (!(out = BIO_new_file (outfile, "wb"))) | ||
227 | { | ||
228 | BIO_printf(bio_err, | 204 | BIO_printf(bio_err, |
229 | "Can't open output file %s\n", outfile); | 205 | "Can't open output file %s\n", outfile); |
230 | goto end; | 206 | goto end; |
231 | } | ||
232 | } | 207 | } |
233 | else | 208 | } else { |
234 | { | ||
235 | out = BIO_new_fp (stdout, BIO_NOCLOSE); | 209 | out = BIO_new_fp (stdout, BIO_NOCLOSE); |
236 | } | 210 | } |
237 | 211 | ||
238 | EVP_PKEY_CTX_set_cb(ctx, genpkey_cb); | 212 | EVP_PKEY_CTX_set_cb(ctx, genpkey_cb); |
239 | EVP_PKEY_CTX_set_app_data(ctx, bio_err); | 213 | EVP_PKEY_CTX_set_app_data(ctx, bio_err); |
240 | 214 | ||
241 | if (do_param) | 215 | if (do_param) { |
242 | { | 216 | if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) { |
243 | if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) | ||
244 | { | ||
245 | BIO_puts(bio_err, "Error generating parameters\n"); | 217 | BIO_puts(bio_err, "Error generating parameters\n"); |
246 | ERR_print_errors(bio_err); | 218 | ERR_print_errors(bio_err); |
247 | goto end; | 219 | goto end; |
248 | } | ||
249 | } | 220 | } |
250 | else | 221 | } else { |
251 | { | 222 | if (EVP_PKEY_keygen(ctx, &pkey) <= 0) { |
252 | if (EVP_PKEY_keygen(ctx, &pkey) <= 0) | ||
253 | { | ||
254 | BIO_puts(bio_err, "Error generating key\n"); | 223 | BIO_puts(bio_err, "Error generating key\n"); |
255 | ERR_print_errors(bio_err); | 224 | ERR_print_errors(bio_err); |
256 | goto end; | 225 | goto end; |
257 | } | ||
258 | } | 226 | } |
227 | } | ||
259 | 228 | ||
260 | if (do_param) | 229 | if (do_param) |
261 | rv = PEM_write_bio_Parameters(out, pkey); | 230 | rv = PEM_write_bio_Parameters(out, pkey); |
262 | else if (outformat == FORMAT_PEM) | 231 | else if (outformat == FORMAT_PEM) |
263 | rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, | 232 | rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, |
264 | NULL, pass); | 233 | NULL, pass); |
265 | else if (outformat == FORMAT_ASN1) | 234 | else if (outformat == FORMAT_ASN1) |
266 | rv = i2d_PrivateKey_bio(out, pkey); | 235 | rv = i2d_PrivateKey_bio(out, pkey); |
267 | else | 236 | else { |
268 | { | ||
269 | BIO_printf(bio_err, "Bad format specified for key\n"); | 237 | BIO_printf(bio_err, "Bad format specified for key\n"); |
270 | goto end; | 238 | goto end; |
271 | } | 239 | } |
272 | 240 | ||
273 | if (rv <= 0) | 241 | if (rv <= 0) { |
274 | { | ||
275 | BIO_puts(bio_err, "Error writing key\n"); | 242 | BIO_puts(bio_err, "Error writing key\n"); |
276 | ERR_print_errors(bio_err); | 243 | ERR_print_errors(bio_err); |
277 | } | 244 | } |
278 | 245 | ||
279 | if (text) | 246 | if (text) { |
280 | { | ||
281 | if (do_param) | 247 | if (do_param) |
282 | rv = EVP_PKEY_print_params(out, pkey, 0, NULL); | 248 | rv = EVP_PKEY_print_params(out, pkey, 0, NULL); |
283 | else | 249 | else |
284 | rv = EVP_PKEY_print_private(out, pkey, 0, NULL); | 250 | rv = EVP_PKEY_print_private(out, pkey, 0, NULL); |
285 | 251 | ||
286 | if (rv <= 0) | 252 | if (rv <= 0) { |
287 | { | ||
288 | BIO_puts(bio_err, "Error printing key\n"); | 253 | BIO_puts(bio_err, "Error printing key\n"); |
289 | ERR_print_errors(bio_err); | 254 | ERR_print_errors(bio_err); |
290 | } | ||
291 | } | 255 | } |
256 | } | ||
292 | 257 | ||
293 | ret = 0; | 258 | ret = 0; |
294 | 259 | ||
295 | end: | 260 | end: |
296 | if (pkey) | 261 | if (pkey) |
297 | EVP_PKEY_free(pkey); | 262 | EVP_PKEY_free(pkey); |
298 | if (ctx) | 263 | if (ctx) |
@@ -304,35 +269,33 @@ int MAIN(int argc, char **argv) | |||
304 | free(pass); | 269 | free(pass); |
305 | 270 | ||
306 | return ret; | 271 | return ret; |
307 | } | 272 | } |
308 | 273 | ||
309 | static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, | 274 | static int |
310 | const char *file, ENGINE *e) | 275 | init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, |
311 | { | 276 | const char *file, ENGINE *e) |
277 | { | ||
312 | BIO *pbio; | 278 | BIO *pbio; |
313 | EVP_PKEY *pkey = NULL; | 279 | EVP_PKEY *pkey = NULL; |
314 | EVP_PKEY_CTX *ctx = NULL; | 280 | EVP_PKEY_CTX *ctx = NULL; |
315 | if (*pctx) | 281 | if (*pctx) { |
316 | { | ||
317 | BIO_puts(err, "Parameters already set!\n"); | 282 | BIO_puts(err, "Parameters already set!\n"); |
318 | return 0; | 283 | return 0; |
319 | } | 284 | } |
320 | 285 | ||
321 | pbio = BIO_new_file(file, "r"); | 286 | pbio = BIO_new_file(file, "r"); |
322 | if (!pbio) | 287 | if (!pbio) { |
323 | { | ||
324 | BIO_printf(err, "Can't open parameter file %s\n", file); | 288 | BIO_printf(err, "Can't open parameter file %s\n", file); |
325 | return 0; | 289 | return 0; |
326 | } | 290 | } |
327 | 291 | ||
328 | pkey = PEM_read_bio_Parameters(pbio, NULL); | 292 | pkey = PEM_read_bio_Parameters(pbio, NULL); |
329 | BIO_free(pbio); | 293 | BIO_free(pbio); |
330 | 294 | ||
331 | if (!pkey) | 295 | if (!pkey) { |
332 | { | ||
333 | BIO_printf(bio_err, "Error reading parameter file %s\n", file); | 296 | BIO_printf(bio_err, "Error reading parameter file %s\n", file); |
334 | return 0; | 297 | return 0; |
335 | } | 298 | } |
336 | 299 | ||
337 | ctx = EVP_PKEY_CTX_new(pkey, e); | 300 | ctx = EVP_PKEY_CTX_new(pkey, e); |
338 | if (!ctx) | 301 | if (!ctx) |
@@ -343,7 +306,7 @@ static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, | |||
343 | *pctx = ctx; | 306 | *pctx = ctx; |
344 | return 1; | 307 | return 1; |
345 | 308 | ||
346 | err: | 309 | err: |
347 | BIO_puts(err, "Error initializing context\n"); | 310 | BIO_puts(err, "Error initializing context\n"); |
348 | ERR_print_errors(err); | 311 | ERR_print_errors(err); |
349 | if (ctx) | 312 | if (ctx) |
@@ -352,21 +315,21 @@ static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, | |||
352 | EVP_PKEY_free(pkey); | 315 | EVP_PKEY_free(pkey); |
353 | return 0; | 316 | return 0; |
354 | 317 | ||
355 | } | 318 | } |
356 | 319 | ||
357 | int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, | 320 | int |
358 | const char *algname, ENGINE *e, int do_param) | 321 | init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, |
359 | { | 322 | const char *algname, ENGINE *e, int do_param) |
323 | { | ||
360 | EVP_PKEY_CTX *ctx = NULL; | 324 | EVP_PKEY_CTX *ctx = NULL; |
361 | const EVP_PKEY_ASN1_METHOD *ameth; | 325 | const EVP_PKEY_ASN1_METHOD *ameth; |
362 | ENGINE *tmpeng = NULL; | 326 | ENGINE *tmpeng = NULL; |
363 | int pkey_id; | 327 | int pkey_id; |
364 | 328 | ||
365 | if (*pctx) | 329 | if (*pctx) { |
366 | { | ||
367 | BIO_puts(err, "Algorithm already set!\n"); | 330 | BIO_puts(err, "Algorithm already set!\n"); |
368 | return 0; | 331 | return 0; |
369 | } | 332 | } |
370 | 333 | ||
371 | ameth = EVP_PKEY_asn1_find_str(&tmpeng, algname, -1); | 334 | ameth = EVP_PKEY_asn1_find_str(&tmpeng, algname, -1); |
372 | 335 | ||
@@ -375,11 +338,10 @@ int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, | |||
375 | ameth = ENGINE_get_pkey_asn1_meth_str(e, algname, -1); | 338 | ameth = ENGINE_get_pkey_asn1_meth_str(e, algname, -1); |
376 | #endif | 339 | #endif |
377 | 340 | ||
378 | if (!ameth) | 341 | if (!ameth) { |
379 | { | ||
380 | BIO_printf(bio_err, "Algorithm %s not found\n", algname); | 342 | BIO_printf(bio_err, "Algorithm %s not found\n", algname); |
381 | return 0; | 343 | return 0; |
382 | } | 344 | } |
383 | 345 | ||
384 | ERR_clear_error(); | 346 | ERR_clear_error(); |
385 | 347 | ||
@@ -392,43 +354,45 @@ int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, | |||
392 | 354 | ||
393 | if (!ctx) | 355 | if (!ctx) |
394 | goto err; | 356 | goto err; |
395 | if (do_param) | 357 | if (do_param) { |
396 | { | ||
397 | if (EVP_PKEY_paramgen_init(ctx) <= 0) | 358 | if (EVP_PKEY_paramgen_init(ctx) <= 0) |
398 | goto err; | 359 | goto err; |
399 | } | 360 | } else { |
400 | else | ||
401 | { | ||
402 | if (EVP_PKEY_keygen_init(ctx) <= 0) | 361 | if (EVP_PKEY_keygen_init(ctx) <= 0) |
403 | goto err; | 362 | goto err; |
404 | } | 363 | } |
405 | 364 | ||
406 | *pctx = ctx; | 365 | *pctx = ctx; |
407 | return 1; | 366 | return 1; |
408 | 367 | ||
409 | err: | 368 | err: |
410 | BIO_printf(err, "Error initializing %s context\n", algname); | 369 | BIO_printf(err, "Error initializing %s context\n", algname); |
411 | ERR_print_errors(err); | 370 | ERR_print_errors(err); |
412 | if (ctx) | 371 | if (ctx) |
413 | EVP_PKEY_CTX_free(ctx); | 372 | EVP_PKEY_CTX_free(ctx); |
414 | return 0; | 373 | return 0; |
415 | 374 | ||
416 | } | 375 | } |
417 | 376 | ||
418 | static int genpkey_cb(EVP_PKEY_CTX *ctx) | 377 | static int |
419 | { | 378 | genpkey_cb(EVP_PKEY_CTX *ctx) |
420 | char c='*'; | 379 | { |
380 | char c = '*'; | ||
421 | BIO *b = EVP_PKEY_CTX_get_app_data(ctx); | 381 | BIO *b = EVP_PKEY_CTX_get_app_data(ctx); |
422 | int p; | 382 | int p; |
423 | p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); | 383 | p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); |
424 | if (p == 0) c='.'; | 384 | if (p == 0) |
425 | if (p == 1) c='+'; | 385 | c = '.'; |
426 | if (p == 2) c='*'; | 386 | if (p == 1) |
427 | if (p == 3) c='\n'; | 387 | c = '+'; |
428 | BIO_write(b,&c,1); | 388 | if (p == 2) |
389 | c = '*'; | ||
390 | if (p == 3) | ||
391 | c = '\n'; | ||
392 | BIO_write(b, &c, 1); | ||
429 | (void)BIO_flush(b); | 393 | (void)BIO_flush(b); |
430 | #ifdef LINT | 394 | #ifdef LINT |
431 | p=n; | 395 | p = n; |
432 | #endif | 396 | #endif |
433 | return 1; | 397 | return 1; |
434 | } | 398 | } |
diff --git a/src/lib/libssl/src/apps/genrsa.c b/src/lib/libssl/src/apps/genrsa.c index 1be17d9ac6..65e136a8d2 100644 --- a/src/lib/libssl/src/apps/genrsa.c +++ b/src/lib/libssl/src/apps/genrsa.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 |
@@ -86,179 +86,171 @@ static int genrsa_cb(int p, int n, BN_GENCB *cb); | |||
86 | 86 | ||
87 | int MAIN(int, char **); | 87 | int MAIN(int, char **); |
88 | 88 | ||
89 | int MAIN(int argc, char **argv) | 89 | int |
90 | { | 90 | MAIN(int argc, char **argv) |
91 | { | ||
91 | BN_GENCB cb; | 92 | BN_GENCB cb; |
92 | #ifndef OPENSSL_NO_ENGINE | 93 | #ifndef OPENSSL_NO_ENGINE |
93 | ENGINE *e = NULL; | 94 | ENGINE *e = NULL; |
94 | #endif | 95 | #endif |
95 | int ret=1; | 96 | int ret = 1; |
96 | int i,num=DEFBITS; | 97 | int i, num = DEFBITS; |
97 | long l; | 98 | long l; |
98 | const EVP_CIPHER *enc=NULL; | 99 | const EVP_CIPHER *enc = NULL; |
99 | unsigned long f4=RSA_F4; | 100 | unsigned long f4 = RSA_F4; |
100 | char *outfile=NULL; | 101 | char *outfile = NULL; |
101 | char *passargout = NULL, *passout = NULL; | 102 | char *passargout = NULL, *passout = NULL; |
102 | #ifndef OPENSSL_NO_ENGINE | 103 | #ifndef OPENSSL_NO_ENGINE |
103 | char *engine=NULL; | 104 | char *engine = NULL; |
104 | #endif | 105 | #endif |
105 | char *inrand=NULL; | 106 | char *inrand = NULL; |
106 | BIO *out=NULL; | 107 | BIO *out = NULL; |
107 | BIGNUM *bn = BN_new(); | 108 | BIGNUM *bn = BN_new(); |
108 | RSA *rsa = NULL; | 109 | RSA *rsa = NULL; |
109 | 110 | ||
110 | if(!bn) goto err; | 111 | if (!bn) goto err; |
111 | 112 | ||
112 | apps_startup(); | 113 | apps_startup(); |
113 | BN_GENCB_set(&cb, genrsa_cb, bio_err); | 114 | BN_GENCB_set(&cb, genrsa_cb, bio_err); |
114 | 115 | ||
115 | if (bio_err == NULL) | 116 | if (bio_err == NULL) |
116 | if ((bio_err=BIO_new(BIO_s_file())) != NULL) | 117 | if ((bio_err = BIO_new(BIO_s_file())) != NULL) |
117 | BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); | 118 | BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); |
118 | 119 | ||
119 | if (!load_config(bio_err, NULL)) | 120 | if (!load_config(bio_err, NULL)) |
120 | goto err; | 121 | goto err; |
121 | if ((out=BIO_new(BIO_s_file())) == NULL) | 122 | if ((out = BIO_new(BIO_s_file())) == NULL) { |
122 | { | 123 | BIO_printf(bio_err, "unable to create BIO for output\n"); |
123 | BIO_printf(bio_err,"unable to create BIO for output\n"); | ||
124 | goto err; | 124 | goto err; |
125 | } | 125 | } |
126 | 126 | ||
127 | argv++; | 127 | argv++; |
128 | argc--; | 128 | argc--; |
129 | for (;;) | 129 | for (;;) { |
130 | { | 130 | if (argc <= 0) |
131 | if (argc <= 0) break; | 131 | break; |
132 | if (strcmp(*argv,"-out") == 0) | 132 | if (strcmp(*argv, "-out") == 0) { |
133 | { | 133 | if (--argc < 1) |
134 | if (--argc < 1) goto bad; | 134 | goto bad; |
135 | outfile= *(++argv); | 135 | outfile= *(++argv); |
136 | } | 136 | } else if (strcmp(*argv, "-3") == 0) |
137 | else if (strcmp(*argv,"-3") == 0) | 137 | f4 = 3; |
138 | f4=3; | 138 | else if (strcmp(*argv, "-F4") == 0 || strcmp(*argv,"-f4") == 0) |
139 | else if (strcmp(*argv,"-F4") == 0 || strcmp(*argv,"-f4") == 0) | 139 | f4 = RSA_F4; |
140 | f4=RSA_F4; | ||
141 | #ifndef OPENSSL_NO_ENGINE | 140 | #ifndef OPENSSL_NO_ENGINE |
142 | else if (strcmp(*argv,"-engine") == 0) | 141 | else if (strcmp(*argv, "-engine") == 0) { |
143 | { | 142 | if (--argc < 1) |
144 | if (--argc < 1) goto bad; | 143 | goto bad; |
145 | engine= *(++argv); | 144 | engine= *(++argv); |
146 | } | 145 | } |
147 | #endif | 146 | #endif |
148 | else if (strcmp(*argv,"-rand") == 0) | 147 | else if (strcmp(*argv, "-rand") == 0) { |
149 | { | 148 | if (--argc < 1) |
150 | if (--argc < 1) goto bad; | 149 | goto bad; |
151 | inrand= *(++argv); | 150 | inrand= *(++argv); |
152 | } | 151 | } |
153 | #ifndef OPENSSL_NO_DES | 152 | #ifndef OPENSSL_NO_DES |
154 | else if (strcmp(*argv,"-des") == 0) | 153 | else if (strcmp(*argv, "-des") == 0) |
155 | enc=EVP_des_cbc(); | 154 | enc = EVP_des_cbc(); |
156 | else if (strcmp(*argv,"-des3") == 0) | 155 | else if (strcmp(*argv, "-des3") == 0) |
157 | enc=EVP_des_ede3_cbc(); | 156 | enc = EVP_des_ede3_cbc(); |
158 | #endif | 157 | #endif |
159 | #ifndef OPENSSL_NO_IDEA | 158 | #ifndef OPENSSL_NO_IDEA |
160 | else if (strcmp(*argv,"-idea") == 0) | 159 | else if (strcmp(*argv, "-idea") == 0) |
161 | enc=EVP_idea_cbc(); | 160 | enc = EVP_idea_cbc(); |
162 | #endif | 161 | #endif |
163 | #ifndef OPENSSL_NO_SEED | 162 | #ifndef OPENSSL_NO_SEED |
164 | else if (strcmp(*argv,"-seed") == 0) | 163 | else if (strcmp(*argv, "-seed") == 0) |
165 | enc=EVP_seed_cbc(); | 164 | enc = EVP_seed_cbc(); |
166 | #endif | 165 | #endif |
167 | #ifndef OPENSSL_NO_AES | 166 | #ifndef OPENSSL_NO_AES |
168 | else if (strcmp(*argv,"-aes128") == 0) | 167 | else if (strcmp(*argv, "-aes128") == 0) |
169 | enc=EVP_aes_128_cbc(); | 168 | enc = EVP_aes_128_cbc(); |
170 | else if (strcmp(*argv,"-aes192") == 0) | 169 | else if (strcmp(*argv, "-aes192") == 0) |
171 | enc=EVP_aes_192_cbc(); | 170 | enc = EVP_aes_192_cbc(); |
172 | else if (strcmp(*argv,"-aes256") == 0) | 171 | else if (strcmp(*argv, "-aes256") == 0) |
173 | enc=EVP_aes_256_cbc(); | 172 | enc = EVP_aes_256_cbc(); |
174 | #endif | 173 | #endif |
175 | #ifndef OPENSSL_NO_CAMELLIA | 174 | #ifndef OPENSSL_NO_CAMELLIA |
176 | else if (strcmp(*argv,"-camellia128") == 0) | 175 | else if (strcmp(*argv, "-camellia128") == 0) |
177 | enc=EVP_camellia_128_cbc(); | 176 | enc = EVP_camellia_128_cbc(); |
178 | else if (strcmp(*argv,"-camellia192") == 0) | 177 | else if (strcmp(*argv, "-camellia192") == 0) |
179 | enc=EVP_camellia_192_cbc(); | 178 | enc = EVP_camellia_192_cbc(); |
180 | else if (strcmp(*argv,"-camellia256") == 0) | 179 | else if (strcmp(*argv, "-camellia256") == 0) |
181 | enc=EVP_camellia_256_cbc(); | 180 | enc = EVP_camellia_256_cbc(); |
182 | #endif | 181 | #endif |
183 | else if (strcmp(*argv,"-passout") == 0) | 182 | else if (strcmp(*argv, "-passout") == 0) { |
184 | { | 183 | if (--argc < 1) |
185 | if (--argc < 1) goto bad; | 184 | goto bad; |
186 | passargout= *(++argv); | 185 | passargout= *(++argv); |
187 | } | 186 | } else |
188 | else | ||
189 | break; | 187 | break; |
190 | argv++; | 188 | argv++; |
191 | argc--; | 189 | argc--; |
192 | } | 190 | } |
193 | if ((argc >= 1) && ((sscanf(*argv,"%d",&num) == 0) || (num < 0))) | 191 | if ((argc >= 1) && ((sscanf(*argv, "%d",&num) == 0) || (num < 0))) { |
194 | { | ||
195 | bad: | 192 | bad: |
196 | BIO_printf(bio_err,"usage: genrsa [args] [numbits]\n"); | 193 | BIO_printf(bio_err, "usage: genrsa [args] [numbits]\n"); |
197 | BIO_printf(bio_err," -des encrypt the generated key with DES in cbc mode\n"); | 194 | BIO_printf(bio_err, " -des encrypt the generated key with DES in cbc mode\n"); |
198 | BIO_printf(bio_err," -des3 encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); | 195 | BIO_printf(bio_err, " -des3 encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); |
199 | #ifndef OPENSSL_NO_IDEA | 196 | #ifndef OPENSSL_NO_IDEA |
200 | BIO_printf(bio_err," -idea encrypt the generated key with IDEA in cbc mode\n"); | 197 | BIO_printf(bio_err, " -idea encrypt the generated key with IDEA in cbc mode\n"); |
201 | #endif | 198 | #endif |
202 | #ifndef OPENSSL_NO_SEED | 199 | #ifndef OPENSSL_NO_SEED |
203 | BIO_printf(bio_err," -seed\n"); | 200 | BIO_printf(bio_err, " -seed\n"); |
204 | BIO_printf(bio_err," encrypt PEM output with cbc seed\n"); | 201 | BIO_printf(bio_err, " encrypt PEM output with cbc seed\n"); |
205 | #endif | 202 | #endif |
206 | #ifndef OPENSSL_NO_AES | 203 | #ifndef OPENSSL_NO_AES |
207 | BIO_printf(bio_err," -aes128, -aes192, -aes256\n"); | 204 | BIO_printf(bio_err, " -aes128, -aes192, -aes256\n"); |
208 | BIO_printf(bio_err," encrypt PEM output with cbc aes\n"); | 205 | BIO_printf(bio_err, " encrypt PEM output with cbc aes\n"); |
209 | #endif | 206 | #endif |
210 | #ifndef OPENSSL_NO_CAMELLIA | 207 | #ifndef OPENSSL_NO_CAMELLIA |
211 | BIO_printf(bio_err," -camellia128, -camellia192, -camellia256\n"); | 208 | BIO_printf(bio_err, " -camellia128, -camellia192, -camellia256\n"); |
212 | BIO_printf(bio_err," encrypt PEM output with cbc camellia\n"); | 209 | BIO_printf(bio_err, " encrypt PEM output with cbc camellia\n"); |
213 | #endif | 210 | #endif |
214 | BIO_printf(bio_err," -out file output the key to 'file\n"); | 211 | BIO_printf(bio_err, " -out file output the key to 'file\n"); |
215 | BIO_printf(bio_err," -passout arg output file pass phrase source\n"); | 212 | BIO_printf(bio_err, " -passout arg output file pass phrase source\n"); |
216 | BIO_printf(bio_err," -f4 use F4 (0x10001) for the E value\n"); | 213 | BIO_printf(bio_err, " -f4 use F4 (0x10001) for the E value\n"); |
217 | BIO_printf(bio_err," -3 use 3 for the E value\n"); | 214 | BIO_printf(bio_err, " -3 use 3 for the E value\n"); |
218 | #ifndef OPENSSL_NO_ENGINE | 215 | #ifndef OPENSSL_NO_ENGINE |
219 | BIO_printf(bio_err," -engine e use engine e, possibly a hardware device.\n"); | 216 | BIO_printf(bio_err, " -engine e use engine e, possibly a hardware device.\n"); |
220 | #endif | 217 | #endif |
221 | BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); | 218 | BIO_printf(bio_err, " -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); |
222 | BIO_printf(bio_err," load the file (or the files in the directory) into\n"); | 219 | BIO_printf(bio_err, " load the file (or the files in the directory) into\n"); |
223 | BIO_printf(bio_err," the random number generator\n"); | 220 | BIO_printf(bio_err, " the random number generator\n"); |
224 | goto err; | 221 | goto err; |
225 | } | 222 | } |
226 | 223 | ||
227 | ERR_load_crypto_strings(); | 224 | ERR_load_crypto_strings(); |
228 | 225 | ||
229 | if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { | 226 | if (!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { |
230 | BIO_printf(bio_err, "Error getting password\n"); | 227 | BIO_printf(bio_err, "Error getting password\n"); |
231 | goto err; | 228 | goto err; |
232 | } | 229 | } |
233 | 230 | ||
234 | #ifndef OPENSSL_NO_ENGINE | 231 | #ifndef OPENSSL_NO_ENGINE |
235 | e = setup_engine(bio_err, engine, 0); | 232 | e = setup_engine(bio_err, engine, 0); |
236 | #endif | 233 | #endif |
237 | 234 | ||
238 | if (outfile == NULL) | 235 | if (outfile == NULL) { |
239 | { | 236 | BIO_set_fp(out, stdout, BIO_NOCLOSE); |
240 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | 237 | } else { |
241 | } | 238 | if (BIO_write_filename(out, outfile) <= 0) { |
242 | else | ||
243 | { | ||
244 | if (BIO_write_filename(out,outfile) <= 0) | ||
245 | { | ||
246 | perror(outfile); | 239 | perror(outfile); |
247 | goto err; | 240 | goto err; |
248 | } | ||
249 | } | 241 | } |
242 | } | ||
250 | 243 | ||
251 | if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL | 244 | if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL && |
252 | && !RAND_status()) | 245 | !RAND_status()) { |
253 | { | 246 | BIO_printf(bio_err, "warning, not much extra random data, consider using the -rand option\n"); |
254 | BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); | 247 | } |
255 | } | ||
256 | if (inrand != NULL) | 248 | if (inrand != NULL) |
257 | BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | 249 | BIO_printf(bio_err, "%ld semi-random bytes loaded\n", |
258 | app_RAND_load_files(inrand)); | 250 | app_RAND_load_files(inrand)); |
259 | 251 | ||
260 | BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n", | 252 | BIO_printf(bio_err, "Generating RSA private key, %d bit long modulus\n", |
261 | num); | 253 | num); |
262 | #ifdef OPENSSL_NO_ENGINE | 254 | #ifdef OPENSSL_NO_ENGINE |
263 | rsa = RSA_new(); | 255 | rsa = RSA_new(); |
264 | #else | 256 | #else |
@@ -267,63 +259,70 @@ bad: | |||
267 | if (!rsa) | 259 | if (!rsa) |
268 | goto err; | 260 | goto err; |
269 | 261 | ||
270 | if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb)) | 262 | if (!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb)) |
271 | goto err; | 263 | goto err; |
272 | 264 | ||
273 | app_RAND_write_file(NULL, bio_err); | 265 | app_RAND_write_file(NULL, bio_err); |
274 | 266 | ||
275 | /* We need to do the following for when the base number size is < | 267 | /* We need to do the following for when the base number size is < |
276 | * long, esp windows 3.1 :-(. */ | 268 | * long, esp windows 3.1 :-(. */ |
277 | l=0L; | 269 | l = 0L; |
278 | for (i=0; i<rsa->e->top; i++) | 270 | for (i = 0; i < rsa->e->top; i++) { |
279 | { | ||
280 | #ifndef SIXTY_FOUR_BIT | 271 | #ifndef SIXTY_FOUR_BIT |
281 | l<<=BN_BITS4; | 272 | l<<=BN_BITS4; |
282 | l<<=BN_BITS4; | 273 | l<<=BN_BITS4; |
283 | #endif | 274 | #endif |
284 | l+=rsa->e->d[i]; | 275 | l += rsa->e->d[i]; |
285 | } | 276 | } |
286 | BIO_printf(bio_err,"e is %ld (0x%lX)\n",l,l); | 277 | BIO_printf(bio_err, "e is %ld (0x%lX)\n",l,l); |
287 | { | 278 | { |
288 | PW_CB_DATA cb_data; | 279 | PW_CB_DATA cb_data; |
289 | cb_data.password = passout; | 280 | cb_data.password = passout; |
290 | cb_data.prompt_info = outfile; | 281 | cb_data.prompt_info = outfile; |
291 | if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0, | 282 | if (!PEM_write_bio_RSAPrivateKey(out, rsa, enc, NULL, 0, |
292 | (pem_password_cb *)password_callback,&cb_data)) | 283 | (pem_password_cb *)password_callback, &cb_data)) |
293 | goto err; | 284 | goto err; |
294 | } | 285 | } |
295 | 286 | ||
296 | ret=0; | 287 | ret = 0; |
297 | err: | 288 | err: |
298 | if (bn) BN_free(bn); | 289 | if (bn) |
299 | if (rsa) RSA_free(rsa); | 290 | BN_free(bn); |
300 | if (out) BIO_free_all(out); | 291 | if (rsa) |
301 | if(passout) free(passout); | 292 | RSA_free(rsa); |
302 | if (ret != 0) | 293 | if (out) |
303 | ERR_print_errors(bio_err); | 294 | BIO_free_all(out); |
295 | if (passout) free(passout); | ||
296 | if (ret != 0) | ||
297 | ERR_print_errors(bio_err); | ||
304 | apps_shutdown(); | 298 | apps_shutdown(); |
305 | OPENSSL_EXIT(ret); | 299 | OPENSSL_EXIT(ret); |
306 | } | 300 | } |
307 | 301 | ||
308 | static int genrsa_cb(int p, int n, BN_GENCB *cb) | 302 | static int |
309 | { | 303 | genrsa_cb(int p, int n, BN_GENCB *cb) |
310 | char c='*'; | 304 | { |
305 | char c = '*'; | ||
311 | 306 | ||
312 | if (p == 0) c='.'; | 307 | if (p == 0) |
313 | if (p == 1) c='+'; | 308 | c = '.'; |
314 | if (p == 2) c='*'; | 309 | if (p == 1) |
315 | if (p == 3) c='\n'; | 310 | c = '+'; |
316 | BIO_write(cb->arg,&c,1); | 311 | if (p == 2) |
312 | c = '*'; | ||
313 | if (p == 3) | ||
314 | c = '\n'; | ||
315 | BIO_write(cb->arg, &c, 1); | ||
317 | (void)BIO_flush(cb->arg); | 316 | (void)BIO_flush(cb->arg); |
318 | #ifdef LINT | 317 | #ifdef LINT |
319 | p=n; | 318 | p = n; |
320 | #endif | 319 | #endif |
321 | return 1; | 320 | return 1; |
322 | } | 321 | } |
323 | #else /* !OPENSSL_NO_RSA */ | 322 | #else /* !OPENSSL_NO_RSA */ |
324 | 323 | ||
325 | # if PEDANTIC | 324 | # if PEDANTIC |
326 | static void *dummy=&dummy; | 325 | static void *dummy = &dummy; |
327 | # endif | 326 | # endif |
328 | 327 | ||
329 | #endif | 328 | #endif |