make update
[openssl.git] / apps / rsa.c
index b4b0651a94bde577728f0697a5bb331a8bbdb26f..8ae67bbac556ea2816afea0d2b03e4c20894e2eb 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 
-#ifndef NO_RSA
+#ifndef OPENSSL_NO_RSA
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -90,6 +90,7 @@ int MAIN(int, char **);
 
 int MAIN(int argc, char **argv)
        {
+       ENGINE *e = NULL;
        int ret=1;
        RSA *rsa=NULL;
        int i,badops=0, sgckey=0;
@@ -100,6 +101,7 @@ int MAIN(int argc, char **argv)
        char *infile,*outfile,*prog;
        char *passargin = NULL, *passargout = NULL;
        char *passin = NULL, *passout = NULL;
+       char *engine=NULL;
        int modulus=0;
 
        apps_startup();
@@ -148,6 +150,11 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        passargout= *(++argv);
                        }
+               else if (strcmp(*argv,"-engine") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       engine= *(++argv);
+                       }
                else if (strcmp(*argv,"-sgckey") == 0)
                        sgckey=1;
                else if (strcmp(*argv,"-pubin") == 0)
@@ -186,7 +193,7 @@ bad:
                BIO_printf(bio_err," -passout arg    output file pass phrase source\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 NO_IDEA
+#ifndef OPENSSL_NO_IDEA
                BIO_printf(bio_err," -idea           encrypt PEM output with cbc idea\n");
 #endif
                BIO_printf(bio_err," -text           print the key in text\n");
@@ -195,11 +202,14 @@ bad:
                BIO_printf(bio_err," -check          verify key consistency\n");
                BIO_printf(bio_err," -pubin          expect a public key in input file\n");
                BIO_printf(bio_err," -pubout         output a public key\n");
+               BIO_printf(bio_err," -engine e       use engine e, possibly a hardware device.\n");
                goto end;
                }
 
        ERR_load_crypto_strings();
 
+        e = setup_engine(bio_err, engine, 0);
+
        if(!app_passwd(bio_err, passargin, passargout, &passin, &passout)) {
                BIO_printf(bio_err, "Error getting passwords\n");
                goto end;
@@ -234,11 +244,11 @@ bad:
                if (pubin) rsa=d2i_RSA_PUBKEY_bio(in,NULL);
                else rsa=d2i_RSAPrivateKey_bio(in,NULL);
        }
-#ifndef NO_RC4
+#ifndef OPENSSL_NO_RC4
        else if (informat == FORMAT_NETSCAPE)
                {
                BUF_MEM *buf=NULL;
-               unsigned char *p;
+               const unsigned char *p;
                int size=0;
 
                buf=BUF_MEM_new();
@@ -280,7 +290,7 @@ bad:
        if (outfile == NULL)
                {
                BIO_set_fp(out,stdout,BIO_NOCLOSE);
-#ifdef VMS
+#ifdef OPENSSL_SYS_VMS
                {
                BIO *tmpbio = BIO_new(BIO_f_linebuffer());
                out = BIO_push(tmpbio, out);
@@ -319,14 +329,14 @@ bad:
                        BIO_printf(out,"RSA key ok\n");
                else if (r == 0)
                        {
-                       long e;
+                       long err;
 
-                       while ((e = ERR_peek_error()) != 0 &&
-                               ERR_GET_LIB(e) == ERR_LIB_RSA &&
-                               ERR_GET_FUNC(e) == RSA_F_RSA_CHECK_KEY &&
-                               ERR_GET_REASON(e) != ERR_R_MALLOC_FAILURE)
+                       while ((err = ERR_peek_error()) != 0 &&
+                               ERR_GET_LIB(err) == ERR_LIB_RSA &&
+                               ERR_GET_FUNC(err) == RSA_F_RSA_CHECK_KEY &&
+                               ERR_GET_REASON(err) != ERR_R_MALLOC_FAILURE)
                                {
-                               BIO_printf(out, "RSA key error: %s\n", ERR_reason_error_string(e));
+                               BIO_printf(out, "RSA key error: %s\n", ERR_reason_error_string(err));
                                ERR_get_error(); /* remove e from error stack */
                                }
                        }
@@ -348,7 +358,7 @@ bad:
                if(pubout || pubin) i=i2d_RSA_PUBKEY_bio(out,rsa);
                else i=i2d_RSAPrivateKey_bio(out,rsa);
        }
-#ifndef NO_RC4
+#ifndef OPENSSL_NO_RC4
        else if (outformat == FORMAT_NETSCAPE)
                {
                unsigned char *p,*pp;
@@ -389,9 +399,10 @@ end:
        if(rsa != NULL) RSA_free(rsa);
        if(passin) OPENSSL_free(passin);
        if(passout) OPENSSL_free(passout);
+       apps_shutdown();
        EXIT(ret);
        }
-#else /* !NO_RSA */
+#else /* !OPENSSL_NO_RSA */
 
 # if PEDANTIC
 static void *dummy=&dummy;