summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dh
diff options
context:
space:
mode:
authorbeck <>2000-12-15 02:58:47 +0000
committerbeck <>2000-12-15 02:58:47 +0000
commit9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch)
tree5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/dh
parente131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff)
downloadopenbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.gz
openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.bz2
openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.zip
openssl-engine-0.9.6 merge
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r--src/lib/libcrypto/dh/Makefile.ssl66
-rw-r--r--src/lib/libcrypto/dh/dh.h26
-rw-r--r--src/lib/libcrypto/dh/dh_key.c34
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c76
-rw-r--r--src/lib/libcrypto/dh/dhtest.c8
5 files changed, 154 insertions, 56 deletions
diff --git a/src/lib/libcrypto/dh/Makefile.ssl b/src/lib/libcrypto/dh/Makefile.ssl
index 8df60872ef..88d0d1748b 100644
--- a/src/lib/libcrypto/dh/Makefile.ssl
+++ b/src/lib/libcrypto/dh/Makefile.ssl
@@ -82,31 +82,57 @@ dh_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
82dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 82dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
83dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 83dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
84dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 84dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85dh_check.o: ../../include/openssl/opensslconf.h 85dh_check.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
86dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 86dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87dh_check.o: ../../include/openssl/stack.h ../cryptlib.h 87dh_check.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
88dh_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h 88dh_check.o: ../cryptlib.h
89dh_err.o: ../../include/openssl/dh.h ../../include/openssl/err.h 89dh_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
90dh_err.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
91dh_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
90dh_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 92dh_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
91dh_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 93dh_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
94dh_err.o: ../../include/openssl/symhacks.h
92dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 95dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
93dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 96dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
94dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 97dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
95dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 98dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
96dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 99dh_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
97dh_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 100dh_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
101dh_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
98dh_gen.o: ../cryptlib.h 102dh_gen.o: ../cryptlib.h
99dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 103dh_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
100dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 104dh_key.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
101dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 105dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
102dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 106dh_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
103dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 107dh_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
104dh_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h 108dh_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
105dh_key.o: ../../include/openssl/stack.h ../cryptlib.h 109dh_key.o: ../../include/openssl/engine.h ../../include/openssl/err.h
106dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 110dh_key.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
107dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 111dh_key.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
108dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h 112dh_key.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
109dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 113dh_key.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
110dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 114dh_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
111dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 115dh_key.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
112dh_lib.o: ../cryptlib.h 116dh_key.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
117dh_key.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
118dh_key.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
119dh_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
120dh_key.o: ../../include/openssl/symhacks.h ../cryptlib.h
121dh_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
122dh_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
123dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
124dh_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
125dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
126dh_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
127dh_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
128dh_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
129dh_lib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
130dh_lib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
131dh_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
132dh_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
133dh_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
134dh_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
135dh_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
136dh_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
137dh_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
138dh_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
index c15b2ad483..7a8d9f88c2 100644
--- a/src/lib/libcrypto/dh/dh.h
+++ b/src/lib/libcrypto/dh/dh.h
@@ -59,19 +59,22 @@
59#ifndef HEADER_DH_H 59#ifndef HEADER_DH_H
60#define HEADER_DH_H 60#define HEADER_DH_H
61 61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_DH 62#ifdef NO_DH
67#error DH is disabled. 63#error DH is disabled.
68#endif 64#endif
69 65
66#ifndef NO_BIO
67#include <openssl/bio.h>
68#endif
70#include <openssl/bn.h> 69#include <openssl/bn.h>
71#include <openssl/crypto.h> 70#include <openssl/crypto.h>
72 71
73#define DH_FLAG_CACHE_MONT_P 0x01 72#define DH_FLAG_CACHE_MONT_P 0x01
74 73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
75typedef struct dh_st DH; 78typedef struct dh_st DH;
76 79
77typedef struct dh_method { 80typedef struct dh_method {
@@ -112,7 +115,11 @@ struct dh_st
112 115
113 int references; 116 int references;
114 CRYPTO_EX_DATA ex_data; 117 CRYPTO_EX_DATA ex_data;
118#if 0
115 DH_METHOD *meth; 119 DH_METHOD *meth;
120#else
121 struct engine_st *engine;
122#endif
116 }; 123 };
117 124
118#define DH_GENERATOR_2 2 125#define DH_GENERATOR_2 2
@@ -147,10 +154,15 @@ struct dh_st
147 154
148DH_METHOD *DH_OpenSSL(void); 155DH_METHOD *DH_OpenSSL(void);
149 156
150void DH_set_default_method(DH_METHOD *meth); 157void DH_set_default_openssl_method(DH_METHOD *meth);
151DH_METHOD *DH_get_default_method(void); 158DH_METHOD *DH_get_default_openssl_method(void);
159#if 0
152DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth); 160DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth);
153DH *DH_new_method(DH_METHOD *meth); 161DH *DH_new_method(DH_METHOD *meth);
162#else
163int DH_set_method(DH *dh, struct engine_st *engine);
164DH *DH_new_method(struct engine_st *engine);
165#endif
154 166
155DH * DH_new(void); 167DH * DH_new(void);
156void DH_free(DH *dh); 168void DH_free(DH *dh);
@@ -169,7 +181,7 @@ int i2d_DHparams(DH *a,unsigned char **pp);
169#ifndef NO_FP_API 181#ifndef NO_FP_API
170int DHparams_print_fp(FILE *fp, DH *x); 182int DHparams_print_fp(FILE *fp, DH *x);
171#endif 183#endif
172#ifdef HEADER_BIO_H 184#ifndef NO_BIO
173int DHparams_print(BIO *bp, DH *x); 185int DHparams_print(BIO *bp, DH *x);
174#else 186#else
175int DHparams_print(char *bp, DH *x); 187int DHparams_print(char *bp, DH *x);
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
index 0c7eeaf260..6915d79dcc 100644
--- a/src/lib/libcrypto/dh/dh_key.c
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -61,6 +61,7 @@
61#include <openssl/bn.h> 61#include <openssl/bn.h>
62#include <openssl/rand.h> 62#include <openssl/rand.h>
63#include <openssl/dh.h> 63#include <openssl/dh.h>
64#include <openssl/engine.h>
64 65
65static int generate_key(DH *dh); 66static int generate_key(DH *dh);
66static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh); 67static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
@@ -72,12 +73,12 @@ static int dh_finish(DH *dh);
72 73
73int DH_generate_key(DH *dh) 74int DH_generate_key(DH *dh)
74 { 75 {
75 return dh->meth->generate_key(dh); 76 return ENGINE_get_DH(dh->engine)->generate_key(dh);
76 } 77 }
77 78
78int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh) 79int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
79 { 80 {
80 return dh->meth->compute_key(key, pub_key, dh); 81 return ENGINE_get_DH(dh->engine)->compute_key(key, pub_key, dh);
81 } 82 }
82 83
83static DH_METHOD dh_ossl = { 84static DH_METHOD dh_ossl = {
@@ -137,8 +138,9 @@ static int generate_key(DH *dh)
137 } 138 }
138 mont=(BN_MONT_CTX *)dh->method_mont_p; 139 mont=(BN_MONT_CTX *)dh->method_mont_p;
139 140
140 if (!dh->meth->bn_mod_exp(dh, pub_key,dh->g,priv_key,dh->p,&ctx,mont)) 141 if (!ENGINE_get_DH(dh->engine)->bn_mod_exp(dh, pub_key, dh->g,
141 goto err; 142 priv_key,dh->p,&ctx,mont))
143 goto err;
142 144
143 dh->pub_key=pub_key; 145 dh->pub_key=pub_key;
144 dh->priv_key=priv_key; 146 dh->priv_key=priv_key;
@@ -177,7 +179,8 @@ static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
177 } 179 }
178 180
179 mont=(BN_MONT_CTX *)dh->method_mont_p; 181 mont=(BN_MONT_CTX *)dh->method_mont_p;
180 if (!dh->meth->bn_mod_exp(dh, tmp,pub_key,dh->priv_key,dh->p,&ctx,mont)) 182 if (!ENGINE_get_DH(dh->engine)->bn_mod_exp(dh, tmp, pub_key,
183 dh->priv_key,dh->p,&ctx,mont))
181 { 184 {
182 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); 185 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
183 goto err; 186 goto err;
@@ -193,19 +196,26 @@ err:
193static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p, 196static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
194 const BIGNUM *m, BN_CTX *ctx, 197 const BIGNUM *m, BN_CTX *ctx,
195 BN_MONT_CTX *m_ctx) 198 BN_MONT_CTX *m_ctx)
196{ 199 {
197 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx); 200 if (a->top == 1)
198} 201 {
202 BN_ULONG A = a->d[0];
203 return BN_mod_exp_mont_word(r,A,p,m,ctx,m_ctx);
204 }
205 else
206 return BN_mod_exp_mont(r,a,p,m,ctx,m_ctx);
207 }
208
199 209
200static int dh_init(DH *dh) 210static int dh_init(DH *dh)
201{ 211 {
202 dh->flags |= DH_FLAG_CACHE_MONT_P; 212 dh->flags |= DH_FLAG_CACHE_MONT_P;
203 return(1); 213 return(1);
204} 214 }
205 215
206static int dh_finish(DH *dh) 216static int dh_finish(DH *dh)
207{ 217 {
208 if(dh->method_mont_p) 218 if(dh->method_mont_p)
209 BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p); 219 BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
210 return(1); 220 return(1);
211} 221 }
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index 6c21463028..66803b5565 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -60,6 +60,7 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/bn.h> 61#include <openssl/bn.h>
62#include <openssl/dh.h> 62#include <openssl/dh.h>
63#include <openssl/engine.h>
63 64
64const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; 65const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
65 66
@@ -67,17 +68,32 @@ static DH_METHOD *default_DH_method;
67static int dh_meth_num = 0; 68static int dh_meth_num = 0;
68static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dh_meth = NULL; 69static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dh_meth = NULL;
69 70
70void DH_set_default_method(DH_METHOD *meth) 71void DH_set_default_openssl_method(DH_METHOD *meth)
71{ 72{
72 default_DH_method = meth; 73 ENGINE *e;
74 /* We'll need to notify the "openssl" ENGINE of this
75 * change too. We won't bother locking things down at
76 * our end as there was never any locking in these
77 * functions! */
78 if(default_DH_method != meth)
79 {
80 default_DH_method = meth;
81 e = ENGINE_by_id("openssl");
82 if(e)
83 {
84 ENGINE_set_DH(e, meth);
85 ENGINE_free(e);
86 }
87 }
73} 88}
74 89
75DH_METHOD *DH_get_default_method(void) 90DH_METHOD *DH_get_default_openssl_method(void)
76{ 91{
77 if(!default_DH_method) default_DH_method = DH_OpenSSL(); 92 if(!default_DH_method) default_DH_method = DH_OpenSSL();
78 return default_DH_method; 93 return default_DH_method;
79} 94}
80 95
96#if 0
81DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth) 97DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth)
82{ 98{
83 DH_METHOD *mtmp; 99 DH_METHOD *mtmp;
@@ -87,25 +103,56 @@ DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth)
87 if (meth->init) meth->init(dh); 103 if (meth->init) meth->init(dh);
88 return mtmp; 104 return mtmp;
89} 105}
106#else
107int DH_set_method(DH *dh, ENGINE *engine)
108{
109 ENGINE *mtmp;
110 DH_METHOD *meth;
111 mtmp = dh->engine;
112 meth = ENGINE_get_DH(mtmp);
113 if (!ENGINE_init(engine))
114 return 0;
115 if (meth->finish) meth->finish(dh);
116 dh->engine= engine;
117 meth = ENGINE_get_DH(engine);
118 if (meth->init) meth->init(dh);
119 /* SHOULD ERROR CHECK THIS!!! */
120 ENGINE_finish(mtmp);
121 return 1;
122}
123#endif
90 124
91DH *DH_new(void) 125DH *DH_new(void)
92{ 126{
93 return DH_new_method(NULL); 127 return DH_new_method(NULL);
94} 128}
95 129
130#if 0
96DH *DH_new_method(DH_METHOD *meth) 131DH *DH_new_method(DH_METHOD *meth)
132#else
133DH *DH_new_method(ENGINE *engine)
134#endif
97 { 135 {
136 DH_METHOD *meth;
98 DH *ret; 137 DH *ret;
99 ret=(DH *)Malloc(sizeof(DH)); 138 ret=(DH *)OPENSSL_malloc(sizeof(DH));
100 139
101 if (ret == NULL) 140 if (ret == NULL)
102 { 141 {
103 DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE); 142 DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);
104 return(NULL); 143 return(NULL);
105 } 144 }
106 if(!default_DH_method) default_DH_method = DH_OpenSSL(); 145 if(engine)
107 if(meth) ret->meth = meth; 146 ret->engine = engine;
108 else ret->meth = default_DH_method; 147 else
148 {
149 if((ret->engine=ENGINE_get_default_DH()) == NULL)
150 {
151 OPENSSL_free(ret);
152 return NULL;
153 }
154 }
155 meth = ENGINE_get_DH(ret->engine);
109 ret->pad=0; 156 ret->pad=0;
110 ret->version=0; 157 ret->version=0;
111 ret->p=NULL; 158 ret->p=NULL;
@@ -120,10 +167,10 @@ DH *DH_new_method(DH_METHOD *meth)
120 ret->counter = NULL; 167 ret->counter = NULL;
121 ret->method_mont_p=NULL; 168 ret->method_mont_p=NULL;
122 ret->references = 1; 169 ret->references = 1;
123 ret->flags=ret->meth->flags; 170 ret->flags=meth->flags;
124 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 171 if ((meth->init != NULL) && !meth->init(ret))
125 { 172 {
126 Free(ret); 173 OPENSSL_free(ret);
127 ret=NULL; 174 ret=NULL;
128 } 175 }
129 else 176 else
@@ -133,6 +180,7 @@ DH *DH_new_method(DH_METHOD *meth)
133 180
134void DH_free(DH *r) 181void DH_free(DH *r)
135 { 182 {
183 DH_METHOD *meth;
136 int i; 184 int i;
137 if(r == NULL) return; 185 if(r == NULL) return;
138 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH); 186 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
@@ -150,17 +198,19 @@ void DH_free(DH *r)
150 198
151 CRYPTO_free_ex_data(dh_meth, r, &r->ex_data); 199 CRYPTO_free_ex_data(dh_meth, r, &r->ex_data);
152 200
153 if(r->meth->finish) r->meth->finish(r); 201 meth = ENGINE_get_DH(r->engine);
202 if(meth->finish) meth->finish(r);
203 ENGINE_finish(r->engine);
154 204
155 if (r->p != NULL) BN_clear_free(r->p); 205 if (r->p != NULL) BN_clear_free(r->p);
156 if (r->g != NULL) BN_clear_free(r->g); 206 if (r->g != NULL) BN_clear_free(r->g);
157 if (r->q != NULL) BN_clear_free(r->q); 207 if (r->q != NULL) BN_clear_free(r->q);
158 if (r->j != NULL) BN_clear_free(r->j); 208 if (r->j != NULL) BN_clear_free(r->j);
159 if (r->seed) Free(r->seed); 209 if (r->seed) OPENSSL_free(r->seed);
160 if (r->counter != NULL) BN_clear_free(r->counter); 210 if (r->counter != NULL) BN_clear_free(r->counter);
161 if (r->pub_key != NULL) BN_clear_free(r->pub_key); 211 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
162 if (r->priv_key != NULL) BN_clear_free(r->priv_key); 212 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
163 Free(r); 213 OPENSSL_free(r);
164 } 214 }
165 215
166int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 216int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c
index d66c28455e..f0151253d7 100644
--- a/src/lib/libcrypto/dh/dhtest.c
+++ b/src/lib/libcrypto/dh/dhtest.c
@@ -140,7 +140,7 @@ int main(int argc, char *argv[])
140 BIO_puts(out,"\n"); 140 BIO_puts(out,"\n");
141 141
142 alen=DH_size(a); 142 alen=DH_size(a);
143 abuf=(unsigned char *)Malloc(alen); 143 abuf=(unsigned char *)OPENSSL_malloc(alen);
144 aout=DH_compute_key(abuf,b->pub_key,a); 144 aout=DH_compute_key(abuf,b->pub_key,a);
145 145
146 BIO_puts(out,"key1 ="); 146 BIO_puts(out,"key1 =");
@@ -152,7 +152,7 @@ int main(int argc, char *argv[])
152 BIO_puts(out,"\n"); 152 BIO_puts(out,"\n");
153 153
154 blen=DH_size(b); 154 blen=DH_size(b);
155 bbuf=(unsigned char *)Malloc(blen); 155 bbuf=(unsigned char *)OPENSSL_malloc(blen);
156 bout=DH_compute_key(bbuf,a->pub_key,b); 156 bout=DH_compute_key(bbuf,a->pub_key,b);
157 157
158 BIO_puts(out,"key2 ="); 158 BIO_puts(out,"key2 =");
@@ -170,8 +170,8 @@ int main(int argc, char *argv[])
170 else 170 else
171 ret=0; 171 ret=0;
172err: 172err:
173 if (abuf != NULL) Free(abuf); 173 if (abuf != NULL) OPENSSL_free(abuf);
174 if (bbuf != NULL) Free(bbuf); 174 if (bbuf != NULL) OPENSSL_free(bbuf);
175 if(b != NULL) DH_free(b); 175 if(b != NULL) DH_free(b);
176 if(a != NULL) DH_free(a); 176 if(a != NULL) DH_free(a);
177 BIO_free(out); 177 BIO_free(out);