diff options
author | beck <> | 2000-12-15 02:58:47 +0000 |
---|---|---|
committer | beck <> | 2000-12-15 02:58:47 +0000 |
commit | 9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch) | |
tree | 5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/dh | |
parent | e131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff) | |
download | openbsd-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.ssl | 66 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh.h | 26 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_key.c | 34 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_lib.c | 76 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dhtest.c | 8 |
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 | |||
82 | dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | 82 | dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h |
83 | dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | 83 | dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h |
84 | dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 84 | dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
85 | dh_check.o: ../../include/openssl/opensslconf.h | 85 | dh_check.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h |
86 | dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | 86 | dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
87 | dh_check.o: ../../include/openssl/stack.h ../cryptlib.h | 87 | dh_check.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h |
88 | dh_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | 88 | dh_check.o: ../cryptlib.h |
89 | dh_err.o: ../../include/openssl/dh.h ../../include/openssl/err.h | 89 | dh_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h |
90 | dh_err.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
91 | dh_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
90 | dh_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 92 | dh_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
91 | dh_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | 93 | dh_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
94 | dh_err.o: ../../include/openssl/symhacks.h | ||
92 | dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | 95 | dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h |
93 | dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | 96 | dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h |
94 | dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | 97 | dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h |
95 | dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 98 | dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
96 | dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 99 | dh_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h |
97 | dh_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | 100 | dh_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h |
101 | dh_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
98 | dh_gen.o: ../cryptlib.h | 102 | dh_gen.o: ../cryptlib.h |
99 | dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | 103 | dh_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h |
100 | dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | 104 | dh_key.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h |
101 | dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | 105 | dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h |
102 | dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 106 | dh_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h |
103 | dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 107 | dh_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h |
104 | dh_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | 108 | dh_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h |
105 | dh_key.o: ../../include/openssl/stack.h ../cryptlib.h | 109 | dh_key.o: ../../include/openssl/engine.h ../../include/openssl/err.h |
106 | dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | 110 | dh_key.o: ../../include/openssl/evp.h ../../include/openssl/idea.h |
107 | dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | 111 | dh_key.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h |
108 | dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | 112 | dh_key.o: ../../include/openssl/md4.h ../../include/openssl/md5.h |
109 | dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 113 | dh_key.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h |
110 | dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 114 | dh_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h |
111 | dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | 115 | dh_key.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h |
112 | dh_lib.o: ../cryptlib.h | 116 | dh_key.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h |
117 | dh_key.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
118 | dh_key.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
119 | dh_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
120 | dh_key.o: ../../include/openssl/symhacks.h ../cryptlib.h | ||
121 | dh_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
122 | dh_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
123 | dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
124 | dh_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
125 | dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
126 | dh_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
127 | dh_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
128 | dh_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
129 | dh_lib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
130 | dh_lib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
131 | dh_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
132 | dh_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
133 | dh_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | ||
134 | dh_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
135 | dh_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
136 | dh_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
137 | dh_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
138 | dh_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 | ||
63 | extern "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 | ||
75 | extern "C" { | ||
76 | #endif | ||
77 | |||
75 | typedef struct dh_st DH; | 78 | typedef struct dh_st DH; |
76 | 79 | ||
77 | typedef struct dh_method { | 80 | typedef 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 | ||
148 | DH_METHOD *DH_OpenSSL(void); | 155 | DH_METHOD *DH_OpenSSL(void); |
149 | 156 | ||
150 | void DH_set_default_method(DH_METHOD *meth); | 157 | void DH_set_default_openssl_method(DH_METHOD *meth); |
151 | DH_METHOD *DH_get_default_method(void); | 158 | DH_METHOD *DH_get_default_openssl_method(void); |
159 | #if 0 | ||
152 | DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth); | 160 | DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth); |
153 | DH *DH_new_method(DH_METHOD *meth); | 161 | DH *DH_new_method(DH_METHOD *meth); |
162 | #else | ||
163 | int DH_set_method(DH *dh, struct engine_st *engine); | ||
164 | DH *DH_new_method(struct engine_st *engine); | ||
165 | #endif | ||
154 | 166 | ||
155 | DH * DH_new(void); | 167 | DH * DH_new(void); |
156 | void DH_free(DH *dh); | 168 | void 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 |
170 | int DHparams_print_fp(FILE *fp, DH *x); | 182 | int DHparams_print_fp(FILE *fp, DH *x); |
171 | #endif | 183 | #endif |
172 | #ifdef HEADER_BIO_H | 184 | #ifndef NO_BIO |
173 | int DHparams_print(BIO *bp, DH *x); | 185 | int DHparams_print(BIO *bp, DH *x); |
174 | #else | 186 | #else |
175 | int DHparams_print(char *bp, DH *x); | 187 | int 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 | ||
65 | static int generate_key(DH *dh); | 66 | static int generate_key(DH *dh); |
66 | static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh); | 67 | static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh); |
@@ -72,12 +73,12 @@ static int dh_finish(DH *dh); | |||
72 | 73 | ||
73 | int DH_generate_key(DH *dh) | 74 | int 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 | ||
78 | int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh) | 79 | int 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 | ||
83 | static DH_METHOD dh_ossl = { | 84 | static 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: | |||
193 | static int dh_bn_mod_exp(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | 196 | static 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 | ||
200 | static int dh_init(DH *dh) | 210 | static 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 | ||
206 | static int dh_finish(DH *dh) | 216 | static 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 | ||
64 | const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; | 65 | const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; |
65 | 66 | ||
@@ -67,17 +68,32 @@ static DH_METHOD *default_DH_method; | |||
67 | static int dh_meth_num = 0; | 68 | static int dh_meth_num = 0; |
68 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dh_meth = NULL; | 69 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dh_meth = NULL; |
69 | 70 | ||
70 | void DH_set_default_method(DH_METHOD *meth) | 71 | void 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 | ||
75 | DH_METHOD *DH_get_default_method(void) | 90 | DH_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 | ||
81 | DH_METHOD *DH_set_method(DH *dh, DH_METHOD *meth) | 97 | DH_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 | ||
107 | int 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 | ||
91 | DH *DH_new(void) | 125 | DH *DH_new(void) |
92 | { | 126 | { |
93 | return DH_new_method(NULL); | 127 | return DH_new_method(NULL); |
94 | } | 128 | } |
95 | 129 | ||
130 | #if 0 | ||
96 | DH *DH_new_method(DH_METHOD *meth) | 131 | DH *DH_new_method(DH_METHOD *meth) |
132 | #else | ||
133 | DH *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 | ||
134 | void DH_free(DH *r) | 181 | void 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 | ||
166 | int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 216 | int 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; |
172 | err: | 172 | err: |
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); |