Initial KNF.
authorjsing <jsing@openbsd.org>
Wed, 16 Apr 2014 17:04:13 +0000 (17:04 +0000)
committerjsing <jsing@openbsd.org>
Wed, 16 Apr 2014 17:04:13 +0000 (17:04 +0000)
lib/libssl/src/apps/dgst.c
lib/libssl/src/apps/dh.c
lib/libssl/src/apps/dhparam.c
lib/libssl/src/apps/dsa.c
lib/libssl/src/apps/dsaparam.c

index 0615fa8..388c95e 100644 (file)
@@ -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:
  *     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
 #define PROG   dgst_main
 
 int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
-         EVP_PKEY *key, unsigned char *sigin, int siglen,
-         const char *sig_name, const char *md_name,
-         const char *file,BIO *bmd);
+    EVP_PKEY *key, unsigned char *sigin, int siglen,
+    const char *sig_name, const char *md_name,
+    const char *file, BIO *bmd);
 
-static void list_md_fn(const EVP_MD *m,
-                       const char *from, const char *to, void *arg)
-       {
+static void
+list_md_fn(const EVP_MD *m, const char *from, const char *to, void *arg)
+{
        const char *mname;
        /* Skip aliases */
        if (!m)
@@ -94,27 +94,28 @@ static void list_md_fn(const EVP_MD *m,
        if (EVP_MD_flags(m) & EVP_MD_FLAG_PKEY_DIGEST)
                return;
        if (strchr(mname, ' '))
-               mname= EVP_MD_name(m);
+               mname = EVP_MD_name(m);
        BIO_printf(arg, "-%-14s to use the %s message digest algorithm\n",
-                       mname, mname);
-       }
+           mname, mname);
+}
 
 int MAIN(int, char **);
 
