Consolidate BUILDENV [idea is to keep all variables in one place].
[openssl.git] / apps / genrsa.c
index 85da98d45d10bde39b2b708c5128b86a72f9c02c..f0bb30c56b8c8a54e41e314db57d881b115cbd89 100644 (file)
@@ -92,7 +92,6 @@ int MAIN(int argc, char **argv)
        ENGINE *e = NULL;
 #endif
        int ret=1;
-       RSA *rsa=NULL;
        int i,num=DEFBITS;
        long l;
        const EVP_CIPHER *enc=NULL;
@@ -104,6 +103,10 @@ int MAIN(int argc, char **argv)
 #endif
        char *inrand=NULL;
        BIO *out=NULL;
+       BIGNUM *bn = BN_new();
+       RSA *rsa = RSA_new();
+
+       if(!bn || !rsa) goto err;
 
        apps_startup();
        BN_GENCB_set(&cb, genrsa_cb, bio_err);
@@ -242,13 +245,11 @@ bad:
        BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n",
                num);
 
-       if(((rsa = RSA_new()) == NULL) || !RSA_generate_key_ex(rsa, num, f4, &cb))
+       if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb))
                goto err;
                
        app_RAND_write_file(NULL, bio_err);
 
-       if (rsa == NULL) goto err;
-       
        /* We need to do the following for when the base number size is <
         * long, esp windows 3.1 :-(. */
        l=0L;
@@ -272,8 +273,9 @@ bad:
 
        ret=0;
 err:
-       if (rsa != NULL) RSA_free(rsa);
-       if (out != NULL) BIO_free_all(out);
+       if (bn) BN_free(bn);
+       if (rsa) RSA_free(rsa);
+       if (out) BIO_free_all(out);
        if(passout) OPENSSL_free(passout);
        if (ret != 0)
                ERR_print_errors(bio_err);