fast reduction for NIST curves
[openssl.git] / apps / apps.c
index 40faa02f9076f79822662f599d0ebff34c967157..be7a80acb8cf99d457fecf851086ce6cb6ae6f6c 100644 (file)
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#define NON_MAIN
-#include "apps.h"
-#undef NON_MAIN
+#include <ctype.h>
 #include <openssl/err.h>
 #include <openssl/x509.h>
 #include <openssl/x509v3.h>
 #  endif /* NO_STRINGS_H */
 #endif
 
+#define NON_MAIN
+#include "apps.h"
+#undef NON_MAIN
+
 #ifdef OPENSSL_SYS_WINDOWS
 #  include "bss_file.c"
 #endif
@@ -354,6 +356,22 @@ int WIN32_rename(char *from, char *to)
        }
 #endif
 
+#ifdef OPENSSL_SYS_VMS
+int VMS_strcasecmp(const char *str1, const char *str2)
+       {
+       while (*str1 && *str2)
+               {
+               int res = toupper(*str1) - toupper(*str2);
+               if (res) return res < 0 ? -1 : 1;
+               }
+       if (*str1)
+               return 1;
+       if (*str2)
+               return -1;
+       return 0;
+       }
+#endif
+
 int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[])
        {
        int num,len,i;
@@ -798,7 +816,7 @@ end:
        return(x);
        }
 
-EVP_PKEY *load_key(BIO *err, const char *file, int format,
+EVP_PKEY *load_key(BIO *err, const char *file, int format, int maybe_stdin,
        const char *pass, ENGINE *e, const char *key_descrip)
        {
        BIO *key=NULL;
@@ -808,7 +826,7 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format,
        cb_data.password = pass;
        cb_data.prompt_info = file;
 
-       if (file == NULL)
+       if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE))
                {
                BIO_printf(err,"no keyfile specified\n");
                goto end;
@@ -828,12 +846,19 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format,
                ERR_print_errors(err);
                goto end;
                }
-       if (BIO_read_filename(key,file) <= 0)
+       if (file == NULL && maybe_stdin)
                {
-               BIO_printf(err, "Error opening %s %s\n", key_descrip, file);
-               ERR_print_errors(err);
-               goto end;
+               setvbuf(stdin, NULL, _IONBF, 0);
+               BIO_set_fp(key,stdin,BIO_NOCLOSE);
                }
+       else
+               if (BIO_read_filename(key,file) <= 0)
+                       {
+                       BIO_printf(err, "Error opening %s %s\n",
+                               key_descrip, file);
+                       ERR_print_errors(err);
+                       goto end;
+                       }
        if (format == FORMAT_ASN1)
                {
                pkey=d2i_PrivateKey_bio(key, NULL);
@@ -867,7 +892,7 @@ EVP_PKEY *load_key(BIO *err, const char *file, int format,
        return(pkey);
        }
 
-EVP_PKEY *load_pubkey(BIO *err, const char *file, int format,
+EVP_PKEY *load_pubkey(BIO *err, const char *file, int format, int maybe_stdin,
        const char *pass, ENGINE *e, const char *key_descrip)
        {
        BIO *key=NULL;
@@ -877,7 +902,7 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format,
        cb_data.password = pass;
        cb_data.prompt_info = file;
 
-       if (file == NULL)
+       if (file == NULL && (!maybe_stdin || format == FORMAT_ENGINE))
                {
                BIO_printf(err,"no keyfile specified\n");
                goto end;
@@ -897,11 +922,18 @@ EVP_PKEY *load_pubkey(BIO *err, const char *file, int format,
                ERR_print_errors(err);
                goto end;
                }
-       if (BIO_read_filename(key,file) <= 0)
+       if (file == NULL && maybe_stdin)
                {
-               BIO_printf(err, "Error opening %s %s\n", key_descrip, file);
-               ERR_print_errors(err);
-               goto end;
+               setvbuf(stdin, NULL, _IONBF, 0);
+               BIO_set_fp(key,stdin,BIO_NOCLOSE);
+               }
+       else
+               if (BIO_read_filename(key,file) <= 0)
+                       {
+                       BIO_printf(err, "Error opening %s %s\n",
+                               key_descrip, file);
+                       ERR_print_errors(err);
+                       goto end;
                }
        if (format == FORMAT_ASN1)
                {
@@ -1074,6 +1106,7 @@ int set_cert_ex(unsigned long *flags, const char *arg)
                { "no_extensions", X509_FLAG_NO_EXTENSIONS, 0},
                { "no_sigdump", X509_FLAG_NO_SIGDUMP, 0},
                { "no_aux", X509_FLAG_NO_AUX, 0},
+               { "no_attributes", X509_FLAG_NO_ATTRIBUTES, 0},
                { "ext_default", X509V3_EXT_DEFAULT, X509V3_EXT_UNKNOWN_MASK},
                { "ext_error", X509V3_EXT_ERROR_UNKNOWN, X509V3_EXT_UNKNOWN_MASK},
                { "ext_parse", X509V3_EXT_PARSE_UNKNOWN, X509V3_EXT_UNKNOWN_MASK},
@@ -1217,7 +1250,7 @@ static int set_table_opts(unsigned long *flags, const char *arg, const NAME_EX_T
 
 void print_name(BIO *out, char *title, X509_NAME *nm, unsigned long lflags)
 {
-       char buf[256];
+       char *buf;
        char mline = 0;
        int indent = 0;
        if(title) BIO_puts(out, title);
@@ -1226,9 +1259,10 @@ void print_name(BIO *out, char *title, X509_NAME *nm, unsigned long lflags)
                indent = 4;
        }
        if(lflags == XN_FLAG_COMPAT) {
-               X509_NAME_oneline(nm,buf,256);
-               BIO_puts(out,buf);
+               buf = X509_NAME_oneline(nm, 0, 0);
+               BIO_puts(out, buf);
                BIO_puts(out, "\n");
+               OPENSSL_free(buf);
        } else {
                if(mline) BIO_puts(out, "\n");
                X509_NAME_print_ex(out, nm, indent, lflags);