summaryrefslogtreecommitdiffstats
path: root/crypto/dh/dh_lib.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2000-10-26 21:07:28 +0000
committerRichard Levitte <levitte@openssl.org>2000-10-26 21:07:28 +0000
commit5270e7025e11b2fd1a5bdf8d81feded1167b1c87 (patch)
tree3bb44c37f4bb6469f738a10127050b023e0d7fb5 /crypto/dh/dh_lib.c
parent1df586bec20de86c3086181c565aaee7629bb0a2 (diff)
Merge the engine branch into the main trunk. All conflicts resolved.
At the same time, add VMS support for Rijndael.
Diffstat (limited to 'crypto/dh/dh_lib.c')
-rw-r--r--crypto/dh/dh_lib.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c
index a8d5340bf4..66803b5565 100644
--- a/crypto/dh/dh_lib.c
+++ b/crypto/dh/dh_lib.c
@@ -60,6 +60,7 @@
#include "cryptlib.h"
#include <openssl/bn.h>
#include <openssl/dh.h>
+#include <openssl/engine.h>
const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
@@ -67,17 +68,32 @@ static DH_METHOD *default_DH_method;
static int dh_meth_num = 0;
static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dh_meth = NULL;
-void DH_set_default_method(DH_METHOD *meth)
+void DH_set_default_openssl_method(DH_METHOD *meth)
{
- default_DH_method = meth;
+ ENGINE *e;
+ /* We'll need to notify the "openssl" ENGINE of this
+ * change too. We won't bother locking things down at
+ * our end as there was never any locking in these
+ * functions! */
+ if(default_DH_method != meth)
+ {
+ default_DH_method = meth;
+ e = ENGINE_by_id("openssl");
+ if(e)
+ {
+ ENGINE_set_DH(e, meth);
+ ENGINE_free(e);
+ }
+ }
}
-DH_METHOD *DH_get_default_method(void)
+DH_METHOD *DH_get_default_openssl_method(void)
{
if(!default_DH_method) default_DH_method = DH_OpenSSL();
return default_DH_method;
}
+#if 0
DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth)
{
DH_METHOD *mtmp;
@@ -87,14 +103,37 @@ DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth)
if (meth->init) meth->init(dh);
return mtmp;
}
+#else
+int DH_set_method(DH *dh, ENGINE *engine)
+{
+ ENGINE *mtmp;
+ DH_METHOD *meth;
+ mtmp = dh->engine;
+ meth = ENGINE_get_DH(mtmp);
+ if (!ENGINE_init(engine))
+ return 0;
+ if (meth->finish) meth->finish(dh);
+ dh->engine= engine;
+ meth = ENGINE_get_DH(engine);
+ if (meth->init) meth->init(dh);
+ /* SHOULD ERROR CHECK THIS!!! */
+ ENGINE_finish(mtmp);
+ return 1;
+}
+#endif
DH *DH_new(void)
{
return DH_new_method(NULL);
}
+#if 0
DH *DH_new_method(DH_METHOD *meth)
+#else
+DH *DH_new_method(ENGINE *engine)
+#endif
{
+ DH_METHOD *meth;
DH *ret;
ret=(DH *)OPENSSL_malloc(sizeof(DH));
@@ -103,8 +142,17 @@ DH *DH_new_method(DH_METHOD *meth)
DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);
return(NULL);
}
- if(meth) ret->meth = meth;
- else ret->meth = DH_get_default_method();
+ if(engine)
+ ret->engine = engine;
+ else
+ {
+ if((ret->engine=ENGINE_get_default_DH()) == NULL)
+ {
+ OPENSSL_free(ret);
+ return NULL;
+ }
+ }
+ meth = ENGINE_get_DH(ret->engine);
ret->pad=0;
ret->version=0;
ret->p=NULL;
@@ -119,8 +167,8 @@ DH *DH_new_method(DH_METHOD *meth)
ret->counter = NULL;
ret->method_mont_p=NULL;
ret->references = 1;
- ret->flags=ret->meth->flags;
- if ((ret->meth->init != NULL) && !ret->meth->init(ret))
+ ret->flags=meth->flags;
+ if ((meth->init != NULL) && !meth->init(ret))
{
OPENSSL_free(ret);
ret=NULL;
@@ -132,6 +180,7 @@ DH *DH_new_method(DH_METHOD *meth)
void DH_free(DH *r)
{
+ DH_METHOD *meth;
int i;
if(r == NULL) return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
@@ -149,7 +198,9 @@ void DH_free(DH *r)
CRYPTO_free_ex_data(dh_meth, r, &r->ex_data);
- if(r->meth->finish) r->meth->finish(r);
+ meth = ENGINE_get_DH(r->engine);
+ if(meth->finish) meth->finish(r);
+ ENGINE_finish(r->engine);
if (r->p != NULL) BN_clear_free(r->p);
if (r->g != NULL) BN_clear_free(r->g);