New function DSA_dup_DH, and fixes for bugs that were found
[openssl.git] / crypto / dh / dh_gen.c
index ff4f18e1e05262bc9bb97c6881ed08570e475776..b7bcd2c7a4183b44b622dab42b7c5a1e4779435a 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/dh/dh_gen.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
@@ -58,8 +58,8 @@
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "bn.h"
-#include "dh.h"
+#include <openssl/bn.h>
+#include <openssl/dh.h>
 
 /* We generate DH parameters as follows
  * find a prime q which is prime_len/2 bits long.
  * this generator function can take a very very long time to run.
  */
 
-DH *DH_generate_parameters(prime_len,generator,callback)
-int prime_len;
-int generator;
-void (*callback)(P_I_I);
+DH *DH_generate_parameters(int prime_len, int generator,
+            void (*callback)(int,int,void *), void *cb_arg)
        {
        BIGNUM *p=NULL,*t1,*t2;
        DH *ret=NULL;
@@ -94,10 +92,11 @@ void (*callback)(P_I_I);
        BN_CTX *ctx=NULL;
 
        ret=DH_new();
+       if (ret == NULL) goto err;
        ctx=BN_CTX_new();
        if (ctx == NULL) goto err;
-       t1=ctx->bn[0];
-       t2=ctx->bn[1];
+       t1= &(ctx->bn[0]);
+       t2= &(ctx->bn[1]);
        ctx->tos=2;
        
        if (generator == DH_GENERATOR_2)
@@ -125,9 +124,9 @@ void (*callback)(P_I_I);
        else
                g=generator;
        
-       p=BN_generate_prime(prime_len,1,t1,t2,callback);
+       p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
        if (p == NULL) goto err;
-       if (callback != NULL) callback(3,0);
+       if (callback != NULL) callback(3,0,cb_arg);
        ret->p=p;
        ret->g=BN_new();
        if (!BN_set_word(ret->g,g)) goto err;