Stop spurious "unable to load config info" errors in req
[openssl.git] / apps / dhparam.c
index 709547ff5e6f5567f261e059eb4fc6942756c46f..e55d0ce0cbbcc8a268c2f9bb86e24b2d0a5db8e4 100644 (file)
  *
  */
 
  *
  */
 
-#ifndef NO_DH
+#ifndef OPENSSL_NO_DH
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
 
 #include <openssl/x509.h>
 #include <openssl/pem.h>
 
-#ifndef NO_DSA
+#ifndef OPENSSL_NO_DSA
 #include <openssl/dsa.h>
 #endif
 
 #include <openssl/dsa.h>
 #endif
 
@@ -148,15 +148,16 @@ int MAIN(int, char **);
 
 int MAIN(int argc, char **argv)
        {
 
 int MAIN(int argc, char **argv)
        {
+       ENGINE *e = NULL;
        DH *dh=NULL;
        int i,badops=0,text=0;
        DH *dh=NULL;
        int i,badops=0,text=0;
-#ifndef NO_DSA
+#ifndef OPENSSL_NO_DSA
        int dsaparam=0;
 #endif
        BIO *in=NULL,*out=NULL;
        int informat,outformat,check=0,noout=0,C=0,ret=1;
        char *infile,*outfile,*prog;
        int dsaparam=0;
 #endif
        BIO *in=NULL,*out=NULL;
        int informat,outformat,check=0,noout=0,C=0,ret=1;
        char *infile,*outfile,*prog;
-       char *inrand=NULL;
+       char *inrand=NULL,*engine=NULL;
        int num = 0, g = 0;
 
        apps_startup();
        int num = 0, g = 0;
 
        apps_startup();
@@ -195,11 +196,16 @@ int MAIN(int argc, char **argv)
                        if (--argc < 1) goto bad;
                        outfile= *(++argv);
                        }
                        if (--argc < 1) goto bad;
                        outfile= *(++argv);
                        }
+               else if (strcmp(*argv,"-engine") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       engine= *(++argv);
+                       }
                else if (strcmp(*argv,"-check") == 0)
                        check=1;
                else if (strcmp(*argv,"-text") == 0)
                        text=1;
                else if (strcmp(*argv,"-check") == 0)
                        check=1;
                else if (strcmp(*argv,"-text") == 0)
                        text=1;
-#ifndef NO_DSA
+#ifndef OPENSSL_NO_DSA
                else if (strcmp(*argv,"-dsaparam") == 0)
                        dsaparam=1;
 #endif
                else if (strcmp(*argv,"-dsaparam") == 0)
                        dsaparam=1;
 #endif
@@ -231,7 +237,7 @@ bad:
                BIO_printf(bio_err," -outform arg  output format - one of DER PEM\n");
                BIO_printf(bio_err," -in arg       input file\n");
                BIO_printf(bio_err," -out arg      output file\n");
                BIO_printf(bio_err," -outform arg  output format - one of DER PEM\n");
                BIO_printf(bio_err," -in arg       input file\n");
                BIO_printf(bio_err," -out arg      output file\n");
-#ifndef NO_DSA
+#ifndef OPENSSL_NO_DSA
                BIO_printf(bio_err," -dsaparam     read or generate DSA parameters, convert to DH\n");
 #endif
                BIO_printf(bio_err," -check        check the DH parameters\n");
                BIO_printf(bio_err," -dsaparam     read or generate DSA parameters, convert to DH\n");
 #endif
                BIO_printf(bio_err," -check        check the DH parameters\n");
@@ -240,6 +246,7 @@ bad:
                BIO_printf(bio_err," -2            generate parameters using  2 as the generator value\n");
                BIO_printf(bio_err," -5            generate parameters using  5 as the generator value\n");
                BIO_printf(bio_err," numbits       number of bits in to generate (default 512)\n");
                BIO_printf(bio_err," -2            generate parameters using  2 as the generator value\n");
                BIO_printf(bio_err," -5            generate parameters using  5 as the generator value\n");
                BIO_printf(bio_err," numbits       number of bits in to generate (default 512)\n");