-int MAIN(int argc, char **argv)
-       {
+int
+MAIN(int argc, char **argv)
+{
        ENGINE *e = NULL;
-       unsigned char *buf=NULL;
-       int i,err=1;
-       const EVP_MD *md=NULL,*m;
-       BIO *in=NULL,*inp;
-       BIO *bmd=NULL;
+       unsigned char *buf = NULL;
+       int i, err = 1;
+       const EVP_MD *md = NULL, *m;
+       BIO *in = NULL, *inp;
+       BIO *bmd = NULL;
        BIO *out = NULL;
 #define PROG_NAME_SIZE  39
-       char pname[PROG_NAME_SIZE+1];
-       int separator=0;
-       int debug=0;
-       int keyform=FORMAT_PEM;
+       char pname[PROG_NAME_SIZE + 1];
+       int separator = 0;
+       int debug = 0;
+       int keyform = FORMAT_PEM;
        const char *outfile = NULL, *keyfile = NULL;
        const char *sigfile = NULL, *randfile = NULL;
        int out_bin = -1, want_pub = 0, do_verify = 0;
@@ -123,418 +124,374 @@ int MAIN(int argc, char **argv)
        int siglen = 0;
        char *passargin = NULL, *passin = NULL;
 #ifndef OPENSSL_NO_ENGINE
-       char *engine=NULL;
+       char *engine = NULL;
 #endif
-       char *hmac_key=NULL;
-       char *mac_name=NULL;
+       char *hmac_key = NULL;
+       char *mac_name = NULL;
        int non_fips_allow = 0;
        STACK_OF(OPENSSL_STRING) *sigopts = NULL, *macopts = NULL;
 
        apps_startup();
 
-       if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)
-               {
-               BIO_printf(bio_err,"out of memory\n");
+       if ((buf = (unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL) {
+               BIO_printf(bio_err, "out of memory\n");
                goto end;
-               }
+       }
        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;
 
        /* first check the program name */
-       program_name(argv[0],pname,sizeof pname);
+       program_name(argv[0], pname, sizeof pname);
 
-       md=EVP_get_digestbyname(pname);
+       md = EVP_get_digestbyname(pname);
 
        argc--;
        argv++;
-       while (argc > 0)
-               {
-               if ((*argv)[0] != '-') break;
-               if (strcmp(*argv,"-c") == 0)
-                       separator=1;
-               else if (strcmp(*argv,"-r") == 0)
-                       separator=2;
-               else if (strcmp(*argv,"-rand") == 0)
-                       {
-                       if (--argc < 1) break;
+       while (argc > 0) {
+               if ((*argv)[0] != '-')
+                       break;
+               if (strcmp(*argv, "-c") == 0)
+                       separator = 1;
+               else if (strcmp(*argv, "-r") == 0)
+                       separator = 2;
+               else if (strcmp(*argv, "-rand") == 0) {
+                       if (--argc < 1)
+                               break;
                        randfile=*(++argv);
-                       }
-               else if (strcmp(*argv,"-out") == 0)
-                       {
-                       if (--argc < 1) break;
+               } else if (strcmp(*argv, "-out") == 0) {
+                       if (--argc < 1)
+                               break;
                        outfile=*(++argv);
-                       }
-               else if (strcmp(*argv,"-sign") == 0)
-                       {
-                       if (--argc < 1) break;
+               } else if (strcmp(*argv, "-sign") == 0) {
+                       if (--argc < 1)
+                               break;
                        keyfile=*(++argv);
-                       }
-               else if (!strcmp(*argv,"-passin"))
-                       {
+               } else if (!strcmp(*argv, "-passin")) {
                        if (--argc < 1)
                                break;
                        passargin=*++argv;
-                       }
-               else if (strcmp(*argv,"-verify") == 0)
-                       {
-                       if (--argc < 1) break;
+               } else if (strcmp(*argv, "-verify") == 0) {
+                       if (--argc < 1)
+                               break;
                        keyfile=*(++argv);
                        want_pub = 1;
                        do_verify = 1;
-                       }
-               else if (strcmp(*argv,"-prverify") == 0)
-                       {
-                       if (--argc < 1) break;
+               } else if (strcmp(*argv, "-prverify") == 0) {
+                       if (--argc < 1)
+                               break;
                        keyfile=*(++argv);
                        do_verify = 1;
-                       }
-               else if (strcmp(*argv,"-signature") == 0)
-                       {
-                       if (--argc < 1) break;
+               } else if (strcmp(*argv, "-signature") == 0) {
+                       if (--argc < 1)
+                               break;
                        sigfile=*(++argv);
-                       }
-               else if (strcmp(*argv,"-keyform") == 0)
-                       {
-                       if (--argc < 1) break;
-                       keyform=str2fmt(*(++argv));
-                       }
+               } else if (strcmp(*argv, "-keyform") == 0) {
+                       if (--argc < 1)
+                               break;
+                       keyform = str2fmt(*(++argv));
+               }
 #ifndef OPENSSL_NO_ENGINE
-               else if (strcmp(*argv,"-engine") == 0)
-                       {
-                       if (--argc < 1) break;
+               else if (strcmp(*argv, "-engine") == 0) {
+                       if (--argc < 1)
+                               break;
                        engine= *(++argv);
-                       e = setup_engine(bio_err, engine, 0);
-                       }
+                       e = setup_engine(bio_err, engine, 0);
+               }
 #endif
-               else if (strcmp(*argv,"-hex") == 0)
+               else if (strcmp(*argv, "-hex") == 0)
                        out_bin = 0;
-               else if (strcmp(*argv,"-binary") == 0)
+               else if (strcmp(*argv, "-binary") == 0)
                        out_bin = 1;
-               else if (strcmp(*argv,"-d") == 0)
-                       debug=1;
-               else if (!strcmp(*argv,"-fips-fingerprint"))
+               else if (strcmp(*argv, "-d") == 0)
+                       debug = 1;
+               else if (!strcmp(*argv, "-fips-fingerprint"))
                        hmac_key = "etaonrishdlcupfm";
-               else if (strcmp(*argv,"-non-fips-allow") == 0)
-                       non_fips_allow=1;
-               else if (!strcmp(*argv,"-hmac"))
-                       {
+               else if (strcmp(*argv, "-non-fips-allow") == 0)
+                       non_fips_allow = 1;
+               else if (!strcmp(*argv, "-hmac")) {
                        if (--argc < 1)
                                break;
                        hmac_key=*++argv;
-                       }
-               else if (!strcmp(*argv,"-mac"))
-                       {
+               } else if (!strcmp(*argv, "-mac")) {
                        if (--argc < 1)
                                break;
                        mac_name=*++argv;
-                       }
-               else if (strcmp(*argv,"-sigopt") == 0)
-                       {
+               } else if (strcmp(*argv, "-sigopt") == 0) {
                        if (--argc < 1)
                                break;
                        if (!sigopts)
                                sigopts = sk_OPENSSL_STRING_new_null();
                        if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, *(++argv)))
                                break;
-                       }
-               else if (strcmp(*argv,"-macopt") == 0)
-                       {
+               } else if (strcmp(*argv, "-macopt") == 0) {
                        if (--argc < 1)
                                break;
                        if (!macopts)
                                macopts = sk_OPENSSL_STRING_new_null();
                        if (!macopts || !sk_OPENSSL_STRING_push(macopts, *(++argv)))
                                break;
-                       }
-               else if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
-                       md=m;
+               } else if ((m = EVP_get_digestbyname(&((*argv)[1]))) != NULL)
+                       md = m;
                else
                        break;
                argc--;
                argv++;
-               }
+       }
 
 
-       if(do_verify && !sigfile) {
+       if (do_verify && !sigfile) {
                BIO_printf(bio_err, "No signature to verify: use the -signature option\n");
                goto end;
        }
 
        if ((argc > 0) && (argv[0][0] == '-')) /* bad option */
-               {
-               BIO_printf(bio_err,"unknown option '%s'\n",*argv);
-               BIO_printf(bio_err,"options are\n");
-               BIO_printf(bio_err,"-c              to output the digest with separating colons\n");
-               BIO_printf(bio_err,"-r              to output the digest in coreutils format\n");
-               BIO_printf(bio_err,"-d              to output debug info\n");
-               BIO_printf(bio_err,"-hex            output as hex dump\n");
-               BIO_printf(bio_err,"-binary         output in binary form\n");
-               BIO_printf(bio_err,"-sign   file    sign digest using private key in file\n");
-               BIO_printf(bio_err,"-verify file    verify a signature using public key in file\n");
-               BIO_printf(bio_err,"-prverify file  verify a signature using private key in file\n");
-               BIO_printf(bio_err,"-keyform arg    key file format (PEM or ENGINE)\n");
-               BIO_printf(bio_err,"-out filename   output to filename rather than stdout\n");
-               BIO_printf(bio_err,"-signature file signature to verify\n");
-               BIO_printf(bio_err,"-sigopt nm:v    signature parameter\n");
-               BIO_printf(bio_err,"-hmac key       create hashed MAC with key\n");
-               BIO_printf(bio_err,"-mac algorithm  create MAC (not neccessarily HMAC)\n"); 
-               BIO_printf(bio_err,"-macopt nm:v    MAC algorithm parameters or key\n");
+       {
+               BIO_printf(bio_err, "unknown option '%s'\n", *argv);
+               BIO_printf(bio_err, "options are\n");
+               BIO_printf(bio_err, "-c              to output the digest with separating colons\n");
+               BIO_printf(bio_err, "-r              to output the digest in coreutils format\n");
+               BIO_printf(bio_err, "-d              to output debug info\n");
+               BIO_printf(bio_err, "-hex            output as hex dump\n");
+               BIO_printf(bio_err, "-binary         output in binary form\n");
+               BIO_printf(bio_err, "-sign   file    sign digest using private key in file\n");
+               BIO_printf(bio_err, "-verify file    verify a signature using public key in file\n");
+               BIO_printf(bio_err, "-prverify file  verify a signature using private key in file\n");
+               BIO_printf(bio_err, "-keyform arg    key file format (PEM or ENGINE)\n");
+               BIO_printf(bio_err, "-out filename   output to filename rather than stdout\n");
+               BIO_printf(bio_err, "-signature file signature to verify\n");
+               BIO_printf(bio_err, "-sigopt nm:v    signature parameter\n");
+               BIO_printf(bio_err, "-hmac key       create hashed MAC with key\n");
+               BIO_printf(bio_err, "-mac algorithm  create MAC (not neccessarily HMAC)\n");
+               BIO_printf(bio_err, "-macopt nm:v    MAC algorithm parameters or key\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
 
                EVP_MD_do_all_sorted(list_md_fn, bio_err);
                goto end;
-               }
+       }
 
-       in=BIO_new(BIO_s_file());
-       bmd=BIO_new(BIO_f_md());
-       if (debug)
-               {
-               BIO_set_callback(in,BIO_debug_callback);
+       in = BIO_new(BIO_s_file());
+       bmd = BIO_new(BIO_f_md());
+       if (debug) {
+               BIO_set_callback(in, BIO_debug_callback);
                /* needed for windows 3.1 */
-               BIO_set_callback_arg(in,(char *)bio_err);
-               }
+               BIO_set_callback_arg(in, (char *)bio_err);
+       }
 
-       if(!app_passwd(bio_err, passargin, NULL, &passin, NULL))
-               {
+       if (!app_passwd(bio_err, passargin, NULL, &passin, NULL)) {
                BIO_printf(bio_err, "Error getting password\n");
                goto end;
-               }
+       }
 
-       if ((in == NULL) || (bmd == NULL))
-               {
+       if ((in == NULL) || (bmd == NULL)) {
                ERR_print_errors(bio_err);
                goto end;
-               }
+       }
 
-       if(out_bin == -1) {
-               if(keyfile)
+       if (out_bin == -1) {
+               if (keyfile)
                        out_bin = 1;
                else
                        out_bin = 0;
        }
 
-       if(randfile)
+       if (randfile)
                app_RAND_load_file(randfile, bio_err, 0);
 
-       if(outfile) {
-               if(out_bin)
+       if (outfile) {
+               if (out_bin)
                        out = BIO_new_file(outfile, "wb");
-               else    out = BIO_new_file(outfile, "w");
+               else
+                       out = BIO_new_file(outfile, "w");
        } else {
                out = BIO_new_fp(stdout, BIO_NOCLOSE);
        }
 
-       if(!out) {
-               BIO_printf(bio_err, "Error opening output file %s\n", 
-                                       outfile ? outfile : "(stdout)");
+       if (!out) {
+               BIO_printf(bio_err, "Error opening output file %s\n",
+                   outfile ? outfile : "(stdout)");
                ERR_print_errors(bio_err);
                goto end;
        }
-       if ((!!mac_name + !!keyfile + !!hmac_key) > 1)
-               {
+       if ((!!mac_name + !!keyfile + !!hmac_key) > 1) {
                BIO_printf(bio_err, "MAC and Signing key cannot both be specified\n");
                goto end;
-               }
+       }
 
-       if(keyfile)
-               {
+       if (keyfile) {
                if (want_pub)
                        sigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL,
-                               e, "key file");
+                           e, "key file");
                else
                        sigkey = load_key(bio_err, keyfile, keyform, 0, passin,
-                               e, "key file");
-               if (!sigkey)
-                       {
+                           e, "key file");
+               if (!sigkey) {
                        /* load_[pub]key() has already printed an appropriate
                           message */
                        goto end;
-                       }
                }
+       }
 
-       if (mac_name)
-               {
+       if (mac_name) {
                EVP_PKEY_CTX *mac_ctx = NULL;
                int r = 0;
-               if (!init_gen_str(bio_err, &mac_ctx, mac_name,e, 0))
+               if (!init_gen_str(bio_err, &mac_ctx, mac_name, e, 0))
                        goto mac_end;
-               if (macopts)
-                       {
+               if (macopts) {
                        char *macopt;
-                       for (i = 0; i < sk_OPENSSL_STRING_num(macopts); i++)
-                               {
+                       for (i = 0; i < sk_OPENSSL_STRING_num(macopts); i++) {
                                macopt = sk_OPENSSL_STRING_value(macopts, i);
-                               if (pkey_ctrl_string(mac_ctx, macopt) <= 0)
-                                       {
+                               if (pkey_ctrl_string(mac_ctx, macopt) <= 0) {
                                        BIO_printf(bio_err,
-                                               "MAC parameter error \"%s\"\n",
-                                               macopt);
+                                           "MAC parameter error \"%s\"\n",
+                                           macopt);
                                        ERR_print_errors(bio_err);
                                        goto mac_end;
-                                       }
                                }
                        }
-               if (EVP_PKEY_keygen(mac_ctx, &sigkey) <= 0)
-                       {
+               }
+               if (EVP_PKEY_keygen(mac_ctx, &sigkey) <= 0) {
                        BIO_puts(bio_err, "Error generating key\n");
                        ERR_print_errors(bio_err);
                        goto mac_end;
-                       }
+               }
                r = 1;
                mac_end:
                if (mac_ctx)
                        EVP_PKEY_CTX_free(mac_ctx);
                if (r == 0)
                        goto end;
-               }
+       }
 
-       if (non_fips_allow)
-               {
+       if (non_fips_allow) {
                EVP_MD_CTX *md_ctx;
-               BIO_get_md_ctx(bmd,&md_ctx);
+               BIO_get_md_ctx(bmd, &md_ctx);
                EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-               }
+       }
 
-       if (hmac_key)
-               {
+       if (hmac_key) {
                sigkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, e,
-                                       (unsigned char *)hmac_key, -1);
+                   (unsigned char *)hmac_key, -1);
                if (!sigkey)
                        goto end;
-               }
+       }
 
-       if (sigkey)
-               {
+       if (sigkey) {
                EVP_MD_CTX *mctx = NULL;
                EVP_PKEY_CTX *pctx = NULL;
                int r;
-               if (!BIO_get_md_ctx(bmd, &mctx))
-                       {
+               if (!BIO_get_md_ctx(bmd, &mctx)) {
                        BIO_printf(bio_err, "Error getting context\n");
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
+               }
                if (do_verify)
                        r = EVP_DigestVerifyInit(mctx, &pctx, md, NULL, sigkey);
                else
                        r = EVP_DigestSignInit(mctx, &pctx, md, NULL, sigkey);
-               if (!r)
-                       {
+               if (!r) {
                        BIO_printf(bio_err, "Error setting context\n");
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
-               if (sigopts)
-                       {
+               }
+               if (sigopts) {
                        char *sigopt;
-                       for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++)
-                               {
+                       for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {
                                sigopt = sk_OPENSSL_STRING_value(sigopts, i);
-                               if (pkey_ctrl_string(pctx, sigopt) <= 0)
-                                       {
+                               if (pkey_ctrl_string(pctx, sigopt) <= 0) {
                                        BIO_printf(bio_err,
-                                               "parameter error \"%s\"\n",
-                                               sigopt);
+                                           "parameter error \"%s\"\n",
+                                           sigopt);
                                        ERR_print_errors(bio_err);
                                        goto end;
-                                       }
                                }
                        }
                }
+       }
        /* we use md as a filter, reading from 'in' */
-       else
-               {
+       else {
                if (md == NULL)
-                       md = EVP_md5(); 
-               if (!BIO_set_md(bmd,md))
-                       {
+                       md = EVP_md5();
+               if (!BIO_set_md(bmd, md)) {
                        BIO_printf(bio_err, "Error setting digest %s\n", pname);
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
                }
+       }
 
-       if(sigfile && sigkey) {
+       if (sigfile && sigkey) {
                BIO *sigbio;
                sigbio = BIO_new_file(sigfile, "rb");
                siglen = EVP_PKEY_size(sigkey);
                sigbuf = OPENSSL_malloc(siglen);
-               if(!sigbio) {
+               if (!sigbio) {
                        BIO_printf(bio_err, "Error opening signature file %s\n",
-                                                               sigfile);
+                           sigfile);
                        ERR_print_errors(bio_err);
                        goto end;
                }
                siglen = BIO_read(sigbio, sigbuf, siglen);
                BIO_free(sigbio);
-               if(siglen <= 0) {
+               if (siglen <= 0) {
                        BIO_printf(bio_err, "Error reading signature file %s\n",
-                                                               sigfile);
+                           sigfile);
                        ERR_print_errors(bio_err);
                        goto end;
                }
        }
-       inp=BIO_push(bmd,in);
+       inp = BIO_push(bmd, in);
 
-       if (md == NULL)
-               {
+       if (md == NULL) {
                EVP_MD_CTX *tctx;
                BIO_get_md_ctx(bmd, &tctx);
                md = EVP_MD_CTX_md(tctx);
-               }
+       }
 
-       if (argc == 0)
-               {
-               BIO_set_fp(in,stdin,BIO_NOCLOSE);
-               err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
-                         siglen,NULL,NULL,"stdin",bmd);
-               }
-       else
-               {
+       if (argc == 0) {
+               BIO_set_fp(in, stdin, BIO_NOCLOSE);
+               err = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf,
+                   siglen, NULL, NULL, "stdin", bmd);
+       } else {
                const char *md_name = NULL, *sig_name = NULL;
-               if(!out_bin)
-                       {
-                       if (sigkey)
-                               {
+               if (!out_bin) {
+                       if (sigkey) {
                                const EVP_PKEY_ASN1_METHOD *ameth;
                                ameth = EVP_PKEY_get0_asn1(sigkey);
                                if (ameth)
                                        EVP_PKEY_asn1_get0_info(NULL, NULL,
-                                               NULL, NULL, &sig_name, ameth);
-                               }
-                       md_name = EVP_MD_name(md);
+                                           NULL, NULL, &sig_name, ameth);
                        }
+                       md_name = EVP_MD_name(md);
+               }
                err = 0;
-               for (i=0; i<argc; i++)
-                       {
+               for (i = 0; i < argc; i++) {
                        int r;
-                       if (BIO_read_filename(in,argv[i]) <= 0)
-                               {
+                       if (BIO_read_filename(in, argv[i]) <= 0) {
                                perror(argv[i]);
                                err++;
                                continue;
-                               }
-                       else
-                       r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
-                               siglen,sig_name,md_name, argv[i],bmd);
-                       if(r)
-                           err=r;
+                       } else
+                               r = do_fp(out, buf, inp, separator, out_bin,
+                                   sigkey, sigbuf, siglen, sig_name, md_name,
+                                   argv[i], bmd);
+                       if (r)
+                               err = r;
                        (void)BIO_reset(bmd);
-                       }
                }
+       }
+
 end:
-       if (buf != NULL)
-               {
-               OPENSSL_cleanse(buf,BUFSIZE);
+       if (buf != NULL) {
+               OPENSSL_cleanse(buf, BUFSIZE);
                OPENSSL_free(buf);
-               }
-       if (in != NULL) BIO_free(in);
+       }
+       if (in != NULL)
+               BIO_free(in);
        if (passin)
                OPENSSL_free(passin);
        BIO_free_all(out);
@@ -543,96 +500,83 @@ end:
                sk_OPENSSL_STRING_free(sigopts);
        if (macopts)
                sk_OPENSSL_STRING_free(macopts);
-       if(sigbuf) OPENSSL_free(sigbuf);
-       if (bmd != NULL) BIO_free(bmd);
+       if (sigbuf) OPENSSL_free(sigbuf);
+               if (bmd != NULL)
+                       BIO_free(bmd);
        apps_shutdown();
        OPENSSL_EXIT(err);
-       }
-
-int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
-         EVP_PKEY *key, unsigned char *sigin, int siglen,
-         const char *sig_name, const char *md_name,
-         const char *file,BIO *bmd)
-       {
+}
+
+int
+do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
+    EVP_PKEY *key, unsigned char *sigin, int siglen,
+    const char *sig_name, const char *md_name,
+    const char *file, BIO *bmd)
+{
        size_t len;
        int i;
 
-       for (;;)
-               {
-               i=BIO_read(bp,(char *)buf,BUFSIZE);
-               if(i < 0)
-                       {
-                       BIO_printf(bio_err, "Read Error in %s\n",file);
+       for (;;) {
+               i = BIO_read(bp, (char *)buf, BUFSIZE);
+               if (i < 0) {
+                       BIO_printf(bio_err, "Read Error in %s\n", file);
                        ERR_print_errors(bio_err);
                        return 1;
-                       }
-               if (i == 0) break;
                }
-       if(sigin)
-               {
+               if (i == 0)
+                       break;
+       }
+       if (sigin) {
                EVP_MD_CTX *ctx;
                BIO_get_md_ctx(bp, &ctx);
-               i = EVP_DigestVerifyFinal(ctx, sigin, (unsigned int)siglen); 
-               if(i > 0)
+               i = EVP_DigestVerifyFinal(ctx, sigin, (unsigned int)siglen);
+               if (i > 0)
                        BIO_printf(out, "Verified OK\n");
-               else if(i == 0)
-                       {
+               else if (i == 0) {
                        BIO_printf(out, "Verification Failure\n");
                        return 1;
-                       }
-               else
-                       {
+               } else {
                        BIO_printf(bio_err, "Error Verifying Data\n");
                        ERR_print_errors(bio_err);
                        return 1;
-                       }
-               return 0;
                }
-       if(key)
-               {
+               return 0;
+       }
+       if (key) {
                EVP_MD_CTX *ctx;
                BIO_get_md_ctx(bp, &ctx);
                len = BUFSIZE;
-               if(!EVP_DigestSignFinal(ctx, buf, &len)) 
-                       {
+               if (!EVP_DigestSignFinal(ctx, buf, &len)) {
                        BIO_printf(bio_err, "Error Signing Data\n");
                        ERR_print_errors(bio_err);
                        return 1;
-                       }
                }
-       else
-               {
-               len=BIO_gets(bp,(char *)buf,BUFSIZE);
-               if ((int)len <0)
-                       {
+       } else {
+               len = BIO_gets(bp, (char *)buf, BUFSIZE);
+               if ((int)len < 0) {
                        ERR_print_errors(bio_err);
                        return 1;
-                       }
                }
+       }
 
-       if(binout) BIO_write(out, buf, len);
-       else if (sep == 2)
-               {
-               for (i=0; i<(int)len; i++)
-                       BIO_printf(out, "%02x",buf[i]);
+       if (binout) BIO_write(out, buf, len);
+               else if (sep == 2) {
+               for (i = 0; i < (int)len; i++)
+                       BIO_printf(out, "%02x", buf[i]);
                BIO_printf(out, " *%s\n", file);
-               }
-       else 
-               {
+       } else {
                if (sig_name)
                        BIO_printf(out, "%s-%s(%s)= ", sig_name, md_name, file);
                else if (md_name)
                        BIO_printf(out, "%s(%s)= ", md_name, file);
                else
                        BIO_printf(out, "(%s)= ", file);
-               for (i=0; i<(int)len; i++)
-                       {
+               for (i = 0; i < (int)len; i++) {
                        if (sep && (i != 0))
                                BIO_printf(out, ":");
-                       BIO_printf(out, "%02x",buf[i]);
-                       }
-               BIO_printf(out, "\n");
+                       BIO_printf(out, "%02x", buf[i]);
                }
-       return 0;
+               BIO_printf(out, "\n");
        }
-
+       return 0;
+}
index 5f53426..0ad7121 100644 (file)
@@ -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:
  *     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
 
 int MAIN(int, char **);
 
-int MAIN(int argc, char **argv)
-       {
-       DH *dh=NULL;
-       int i,badops=0,text=0;
-       BIO *in=NULL,*out=NULL;
-       int informat,outformat,check=0,noout=0,C=0,ret=1;
-       char *infile,*outfile,*prog;
+int
+MAIN(int argc, char **argv)
+{
+       DH *dh = NULL;
+       int i, badops = 0, text = 0;
+       BIO *in = NULL, *out = NULL;
+       int informat, outformat, check = 0, noout = 0, C = 0, ret = 1;
+       char *infile, *outfile, *prog;
 #ifndef OPENSSL_NO_ENGINE
        char *engine;
 #endif
@@ -100,165 +101,148 @@ int MAIN(int argc, char **argv)
        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;
 
 #ifndef OPENSSL_NO_ENGINE
-       engine=NULL;
+       engine = NULL;
 #endif
-       infile=NULL;
-       outfile=NULL;
-       informat=FORMAT_PEM;
-       outformat=FORMAT_PEM;
+       infile = NULL;
+       outfile = NULL;
+       informat = FORMAT_PEM;
+       outformat = FORMAT_PEM;
 
-       prog=argv[0];
+       prog = argv[0];
        argc--;
        argv++;
-       while (argc >= 1)
-               {
-               if      (strcmp(*argv,"-inform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       informat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-outform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       outformat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-in") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+       while (argc >= 1) {
+               if (strcmp(*argv, "-inform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       informat = str2fmt(*(++argv));
+               }
+               else if (strcmp(*argv, "-outform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       outformat = str2fmt(*(++argv));
+               }
+               else if (strcmp(*argv, "-in") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        infile= *(++argv);
-                       }
-               else if (strcmp(*argv,"-out") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               }
+               else if (strcmp(*argv, "-out") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        outfile= *(++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,"-check") == 0)
-                       check=1;
-               else if (strcmp(*argv,"-text") == 0)
-                       text=1;
-               else if (strcmp(*argv,"-C") == 0)
-                       C=1;
-               else if (strcmp(*argv,"-noout") == 0)
-                       noout=1;
-               else
-                       {
-                       BIO_printf(bio_err,"unknown option %s\n",*argv);
-                       badops=1;
+               else if (strcmp(*argv, "-check") == 0)
+                       check = 1;
+               else if (strcmp(*argv, "-text") == 0)
+                       text = 1;
+               else if (strcmp(*argv, "-C") == 0)
+                       C = 1;
+               else if (strcmp(*argv, "-noout") == 0)
+                       noout = 1;
+               else {
+                       BIO_printf(bio_err, "unknown option %s\n", *argv);
+                       badops = 1;
                        break;
-                       }
+               }
                argc--;
                argv++;
-               }
+       }
 
-       if (badops)
-               {
+       if (badops) {
 bad:
-               BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
-               BIO_printf(bio_err,"where options are\n");
-               BIO_printf(bio_err," -inform arg   input format - one of DER PEM\n");
-               BIO_printf(bio_err," -outform arg  output format - one of DER PEM\n");
-               BIO_printf(bio_err," -in arg       input file\n");
-               BIO_printf(bio_err," -out arg      output file\n");
-               BIO_printf(bio_err," -check        check the DH parameters\n");
-               BIO_printf(bio_err," -text         print a text form of the DH parameters\n");
-               BIO_printf(bio_err," -C            Output C code\n");
-               BIO_printf(bio_err," -noout        no output\n");
+               BIO_printf(bio_err, "%s [options] <infile >outfile\n", prog);
+               BIO_printf(bio_err, "where options are\n");
+               BIO_printf(bio_err, " -inform arg   input format - one of DER PEM\n");
+               BIO_printf(bio_err, " -outform arg  output format - one of DER PEM\n");
+               BIO_printf(bio_err, " -in arg       input file\n");
+               BIO_printf(bio_err, " -out arg      output file\n");
+               BIO_printf(bio_err, " -check        check the DH parameters\n");
+               BIO_printf(bio_err, " -text         print a text form of the DH parameters\n");
+               BIO_printf(bio_err, " -C            Output C code\n");
+               BIO_printf(bio_err, " -noout        no output\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
                goto end;
-               }
+       }
 
        ERR_load_crypto_strings();
 
 #ifndef OPENSSL_NO_ENGINE
-        setup_engine(bio_err, engine, 0);
+       setup_engine(bio_err, engine, 0);
 #endif
 
-       in=BIO_new(BIO_s_file());
-       out=BIO_new(BIO_s_file());
-       if ((in == NULL) || (out == NULL))
-               {
+       in = BIO_new(BIO_s_file());
+       out = BIO_new(BIO_s_file());
+       if ((in == NULL) || (out == NULL)) {
                ERR_print_errors(bio_err);
                goto end;
-               }
+       }
 
        if (infile == NULL)
-               BIO_set_fp(in,stdin,BIO_NOCLOSE);
-       else
-               {
-               if (BIO_read_filename(in,infile) <= 0)
-                       {
+               BIO_set_fp(in, stdin, BIO_NOCLOSE);
+       else {
+               if (BIO_read_filename(in, infile) <= 0) {
                        perror(infile);
                        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      (informat == FORMAT_ASN1)
-               dh=d2i_DHparams_bio(in,NULL);
+       if (informat == FORMAT_ASN1)
+               dh = d2i_DHparams_bio(in, NULL);
        else if (informat == FORMAT_PEM)
-               dh=PEM_read_bio_DHparams(in,NULL,NULL,NULL);
-       else
-               {
-               BIO_printf(bio_err,"bad input format specified\n");
+               dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
+       else {
+               BIO_printf(bio_err, "bad input format specified\n");
                goto end;
-               }
-       if (dh == NULL)
-               {
-               BIO_printf(bio_err,"unable to load DH parameters\n");
+       }
+       if (dh == NULL) {
+               BIO_printf(bio_err, "unable to load DH parameters\n");
                ERR_print_errors(bio_err);
                goto end;
-               }
-
-       
+       }
 
-       if (text)
-               {
-               DHparams_print(out,dh);
+       if (text) {
+               DHparams_print(out, dh);
 #ifdef undef
                printf("p=");
-               BN_print(stdout,dh->p);
+               BN_print(stdout, dh->p);
                printf("\ng=");
-               BN_print(stdout,dh->g);
+               BN_print(stdout, dh->g);
                printf("\n");
                if (dh->length != 0)
-                       printf("recommended private length=%ld\n",dh->length);
+                       printf("recommended private length=%ld\n", dh->length);
 #endif
-               }
-       
-       if (check)
-               {
-               if (!DH_check(dh,&i))
-                       {
+       }
+
+       if (check) {
+               if (!DH_check(dh, &i)) {
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
+               }
                if (i & DH_CHECK_P_NOT_PRIME)
                        printf("p value is not prime\n");
                if (i & DH_CHECK_P_NOT_SAFE_PRIME)
@@ -269,81 +253,81 @@ bad:
                        printf("the g value is not a generator\n");
                if (i == 0)
                        printf("DH parameters appear to be ok.\n");
-               }
-       if (C)
-               {
+       }
+
+       if (C) {
                unsigned char *data;
-               int len,l,bits;
+               int len, l, bits;
 
-               len=BN_num_bytes(dh->p);
-               bits=BN_num_bits(dh->p);
-               data=(unsigned char *)OPENSSL_malloc(len);
-               if (data == NULL)
-                       {
+               len = BN_num_bytes(dh->p);
+               bits = BN_num_bits(dh->p);
+               data = (unsigned char *)OPENSSL_malloc(len);
+               if (data == NULL) {
                        perror("OPENSSL_malloc");
                        goto end;
-                       }
-               l=BN_bn2bin(dh->p,data);
-               printf("static unsigned char dh%d_p[]={",bits);
-               for (i=0; i<l; i++)
-                       {
-                       if ((i%12) == 0) printf("\n\t");
-                       printf("0x%02X,",data[i]);
-                       }
+               }
+               l = BN_bn2bin(dh->p, data);
+               printf("static unsigned char dh%d_p[] = {", bits);
+               for (i = 0; i < l; i++) {
+                       if ((i % 12) == 0)
+                               printf("\n\t");
+                       printf("0x%02X, ", data[i]);
+               }
                printf("\n\t};\n");
 
-               l=BN_bn2bin(dh->g,data);
-               printf("static unsigned char dh%d_g[]={",bits);
-               for (i=0; i<l; i++)
-                       {
-                       if ((i%12) == 0) printf("\n\t");
-                       printf("0x%02X,",data[i]);
-                       }
+               l = BN_bn2bin(dh->g, data);
+               printf("static unsigned char dh%d_g[] = {", bits);
+               for (i = 0; i < l; i++) {
+                       if ((i % 12) == 0)
+                               printf("\n\t");
+                       printf("0x%02X, ", data[i]);
+               }
                printf("\n\t};\n\n");
 
-               printf("DH *get_dh%d()\n\t{\n",bits);
+               printf("DH *get_dh%d()\n\t{\n", bits);
                printf("\tDH *dh;\n\n");
-               printf("\tif ((dh=DH_new()) == NULL) return(NULL);\n");
-               printf("\tdh->p=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\n",
-                       bits,bits);
-               printf("\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\n",
-                       bits,bits);
+               printf("\tif ((dh = DH_new()) == NULL) return(NULL);\n");
+               printf("\tdh->p = BN_bin2bn(dh%d_p, sizeof(dh%d_p), NULL);\n",
+                   bits, bits);
+               printf("\tdh->g = BN_bin2bn(dh%d_g, sizeof(dh%d_g), NULL);\n",
+                   bits, bits);
                printf("\tif ((dh->p == NULL) || (dh->g == NULL))\n");
                printf("\t\treturn(NULL);\n");
                printf("\treturn(dh);\n\t}\n");
                OPENSSL_free(data);
-               }
-
+       }
 
-       if (!noout)
-               {
-               if      (outformat == FORMAT_ASN1)
-                       i=i2d_DHparams_bio(out,dh);
+       if (!noout) {
+               if (outformat == FORMAT_ASN1)
+                       i = i2d_DHparams_bio(out, dh);
                else if (outformat == FORMAT_PEM)
-                       i=PEM_write_bio_DHparams(out,dh);
-               else    {
-                       BIO_printf(bio_err,"bad output format specified for outfile\n");
+                       i = PEM_write_bio_DHparams(out, dh);
+               else {
+                       BIO_printf(bio_err, "bad output format specified for outfile\n");
                        goto end;
-                       }
-               if (!i)
-                       {
-                       BIO_printf(bio_err,"unable to write DH parameters\n");
+               }
+               if (!i) {
+                       BIO_printf(bio_err, "unable to write DH parameters\n");
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
                }
-       ret=0;
+       }
+       ret = 0;
+
 end:
-       if (in != NULL) BIO_free(in);
-       if (out != NULL) BIO_free_all(out);
-       if (dh != NULL) DH_free(dh);
+       if (in != NULL)
+               BIO_free(in);
+       if (out != NULL)
+               BIO_free_all(out);
+       if (dh != NULL)
+               DH_free(dh);
        apps_shutdown();
        OPENSSL_EXIT(ret);
-       }
+}
 #else /* !OPENSSL_NO_DH */
 
 # if PEDANTIC
-static void *dummy=&dummy;
+static void *dummy = &dummy;
 # endif
 
 #endif
index 193e59b..718c744 100644 (file)
@@ -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:
  *     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
@@ -63,7 +63,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
@@ -147,298 +147,268 @@ static int dh_cb(int p, int n, BN_GENCB *cb);
 
 int MAIN(int, char **);
 
-int MAIN(int argc, char **argv)
-       {
-       DH *dh=NULL;
-       int i,badops=0,text=0;
+int
+MAIN(int argc, char **argv)
+{
+       DH *dh = NULL;
+       int i, badops = 0, text = 0;
 #ifndef OPENSSL_NO_DSA
-       int dsaparam=0;
+       int dsaparam = 0;
 #endif
-       BIO *in=NULL,*out=NULL;
-       int informat,outformat,check=0,noout=0,C=0,ret=1;
-       char *infile,*outfile,*prog;
-       char *inrand=NULL;
+       BIO *in = NULL, *out = NULL;
+       int informat, outformat, check = 0, noout = 0, C = 0, ret = 1;
+       char *infile, *outfile, *prog;
+       char *inrand = NULL;
 #ifndef OPENSSL_NO_ENGINE
-       char *engine=NULL;
+       char *engine = NULL;
 #endif
        int num = 0, g = 0;
 
        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;
 
-       infile=NULL;
-       outfile=NULL;
-       informat=FORMAT_PEM;
-       outformat=FORMAT_PEM;
+       infile = NULL;
+       outfile = NULL;
+       informat = FORMAT_PEM;
+       outformat = FORMAT_PEM;
 
-       prog=argv[0];
+       prog = argv[0];
        argc--;
        argv++;
-       while (argc >= 1)
-               {
-               if      (strcmp(*argv,"-inform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       informat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-outform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       outformat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-in") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+       while (argc >= 1) {
+               if (strcmp(*argv, "-inform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       informat = str2fmt(*(++argv));
+               } else if (strcmp(*argv, "-outform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       outformat = str2fmt(*(++argv));
+               } else if (strcmp(*argv, "-in") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        infile= *(++argv);
-                       }
-               else if (strcmp(*argv,"-out") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               } else if (strcmp(*argv, "-out") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        outfile= *(++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,"-check") == 0)
-                       check=1;
-               else if (strcmp(*argv,"-text") == 0)
-                       text=1;
+               else if (strcmp(*argv, "-check") == 0)
+                       check = 1;
+               else if (strcmp(*argv, "-text") == 0)
+                       text = 1;
 #ifndef OPENSSL_NO_DSA
-               else if (strcmp(*argv,"-dsaparam") == 0)
-                       dsaparam=1;
+               else if (strcmp(*argv, "-dsaparam") == 0)
+                       dsaparam = 1;
 #endif
-               else if (strcmp(*argv,"-C") == 0)
-                       C=1;
-               else if (strcmp(*argv,"-noout") == 0)
-                       noout=1;
-               else if (strcmp(*argv,"-2") == 0)
-                       g=2;
-               else if (strcmp(*argv,"-5") == 0)
-                       g=5;
-               else if (strcmp(*argv,"-rand") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               else if (strcmp(*argv, "-C") == 0)
+                       C = 1;
+               else if (strcmp(*argv, "-noout") == 0)
+                       noout = 1;
+               else if (strcmp(*argv, "-2") == 0)
+                       g = 2;
+               else if (strcmp(*argv, "-5") == 0)
+                       g = 5;
+               else if (strcmp(*argv, "-rand") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        inrand= *(++argv);
-                       }
-               else if (((sscanf(*argv,"%d",&num) == 0) || (num <= 0)))
+               }
+               else if (((sscanf(*argv, "%d", &num) == 0) || (num <= 0)))
                        goto bad;
                argv++;
                argc--;
-               }
+       }
 
-       if (badops)
-               {
+       if (badops) {
 bad:
-               BIO_printf(bio_err,"%s [options] [numbits]\n",prog);
-               BIO_printf(bio_err,"where options are\n");
-               BIO_printf(bio_err," -inform arg   input format - one of DER PEM\n");
-               BIO_printf(bio_err," -outform arg  output format - one of DER PEM\n");
-               BIO_printf(bio_err," -in arg       input file\n");
-               BIO_printf(bio_err," -out arg      output file\n");
+               BIO_printf(bio_err, "%s [options] [numbits]\n", prog);
+               BIO_printf(bio_err, "where options are\n");
+               BIO_printf(bio_err, " -inform arg   input format - one of DER PEM\n");
+               BIO_printf(bio_err, " -outform arg  output format - one of DER PEM\n");
+               BIO_printf(bio_err, " -in arg       input file\n");
+               BIO_printf(bio_err, " -out arg      output file\n");
 #ifndef OPENSSL_NO_DSA
-               BIO_printf(bio_err," -dsaparam     read or generate DSA parameters, convert to DH\n");
+               BIO_printf(bio_err, " -dsaparam     read or generate DSA parameters, convert to DH\n");
 #endif
-               BIO_printf(bio_err," -check        check the DH parameters\n");
-               BIO_printf(bio_err," -text         print a text form of the DH parameters\n");
-               BIO_printf(bio_err," -C            Output C code\n");
-               BIO_printf(bio_err," -2            generate parameters using  2 as the generator value\n");
-               BIO_printf(bio_err," -5            generate parameters using  5 as the generator value\n");
-               BIO_printf(bio_err," numbits       number of bits in to generate (default 512)\n");
+               BIO_printf(bio_err, " -check        check the DH parameters\n");
+               BIO_printf(bio_err, " -text         print a text form of the DH parameters\n");
+               BIO_printf(bio_err, " -C            Output C code\n");
+               BIO_printf(bio_err, " -2            generate parameters using  2 as the generator value\n");
+               BIO_printf(bio_err, " -5            generate parameters using  5 as the generator value\n");
+               BIO_printf(bio_err, " numbits       number of bits in to generate (default 512)\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," -noout        no output\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, " -noout        no output\n");
                goto end;
-               }
+       }
 
        ERR_load_crypto_strings();
 
 #ifndef OPENSSL_NO_ENGINE
-        setup_engine(bio_err, engine, 0);
+       setup_engine(bio_err, engine, 0);
 #endif
 
        if (g && !num)
                num = DEFBITS;
 
 #ifndef OPENSSL_NO_DSA
-       if (dsaparam)
-               {
-               if (g)
-                       {
+       if (dsaparam) {
+               if (g) {
                        BIO_printf(bio_err, "generator may not be chosen for DSA parameters\n");
                        goto end;
-                       }
                }
-       else
+       else
 #endif
-               {
+       {
                /* DH parameters */
                if (num && !g)
                        g = 2;
-               }
+       }
 
-       if(num) {
+       if (num) {
 
                BN_GENCB cb;
                BN_GENCB_set(&cb, dh_cb, bio_err);
-               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));
 
 #ifndef OPENSSL_NO_DSA
-               if (dsaparam)
-                       {
+               if (dsaparam) {
                        DSA *dsa = DSA_new();
-                       
-                       BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num);
-                       if(!dsa || !DSA_generate_parameters_ex(dsa, num,
-                                               NULL, 0, NULL, NULL, &cb))
-                               {
-                               if(dsa) DSA_free(dsa);
-                               ERR_print_errors(bio_err);
+
+                       BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num);
+                       if (!dsa || !DSA_generate_parameters_ex(dsa, num,
+                                   NULL, 0, NULL, NULL, &cb)) {
+                               if (dsa) DSA_free(dsa);
+                                       ERR_print_errors(bio_err);
                                goto end;
-                               }
+                       }
 
                        dh = DSA_dup_DH(dsa);
                        DSA_free(dsa);
-                       if (dh == NULL)
-                               {
+                       if (dh == NULL) {
                                ERR_print_errors(bio_err);
                                goto end;
-                               }
                        }
-               else
+               else
 #endif
-                       {
+               {
                        dh = DH_new();
-                       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_generate_parameters_ex(dh, num, g, &cb))
-                               {
+                       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_generate_parameters_ex(dh, num, g, &cb)) {
                                ERR_print_errors(bio_err);
                                goto end;
-                               }
                        }
+               }
 
                app_RAND_write_file(NULL, bio_err);
        } else {
 
-               in=BIO_new(BIO_s_file());
-               if (in == NULL)
-                       {
+               in = BIO_new(BIO_s_file());
+               if (in == NULL) {
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
+               }
                if (infile == NULL)
-                       BIO_set_fp(in,stdin,BIO_NOCLOSE);
-               else
-                       {
-                       if (BIO_read_filename(in,infile) <= 0)
-                               {
+                       BIO_set_fp(in, stdin, BIO_NOCLOSE);
+               else {
+                       if (BIO_read_filename(in, infile) <= 0) {
                                perror(infile);
                                goto end;
-                               }
                        }
+               }
 
-               if      (informat != FORMAT_ASN1 && informat != FORMAT_PEM)
-                       {
-                       BIO_printf(bio_err,"bad input format specified\n");
+               if (informat != FORMAT_ASN1 && informat != FORMAT_PEM) {
+                       BIO_printf(bio_err, "bad input format specified\n");
                        goto end;
-                       }
+               }
 
 #ifndef OPENSSL_NO_DSA
-               if (dsaparam)
-                       {
+               if (dsaparam) {
                        DSA *dsa;
-                       
+
                        if (informat == FORMAT_ASN1)
-                               dsa=d2i_DSAparams_bio(in,NULL);
+                               dsa = d2i_DSAparams_bio(in, NULL);
                        else /* informat == FORMAT_PEM */
-                               dsa=PEM_read_bio_DSAparams(in,NULL,NULL,NULL);
-                       
-                       if (dsa == NULL)
-                               {
-                               BIO_printf(bio_err,"unable to load DSA parameters\n");
+                               dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL);
+
+                       if (dsa == NULL) {
+                               BIO_printf(bio_err, "unable to load DSA parameters\n");
                                ERR_print_errors(bio_err);
                                goto end;
-                               }
-                       
+                       }
+
                        dh = DSA_dup_DH(dsa);
                        DSA_free(dsa);
-                       if (dh == NULL)
-                               {
+                       if (dh == NULL) {
                                ERR_print_errors(bio_err);
                                goto end;
-                               }
                        }
-               else
+               else
 #endif
-                       {
+               {
                        if (informat == FORMAT_ASN1)
-                               dh=d2i_DHparams_bio(in,NULL);
+                               dh = d2i_DHparams_bio(in, NULL);
                        else /* informat == FORMAT_PEM */
-                               dh=PEM_read_bio_DHparams(in,NULL,NULL,NULL);
-                       
-                       if (dh == NULL)
-                               {
-                               BIO_printf(bio_err,"unable to load DH parameters\n");
+                               dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
+
+                       if (dh == NULL) {
+                               BIO_printf(bio_err, "unable to load DH parameters\n");
                                ERR_print_errors(bio_err);
                                goto end;
-                               }
                        }
-               
+               }
+
                /* dh != NULL */
        }
-       
-       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 (text)
-               {
-               DHparams_print(out,dh);
-               }
-       
-       if (check)
-               {
-               if (!DH_check(dh,&i))
-                       {
+       if (text) {
+               DHparams_print(out, dh);
+       }
+
+       if (check) {
+               if (!DH_check(dh, &i)) {
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
+               }
                if (i & DH_CHECK_P_NOT_PRIME)
                        printf("p value is not prime\n");
                if (i & DH_CHECK_P_NOT_SAFE_PRIME)
@@ -449,105 +419,109 @@ bad:
                        printf("the g value is not a generator\n");
                if (i == 0)
                        printf("DH parameters appear to be ok.\n");
-               }
-       if (C)
-               {
+       }
+       if (C) {
                unsigned char *data;
-               int len,l,bits;
+               int len, l, bits;
 
-               len=BN_num_bytes(dh->p);
-               bits=BN_num_bits(dh->p);
-               data=(unsigned char *)OPENSSL_malloc(len);
-               if (data == NULL)
-                       {
+               len = BN_num_bytes(dh->p);
+               bits = BN_num_bits(dh->p);
+               data = (unsigned char *)OPENSSL_malloc(len);
+               if (data == NULL) {
                        perror("OPENSSL_malloc");
                        goto end;
-                       }
+               }
                printf("#ifndef HEADER_DH_H\n"
-                      "#include <openssl/dh.h>\n"
-                      "#endif\n");
-               printf("DH *get_dh%d()\n\t{\n",bits);
-
-               l=BN_bn2bin(dh->p,data);
-               printf("\tstatic unsigned char dh%d_p[]={",bits);
-               for (i=0; i<l; i++)
-                       {
-                       if ((i%12) == 0) printf("\n\t\t");
-                       printf("0x%02X,",data[i]);
-                       }
+                   "#include <openssl/dh.h>\n"
+                   "#endif\n");
+               printf("DH *get_dh%d()\n\t{\n", bits);
+
+               l = BN_bn2bin(dh->p, data);
+               printf("\tstatic unsigned char dh%d_p[] = {", bits);
+               for (i = 0; i < l; i++) {
+                       if ((i % 12) == 0)
+                               printf("\n\t\t");
+                       printf("0x%02X, ", data[i]);
+               }
                printf("\n\t\t};\n");
 
-               l=BN_bn2bin(dh->g,data);
-               printf("\tstatic unsigned char dh%d_g[]={",bits);
-               for (i=0; i<l; i++)
-                       {
-                       if ((i%12) == 0) printf("\n\t\t");
-                       printf("0x%02X,",data[i]);
-                       }
+               l = BN_bn2bin(dh->g, data);
+               printf("\tstatic unsigned char dh%d_g[] = {", bits);
+               for (i = 0; i < l; i++) {
+                       if ((i % 12) == 0)
+                               printf("\n\t\t");
+                       printf("0x%02X, ", data[i]);
+               }
                printf("\n\t\t};\n");
 
                printf("\tDH *dh;\n\n");
-               printf("\tif ((dh=DH_new()) == NULL) return(NULL);\n");
-               printf("\tdh->p=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\n",
-                       bits,bits);
-               printf("\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\n",
-                       bits,bits);
+               printf("\tif ((dh = DH_new()) == NULL) return(NULL);\n");
+               printf("\tdh->p = BN_bin2bn(dh%d_p, sizeof(dh%d_p), NULL);\n",
+                   bits, bits);
+               printf("\tdh->g = BN_bin2bn(dh%d_g, sizeof(dh%d_g), NULL);\n",
+                   bits, bits);
                printf("\tif ((dh->p == NULL) || (dh->g == NULL))\n");
                printf("\t\t{ DH_free(dh); return(NULL); }\n");
                if (dh->length)
                        printf("\tdh->length = %ld;\n", dh->length);
                printf("\treturn(dh);\n\t}\n");
                OPENSSL_free(data);
-               }
-
+       }
 
-       if (!noout)
-               {
-               if      (outformat == FORMAT_ASN1)
-                       i=i2d_DHparams_bio(out,dh);
+       if (!noout) {
+               if (outformat == FORMAT_ASN1)
+                       i = i2d_DHparams_bio(out, dh);
                else if (outformat == FORMAT_PEM)
-                       i=PEM_write_bio_DHparams(out,dh);
+                       i = PEM_write_bio_DHparams(out, dh);
                else    {
-                       BIO_printf(bio_err,"bad output format specified for outfile\n");
+                       BIO_printf(bio_err, "bad output format specified for outfile\n");
                        goto end;
-                       }
-               if (!i)
-                       {
-                       BIO_printf(bio_err,"unable to write DH parameters\n");
+               }
+               if (!i) {
+                       BIO_printf(bio_err, "unable to write DH parameters\n");
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
                }
-       ret=0;
+       }
+       ret = 0;
+
 end:
-       if (in != NULL) BIO_free(in);
-       if (out != NULL) BIO_free_all(out);
-       if (dh != NULL) DH_free(dh);
+       if (in != NULL)
+               BIO_free(in);
+       if (out != NULL)
+               BIO_free_all(out);
+       if (dh != NULL)
+               DH_free(dh);
        apps_shutdown();
        OPENSSL_EXIT(ret);
-       }
+}
 
 /* dh_cb is identical to dsa_cb in apps/dsaparam.c */
-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
index 45bac4a..b2c58d0 100644 (file)
@@ -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:
  *     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
 
 int MAIN(int, char **);
 
-int MAIN(int argc, char **argv)
-       {
+int
+MAIN(int argc, char **argv)
+{
        ENGINE *e = NULL;
-       int ret=1;
-       DSA *dsa=NULL;
-       int i,badops=0;
-       const EVP_CIPHER *enc=NULL;
-       BIO *in=NULL,*out=NULL;
-       int informat,outformat,text=0,noout=0;
+       int ret = 1;
+       DSA *dsa = NULL;
+       int i, badops = 0;
+       const EVP_CIPHER *enc = NULL;
+       BIO *in = NULL, *out = NULL;
+       int informat, outformat, text = 0, noout = 0;
        int pubin = 0, pubout = 0;
-       char *infile,*outfile,*prog;
+       char *infile, *outfile, *prog;
 #ifndef OPENSSL_NO_ENGINE
        char *engine;
 #endif
        char *passargin = NULL, *passargout = NULL;
        char *passin = NULL, *passout = NULL;
-       int modulus=0;
+       int modulus = 0;
 
        int pvk_encr = 2;
 
        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;
 
 #ifndef OPENSSL_NO_ENGINE
-       engine=NULL;
+       engine = NULL;
 #endif
-       infile=NULL;
-       outfile=NULL;
-       informat=FORMAT_PEM;
-       outformat=FORMAT_PEM;
+       infile = NULL;
+       outfile = NULL;
+       informat = FORMAT_PEM;
+       outformat = FORMAT_PEM;
 
-       prog=argv[0];
+       prog = argv[0];
        argc--;
        argv++;
-       while (argc >= 1)
-               {
-               if      (strcmp(*argv,"-inform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       informat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-outform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       outformat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-in") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+       while (argc >= 1) {
+               if (strcmp(*argv, "-inform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       informat = str2fmt(*(++argv));
+               } else if (strcmp(*argv, "-outform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       outformat = str2fmt(*(++argv));
+               } else if (strcmp(*argv, "-in") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        infile= *(++argv);
-                       }
-               else if (strcmp(*argv,"-out") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               }
+               else if (strcmp(*argv, "-out") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        outfile= *(++argv);
-                       }
-               else if (strcmp(*argv,"-passin") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               } else if (strcmp(*argv, "-passin") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        passargin= *(++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,"-pvk-strong") == 0)
-                       pvk_encr=2;
-               else if (strcmp(*argv,"-pvk-weak") == 0)
-                       pvk_encr=1;
-               else if (strcmp(*argv,"-pvk-none") == 0)
-                       pvk_encr=0;
-               else if (strcmp(*argv,"-noout") == 0)
-                       noout=1;
-               else if (strcmp(*argv,"-text") == 0)
-                       text=1;
-               else if (strcmp(*argv,"-modulus") == 0)
-                       modulus=1;
-               else if (strcmp(*argv,"-pubin") == 0)
-                       pubin=1;
-               else if (strcmp(*argv,"-pubout") == 0)
-                       pubout=1;
-               else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)
-                       {
-                       BIO_printf(bio_err,"unknown option %s\n",*argv);
-                       badops=1;
+               else if (strcmp(*argv, "-pvk-strong") == 0)
+                       pvk_encr = 2;
+               else if (strcmp(*argv, "-pvk-weak") == 0)
+                       pvk_encr = 1;
+               else if (strcmp(*argv, "-pvk-none") == 0)
+                       pvk_encr = 0;
+               else if (strcmp(*argv, "-noout") == 0)
+                       noout = 1;
+               else if (strcmp(*argv, "-text") == 0)
+                       text = 1;
+               else if (strcmp(*argv, "-modulus") == 0)
+                       modulus = 1;
+               else if (strcmp(*argv, "-pubin") == 0)
+                       pubin = 1;
+               else if (strcmp(*argv, "-pubout") == 0)
+                       pubout = 1;
+               else if ((enc = EVP_get_cipherbyname(&(argv[0][1]))) == NULL) {
+                       BIO_printf(bio_err, "unknown option %s\n", *argv);
+                       badops = 1;
                        break;
-                       }
+               }
                argc--;
                argv++;
-               }
+       }
 
-       if (badops)
-               {
+       if (badops) {
 bad:
-               BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
-               BIO_printf(bio_err,"where options are\n");
-               BIO_printf(bio_err," -inform arg     input format - DER or PEM\n");
-               BIO_printf(bio_err," -outform arg    output format - DER or PEM\n");
-               BIO_printf(bio_err," -in arg         input file\n");
-               BIO_printf(bio_err," -passin arg     input file pass phrase source\n");
-               BIO_printf(bio_err," -out arg        output file\n");
-               BIO_printf(bio_err," -passout arg    output file pass phrase source\n");
+               BIO_printf(bio_err, "%s [options] <infile >outfile\n", prog);
+               BIO_printf(bio_err, "where options are\n");
+               BIO_printf(bio_err, " -inform arg     input format - DER or PEM\n");
+               BIO_printf(bio_err, " -outform arg    output format - DER or PEM\n");
+               BIO_printf(bio_err, " -in arg         input file\n");
+               BIO_printf(bio_err, " -passin arg     input file pass phrase source\n");
+               BIO_printf(bio_err, " -out arg        output file\n");
+               BIO_printf(bio_err, " -passout arg    output file pass phrase source\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," -des            encrypt PEM output with cbc des\n");
-               BIO_printf(bio_err," -des3           encrypt PEM output with ede cbc des using 168 bit key\n");
+               BIO_printf(bio_err, " -des            encrypt PEM output with cbc des\n");
+               BIO_printf(bio_err, " -des3           encrypt PEM output with ede cbc des using 168 bit key\n");
 #ifndef OPENSSL_NO_IDEA
-               BIO_printf(bio_err," -idea           encrypt PEM output with cbc idea\n");
+               BIO_printf(bio_err, " -idea           encrypt PEM output with cbc idea\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_SEED
-               BIO_printf(bio_err," -seed           encrypt PEM output with cbc seed\n");
+               BIO_printf(bio_err, " -seed           encrypt PEM output with cbc seed\n");
 #endif
-               BIO_printf(bio_err," -text           print the key in text\n");
-               BIO_printf(bio_err," -noout          don't print key out\n");
-               BIO_printf(bio_err," -modulus        print the DSA public value\n");
+               BIO_printf(bio_err, " -text           print the key in text\n");
+               BIO_printf(bio_err, " -noout          don't print key out\n");
+               BIO_printf(bio_err, " -modulus        print the DSA public value\n");
                goto end;
-               }
+       }
 
        ERR_load_crypto_strings();
 
 #ifndef OPENSSL_NO_ENGINE
-        e = setup_engine(bio_err, engine, 0);
+       e = setup_engine(bio_err, engine, 0);
 #endif
 
-       if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
+       if (!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
                BIO_printf(bio_err, "Error getting passwords\n");
                goto end;
        }
 
-       in=BIO_new(BIO_s_file());
-       out=BIO_new(BIO_s_file());
-       if ((in == NULL) || (out == NULL))
-               {
+       in = BIO_new(BIO_s_file());
+       out = BIO_new(BIO_s_file());
+       if ((in == NULL) || (out == NULL)) {
                ERR_print_errors(bio_err);
                goto end;
-               }
+       }
 
        if (infile == NULL)
-               BIO_set_fp(in,stdin,BIO_NOCLOSE);
-       else
-               {
-               if (BIO_read_filename(in,infile) <= 0)
-                       {
+               BIO_set_fp(in, stdin, BIO_NOCLOSE);
+       else {
+               if (BIO_read_filename(in, infile) <= 0) {
                        perror(infile);
                        goto end;
-                       }
                }
+       }
 
-       BIO_printf(bio_err,"read DSA key\n");
+       BIO_printf(bio_err, "read DSA key\n");
 
-               {
+       {
                EVP_PKEY        *pkey;
 
                if (pubin)
                        pkey = load_pubkey(bio_err, infile, informat, 1,
-                               passin, e, "Public Key");
+                           passin, e, "Public Key");
                else
                        pkey = load_key(bio_err, infile, informat, 1,
-                               passin, e, "Private Key");
+                   passin, e, "Private Key");
 
-               if (pkey)
-                       {
+               if (pkey) {
                        dsa = EVP_PKEY_get1_DSA(pkey);
                        EVP_PKEY_free(pkey);
-                       }
                }
-       if (dsa == NULL)
-               {
-               BIO_printf(bio_err,"unable to load Key\n");
+       }
+       if (dsa == NULL) {
+               BIO_printf(bio_err, "unable to load Key\n");
                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 (text) 
-               if (!DSA_print(out,dsa,0))
-                       {
-                       perror(outfile);
-                       ERR_print_errors(bio_err);
-                       goto end;
-                       }
+       if (text)
+               if (!DSA_print(out, dsa, 0)) {
+               perror(outfile);
+               ERR_print_errors(bio_err);
+               goto end;
+       }
 
-       if (modulus)
-               {
-               fprintf(stdout,"Public Key=");
-               BN_print(out,dsa->pub_key);
-               fprintf(stdout,"\n");
-               }
+       if (modulus) {
+               fprintf(stdout, "Public Key=");
+               BN_print(out, dsa->pub_key);
+               fprintf(stdout, "\n");
+       }
 
-       if (noout) goto end;
-       BIO_printf(bio_err,"writing DSA key\n");
-       if      (outformat == FORMAT_ASN1) {
-               if(pubin || pubout) i=i2d_DSA_PUBKEY_bio(out,dsa);
-               else i=i2d_DSAPrivateKey_bio(out,dsa);
+       if (noout)
+               goto end;
+       BIO_printf(bio_err, "writing DSA key\n");
+       if (outformat == FORMAT_ASN1) {
+               if (pubin || pubout)
+                       i = i2d_DSA_PUBKEY_bio(out, dsa);
+               else
+                       i = i2d_DSAPrivateKey_bio(out, dsa);
        } else if (outformat == FORMAT_PEM) {
-               if(pubin || pubout)
-                       i=PEM_write_bio_DSA_PUBKEY(out,dsa);
-               else i=PEM_write_bio_DSAPrivateKey(out,dsa,enc,
-                                                       NULL,0,NULL, passout);
+               if (pubin || pubout)
+                       i = PEM_write_bio_DSA_PUBKEY(out, dsa);
+               else
+                       i = PEM_write_bio_DSAPrivateKey(out, dsa, enc,
+                           NULL, 0, NULL, passout);
 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_RC4)
        } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
                EVP_PKEY *pk;
@@ -342,29 +329,27 @@ bad:
                EVP_PKEY_free(pk);
 #endif
        } else {
-               BIO_printf(bio_err,"bad output format specified for outfile\n");
+               BIO_printf(bio_err, "bad output format specified for outfile\n");
                goto end;
-               }
-       if (i <= 0)
-               {
-               BIO_printf(bio_err,"unable to write private key\n");
+       }
+       if (i <= 0) {
+               BIO_printf(bio_err, "unable to write private key\n");
                ERR_print_errors(bio_err);
-               }
-       else
-               ret=0;
+       } else
+               ret = 0;
 end:
-       if(in != NULL) BIO_free(in);
-       if(out != NULL) BIO_free_all(out);
-       if(dsa != NULL) DSA_free(dsa);
-       if(passin) OPENSSL_free(passin);
-       if(passout) OPENSSL_free(passout);
-       apps_shutdown();
+       if (in != NULL) BIO_free(in);
+               if (out != NULL) BIO_free_all(out);
+               if (dsa != NULL) DSA_free(dsa);
+               if (passin) OPENSSL_free(passin);
+               if (passout) OPENSSL_free(passout);
+               apps_shutdown();
        OPENSSL_EXIT(ret);
-       }
+}
 #else /* !OPENSSL_NO_DSA */
 
 # if PEDANTIC
-static void *dummy=&dummy;
+static void *dummy = &dummy;
 # endif
 
 #endif
index 47f8c83..9cd81ff 100644 (file)
@@ -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:
  *     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
 
 static int stop_keygen_flag = 0;
 
-static void timebomb_sigalarm(int foo)
-       {
+static void
+timebomb_sigalarm(int foo)
+{
        stop_keygen_flag = 1;
-       }
+}
 
 #endif
 
@@ -109,372 +110,347 @@ static int dsa_cb(int p, int n, BN_GENCB *cb);
 
 int MAIN(int, char **);
 
-int MAIN(int argc, char **argv)
-       {
-       DSA *dsa=NULL;
-       int i,badops=0,text=0;
-       BIO *in=NULL,*out=NULL;
-       int informat,outformat,noout=0,C=0,ret=1;
-       char *infile,*outfile,*prog,*inrand=NULL;
-       int numbits= -1,num,genkey=0;
-       int need_rand=0;
+int
+MAIN(int argc, char **argv)
+{
+       DSA *dsa = NULL;
+       int i, badops = 0, text = 0;
+       BIO *in = NULL, *out = NULL;
+       int informat, outformat, noout = 0, C = 0, ret = 1;
+       char *infile, *outfile, *prog, *inrand = NULL;
+       int numbits = -1, num, genkey = 0;
+       int need_rand = 0;
 #ifndef OPENSSL_NO_ENGINE
-       char *engine=NULL;
+       char *engine = NULL;
 #endif
 #ifdef GENCB_TEST
-       int timebomb=0;
+       int timebomb = 0;
 #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;
 
-       infile=NULL;
-       outfile=NULL;
-       informat=FORMAT_PEM;
-       outformat=FORMAT_PEM;
+       infile = NULL;
+       outfile = NULL;
+       informat = FORMAT_PEM;
+       outformat = FORMAT_PEM;
 
-       prog=argv[0];
+       prog = argv[0];
        argc--;
        argv++;
-       while (argc >= 1)
-               {
-               if      (strcmp(*argv,"-inform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       informat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-outform") == 0)
-                       {
-                       if (--argc < 1) goto bad;
-                       outformat=str2fmt(*(++argv));
-                       }
-               else if (strcmp(*argv,"-in") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+       while (argc >= 1) {
+               if (strcmp(*argv, "-inform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       informat = str2fmt(*(++argv));
+               } else if (strcmp(*argv, "-outform") == 0) {
+                       if (--argc < 1)
+                               goto bad;
+                       outformat = str2fmt(*(++argv));
+               } else if (strcmp(*argv, "-in") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        infile= *(++argv);
-                       }
-               else if (strcmp(*argv,"-out") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               } else if (strcmp(*argv, "-out") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        outfile= *(++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
 #ifdef GENCB_TEST
-               else if(strcmp(*argv, "-timebomb") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               else if (strcmp(*argv, "-timebomb") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        timebomb = atoi(*(++argv));
-                       }
+               }
 #endif
-               else if (strcmp(*argv,"-text") == 0)
-                       text=1;
-               else if (strcmp(*argv,"-C") == 0)
-                       C=1;
-               else if (strcmp(*argv,"-genkey") == 0)
-                       {
-                       genkey=1;
-                       need_rand=1;
-                       }
-               else if (strcmp(*argv,"-rand") == 0)
-                       {
-                       if (--argc < 1) goto bad;
+               else if (strcmp(*argv, "-text") == 0)
+                       text = 1;
+               else if (strcmp(*argv, "-C") == 0)
+                       C = 1;
+               else if (strcmp(*argv, "-genkey") == 0) {
+                       genkey = 1;
+                       need_rand = 1;
+               } else if (strcmp(*argv, "-rand") == 0) {
+                       if (--argc < 1)
+                               goto bad;
                        inrand= *(++argv);
-                       need_rand=1;
-                       }
-               else if (strcmp(*argv,"-noout") == 0)
-                       noout=1;
-               else if (sscanf(*argv,"%d",&num) == 1)
-                       {
+                       need_rand = 1;
+               } else if (strcmp(*argv, "-noout") == 0)
+                       noout = 1;
+               else if (sscanf(*argv, "%d", &num) == 1) {
                        /* generate a key */
-                       numbits=num;
-                       need_rand=1;
-                       }
-               else
-                       {
-                       BIO_printf(bio_err,"unknown option %s\n",*argv);
-                       badops=1;
+                       numbits = num;
+                       need_rand = 1;
+               } else {
+                       BIO_printf(bio_err, "unknown option %s\n", *argv);
+                       badops = 1;
                        break;
-                       }
+               }
                argc--;
                argv++;
-               }
+       }
 
-       if (badops)
-               {
+       if (badops) {
 bad:
-               BIO_printf(bio_err,"%s [options] [bits] <infile >outfile\n",prog);
-               BIO_printf(bio_err,"where options are\n");
-               BIO_printf(bio_err," -inform arg   input format - DER or PEM\n");
-               BIO_printf(bio_err," -outform arg  output format - DER or PEM\n");
-               BIO_printf(bio_err," -in arg       input file\n");
-               BIO_printf(bio_err," -out arg      output file\n");
-               BIO_printf(bio_err," -text         print as text\n");
-               BIO_printf(bio_err," -C            Output C code\n");
-               BIO_printf(bio_err," -noout        no output\n");
-               BIO_printf(bio_err," -genkey       generate a DSA key\n");
-               BIO_printf(bio_err," -rand         files to use for random number input\n");
+               BIO_printf(bio_err, "%s [options] [bits] <infile >outfile\n", prog);
+               BIO_printf(bio_err, "where options are\n");
+               BIO_printf(bio_err, " -inform arg   input format - DER or PEM\n");
+               BIO_printf(bio_err, " -outform arg  output format - DER or PEM\n");
+               BIO_printf(bio_err, " -in arg       input file\n");
+               BIO_printf(bio_err, " -out arg      output file\n");
+               BIO_printf(bio_err, " -text         print as text\n");
+               BIO_printf(bio_err, " -C            Output C code\n");
+               BIO_printf(bio_err, " -noout        no output\n");
+               BIO_printf(bio_err, " -genkey       generate a DSA key\n");
+               BIO_printf(bio_err, " -rand         files to use for random number input\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
 #ifdef GENCB_TEST
-               BIO_printf(bio_err," -timebomb n   interrupt keygen after <n> seconds\n");
+               BIO_printf(bio_err, " -timebomb n   interrupt keygen after <n> seconds\n");
 #endif
-               BIO_printf(bio_err," number        number of bits to use for generating private key\n");
+               BIO_printf(bio_err, " number        number of bits to use for generating private key\n");
                goto end;
-               }
+       }
 
        ERR_load_crypto_strings();
 
-       in=BIO_new(BIO_s_file());
-       out=BIO_new(BIO_s_file());
-       if ((in == NULL) || (out == NULL))
-               {
+       in = BIO_new(BIO_s_file());
+       out = BIO_new(BIO_s_file());
+       if ((in == NULL) || (out == NULL)) {
                ERR_print_errors(bio_err);
                goto end;
-               }
+       }
 
        if (infile == NULL)
-               BIO_set_fp(in,stdin,BIO_NOCLOSE);
-       else
-               {
-               if (BIO_read_filename(in,infile) <= 0)
-                       {
+               BIO_set_fp(in, stdin, BIO_NOCLOSE);
+       else {
+               if (BIO_read_filename(in, infile) <= 0) {
                        perror(infile);
                        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;
-                       }
                }
+       }
 
 #ifndef OPENSSL_NO_ENGINE
-        setup_engine(bio_err, engine, 0);
+       setup_engine(bio_err, engine, 0);
 #endif
 
-       if (need_rand)
-               {
+       if (need_rand) {
                app_RAND_load_file(NULL, bio_err, (inrand != NULL));
                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));
+       }
 
-       if (numbits > 0)
-               {
+       if (numbits > 0) {
                BN_GENCB cb;
                BN_GENCB_set(&cb, dsa_cb, bio_err);
                assert(need_rand);
                dsa = DSA_new();
-               if(!dsa)
-                       {
-                       BIO_printf(bio_err,"Error allocating DSA object\n");
+               if (!dsa) {
+                       BIO_printf(bio_err, "Error allocating DSA object\n");
                        goto end;
-                       }
-               BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num);
-               BIO_printf(bio_err,"This could take some time\n");
+               }
+               BIO_printf(bio_err, "Generating DSA parameters, %d bit long prime\n", num);
+               BIO_printf(bio_err, "This could take some time\n");
 #ifdef GENCB_TEST
-               if(timebomb > 0)
-       {
-               struct sigaction act;
-               act.sa_handler = timebomb_sigalarm;
-               act.sa_flags = 0;
-               BIO_printf(bio_err,"(though I'll stop it if not done within %d secs)\n",
-                               timebomb);
-               if(sigaction(SIGALRM, &act, NULL) != 0)
-                       {
-                       BIO_printf(bio_err,"Error, couldn't set SIGALRM handler\n");
-                       goto end;
+               if (timebomb > 0) {
+                       struct sigaction act;
+                       act.sa_handler = timebomb_sigalarm;
+                       act.sa_flags = 0;
+                       BIO_printf(bio_err, "(though I'll stop it if not done within %d secs)\n",
+                           timebomb);
+                       if (sigaction(SIGALRM, &act, NULL) != 0) {
+                               BIO_printf(bio_err, "Error, couldn't set SIGALRM handler\n");
+                               goto end;
                        }
-               alarm(timebomb);
-       }
+                       alarm(timebomb);
+               }
 #endif
-               if(!DSA_generate_parameters_ex(dsa,num,NULL,0,NULL,NULL, &cb))
-                       {
+               if (!DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL, &cb)) {
 #ifdef GENCB_TEST
-                       if(stop_keygen_flag)
-                               {
-                               BIO_printf(bio_err,"DSA key generation time-stopped\n");
+                       if (stop_keygen_flag) {
+                               BIO_printf(bio_err, "DSA key generation time-stopped\n");
                                /* This is an asked-for behaviour! */
                                ret = 0;
                                goto end;
-                               }
+                       }
 #endif
                        ERR_print_errors(bio_err);
-                       BIO_printf(bio_err,"Error, DSA key generation failed\n");
+                       BIO_printf(bio_err, "Error, DSA key generation failed\n");
                        goto end;
-                       }
                }
-       else if (informat == FORMAT_ASN1)
-               dsa=d2i_DSAparams_bio(in,NULL);
+       else if (informat == FORMAT_ASN1)
+               dsa = d2i_DSAparams_bio(in, NULL);
        else if (informat == FORMAT_PEM)
-               dsa=PEM_read_bio_DSAparams(in,NULL,NULL,NULL);
-       else
-               {
-               BIO_printf(bio_err,"bad input format specified\n");
+               dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL);
+       else {
+               BIO_printf(bio_err, "bad input format specified\n");
                goto end;
-               }
-       if (dsa == NULL)
-               {
-               BIO_printf(bio_err,"unable to load DSA parameters\n");
+       }
+       if (dsa == NULL) {
+               BIO_printf(bio_err, "unable to load DSA parameters\n");
                ERR_print_errors(bio_err);
                goto end;
-               }
+       }
 
-       if (text)
-               {
-               DSAparams_print(out,dsa);
-               }
-       
-       if (C)
-               {
+       if (text) {
+               DSAparams_print(out, dsa);
+       }
+
+       if (C) {
                unsigned char *data;
-               int l,len,bits_p;
+               int l, len, bits_p;
 
-               len=BN_num_bytes(dsa->p);
-               bits_p=BN_num_bits(dsa->p);
-               data=(unsigned char *)OPENSSL_malloc(len+20);
-               if (data == NULL)
-                       {
+               len = BN_num_bytes(dsa->p);
+               bits_p = BN_num_bits(dsa->p);
+               data = (unsigned char *)OPENSSL_malloc(len + 20);
+               if (data == NULL) {
                        perror("OPENSSL_malloc");
                        goto end;
-                       }
-               l=BN_bn2bin(dsa->p,data);
-               printf("static unsigned char dsa%d_p[]={",bits_p);
-               for (i=0; i<l; i++)
-                       {
-                       if ((i%12) == 0) printf("\n\t");
-                       printf("0x%02X,",data[i]);
-                       }
+               }
+               l = BN_bn2bin(dsa->p, data);
+               printf("static unsigned char dsa%d_p[] = {", bits_p);
+               for (i = 0; i < l; i++) {
+                       if ((i % 12) == 0)
+                               printf("\n\t");
+                       printf("0x%02X, ", data[i]);
+               }
                printf("\n\t};\n");
 
-               l=BN_bn2bin(dsa->q,data);
-               printf("static unsigned char dsa%d_q[]={",bits_p);
-               for (i=0; i<l; i++)
-                       {
-                       if ((i%12) == 0) printf("\n\t");
-                       printf("0x%02X,",data[i]);
-                       }
+               l = BN_bn2bin(dsa->q, data);
+               printf("static unsigned char dsa%d_q[] = {", bits_p);
+               for (i = 0; i < l; i++) {
+                       if ((i % 12) == 0)
+                               printf("\n\t");
+                       printf("0x%02X, ", data[i]);
+               }
                printf("\n\t};\n");
 
-               l=BN_bn2bin(dsa->g,data);
-               printf("static unsigned char dsa%d_g[]={",bits_p);
-               for (i=0; i<l; i++)
-                       {
-                       if ((i%12) == 0) printf("\n\t");
-                       printf("0x%02X,",data[i]);
-                       }
+               l = BN_bn2bin(dsa->g, data);
+               printf("static unsigned char dsa%d_g[] = {", bits_p);
+               for (i = 0; i < l; i++) {
+                       if ((i % 12) == 0)
+                               printf("\n\t");
+                       printf("0x%02X, ", data[i]);
+               }
                printf("\n\t};\n\n");
 
-               printf("DSA *get_dsa%d()\n\t{\n",bits_p);
+               printf("DSA *get_dsa%d()\n\t{\n", bits_p);
                printf("\tDSA *dsa;\n\n");
-               printf("\tif ((dsa=DSA_new()) == NULL) return(NULL);\n");
-               printf("\tdsa->p=BN_bin2bn(dsa%d_p,sizeof(dsa%d_p),NULL);\n",
-                       bits_p,bits_p);
-               printf("\tdsa->q=BN_bin2bn(dsa%d_q,sizeof(dsa%d_q),NULL);\n",
-                       bits_p,bits_p);
-               printf("\tdsa->g=BN_bin2bn(dsa%d_g,sizeof(dsa%d_g),NULL);\n",
-                       bits_p,bits_p);
+               printf("\tif ((dsa = DSA_new()) == NULL) return(NULL);\n");
+               printf("\tdsa->p = BN_bin2bn(dsa%d_p, sizeof(dsa%d_p), NULL);\n",
+                   bits_p, bits_p);
+               printf("\tdsa->q = BN_bin2bn(dsa%d_q, sizeof(dsa%d_q), NULL);\n",
+                   bits_p, bits_p);
+               printf("\tdsa->g = BN_bin2bn(dsa%d_g, sizeof(dsa%d_g), NULL);\n",
+                   bits_p, bits_p);
                printf("\tif ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))\n");
                printf("\t\t{ DSA_free(dsa); return(NULL); }\n");
                printf("\treturn(dsa);\n\t}\n");
-               }
-
+       }
 
-       if (!noout)
-               {
-               if      (outformat == FORMAT_ASN1)
-                       i=i2d_DSAparams_bio(out,dsa);
+       if (!noout) {
+               if (outformat == FORMAT_ASN1)
+                       i = i2d_DSAparams_bio(out, dsa);
                else if (outformat == FORMAT_PEM)
-                       i=PEM_write_bio_DSAparams(out,dsa);
-               else    {
-                       BIO_printf(bio_err,"bad output format specified for outfile\n");
+                       i = PEM_write_bio_DSAparams(out, dsa);
+               else {
+                       BIO_printf(bio_err, "bad output format specified for outfile\n");
                        goto end;
-                       }
-               if (!i)
-                       {
-                       BIO_printf(bio_err,"unable to write DSA parameters\n");
+               }
+               if (!i) {
+                       BIO_printf(bio_err, "unable to write DSA parameters\n");
                        ERR_print_errors(bio_err);
                        goto end;
-                       }
                }
-       if (genkey)
-               {
+       }
+       if (genkey) {
                DSA *dsakey;
 
                assert(need_rand);
-               if ((dsakey=DSAparams_dup(dsa)) == NULL) goto end;
-               if (!DSA_generate_key(dsakey))
-                       {
+               if ((dsakey = DSAparams_dup(dsa)) == NULL)
+                       goto end;
+               if (!DSA_generate_key(dsakey)) {
                        ERR_print_errors(bio_err);
                        DSA_free(dsakey);
                        goto end;
-                       }
-               if      (outformat == FORMAT_ASN1)
-                       i=i2d_DSAPrivateKey_bio(out,dsakey);
+               }
+               if (outformat == FORMAT_ASN1)
+                       i = i2d_DSAPrivateKey_bio(out, dsakey);
                else if (outformat == FORMAT_PEM)
-                       i=PEM_write_bio_DSAPrivateKey(out,dsakey,NULL,NULL,0,NULL,NULL);
-               else    {
-                       BIO_printf(bio_err,"bad output format specified for outfile\n");
+                       i = PEM_write_bio_DSAPrivateKey(out, dsakey, NULL, NULL, 0, NULL, NULL);
+               else {
+                       BIO_printf(bio_err, "bad output format specified for outfile\n");
                        DSA_free(dsakey);
                        goto end;
-                       }
-               DSA_free(dsakey);
                }
+               DSA_free(dsakey);
+       }
        if (need_rand)
                app_RAND_write_file(NULL, bio_err);
-       ret=0;
+       ret = 0;
+
 end:
-       if (in != NULL) BIO_free(in);
-       if (out != NULL) BIO_free_all(out);
-       if (dsa != NULL) DSA_free(dsa);
+       if (in != NULL)
+               BIO_free(in);
+       if (out != NULL)
+               BIO_free_all(out);
+       if (dsa != NULL)
+               DSA_free(dsa);
        apps_shutdown();
        OPENSSL_EXIT(ret);
-       }
-
-static int dsa_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
+dsa_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
 #ifdef GENCB_TEST
-       if(stop_keygen_flag)
+       if (stop_keygen_flag)
                return 0;
 #endif
        return 1;
-       }
+}
 #else /* !OPENSSL_NO_DSA */
 
 # if PEDANTIC
-static void *dummy=&dummy;
+static void *dummy = &dummy;
 # endif
 
 #endif