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/dh_lib.c | |
| 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/dh_lib.c')
| -rw-r--r-- | src/lib/libcrypto/dh/dh_lib.c | 76 |
1 files changed, 63 insertions, 13 deletions
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, |
