| OLD | NEW |
| 1 /* apps/genrsa.c */ | 1 /* apps/genrsa.c */ |
| 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 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 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 int MAIN(int argc, char **argv) | 89 int MAIN(int argc, char **argv) |
| 90 { | 90 { |
| 91 BN_GENCB cb; | 91 BN_GENCB cb; |
| 92 #ifndef OPENSSL_NO_ENGINE | 92 #ifndef OPENSSL_NO_ENGINE |
| 93 ENGINE *e = NULL; | 93 ENGINE *e = NULL; |
| 94 #endif | 94 #endif |
| 95 int ret=1; | 95 int ret=1; |
| 96 int i,num=DEFBITS; | 96 int i,num=DEFBITS; |
| 97 long l; | 97 long l; |
| 98 int use_x931 = 0; | |
| 99 const EVP_CIPHER *enc=NULL; | 98 const EVP_CIPHER *enc=NULL; |
| 100 unsigned long f4=RSA_F4; | 99 unsigned long f4=RSA_F4; |
| 101 char *outfile=NULL; | 100 char *outfile=NULL; |
| 102 char *passargout = NULL, *passout = NULL; | 101 char *passargout = NULL, *passout = NULL; |
| 103 #ifndef OPENSSL_NO_ENGINE | 102 #ifndef OPENSSL_NO_ENGINE |
| 104 char *engine=NULL; | 103 char *engine=NULL; |
| 105 #endif | 104 #endif |
| 106 char *inrand=NULL; | 105 char *inrand=NULL; |
| 107 BIO *out=NULL; | 106 BIO *out=NULL; |
| 108 BIGNUM *bn = BN_new(); | 107 BIGNUM *bn = BN_new(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 132 if (argc <= 0) break; | 131 if (argc <= 0) break; |
| 133 if (strcmp(*argv,"-out") == 0) | 132 if (strcmp(*argv,"-out") == 0) |
| 134 { | 133 { |
| 135 if (--argc < 1) goto bad; | 134 if (--argc < 1) goto bad; |
| 136 outfile= *(++argv); | 135 outfile= *(++argv); |
| 137 } | 136 } |
| 138 else if (strcmp(*argv,"-3") == 0) | 137 else if (strcmp(*argv,"-3") == 0) |
| 139 f4=3; | 138 f4=3; |
| 140 else if (strcmp(*argv,"-F4") == 0 || strcmp(*argv,"-f4") == 0) | 139 else if (strcmp(*argv,"-F4") == 0 || strcmp(*argv,"-f4") == 0) |
| 141 f4=RSA_F4; | 140 f4=RSA_F4; |
| 142 else if (strcmp(*argv,"-x931") == 0) | |
| 143 use_x931 = 1; | |
| 144 #ifndef OPENSSL_NO_ENGINE | 141 #ifndef OPENSSL_NO_ENGINE |
| 145 else if (strcmp(*argv,"-engine") == 0) | 142 else if (strcmp(*argv,"-engine") == 0) |
| 146 { | 143 { |
| 147 if (--argc < 1) goto bad; | 144 if (--argc < 1) goto bad; |
| 148 engine= *(++argv); | 145 engine= *(++argv); |
| 149 } | 146 } |
| 150 #endif | 147 #endif |
| 151 else if (strcmp(*argv,"-rand") == 0) | 148 else if (strcmp(*argv,"-rand") == 0) |
| 152 { | 149 { |
| 153 if (--argc < 1) goto bad; | 150 if (--argc < 1) goto bad; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 && !RAND_status()) | 258 && !RAND_status()) |
| 262 { | 259 { |
| 263 BIO_printf(bio_err,"warning, not much extra random data, conside
r using the -rand option\n"); | 260 BIO_printf(bio_err,"warning, not much extra random data, conside
r using the -rand option\n"); |
| 264 } | 261 } |
| 265 if (inrand != NULL) | 262 if (inrand != NULL) |
| 266 BIO_printf(bio_err,"%ld semi-random bytes loaded\n", | 263 BIO_printf(bio_err,"%ld semi-random bytes loaded\n", |
| 267 app_RAND_load_files(inrand)); | 264 app_RAND_load_files(inrand)); |
| 268 | 265 |
| 269 BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n", | 266 BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n", |
| 270 num); | 267 num); |
| 271 | 268 #ifdef OPENSSL_NO_ENGINE |
| 272 rsa = RSA_new(); | 269 rsa = RSA_new(); |
| 270 #else |
| 271 rsa = RSA_new_method(e); |
| 272 #endif |
| 273 if (!rsa) | 273 if (!rsa) |
| 274 goto err; | 274 goto err; |
| 275 | 275 |
| 276 » if (use_x931) | 276 » if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb)) |
| 277 » » { | |
| 278 » » BIGNUM *pubexp; | |
| 279 » » pubexp = BN_new(); | |
| 280 » » if (!BN_set_word(pubexp, f4)) | |
| 281 » » » goto err; | |
| 282 » » if (!RSA_X931_generate_key_ex(rsa, num, pubexp, &cb)) | |
| 283 » » » goto err; | |
| 284 » » BN_free(pubexp); | |
| 285 » » } | |
| 286 » else if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb)) | |
| 287 goto err; | 277 goto err; |
| 288 | 278 |
| 289 app_RAND_write_file(NULL, bio_err); | 279 app_RAND_write_file(NULL, bio_err); |
| 290 | 280 |
| 291 /* We need to do the following for when the base number size is < | 281 /* We need to do the following for when the base number size is < |
| 292 * long, esp windows 3.1 :-(. */ | 282 * long, esp windows 3.1 :-(. */ |
| 293 l=0L; | 283 l=0L; |
| 294 for (i=0; i<rsa->e->top; i++) | 284 for (i=0; i<rsa->e->top; i++) |
| 295 { | 285 { |
| 296 #ifndef SIXTY_FOUR_BIT | 286 #ifndef SIXTY_FOUR_BIT |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 #endif | 326 #endif |
| 337 return 1; | 327 return 1; |
| 338 } | 328 } |
| 339 #else /* !OPENSSL_NO_RSA */ | 329 #else /* !OPENSSL_NO_RSA */ |
| 340 | 330 |
| 341 # if PEDANTIC | 331 # if PEDANTIC |
| 342 static void *dummy=&dummy; | 332 static void *dummy=&dummy; |
| 343 # endif | 333 # endif |
| 344 | 334 |
| 345 #endif | 335 #endif |
| OLD | NEW |