Add DH_new_method, add ENGINE refcounting.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16494 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-01-08 23:22:55 +00:00
parent f79e06f081
commit 018ec753ff

View File

@@ -49,14 +49,42 @@ RCSID("$Id$");
DH * DH *
DH_new(void) DH_new(void)
{
return DH_new_method(NULL);
}
DH *
DH_new_method(ENGINE *engine)
{ {
DH *dh; DH *dh;
dh = calloc(1, sizeof(*dh)); dh = calloc(1, sizeof(*dh));
if (dh == NULL) if (dh == NULL)
return NULL; return NULL;
dh->meth = rk_UNCONST(DH_get_default_method());
dh->references = 1; dh->references = 1;
if (engine) {
ENGINE_up_ref(engine);
dh->engine = engine;
} else {
dh->engine = ENGINE_get_default_DH();
}
if (dh->engine) {
dh->meth = ENGINE_get_DH(dh->engine);
if (dh->meth == NULL) {
ENGINE_finish(engine);
free(dh);
return 0;
}
}
if (dh->meth == NULL)
dh->meth = DH_get_default_method();
(*dh->meth->init)(dh);
return dh; return dh;
} }
@@ -71,6 +99,9 @@ DH_free(DH *dh)
(*dh->meth->finish)(dh); (*dh->meth->finish)(dh);
if (dh->engine)
ENGINE_finish(dh->engine);
#define free_if(f) if (f) { BN_free(f); } #define free_if(f) if (f) { BN_free(f); }
free_if(dh->p); free_if(dh->p);
free_if(dh->g); free_if(dh->g);
@@ -141,6 +172,10 @@ int
DH_set_method(DH *dh, const DH_METHOD *method) DH_set_method(DH *dh, const DH_METHOD *method)
{ {
(*dh->meth->finish)(dh); (*dh->meth->finish)(dh);
if (dh->engine) {
ENGINE_finish(dh->engine);
dh->engine = NULL;
}
dh->meth = method; dh->meth = method;
(*dh->meth->init)(dh); (*dh->meth->init)(dh);
return 1; return 1;