+               BIO_printf(bio_err," -engine e     use engine e, possibly a hardware device.\n");
                BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
                BIO_printf(bio_err,"               - load the file (or the files in the directory) into\n");
                BIO_printf(bio_err,"               the random number generator\n");
                BIO_printf(bio_err," -rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
                BIO_printf(bio_err,"               - load the file (or the files in the directory) into\n");
                BIO_printf(bio_err,"               the random number generator\n");
@@ -249,10 +256,12 @@ bad:
 
        ERR_load_crypto_strings();
 
 
        ERR_load_crypto_strings();
 
+        e = setup_engine(bio_err, engine, 0);
+
        if (g && !num)
                num = DEFBITS;
 
        if (g && !num)
                num = DEFBITS;
 
-#ifndef NO_DSA
+#ifndef OPENSSL_NO_DSA
        if (dsaparam)
                {
                if (g)
        if (dsaparam)
                {
                if (g)
@@ -279,13 +288,13 @@ bad:
                        BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
                                app_RAND_load_files(inrand));
 
                        BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
                                app_RAND_load_files(inrand));
 
-#ifndef NO_DSA
+#ifndef OPENSSL_NO_DSA
                if (dsaparam)
                        {
                        DSA *dsa;
                        
                        BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num);
                if (dsaparam)
                        {
                        DSA *dsa;
                        
                        BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num);
-               dsa = DSA_generate_parameters(num, NULL, 0, NULL, NULL, dh_cb, bio_err);
+                       dsa = DSA_generate_parameters(num, NULL, 0, NULL, NULL, dh_cb, bio_err);
                        if (dsa == NULL)
                                {
                                ERR_print_errors(bio_err);
                        if (dsa == NULL)
                                {
                                ERR_print_errors(bio_err);
@@ -340,7 +349,7 @@ bad:
                        goto end;
                        }
 
                        goto end;
                        }
 
-#ifndef NO_DSA
+#ifndef OPENSSL_NO_DSA
                if (dsaparam)
                        {
                        DSA *dsa;
                if (dsaparam)
                        {
                        DSA *dsa;
@@ -391,7 +400,15 @@ bad:
                goto end;
                }
        if (outfile == NULL)
                goto end;
                }
        if (outfile == NULL)
+               {
                BIO_set_fp(out,stdout,BIO_NOCLOSE);
                BIO_set_fp(out,stdout,BIO_NOCLOSE);
+#ifdef OPENSSL_SYS_VMS
+               {
+               BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+               out = BIO_push(tmpbio, out);
+               }
+#endif
+               }
        else
                {
                if (BIO_write_filename(out,outfile) <= 0)
        else
                {
                if (BIO_write_filename(out,outfile) <= 0)
@@ -432,10 +449,10 @@ bad:
 
                len=BN_num_bytes(dh->p);
                bits=BN_num_bits(dh->p);
 
                len=BN_num_bytes(dh->p);
                bits=BN_num_bits(dh->p);
-               data=(unsigned char *)Malloc(len);
+               data=(unsigned char *)OPENSSL_malloc(len);
                if (data == NULL)
                        {
                if (data == NULL)
                        {
-                       perror("Malloc");
+                       perror("OPENSSL_malloc");
                        goto end;
                        }
                printf("#ifndef HEADER_DH_H\n"
                        goto end;
                        }
                printf("#ifndef HEADER_DH_H\n"
@@ -472,7 +489,7 @@ bad:
                if (dh->length)
                        printf("\tdh->length = %d;\n", dh->length);
                printf("\treturn(dh);\n\t}\n");
                if (dh->length)
                        printf("\tdh->length = %d;\n", dh->length);
                printf("\treturn(dh);\n\t}\n");
-               Free(data);
+               OPENSSL_free(data);
                }
 
 
                }
 
 
@@ -496,8 +513,9 @@ bad:
        ret=0;
 end:
        if (in != NULL) BIO_free(in);
        ret=0;
 end:
        if (in != NULL) BIO_free(in);
-       if (out != NULL) BIO_free(out);
+       if (out != NULL) BIO_free_all(out);
        if (dh != NULL) DH_free(dh);
        if (dh != NULL) DH_free(dh);
+       apps_shutdown();
        EXIT(ret);
        }
 
        EXIT(ret);
        }