New function EC_GROUP_check_discriminant().
[openssl.git] / crypto / dh / dh_gen.c
index fc577af05dddefb866db05ec8282dd8df59b225d..7a6a38fbb4849368beeff620a3611f9d0e6c60ef 100644 (file)
@@ -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.
  * Having said all that,
  * there is another special case method for the generators 2, 3 and 5.
  * for 2, p mod 24 == 11
- * for 3, p mod 12 == 5  <<<<< does not work for strong primes.
+ * for 3, p mod 12 == 5  <<<<< does not work for safe primes.
  * for 5, p mod 10 == 3 or 7
  *
  * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
  * special generators and for answering some of my questions.
  *
  * I've implemented the second simple method :-).
- * Since DH should be using a strong prime (both p and q are prime),
+ * Since DH should be using a safe prime (both p and q are prime),
  * this generator function can take a very very long time to run.
  */
 
 DH *DH_generate_parameters(int prime_len, int generator,
-            void (*callback)(P_I_I_P), char *cb_arg)
+            void (*callback)(int,int,void *), void *cb_arg)
        {
        BIGNUM *p=NULL,*t1,*t2;
        DH *ret=NULL;
@@ -92,11 +92,13 @@ DH *DH_generate_parameters(int prime_len, int generator,
        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]);
-       ctx->tos=2;
+       BN_CTX_start(ctx);
+       t1 = BN_CTX_get(ctx);
+       t2 = BN_CTX_get(ctx);
+       if (t1 == NULL || t2 == NULL) goto err;
        
        if (generator == DH_GENERATOR_2)
                {
@@ -104,7 +106,7 @@ DH *DH_generate_parameters(int prime_len, int generator,
                BN_set_word(t2,11);
                g=2;
                }
-#ifdef undef  /* does not work for strong primes */
+#ifdef undef  /* does not work for safe primes */
        else if (generator == DH_GENERATOR_3)
                {
                BN_set_word(t1,12);
@@ -137,7 +139,11 @@ err:
                ok=0;
                }
 
-       if (ctx != NULL) BN_CTX_free(ctx);
+       if (ctx != NULL)
+               {
+               BN_CTX_end(ctx);
+               BN_CTX_free(ctx);
+               }
        if (!ok && (ret != NULL))
                {
                DH_free(ret);