Add AES support in the applications that support -des and -des3.
[openssl.git] / apps / genrsa.c
index 5d7fca404d2639c973eb3a16dd79c01279efbf46..5a58235e0c6b97d2e349f2a6619bd1c62a8c3976 100644 (file)
@@ -69,7 +69,7 @@
 #include <openssl/evp.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
-#include <openssl/engine.h>
+#include <openssl/rand.h>
 
 #define DEFBITS        512
 #undef PROG
@@ -138,6 +138,14 @@ int MAIN(int argc, char **argv)
 #ifndef OPENSSL_NO_IDEA
                else if (strcmp(*argv,"-idea") == 0)
                        enc=EVP_idea_cbc();
+#endif
+#ifndef OPENSSL_NO_AES
+               else if (strcmp(*argv,"-aes128") == 0)
+                       enc=EVP_aes_128_cbc();
+               else if (strcmp(*argv,"-aes192") == 0)
+                       enc=EVP_aes_192_cbc();
+               else if (strcmp(*argv,"-aes256") == 0)
+                       enc=EVP_aes_256_cbc();
 #endif
                else if (strcmp(*argv,"-passout") == 0)
                        {
@@ -157,6 +165,10 @@ bad:
                BIO_printf(bio_err," -des3           encrypt the generated key with DES in ede cbc mode (168 bit key)\n");
 #ifndef OPENSSL_NO_IDEA
                BIO_printf(bio_err," -idea           encrypt the generated key with IDEA in cbc mode\n");
+#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
                BIO_printf(bio_err," -out file       output the key to 'file\n");
                BIO_printf(bio_err," -passout arg    output file pass phrase source\n");
@@ -226,8 +238,14 @@ bad:
                l+=rsa->e->d[i];
                }
        BIO_printf(bio_err,"e is %ld (0x%lX)\n",l,l);
-       if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,NULL, passout))
+       {
+       PW_CB_DATA cb_data;
+       cb_data.password = passout;
+       cb_data.prompt_info = outfile;
+       if (!PEM_write_bio_RSAPrivateKey(out,rsa,enc,NULL,0,
+               (pem_password_cb *)password_callback,&cb_data))
                goto err;
+       }
 
        ret=0;
 err:
@@ -236,6 +254,7 @@ err:
        if(passout) OPENSSL_free(passout);
        if (ret != 0)
                ERR_print_errors(bio_err);
+       apps_shutdown();
        EXIT(ret);
        }