Add support for experimental code, not compiled in by default and
[openssl.git] / apps / genrsa.c
index f0bb30c56b8c8a54e41e314db57d881b115cbd89..fdc0d4a07dfe159ea8a5f8d38fa0b43ba36a3f2f 100644 (file)
@@ -56,6 +56,7 @@
  * [including the GNU Public Licence.]
  */
 
+#include <openssl/opensslconf.h>
 /* Until the key-gen callbacks are modified to use newer prototypes, we allow
  * deprecated functions for openssl-internal code */
 #ifdef OPENSSL_NO_DEPRECATED
@@ -94,6 +95,7 @@ int MAIN(int argc, char **argv)
        int ret=1;
        int i,num=DEFBITS;
        long l;
+       int use_x931 = 0;
        const EVP_CIPHER *enc=NULL;
        unsigned long f4=RSA_F4;
        char *outfile=NULL;
@@ -137,6 +139,8 @@ int MAIN(int argc, char **argv)
                        f4=3;
                else if (strcmp(*argv,"-F4") == 0 || strcmp(*argv,"-f4") == 0)
                        f4=RSA_F4;
+               else if (strcmp(*argv,"-x931") == 0)
+                       use_x931 = 1;
 #ifndef OPENSSL_NO_ENGINE
                else if (strcmp(*argv,"-engine") == 0)
                        {
@@ -159,6 +163,10 @@ int MAIN(int argc, char **argv)
                else if (strcmp(*argv,"-idea") == 0)
                        enc=EVP_idea_cbc();
 #endif
+#ifndef OPENSSL_NO_SEED
+               else if (strcmp(*argv,"-seed") == 0)
+                       enc=EVP_seed_cbc();
+#endif
 #ifndef OPENSSL_NO_AES
                else if (strcmp(*argv,"-aes128") == 0)
                        enc=EVP_aes_128_cbc();
@@ -166,6 +174,14 @@ int MAIN(int argc, char **argv)
                        enc=EVP_aes_192_cbc();
                else if (strcmp(*argv,"-aes256") == 0)
                        enc=EVP_aes_256_cbc();
+#endif
+#ifndef OPENSSL_NO_CAMELLIA
+               else if (strcmp(*argv,"-camellia128") == 0)
+                       enc=EVP_camellia_128_cbc();
+               else if (strcmp(*argv,"-camellia192") == 0)
+                       enc=EVP_camellia_192_cbc();
+               else if (strcmp(*argv,"-camellia256") == 0)
+                       enc=EVP_camellia_256_cbc();
 #endif
                else if (strcmp(*argv,"-passout") == 0)
                        {
@@ -186,9 +202,17 @@ bad:
 #ifndef OPENSSL_NO_IDEA
                BIO_printf(bio_err," -idea           encrypt the generated key with IDEA in cbc mode\n");
 #endif
+#ifndef OPENSSL_NO_SEED
+               BIO_printf(bio_err," -seed\n");
+               BIO_printf(bio_err,"                 encrypt PEM output with cbc seed\n");
+#endif
 #ifndef OPENSSL_NO_AES
                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");
 #endif
                BIO_printf(bio_err," -out file       output the key to 'file\n");
                BIO_printf(bio_err," -passout arg    output file pass phrase source\n");
@@ -245,7 +269,17 @@ bad:
        BIO_printf(bio_err,"Generating RSA private key, %d bit long modulus\n",
                num);
 
-       if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb))
+       if (use_x931)
+               {
+               BIGNUM *pubexp;
+               pubexp = BN_new();
+               if (!BN_set_word(pubexp, f4))
+                       goto err;
+               if (!RSA_X931_generate_key_ex(rsa, num, pubexp, &cb))
+                       goto err;
+               BN_free(pubexp);
+               }
+       else if(!BN_set_word(bn, f4) || !RSA_generate_key_ex(rsa, num, bn, &cb))
                goto err;
                
        app_RAND_write_file(NULL, bio_err);