/* 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
#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(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;
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)
{
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);
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;
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);