Update apps for bn opaque change
[openssl.git] / apps / dhparam.c
index 04bd57c6e8aa22c16dadc9772ecc55484bcb6b2a..c4cf1685a35f97f1cf4dbd1b2a5f5fb897ca73d7 100644 (file)
 #undef PROG
 #define PROG   dhparam_main
 
-#define DEFBITS        512
+#define DEFBITS        2048
 
 /* -inform arg - input format - default PEM (DER or PEM)
  * -outform arg - output format - default PEM
@@ -149,9 +149,6 @@ int MAIN(int, char **);
 
 int MAIN(int argc, char **argv)
        {
-#ifndef OPENSSL_NO_ENGINE
-       ENGINE *e = NULL;
-#endif
        DH *dh=NULL;
        int i,badops=0,text=0;
 #ifndef OPENSSL_NO_DSA
@@ -256,7 +253,7 @@ bad:
                BIO_printf(bio_err," -C            Output C code\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," numbits       number of bits in to generate (default 2048)\n");
 #ifndef OPENSSL_NO_ENGINE
                BIO_printf(bio_err," -engine e     use engine e, possibly a hardware device.\n");
 #endif
@@ -270,7 +267,7 @@ bad:
        ERR_load_crypto_strings();
 
 #ifndef OPENSSL_NO_ENGINE
-        e = setup_engine(bio_err, engine, 0);
+        setup_engine(bio_err, engine, 0);
 #endif
 
        if (g && !num)
@@ -295,8 +292,15 @@ bad:
 
        if(num) {
 
-               BN_GENCB cb;
-               BN_GENCB_set(&cb, dh_cb, bio_err);
+               BN_GENCB *cb;
+               cb = BN_GENCB_new();
+               if(!cb)
+                       {
+                       ERR_print_errors(bio_err);
+                       goto end;
+                       }
+
+               BN_GENCB_set(cb, dh_cb, bio_err);
                if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL)
                        {
                        BIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\n");
@@ -312,9 +316,10 @@ bad:
                        
                        BIO_printf(bio_err,"Generating DSA parameters, %d bit long prime\n",num);
                        if(!dsa || !DSA_generate_parameters_ex(dsa, num,
-                                               NULL, 0, NULL, NULL, &cb))
+                                               NULL, 0, NULL, NULL, cb))
                                {
                                if(dsa) DSA_free(dsa);
+                               BN_GENCB_free(cb);
                                ERR_print_errors(bio_err);
                                goto end;
                                }
@@ -323,6 +328,7 @@ bad:
                        DSA_free(dsa);
                        if (dh == NULL)
                                {
+                               BN_GENCB_free(cb);
                                ERR_print_errors(bio_err);
                                goto end;
                                }
@@ -333,14 +339,15 @@ bad:
                        dh = DH_new();
                        BIO_printf(bio_err,"Generating DH parameters, %d bit long safe prime, generator %d\n",num,g);
                        BIO_printf(bio_err,"This is going to take a long time\n");
-                       if(!dh || !DH_generate_parameters_ex(dh, num, g, &cb))
+                       if(!dh || !DH_generate_parameters_ex(dh, num, g, cb))
                                {
-                               if(dh) DH_free(dh);
+                               BN_GENCB_free(cb);
                                ERR_print_errors(bio_err);
                                goto end;
                                }
                        }
 
+               BN_GENCB_free(cb);
                app_RAND_write_file(NULL, bio_err);
        } else {
 
@@ -516,7 +523,12 @@ bad:
                if      (outformat == FORMAT_ASN1)
                        i=i2d_DHparams_bio(out,dh);
                else if (outformat == FORMAT_PEM)
-                       i=PEM_write_bio_DHparams(out,dh);
+                       {
+                       if (dh->q)
+                               i=PEM_write_bio_DHxparams(out,dh);
+                       else
+                               i=PEM_write_bio_DHparams(out,dh);
+                       }
                else    {
                        BIO_printf(bio_err,"bad output format specified for outfile\n");
                        goto end;
@@ -546,12 +558,18 @@ static int MS_CALLBACK dh_cb(int p, int n, BN_GENCB *cb)
        if (p == 1) c='+';
        if (p == 2) c='*';
        if (p == 3) c='\n';
-       BIO_write(cb->arg,&c,1);
-       (void)BIO_flush(cb->arg);
+       BIO_write(BN_GENCB_get_arg(cb),&c,1);
+       (void)BIO_flush(BN_GENCB_get_arg(cb));
 #ifdef LINT
        p=n;
 #endif
        return 1;
        }
 
+#else /* !OPENSSL_NO_DH */
+
+# if PEDANTIC
+static void *dummy=&dummy;
+# endif
+
 #endif