diff options
Diffstat (limited to 'src/lib/libssl/src/apps/genrsa.c')
-rw-r--r-- | src/lib/libssl/src/apps/genrsa.c | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/lib/libssl/src/apps/genrsa.c b/src/lib/libssl/src/apps/genrsa.c index e6e9877cb9..67e68fc20a 100644 --- a/src/lib/libssl/src/apps/genrsa.c +++ b/src/lib/libssl/src/apps/genrsa.c | |||
@@ -82,7 +82,7 @@ | |||
82 | #undef PROG | 82 | #undef PROG |
83 | #define PROG genrsa_main | 83 | #define PROG genrsa_main |
84 | 84 | ||
85 | static int genrsa_cb(int p, int n, BN_GENCB *cb); | 85 | 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 | ||
@@ -108,14 +108,15 @@ MAIN(int argc, char **argv) | |||
108 | BIGNUM *bn = BN_new(); | 108 | BIGNUM *bn = BN_new(); |
109 | RSA *rsa = NULL; | 109 | RSA *rsa = NULL; |
110 | 110 | ||
111 | if (!bn) goto err; | 111 | if (!bn) |
112 | goto err; | ||
112 | 113 | ||
113 | apps_startup(); | 114 | apps_startup(); |
114 | BN_GENCB_set(&cb, genrsa_cb, bio_err); | 115 | BN_GENCB_set(&cb, genrsa_cb, bio_err); |
115 | 116 | ||
116 | if (bio_err == NULL) | 117 | if (bio_err == NULL) |
117 | if ((bio_err = BIO_new(BIO_s_file())) != NULL) | 118 | if ((bio_err = BIO_new(BIO_s_file())) != NULL) |
118 | BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); | 119 | BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT); |
119 | 120 | ||
120 | if (!load_config(bio_err, NULL)) | 121 | if (!load_config(bio_err, NULL)) |
121 | goto err; | 122 | goto err; |
@@ -123,7 +124,6 @@ MAIN(int argc, char **argv) | |||
123 | BIO_printf(bio_err, "unable to create BIO for output\n"); | 124 | BIO_printf(bio_err, "unable to create BIO for output\n"); |
124 | goto err; | 125 | goto err; |
125 | } | 126 | } |
126 | |||
127 | argv++; | 127 | argv++; |
128 | argc--; | 128 | argc--; |
129 | for (;;) { | 129 | for (;;) { |
@@ -132,22 +132,22 @@ MAIN(int argc, char **argv) | |||
132 | if (strcmp(*argv, "-out") == 0) { | 132 | if (strcmp(*argv, "-out") == 0) { |
133 | if (--argc < 1) | 133 | if (--argc < 1) |
134 | goto bad; | 134 | goto bad; |
135 | outfile= *(++argv); | 135 | outfile = *(++argv); |
136 | } else if (strcmp(*argv, "-3") == 0) | 136 | } else if (strcmp(*argv, "-3") == 0) |
137 | f4 = 3; | 137 | f4 = 3; |
138 | else if (strcmp(*argv, "-F4") == 0 || strcmp(*argv,"-f4") == 0) | 138 | else if (strcmp(*argv, "-F4") == 0 || strcmp(*argv, "-f4") == 0) |
139 | f4 = RSA_F4; | 139 | f4 = RSA_F4; |
140 | #ifndef OPENSSL_NO_ENGINE | 140 | #ifndef OPENSSL_NO_ENGINE |
141 | else if (strcmp(*argv, "-engine") == 0) { | 141 | else if (strcmp(*argv, "-engine") == 0) { |
142 | if (--argc < 1) | 142 | if (--argc < 1) |
143 | goto bad; | 143 | goto bad; |
144 | engine= *(++argv); | 144 | engine = *(++argv); |
145 | } | 145 | } |
146 | #endif | 146 | #endif |
147 | else if (strcmp(*argv, "-rand") == 0) { | 147 | else if (strcmp(*argv, "-rand") == 0) { |
148 | if (--argc < 1) | 148 | if (--argc < 1) |
149 | goto bad; | 149 | goto bad; |
150 | inrand= *(++argv); | 150 | inrand = *(++argv); |
151 | } | 151 | } |
152 | #ifndef OPENSSL_NO_DES | 152 | #ifndef OPENSSL_NO_DES |
153 | else if (strcmp(*argv, "-des") == 0) | 153 | else if (strcmp(*argv, "-des") == 0) |
@@ -182,13 +182,13 @@ MAIN(int argc, char **argv) | |||
182 | else if (strcmp(*argv, "-passout") == 0) { | 182 | else if (strcmp(*argv, "-passout") == 0) { |
183 | if (--argc < 1) | 183 | if (--argc < 1) |
184 | goto bad; | 184 | goto bad; |
185 | passargout= *(++argv); | 185 | passargout = *(++argv); |
186 | } else | 186 | } else |
187 | break; | 187 | break; |
188 | argv++; | 188 | argv++; |
189 | argc--; | 189 | argc--; |
190 | } | 190 | } |
191 | if ((argc >= 1) && ((sscanf(*argv, "%d",&num) == 0) || (num < 0))) { | 191 | if ((argc >= 1) && ((sscanf(*argv, "%d", &num) == 0) || (num < 0))) { |
192 | bad: | 192 | bad: |
193 | BIO_printf(bio_err, "usage: genrsa [args] [numbits]\n"); | 193 | BIO_printf(bio_err, "usage: genrsa [args] [numbits]\n"); |
194 | 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"); |
@@ -220,14 +220,12 @@ bad: | |||
220 | BIO_printf(bio_err, " the random number generator\n"); | 220 | BIO_printf(bio_err, " the random number generator\n"); |
221 | goto err; | 221 | goto err; |
222 | } | 222 | } |
223 | |||
224 | ERR_load_crypto_strings(); | 223 | ERR_load_crypto_strings(); |
225 | 224 | ||
226 | if (!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { | 225 | if (!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { |
227 | BIO_printf(bio_err, "Error getting password\n"); | 226 | BIO_printf(bio_err, "Error getting password\n"); |
228 | goto err; | 227 | goto err; |
229 | } | 228 | } |
230 | |||
231 | #ifndef OPENSSL_NO_ENGINE | 229 | #ifndef OPENSSL_NO_ENGINE |
232 | e = setup_engine(bio_err, engine, 0); | 230 | e = setup_engine(bio_err, engine, 0); |
233 | #endif | 231 | #endif |
@@ -264,23 +262,25 @@ bad: | |||
264 | 262 | ||
265 | app_RAND_write_file(NULL, bio_err); | 263 | app_RAND_write_file(NULL, bio_err); |
266 | 264 | ||
267 | /* We need to do the following for when the base number size is < | 265 | /* |
268 | * long, esp windows 3.1 :-(. */ | 266 | * We need to do the following for when the base number size is < |
267 | * long, esp windows 3.1 :-(. | ||
268 | */ | ||
269 | l = 0L; | 269 | l = 0L; |
270 | for (i = 0; i < rsa->e->top; i++) { | 270 | for (i = 0; i < rsa->e->top; i++) { |
271 | #ifndef SIXTY_FOUR_BIT | 271 | #ifndef SIXTY_FOUR_BIT |
272 | l<<=BN_BITS4; | 272 | l <<= BN_BITS4; |
273 | l<<=BN_BITS4; | 273 | l <<= BN_BITS4; |
274 | #endif | 274 | #endif |
275 | l += rsa->e->d[i]; | 275 | l += rsa->e->d[i]; |
276 | } | 276 | } |
277 | 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); |
278 | { | 278 | { |
279 | PW_CB_DATA cb_data; | 279 | PW_CB_DATA cb_data; |
280 | cb_data.password = passout; | 280 | cb_data.password = passout; |
281 | cb_data.prompt_info = outfile; | 281 | cb_data.prompt_info = outfile; |
282 | if (!PEM_write_bio_RSAPrivateKey(out, rsa, enc, NULL, 0, | 282 | if (!PEM_write_bio_RSAPrivateKey(out, rsa, enc, NULL, 0, |
283 | (pem_password_cb *)password_callback, &cb_data)) | 283 | (pem_password_cb *) password_callback, &cb_data)) |
284 | goto err; | 284 | goto err; |
285 | } | 285 | } |
286 | 286 | ||
@@ -292,15 +292,16 @@ err: | |||
292 | RSA_free(rsa); | 292 | RSA_free(rsa); |
293 | if (out) | 293 | if (out) |
294 | BIO_free_all(out); | 294 | BIO_free_all(out); |
295 | if (passout) free(passout); | 295 | if (passout) |
296 | if (ret != 0) | 296 | free(passout); |
297 | ERR_print_errors(bio_err); | 297 | if (ret != 0) |
298 | ERR_print_errors(bio_err); | ||
298 | apps_shutdown(); | 299 | apps_shutdown(); |
299 | return(ret); | 300 | return (ret); |
300 | } | 301 | } |
301 | 302 | ||
302 | static int | 303 | static int |
303 | genrsa_cb(int p, int n, BN_GENCB *cb) | 304 | genrsa_cb(int p, int n, BN_GENCB * cb) |
304 | { | 305 | { |
305 | char c = '*'; | 306 | char c = '*'; |
306 | 307 | ||
@@ -313,16 +314,16 @@ genrsa_cb(int p, int n, BN_GENCB *cb) | |||
313 | if (p == 3) | 314 | if (p == 3) |
314 | c = '\n'; | 315 | c = '\n'; |
315 | BIO_write(cb->arg, &c, 1); | 316 | BIO_write(cb->arg, &c, 1); |
316 | (void)BIO_flush(cb->arg); | 317 | (void) BIO_flush(cb->arg); |
317 | #ifdef LINT | 318 | #ifdef LINT |
318 | p = n; | 319 | p = n; |
319 | #endif | 320 | #endif |
320 | return 1; | 321 | return 1; |
321 | } | 322 | } |
322 | #else /* !OPENSSL_NO_RSA */ | 323 | #else /* !OPENSSL_NO_RSA */ |
323 | 324 | ||
324 | # if PEDANTIC | 325 | #if PEDANTIC |
325 | static void *dummy = &dummy; | 326 | static void *dummy = &dummy; |
326 | # endif | 327 | #endif |
327 | 328 | ||
328 | #endif | 329 | #endif |