aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/dh/dh_gen.c
diff options
context:
space:
mode:
authorGeoff Thorpe <geoff@openssl.org>2002-12-08 05:24:31 +0000
committerGeoff Thorpe <geoff@openssl.org>2002-12-08 05:24:31 +0000
commite9224c717711eefb30038c9b37c69795dda93c9a (patch)
treecdb7a95f6ef21a6434008c494c38d530b629def0 /crypto/dh/dh_gen.c
parente90e7197398ce87786e92468e946d50f3c6728b7 (diff)
downloadopenssl-e9224c717711eefb30038c9b37c69795dda93c9a.tar.gz
This is a first-cut at improving the callback mechanisms used in
key-generation and prime-checking functions. Rather than explicitly passing callback functions and caller-defined context data for the callbacks, a new structure BN_GENCB is defined that encapsulates this; a pointer to the structure is passed to all such functions instead. This wrapper structure allows the encapsulation of "old" and "new" style callbacks - "new" callbacks return a boolean result on the understanding that returning FALSE should terminate keygen/primality processing. The BN_GENCB abstraction will allow future callback modifications without needing to break binary compatibility nor change the API function prototypes. The new API functions have been given names ending in "_ex" and the old functions are implemented as wrappers to the new ones. The OPENSSL_NO_DEPRECATED symbol has been introduced so that, if defined, declaration of the older functions will be skipped. NB: Some openssl-internal code will stick with the older callbacks for now, so appropriate "#undef" logic will be put in place - this is in case the user is *building* openssl (rather than *including* its headers) with this symbol defined. There is another change in the new _ex functions; the key-generation functions do not return key structures but operate on structures passed by the caller, the return value is a boolean. This will allow for a smoother transition to having key-generation as "virtual function" in the various ***_METHOD tables.
Diffstat (limited to 'crypto/dh/dh_gen.c')
-rw-r--r--crypto/dh/dh_gen.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/crypto/dh/dh_gen.c b/crypto/dh/dh_gen.c
index 06f78b35ab..a929a0f064 100644
--- a/crypto/dh/dh_gen.c
+++ b/crypto/dh/dh_gen.c
@@ -56,6 +56,11 @@
* [including the GNU Public Licence.]
*/
+/* NB: These functions have been upgraded - the previous prototypes are in
+ * dh_depr.c as wrappers to these ones.
+ * - Geoff
+ */
+
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/bn.h>
@@ -86,22 +91,22 @@
* It's just as OK (and in some sense better) to use a generator of the
* order-q subgroup.
*/
-DH *DH_generate_parameters(int prime_len, int generator,
- void (*callback)(int,int,void *), void *cb_arg)
+int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
{
- BIGNUM *p=NULL,*t1,*t2;
- DH *ret=NULL;
+ BIGNUM *t1,*t2;
int g,ok= -1;
BN_CTX *ctx=NULL;
- ret=DH_new();
- if (ret == NULL) goto err;
ctx=BN_CTX_new();
if (ctx == NULL) goto err;
BN_CTX_start(ctx);
t1 = BN_CTX_get(ctx);
t2 = BN_CTX_get(ctx);
if (t1 == NULL || t2 == NULL) goto err;
+
+ /* Make sure 'ret' has the necessary elements */
+ if(!ret->p && ((ret->p = BN_new()) == NULL)) goto err;
+ if(!ret->g && ((ret->g = BN_new()) == NULL)) goto err;
if (generator <= 1)
{
@@ -141,11 +146,8 @@ DH *DH_generate_parameters(int prime_len, int generator,
g=generator;
}
- p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
- if (p == NULL) goto err;
- if (callback != NULL) callback(3,0,cb_arg);
- ret->p=p;
- ret->g=BN_new();
+ if(!BN_generate_prime_ex(ret->p,prime_len,1,t1,t2,cb)) goto err;
+ if(!BN_GENCB_call(cb, 3, 0)) goto err;
if (!BN_set_word(ret->g,g)) goto err;
ok=1;
err:
@@ -160,10 +162,5 @@ err:
BN_CTX_end(ctx);
BN_CTX_free(ctx);
}
- if (!ok && (ret != NULL))
- {
- DH_free(ret);
- ret=NULL;
- }
- return(ret);
+ return ok;
}