From 767dd251cfd92010e07aa99c16f1ece81b4b54e0 Mon Sep 17 00:00:00 2001 From: jsing Date: Thu, 17 Apr 2014 15:43:33 +0000 Subject: [PATCH] Initial KNF. --- lib/libssl/src/apps/gendh.c | 185 +++++++++++----------- lib/libssl/src/apps/gendsa.c | 237 ++++++++++++++-------------- lib/libssl/src/apps/genpkey.c | 252 +++++++++++++---------------- lib/libssl/src/apps/genrsa.c | 287 +++++++++++++++++----------------- 4 files changed, 459 insertions(+), 502 deletions(-) diff --git a/lib/libssl/src/apps/gendh.c b/lib/libssl/src/apps/gendh.c index c80fc0c21ca..00c31cf40d2 100644 --- a/lib/libssl/src/apps/gendh.c +++ b/lib/libssl/src/apps/gendh.c @@ -6,21 +6,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -35,10 +35,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -50,7 +50,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -86,150 +86,149 @@ static int dh_cb(int p, int n, BN_GENCB *cb); int MAIN(int, char **); -int MAIN(int argc, char **argv) - { +int +MAIN(int argc, char **argv) +{ BN_GENCB cb; - DH *dh=NULL; - int ret=1,num=DEFBITS; - int g=2; - char *outfile=NULL; - char *inrand=NULL; + DH *dh = NULL; + int ret = 1, num = DEFBITS; + int g = 2; + char *outfile = NULL; + char *inrand = NULL; #ifndef OPENSSL_NO_ENGINE - char *engine=NULL; + char *engine = NULL; #endif - BIO *out=NULL; + BIO *out = NULL; apps_startup(); BN_GENCB_set(&cb, dh_cb, bio_err); if (bio_err == NULL) - if ((bio_err=BIO_new(BIO_s_file())) != NULL) - BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + if ((bio_err = BIO_new(BIO_s_file())) != NULL) + BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; argv++; argc--; - for (;;) - { - if (argc <= 0) break; - if (strcmp(*argv,"-out") == 0) - { - if (--argc < 1) goto bad; + for (;;) { + if (argc <= 0) + break; + if (strcmp(*argv, "-out") == 0) { + if (--argc < 1) + goto bad; outfile= *(++argv); - } - else if (strcmp(*argv,"-2") == 0) - g=2; + } else if (strcmp(*argv, "-2") == 0) + g = 2; /* else if (strcmp(*argv,"-3") == 0) g=3; */ - else if (strcmp(*argv,"-5") == 0) - g=5; + else if (strcmp(*argv, "-5") == 0) + g = 5; #ifndef OPENSSL_NO_ENGINE - else if (strcmp(*argv,"-engine") == 0) - { - if (--argc < 1) goto bad; + else if (strcmp(*argv, "-engine") == 0) { + if (--argc < 1) + goto bad; engine= *(++argv); - } + } #endif - else if (strcmp(*argv,"-rand") == 0) - { - if (--argc < 1) goto bad; + else if (strcmp(*argv, "-rand") == 0) { + if (--argc < 1) + goto bad; inrand= *(++argv); - } - else + } else break; argv++; argc--; - } - if ((argc >= 1) && ((sscanf(*argv,"%d",&num) == 0) || (num < 0))) - { + } + if ((argc >= 1) && ((sscanf(*argv, "%d",&num) == 0) || (num < 0))) { bad: - BIO_printf(bio_err,"usage: gendh [args] [numbits]\n"); - BIO_printf(bio_err," -out file - output the key to 'file\n"); - BIO_printf(bio_err," -2 - use 2 as the generator value\n"); - /* BIO_printf(bio_err," -3 - use 3 as the generator value\n"); */ - BIO_printf(bio_err," -5 - use 5 as the generator value\n"); + BIO_printf(bio_err, "usage: gendh [args] [numbits]\n"); + BIO_printf(bio_err, " -out file - output the key to 'file\n"); + BIO_printf(bio_err, " -2 - use 2 as the generator value\n"); + /* BIO_printf(bio_err," -3 - use 3 as the generator value\n"); */ + BIO_printf(bio_err, " -5 - use 5 as the generator value\n"); #ifndef OPENSSL_NO_ENGINE - BIO_printf(bio_err," -engine e - use engine e, possibly a hardware device.\n"); + BIO_printf(bio_err, " -engine e - use engine e, possibly a hardware device.\n"); #endif - BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); - BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); - BIO_printf(bio_err," the random number generator\n"); + BIO_printf(bio_err, " -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err, " - load the file (or the files in the directory) into\n"); + BIO_printf(bio_err, " the random number generator\n"); goto end; - } - + } + #ifndef OPENSSL_NO_ENGINE - setup_engine(bio_err, engine, 0); + setup_engine(bio_err, engine, 0); #endif - out=BIO_new(BIO_s_file()); - if (out == NULL) - { + out = BIO_new(BIO_s_file()); + if (out == NULL) { ERR_print_errors(bio_err); goto end; - } + } - if (outfile == NULL) - { - BIO_set_fp(out,stdout,BIO_NOCLOSE); - } - else - { - if (BIO_write_filename(out,outfile) <= 0) - { + if (outfile == NULL) { + BIO_set_fp(out, stdout, BIO_NOCLOSE); + } else { + if (BIO_write_filename(out, outfile) <= 0) { perror(outfile); goto end; - } } + } - if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) - { - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - } + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { + BIO_printf(bio_err, "warning, not much extra random data, consider using the -rand option\n"); + } if (inrand != NULL) - BIO_printf(bio_err,"%ld semi-random bytes loaded\n", - app_RAND_load_files(inrand)); + BIO_printf(bio_err, "%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); - BIO_printf(bio_err,"Generating DH parameters, %d bit long safe prime, generator %d\n",num,g); - BIO_printf(bio_err,"This is going to take a long time\n"); + BIO_printf(bio_err, "Generating DH parameters, %d bit long safe prime, generator %d\n",num,g); + BIO_printf(bio_err, "This is going to take a long time\n"); - if(((dh = DH_new()) == NULL) || !DH_generate_parameters_ex(dh, num, g, &cb)) + if (((dh = DH_new()) == NULL) || !DH_generate_parameters_ex(dh, num, g, &cb)) goto end; - + app_RAND_write_file(NULL, bio_err); - if (!PEM_write_bio_DHparams(out,dh)) + if (!PEM_write_bio_DHparams(out, dh)) goto end; - ret=0; + ret = 0; end: if (ret != 0) ERR_print_errors(bio_err); - if (out != NULL) BIO_free_all(out); - if (dh != NULL) DH_free(dh); + if (out != NULL) + BIO_free_all(out); + if (dh != NULL) + DH_free(dh); apps_shutdown(); OPENSSL_EXIT(ret); - } - -static int dh_cb(int p, int n, BN_GENCB *cb) - { - char c='*'; - - if (p == 0) c='.'; - if (p == 1) c='+'; - if (p == 2) c='*'; - if (p == 3) c='\n'; - BIO_write(cb->arg,&c,1); +} + +static int +dh_cb(int p, int n, BN_GENCB *cb) +{ + char c = '*'; + + if (p == 0) + c = '.'; + if (p == 1) + c = '+'; + if (p == 2) + c = '*'; + if (p == 3) + c = '\n'; + BIO_write(cb->arg, &c, 1); (void)BIO_flush(cb->arg); #ifdef LINT - p=n; + p = n; #endif return 1; - } +} #else /* !OPENSSL_NO_DH */ # if PEDANTIC -static void *dummy=&dummy; +static void *dummy = &dummy; # endif #endif diff --git a/lib/libssl/src/apps/gendsa.c b/lib/libssl/src/apps/gendsa.c index 5c9ec7d24b5..17dbd9d6d3a 100644 --- a/lib/libssl/src/apps/gendsa.c +++ b/lib/libssl/src/apps/gendsa.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -76,204 +76,199 @@ int MAIN(int, char **); -int MAIN(int argc, char **argv) - { - DSA *dsa=NULL; - int ret=1; - char *outfile=NULL; - char *inrand=NULL,*dsaparams=NULL; +int +MAIN(int argc, char **argv) +{ + DSA *dsa = NULL; + int ret = 1; + char *outfile = NULL; + char *inrand = NULL, *dsaparams = NULL; char *passargout = NULL, *passout = NULL; - BIO *out=NULL,*in=NULL; - const EVP_CIPHER *enc=NULL; + BIO *out = NULL, *in = NULL; + const EVP_CIPHER *enc = NULL; #ifndef OPENSSL_NO_ENGINE - char *engine=NULL; + char *engine = NULL; #endif apps_startup(); if (bio_err == NULL) - if ((bio_err=BIO_new(BIO_s_file())) != NULL) - BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + if ((bio_err = BIO_new(BIO_s_file())) != NULL) + BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; argv++; argc--; - for (;;) - { - if (argc <= 0) break; - if (strcmp(*argv,"-out") == 0) - { - if (--argc < 1) goto bad; + for (;;) { + if (argc <= 0) + break; + if (strcmp(*argv, "-out") == 0) { + if (--argc < 1) + goto bad; outfile= *(++argv); - } - else if (strcmp(*argv,"-passout") == 0) - { - if (--argc < 1) goto bad; + } else if (strcmp(*argv, "-passout") == 0) { + if (--argc < 1) + goto bad; passargout= *(++argv); - } + } #ifndef OPENSSL_NO_ENGINE - else if (strcmp(*argv,"-engine") == 0) - { - if (--argc < 1) goto bad; + else if (strcmp(*argv, "-engine") == 0) { + if (--argc < 1) + goto bad; engine= *(++argv); - } + } #endif - else if (strcmp(*argv,"-rand") == 0) - { - if (--argc < 1) goto bad; + else if (strcmp(*argv, "-rand") == 0) { + if (--argc < 1) + goto bad; inrand= *(++argv); - } - else if (strcmp(*argv,"-") == 0) + } else if (strcmp(*argv, "-") == 0) goto bad; #ifndef OPENSSL_NO_DES - else if (strcmp(*argv,"-des") == 0) - enc=EVP_des_cbc(); - else if (strcmp(*argv,"-des3") == 0) - enc=EVP_des_ede3_cbc(); + else if (strcmp(*argv, "-des") == 0) + enc = EVP_des_cbc(); + else if (strcmp(*argv, "-des3") == 0) + enc = EVP_des_ede3_cbc(); #endif #ifndef OPENSSL_NO_IDEA - else if (strcmp(*argv,"-idea") == 0) - enc=EVP_idea_cbc(); + else if (strcmp(*argv, "-idea") == 0) + enc = EVP_idea_cbc(); #endif #ifndef OPENSSL_NO_SEED - else if (strcmp(*argv,"-seed") == 0) - enc=EVP_seed_cbc(); + else if (strcmp(*argv, "-seed") == 0) + enc = EVP_seed_cbc(); #endif #ifndef OPENSSL_NO_AES - else if (strcmp(*argv,"-aes128") == 0) - enc=EVP_aes_128_cbc(); - else if (strcmp(*argv,"-aes192") == 0) - enc=EVP_aes_192_cbc(); - else if (strcmp(*argv,"-aes256") == 0) - enc=EVP_aes_256_cbc(); + else if (strcmp(*argv, "-aes128") == 0) + enc = EVP_aes_128_cbc(); + else if (strcmp(*argv, "-aes192") == 0) + enc = EVP_aes_192_cbc(); + else if (strcmp(*argv, "-aes256") == 0) + enc = EVP_aes_256_cbc(); #endif #ifndef OPENSSL_NO_CAMELLIA - else if (strcmp(*argv,"-camellia128") == 0) - enc=EVP_camellia_128_cbc(); - else if (strcmp(*argv,"-camellia192") == 0) - enc=EVP_camellia_192_cbc(); - else if (strcmp(*argv,"-camellia256") == 0) - enc=EVP_camellia_256_cbc(); + else if (strcmp(*argv, "-camellia128") == 0) + enc = EVP_camellia_128_cbc(); + else if (strcmp(*argv, "-camellia192") == 0) + enc = EVP_camellia_192_cbc(); + else if (strcmp(*argv, "-camellia256") == 0) + enc = EVP_camellia_256_cbc(); #endif - else if (**argv != '-' && dsaparams == NULL) - { + else if (**argv != '-' && dsaparams == NULL) { dsaparams = *argv; - } - else + } else goto bad; argv++; argc--; - } + } - if (dsaparams == NULL) - { + if (dsaparams == NULL) { bad: - BIO_printf(bio_err,"usage: gendsa [args] dsaparam-file\n"); - BIO_printf(bio_err," -out file - output the key to 'file'\n"); + BIO_printf(bio_err, "usage: gendsa [args] dsaparam-file\n"); + BIO_printf(bio_err, " -out file - output the key to 'file'\n"); #ifndef OPENSSL_NO_DES - BIO_printf(bio_err," -des - encrypt the generated key with DES in cbc mode\n"); - BIO_printf(bio_err," -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); + BIO_printf(bio_err, " -des - encrypt the generated key with DES in cbc mode\n"); + BIO_printf(bio_err, " -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); #endif #ifndef OPENSSL_NO_IDEA - BIO_printf(bio_err," -idea - encrypt the generated key with IDEA in cbc mode\n"); + BIO_printf(bio_err, " -idea - encrypt the generated key with IDEA in cbc mode\n"); #endif #ifndef OPENSSL_NO_SEED - BIO_printf(bio_err," -seed\n"); - BIO_printf(bio_err," encrypt PEM output with cbc seed\n"); + BIO_printf(bio_err, " -seed\n"); + BIO_printf(bio_err, " encrypt PEM output with cbc seed\n"); #endif #ifndef OPENSSL_NO_AES - BIO_printf(bio_err," -aes128, -aes192, -aes256\n"); - BIO_printf(bio_err," encrypt PEM output with cbc aes\n"); + BIO_printf(bio_err, " -aes128, -aes192, -aes256\n"); + BIO_printf(bio_err, " encrypt PEM output with cbc aes\n"); #endif #ifndef OPENSSL_NO_CAMELLIA - BIO_printf(bio_err," -camellia128, -camellia192, -camellia256\n"); - BIO_printf(bio_err," encrypt PEM output with cbc camellia\n"); + BIO_printf(bio_err, " -camellia128, -camellia192, -camellia256\n"); + BIO_printf(bio_err, " encrypt PEM output with cbc camellia\n"); #endif #ifndef OPENSSL_NO_ENGINE - BIO_printf(bio_err," -engine e - use engine e, possibly a hardware device.\n"); + BIO_printf(bio_err, " -engine e - use engine e, possibly a hardware device.\n"); #endif - BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); - BIO_printf(bio_err," - load the file (or the files in the directory) into\n"); - BIO_printf(bio_err," the random number generator\n"); - BIO_printf(bio_err," dsaparam-file\n"); - BIO_printf(bio_err," - a DSA parameter file as generated by the dsaparam command\n"); + BIO_printf(bio_err, " -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err, " - load the file (or the files in the directory) into\n"); + BIO_printf(bio_err, " the random number generator\n"); + BIO_printf(bio_err, " dsaparam-file\n"); + BIO_printf(bio_err, " - a DSA parameter file as generated by the dsaparam command\n"); goto end; - } + } #ifndef OPENSSL_NO_ENGINE - setup_engine(bio_err, engine, 0); + setup_engine(bio_err, engine, 0); #endif - if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { + if (!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { BIO_printf(bio_err, "Error getting password\n"); goto end; } - in=BIO_new(BIO_s_file()); - if (!(BIO_read_filename(in,dsaparams))) - { + in = BIO_new(BIO_s_file()); + if (!(BIO_read_filename(in, dsaparams))) { perror(dsaparams); goto end; - } + } - if ((dsa=PEM_read_bio_DSAparams(in,NULL,NULL,NULL)) == NULL) - { - BIO_printf(bio_err,"unable to load DSA parameter file\n"); + if ((dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL)) == NULL) { + BIO_printf(bio_err, "unable to load DSA parameter file\n"); goto end; - } + } BIO_free(in); in = NULL; - - out=BIO_new(BIO_s_file()); - if (out == NULL) goto end; - if (outfile == NULL) - { - BIO_set_fp(out,stdout,BIO_NOCLOSE); - } - else - { - if (BIO_write_filename(out,outfile) <= 0) - { + out = BIO_new(BIO_s_file()); + if (out == NULL) + goto end; + + if (outfile == NULL) { + BIO_set_fp(out, stdout, BIO_NOCLOSE); + } else { + if (BIO_write_filename(out, outfile) <= 0) { perror(outfile); goto end; - } } + } - if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) - { - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - } + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL) { + BIO_printf(bio_err, "warning, not much extra random data, consider using the -rand option\n"); + } if (inrand != NULL) - BIO_printf(bio_err,"%ld semi-random bytes loaded\n", - app_RAND_load_files(inrand)); + BIO_printf(bio_err, "%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); - BIO_printf(bio_err,"Generating DSA key, %d bits\n", - BN_num_bits(dsa->p)); - if (!DSA_generate_key(dsa)) goto end; + BIO_printf(bio_err, "Generating DSA key, %d bits\n", + BN_num_bits(dsa->p)); + if (!DSA_generate_key(dsa)) + goto end; app_RAND_write_file(NULL, bio_err); - if (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL, passout)) + if (!PEM_write_bio_DSAPrivateKey(out, dsa, enc, NULL, 0, NULL, passout)) goto end; - ret=0; + ret = 0; end: if (ret != 0) ERR_print_errors(bio_err); - if (in != NULL) BIO_free(in); - if (out != NULL) BIO_free_all(out); - if (dsa != NULL) DSA_free(dsa); - if(passout) free(passout); + if (in != NULL) + BIO_free(in); + if (out != NULL) + BIO_free_all(out); + if (dsa != NULL) + DSA_free(dsa); + if (passout) + free(passout); apps_shutdown(); OPENSSL_EXIT(ret); - } +} #else /* !OPENSSL_NO_DSA */ # if PEDANTIC -static void *dummy=&dummy; +static void *dummy = &dummy; # endif #endif diff --git a/lib/libssl/src/apps/genpkey.c b/lib/libssl/src/apps/genpkey.c index f6b23ac5a64..de375a571bf 100644 --- a/lib/libssl/src/apps/genpkey.c +++ b/lib/libssl/src/apps/genpkey.c @@ -10,7 +10,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -65,16 +65,17 @@ #include #endif -static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, - const char *file, ENGINE *e); +static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, const char *file, + ENGINE *e); static int genpkey_cb(EVP_PKEY_CTX *ctx); #define PROG genpkey_main int MAIN(int, char **); -int MAIN(int argc, char **argv) - { +int +MAIN(int argc, char **argv) +{ ENGINE *e = NULL; char **args, *outfile = NULL; char *passarg = NULL; @@ -82,7 +83,7 @@ int MAIN(int argc, char **argv) const EVP_CIPHER *cipher = NULL; int outformat; int text = 0; - EVP_PKEY *pkey=NULL; + EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; char *pass = NULL; int badarg = 0; @@ -91,42 +92,36 @@ int MAIN(int argc, char **argv) int do_param = 0; if (bio_err == NULL) - bio_err = BIO_new_fp (stderr, BIO_NOCLOSE); + bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); if (!load_config(bio_err, NULL)) goto end; - outformat=FORMAT_PEM; + outformat = FORMAT_PEM; ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); args = argv + 1; - while (!badarg && *args && *args[0] == '-') - { - if (!strcmp(*args,"-outform")) - { - if (args[1]) - { + while (!badarg && *args && *args[0] == '-') { + if (!strcmp(*args, "-outform")) { + if (args[1]) { args++; - outformat=str2fmt(*args); - } - else badarg = 1; - } - else if (!strcmp(*args,"-pass")) - { - if (!args[1]) goto bad; + outformat = str2fmt(*args); + } else + badarg = 1; + } else if (!strcmp(*args, "-pass")) { + if (!args[1]) + goto bad; passarg= *(++args); - } + } #ifndef OPENSSL_NO_ENGINE - else if (strcmp(*args,"-engine") == 0) - { + else if (strcmp(*args, "-engine") == 0) { if (!args[1]) goto bad; - e = setup_engine(bio_err, *(++args), 0); - } + e = setup_engine(bio_err, *(++args), 0); + } #endif - else if (!strcmp (*args, "-paramfile")) - { + else if (!strcmp (*args, "-paramfile")) { if (!args[1]) goto bad; args++; @@ -134,68 +129,52 @@ int MAIN(int argc, char **argv) goto bad; if (!init_keygen_file(bio_err, &ctx, *args, e)) goto end; - } - else if (!strcmp (*args, "-out")) - { - if (args[1]) - { + } else if (!strcmp (*args, "-out")) { + if (args[1]) { args++; outfile = *args; - } - else badarg = 1; - } - else if (strcmp(*args,"-algorithm") == 0) - { + } else + badarg = 1; + } else if (strcmp(*args, "-algorithm") == 0) { if (!args[1]) goto bad; - if (!init_gen_str(bio_err, &ctx, *(++args),e, do_param)) + if (!init_gen_str(bio_err, &ctx, *(++args), e, do_param)) goto end; - } - else if (strcmp(*args,"-pkeyopt") == 0) - { + } else if (strcmp(*args, "-pkeyopt") == 0) { if (!args[1]) goto bad; - if (!ctx) - { + if (!ctx) { BIO_puts(bio_err, "No keytype specified\n"); goto bad; - } - else if (pkey_ctrl_string(ctx, *(++args)) <= 0) - { + } else if (pkey_ctrl_string(ctx, *(++args)) <= 0) { BIO_puts(bio_err, "parameter setting error\n"); ERR_print_errors(bio_err); goto end; - } } - else if (strcmp(*args,"-genparam") == 0) - { + } else if (strcmp(*args, "-genparam") == 0) { if (ctx) goto bad; do_param = 1; - } - else if (strcmp(*args,"-text") == 0) - text=1; - else - { + } else if (strcmp(*args, "-text") == 0) + text = 1; + else { cipher = EVP_get_cipherbyname(*args + 1); - if (!cipher) - { + if (!cipher) { BIO_printf(bio_err, "Unknown cipher %s\n", - *args + 1); + *args + 1); badarg = 1; - } + } if (do_param == 1) badarg = 1; - } - args++; } + args++; + } if (!ctx) badarg = 1; - if (badarg) - { - bad: + if (badarg) { +bad: BIO_printf(bio_err, "Usage: genpkey [options]\n"); BIO_printf(bio_err, "where options may be\n"); BIO_printf(bio_err, "-out file output file\n"); @@ -208,91 +187,77 @@ int MAIN(int argc, char **argv) BIO_printf(bio_err, "-paramfile file parameters file\n"); BIO_printf(bio_err, "-algorithm alg the public key algorithm\n"); BIO_printf(bio_err, "-pkeyopt opt:value set the public key algorithm option \n" - " to value \n"); + " to value \n"); BIO_printf(bio_err, "-genparam generate parameters, not key\n"); BIO_printf(bio_err, "-text print the in text\n"); BIO_printf(bio_err, "NB: options order may be important! See the manual page.\n"); goto end; - } + } - if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) - { + if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) { BIO_puts(bio_err, "Error getting password\n"); goto end; - } + } - if (outfile) - { - if (!(out = BIO_new_file (outfile, "wb"))) - { + if (outfile) { + if (!(out = BIO_new_file (outfile, "wb"))) { BIO_printf(bio_err, - "Can't open output file %s\n", outfile); + "Can't open output file %s\n", outfile); goto end; - } } - else - { + } else { out = BIO_new_fp (stdout, BIO_NOCLOSE); - } + } EVP_PKEY_CTX_set_cb(ctx, genpkey_cb); EVP_PKEY_CTX_set_app_data(ctx, bio_err); - if (do_param) - { - if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) - { + if (do_param) { + if (EVP_PKEY_paramgen(ctx, &pkey) <= 0) { BIO_puts(bio_err, "Error generating parameters\n"); ERR_print_errors(bio_err); goto end; - } } - else - { - if (EVP_PKEY_keygen(ctx, &pkey) <= 0) - { + } else { + if (EVP_PKEY_keygen(ctx, &pkey) <= 0) { BIO_puts(bio_err, "Error generating key\n"); ERR_print_errors(bio_err); goto end; - } } + } if (do_param) rv = PEM_write_bio_Parameters(out, pkey); - else if (outformat == FORMAT_PEM) + else if (outformat == FORMAT_PEM) rv = PEM_write_bio_PrivateKey(out, pkey, cipher, NULL, 0, - NULL, pass); + NULL, pass); else if (outformat == FORMAT_ASN1) rv = i2d_PrivateKey_bio(out, pkey); - else - { + else { BIO_printf(bio_err, "Bad format specified for key\n"); goto end; - } + } - if (rv <= 0) - { + if (rv <= 0) { BIO_puts(bio_err, "Error writing key\n"); ERR_print_errors(bio_err); - } + } - if (text) - { + if (text) { if (do_param) rv = EVP_PKEY_print_params(out, pkey, 0, NULL); else rv = EVP_PKEY_print_private(out, pkey, 0, NULL); - if (rv <= 0) - { + if (rv <= 0) { BIO_puts(bio_err, "Error printing key\n"); ERR_print_errors(bio_err); - } } + } ret = 0; - end: +end: if (pkey) EVP_PKEY_free(pkey); if (ctx) @@ -304,35 +269,33 @@ int MAIN(int argc, char **argv) free(pass); return ret; - } +} -static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, - const char *file, ENGINE *e) - { +static int +init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, + const char *file, ENGINE *e) +{ BIO *pbio; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; - if (*pctx) - { + if (*pctx) { BIO_puts(err, "Parameters already set!\n"); return 0; - } + } pbio = BIO_new_file(file, "r"); - if (!pbio) - { + if (!pbio) { BIO_printf(err, "Can't open parameter file %s\n", file); return 0; - } + } pkey = PEM_read_bio_Parameters(pbio, NULL); BIO_free(pbio); - if (!pkey) - { + if (!pkey) { BIO_printf(bio_err, "Error reading parameter file %s\n", file); return 0; - } + } ctx = EVP_PKEY_CTX_new(pkey, e); if (!ctx) @@ -343,7 +306,7 @@ static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, *pctx = ctx; return 1; - err: +err: BIO_puts(err, "Error initializing context\n"); ERR_print_errors(err); if (ctx) @@ -352,21 +315,21 @@ static int init_keygen_file(BIO *err, EVP_PKEY_CTX **pctx, EVP_PKEY_free(pkey); return 0; - } +} -int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, - const char *algname, ENGINE *e, int do_param) - { +int +init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, + const char *algname, ENGINE *e, int do_param) +{ EVP_PKEY_CTX *ctx = NULL; const EVP_PKEY_ASN1_METHOD *ameth; ENGINE *tmpeng = NULL; int pkey_id; - if (*pctx) - { + if (*pctx) { BIO_puts(err, "Algorithm already set!\n"); return 0; - } + } ameth = EVP_PKEY_asn1_find_str(&tmpeng, algname, -1); @@ -375,11 +338,10 @@ int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, ameth = ENGINE_get_pkey_asn1_meth_str(e, algname, -1); #endif - if (!ameth) - { + if (!ameth) { BIO_printf(bio_err, "Algorithm %s not found\n", algname); return 0; - } + } ERR_clear_error(); @@ -392,43 +354,45 @@ int init_gen_str(BIO *err, EVP_PKEY_CTX **pctx, if (!ctx) goto err; - if (do_param) - { + if (do_param) { if (EVP_PKEY_paramgen_init(ctx) <= 0) goto err; - } - else - { + } else { if (EVP_PKEY_keygen_init(ctx) <= 0) goto err; - } + } *pctx = ctx; return 1; - err: +err: BIO_printf(err, "Error initializing %s context\n", algname); ERR_print_errors(err); if (ctx) EVP_PKEY_CTX_free(ctx); return 0; - } +} -static int genpkey_cb(EVP_PKEY_CTX *ctx) - { - char c='*'; +static int +genpkey_cb(EVP_PKEY_CTX *ctx) +{ + char c = '*'; BIO *b = EVP_PKEY_CTX_get_app_data(ctx); int p; p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); - if (p == 0) c='.'; - if (p == 1) c='+'; - if (p == 2) c='*'; - if (p == 3) c='\n'; - BIO_write(b,&c,1); + if (p == 0) + c = '.'; + if (p == 1) + c = '+'; + if (p == 2) + c = '*'; + if (p == 3) + c = '\n'; + BIO_write(b, &c, 1); (void)BIO_flush(b); #ifdef LINT - p=n; + p = n; #endif return 1; - } +} diff --git a/lib/libssl/src/apps/genrsa.c b/lib/libssl/src/apps/genrsa.c index 1be17d9ac62..65e136a8d26 100644 --- a/lib/libssl/src/apps/genrsa.c +++ b/lib/libssl/src/apps/genrsa.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -86,179 +86,171 @@ static int genrsa_cb(int p, int n, BN_GENCB *cb); int MAIN(int, char **); -int MAIN(int argc, char **argv) - { +int +MAIN(int argc, char **argv) +{ BN_GENCB cb; #ifndef OPENSSL_NO_ENGINE ENGINE *e = NULL; #endif - int ret=1; - int i,num=DEFBITS; + int ret = 1; + int i, num = DEFBITS; long l; - const EVP_CIPHER *enc=NULL; - unsigned long f4=RSA_F4; - char *outfile=NULL; + const EVP_CIPHER *enc = NULL; + unsigned long f4 = RSA_F4; + char *outfile = NULL; char *passargout = NULL, *passout = NULL; #ifndef OPENSSL_NO_ENGINE - char *engine=NULL; + char *engine = NULL; #endif - char *inrand=NULL; - BIO *out=NULL; + char *inrand = NULL; + BIO *out = NULL; BIGNUM *bn = BN_new(); RSA *rsa = NULL; - if(!bn) goto err; + if (!bn) goto err; - apps_startup(); + apps_startup(); BN_GENCB_set(&cb, genrsa_cb, bio_err); if (bio_err == NULL) - if ((bio_err=BIO_new(BIO_s_file())) != NULL) - BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + if ((bio_err = BIO_new(BIO_s_file())) != NULL) + BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto err; - if ((out=BIO_new(BIO_s_file())) == NULL) - { - BIO_printf(bio_err,"unable to create BIO for output\n"); + if ((out = BIO_new(BIO_s_file())) == NULL) { + BIO_printf(bio_err, "unable to create BIO for output\n"); goto err; - } + } argv++; argc--; - for (;;) - { - if (argc <= 0) break; - if (strcmp(*argv,"-out") == 0) - { - if (--argc < 1) goto bad; + for (;;) { + if (argc <= 0) + break; + if (strcmp(*argv, "-out") == 0) { + if (--argc < 1) + goto bad; outfile= *(++argv); - } - else if (strcmp(*argv,"-3") == 0) - f4=3; - else if (strcmp(*argv,"-F4") == 0 || strcmp(*argv,"-f4") == 0) - f4=RSA_F4; + } else if (strcmp(*argv, "-3") == 0) + f4 = 3; + else if (strcmp(*argv, "-F4") == 0 || strcmp(*argv,"-f4") == 0) + f4 = RSA_F4; #ifndef OPENSSL_NO_ENGINE - else if (strcmp(*argv,"-engine") == 0) - { - if (--argc < 1) goto bad; + else if (strcmp(*argv, "-engine") == 0) { + if (--argc < 1) + goto bad; engine= *(++argv); - } + } #endif - else if (strcmp(*argv,"-rand") == 0) - { - if (--argc < 1) goto bad; + else if (strcmp(*argv, "-rand") == 0) { + if (--argc < 1) + goto bad; inrand= *(++argv); - } + } #ifndef OPENSSL_NO_DES - else if (strcmp(*argv,"-des") == 0) - enc=EVP_des_cbc(); - else if (strcmp(*argv,"-des3") == 0) - enc=EVP_des_ede3_cbc(); + else if (strcmp(*argv, "-des") == 0) + enc = EVP_des_cbc(); + else if (strcmp(*argv, "-des3") == 0) + enc = EVP_des_ede3_cbc(); #endif #ifndef OPENSSL_NO_IDEA - else if (strcmp(*argv,"-idea") == 0) - enc=EVP_idea_cbc(); + else if (strcmp(*argv, "-idea") == 0) + enc = EVP_idea_cbc(); #endif #ifndef OPENSSL_NO_SEED - else if (strcmp(*argv,"-seed") == 0) - enc=EVP_seed_cbc(); + else if (strcmp(*argv, "-seed") == 0) + enc = EVP_seed_cbc(); #endif #ifndef OPENSSL_NO_AES - else if (strcmp(*argv,"-aes128") == 0) - enc=EVP_aes_128_cbc(); - else if (strcmp(*argv,"-aes192") == 0) - enc=EVP_aes_192_cbc(); - else if (strcmp(*argv,"-aes256") == 0) - enc=EVP_aes_256_cbc(); + else if (strcmp(*argv, "-aes128") == 0) + enc = EVP_aes_128_cbc(); + else if (strcmp(*argv, "-aes192") == 0) + enc = EVP_aes_192_cbc(); + else if (strcmp(*argv, "-aes256") == 0) + enc = EVP_aes_256_cbc(); #endif #ifndef OPENSSL_NO_CAMELLIA - else if (strcmp(*argv,"-camellia128") == 0) - enc=EVP_camellia_128_cbc(); - else if (strcmp(*argv,"-camellia192") == 0) - enc=EVP_camellia_192_cbc(); - else if (strcmp(*argv,"-camellia256") == 0) - enc=EVP_camellia_256_cbc(); + else if (strcmp(*argv, "-camellia128") == 0) + enc = EVP_camellia_128_cbc(); + else if (strcmp(*argv, "-camellia192") == 0) + enc = EVP_camellia_192_cbc(); + else if (strcmp(*argv, "-camellia256") == 0) + enc = EVP_camellia_256_cbc(); #endif - else if (strcmp(*argv,"-passout") == 0) - { - if (--argc < 1) goto bad; + else if (strcmp(*argv, "-passout") == 0) { + if (--argc < 1) + goto bad; passargout= *(++argv); - } - else + } else break; argv++; argc--; - } - if ((argc >= 1) && ((sscanf(*argv,"%d",&num) == 0) || (num < 0))) - { + } + if ((argc >= 1) && ((sscanf(*argv, "%d",&num) == 0) || (num < 0))) { bad: - BIO_printf(bio_err,"usage: genrsa [args] [numbits]\n"); - BIO_printf(bio_err," -des encrypt the generated key with DES in cbc mode\n"); - BIO_printf(bio_err," -des3 encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); + BIO_printf(bio_err, "usage: genrsa [args] [numbits]\n"); + BIO_printf(bio_err, " -des encrypt the generated key with DES in cbc mode\n"); + BIO_printf(bio_err, " -des3 encrypt the generated key with DES in ede cbc mode (168 bit key)\n"); #ifndef OPENSSL_NO_IDEA - BIO_printf(bio_err," -idea encrypt the generated key with IDEA in cbc mode\n"); + BIO_printf(bio_err, " -idea encrypt the generated key with IDEA in cbc mode\n"); #endif #ifndef OPENSSL_NO_SEED - BIO_printf(bio_err," -seed\n"); - BIO_printf(bio_err," encrypt PEM output with cbc seed\n"); + BIO_printf(bio_err, " -seed\n"); + BIO_printf(bio_err, " encrypt PEM output with cbc seed\n"); #endif #ifndef OPENSSL_NO_AES - BIO_printf(bio_err," -aes128, -aes192, -aes256\n"); - BIO_printf(bio_err," encrypt PEM output with cbc aes\n"); + BIO_printf(bio_err, " -aes128, -aes192, -aes256\n"); + BIO_printf(bio_err, " encrypt PEM output with cbc aes\n"); #endif #ifndef OPENSSL_NO_CAMELLIA - BIO_printf(bio_err," -camellia128, -camellia192, -camellia256\n"); - BIO_printf(bio_err," encrypt PEM output with cbc camellia\n"); + BIO_printf(bio_err, " -camellia128, -camellia192, -camellia256\n"); + BIO_printf(bio_err, " encrypt PEM output with cbc camellia\n"); #endif - BIO_printf(bio_err," -out file output the key to 'file\n"); - BIO_printf(bio_err," -passout arg output file pass phrase source\n"); - BIO_printf(bio_err," -f4 use F4 (0x10001) for the E value\n"); - BIO_printf(bio_err," -3 use 3 for the E value\n"); + BIO_printf(bio_err, " -out file output the key to 'file\n"); + BIO_printf(bio_err, " -passout arg output file pass phrase source\n"); + BIO_printf(bio_err, " -f4 use F4 (0x10001) for the E value\n"); + BIO_printf(bio_err, " -3 use 3 for the E value\n"); #ifndef OPENSSL_NO_ENGINE - BIO_printf(bio_err," -engine e use engine e, possibly a hardware device.\n"); + BIO_printf(bio_err, " -engine e use engine e, possibly a hardware device.\n"); #endif - BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); - BIO_printf(bio_err," load the file (or the files in the directory) into\n"); - BIO_printf(bio_err," the random number generator\n"); + BIO_printf(bio_err, " -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR); + BIO_printf(bio_err, " load the file (or the files in the directory) into\n"); + BIO_printf(bio_err, " the random number generator\n"); goto err; - } - + } + ERR_load_crypto_strings(); - if(!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { + if (!app_passwd(bio_err, NULL, passargout, NULL, &passout)) { BIO_printf(bio_err, "Error getting password\n"); goto err; } #ifndef OPENSSL_NO_ENGINE - e = setup_engine(bio_err, engine, 0); + e = setup_engine(bio_err, engine, 0); #endif - if (outfile == NULL) - { - BIO_set_fp(out,stdout,BIO_NOCLOSE); - } - else - { - if (BIO_write_filename(out,outfile) <= 0) - { + if (outfile == NULL) { + BIO_set_fp(out, stdout, BIO_NOCLOSE); + } else { + if (BIO_write_filename(out, outfile) <= 0) { perror(outfile); goto err; - } } + } - if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL - && !RAND_status()) - { - BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n"); - } + if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL && + !RAND_status()) { + BIO_printf(bio_err, "warning, not much extra random data, consider using the -rand option\n"); + } if (inrand != NULL) - BIO_printf(bio_err,"%ld semi-random bytes loaded\n", - app_RAND_load_files(inrand)); + BIO_printf(bio_err, "%ld semi-random bytes loaded\n", + app_RAND_load_files(inrand)); - BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n", - num); + BIO_printf(bio_err, "Generating RSA private key, %d bit long modulus\n", + num); #ifdef OPENSSL_NO_ENGINE rsa = RSA_new(); #else @@ -267,63 +259,70 @@ bad: if (!rsa) goto err; - if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb)) + if (!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb)) goto err; - + app_RAND_write_file(NULL, bio_err); /* We need to do the following for when the base number size is < * long, esp windows 3.1 :-(. */ - l=0L; - for (i=0; ie->top; i++) - { + l = 0L; + for (i = 0; i < rsa->e->top; i++) { #ifndef SIXTY_FOUR_BIT l<<=BN_BITS4; l<<=BN_BITS4; #endif - l+=rsa->e->d[i]; - } - BIO_printf(bio_err,"e is %ld (0x%lX)\n",l,l); + l += rsa->e->d[i]; + } + BIO_printf(bio_err, "e is %ld (0x%lX)\n",l,l); { - PW_CB_DATA cb_data; - cb_data.password = passout; - cb_data.prompt_info = outfile; - if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0, - (pem_password_cb *)password_callback,&cb_data)) - goto err; + PW_CB_DATA cb_data; + cb_data.password = passout; + cb_data.prompt_info = outfile; + if (!PEM_write_bio_RSAPrivateKey(out, rsa, enc, NULL, 0, + (pem_password_cb *)password_callback, &cb_data)) + goto err; } - ret=0; + ret = 0; err: - if (bn) BN_free(bn); - if (rsa) RSA_free(rsa); - if (out) BIO_free_all(out); - if(passout) free(passout); - if (ret != 0) - ERR_print_errors(bio_err); + if (bn) + BN_free(bn); + if (rsa) + RSA_free(rsa); + if (out) + BIO_free_all(out); + if (passout) free(passout); + if (ret != 0) + ERR_print_errors(bio_err); apps_shutdown(); OPENSSL_EXIT(ret); - } +} -static int genrsa_cb(int p, int n, BN_GENCB *cb) - { - char c='*'; +static int +genrsa_cb(int p, int n, BN_GENCB *cb) +{ + char c = '*'; - if (p == 0) c='.'; - if (p == 1) c='+'; - if (p == 2) c='*'; - if (p == 3) c='\n'; - BIO_write(cb->arg,&c,1); + if (p == 0) + c = '.'; + if (p == 1) + c = '+'; + if (p == 2) + c = '*'; + if (p == 3) + c = '\n'; + BIO_write(cb->arg, &c, 1); (void)BIO_flush(cb->arg); #ifdef LINT - p=n; + p = n; #endif return 1; - } +} #else /* !OPENSSL_NO_RSA */ # if PEDANTIC -static void *dummy=&dummy; +static void *dummy = &dummy; # endif #endif -- 2.20.1