diff options
| author | beck <> | 2002-05-15 02:29:21 +0000 |
|---|---|---|
| committer | beck <> | 2002-05-15 02:29:21 +0000 |
| commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
| tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/dsa/dsa_lib.c | |
| parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
| download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip | |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_lib.c')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_lib.c | 151 |
1 files changed, 75 insertions, 76 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c index 15f667a203..da2cdfa3d6 100644 --- a/src/lib/libcrypto/dsa/dsa_lib.c +++ b/src/lib/libcrypto/dsa/dsa_lib.c | |||
| @@ -67,96 +67,78 @@ | |||
| 67 | 67 | ||
| 68 | const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; | 68 | const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; |
| 69 | 69 | ||
| 70 | static DSA_METHOD *default_DSA_method; | 70 | static const DSA_METHOD *default_DSA_method = NULL; |
| 71 | static int dsa_meth_num = 0; | ||
| 72 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dsa_meth = NULL; | ||
| 73 | |||
| 74 | void DSA_set_default_openssl_method(DSA_METHOD *meth) | ||
| 75 | { | ||
| 76 | ENGINE *e; | ||
| 77 | /* We'll need to notify the "openssl" ENGINE of this | ||
| 78 | * change too. We won't bother locking things down at | ||
| 79 | * our end as there was never any locking in these | ||
| 80 | * functions! */ | ||
| 81 | if(default_DSA_method != meth) | ||
| 82 | { | ||
| 83 | default_DSA_method = meth; | ||
| 84 | e = ENGINE_by_id("openssl"); | ||
| 85 | if(e) | ||
| 86 | { | ||
| 87 | ENGINE_set_DSA(e, meth); | ||
| 88 | ENGINE_free(e); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | 71 | ||
| 93 | DSA_METHOD *DSA_get_default_openssl_method(void) | 72 | void DSA_set_default_method(const DSA_METHOD *meth) |
| 94 | { | 73 | { |
| 95 | if(!default_DSA_method) default_DSA_method = DSA_OpenSSL(); | 74 | default_DSA_method = meth; |
| 75 | } | ||
| 76 | |||
| 77 | const DSA_METHOD *DSA_get_default_method(void) | ||
| 78 | { | ||
| 79 | if(!default_DSA_method) | ||
| 80 | default_DSA_method = DSA_OpenSSL(); | ||
| 96 | return default_DSA_method; | 81 | return default_DSA_method; |
| 97 | } | 82 | } |
| 98 | 83 | ||
| 99 | DSA *DSA_new(void) | 84 | DSA *DSA_new(void) |
| 100 | { | 85 | { |
| 101 | return DSA_new_method(NULL); | 86 | return DSA_new_method(NULL); |
| 102 | } | 87 | } |
| 103 | 88 | ||
| 104 | #if 0 | 89 | int DSA_set_method(DSA *dsa, const DSA_METHOD *meth) |
| 105 | DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth) | 90 | { |
| 106 | { | 91 | /* NB: The caller is specifically setting a method, so it's not up to us |
| 107 | DSA_METHOD *mtmp; | 92 | * to deal with which ENGINE it comes from. */ |
| 93 | const DSA_METHOD *mtmp; | ||
| 108 | mtmp = dsa->meth; | 94 | mtmp = dsa->meth; |
| 109 | if (mtmp->finish) mtmp->finish(dsa); | 95 | if (mtmp->finish) mtmp->finish(dsa); |
| 96 | if (dsa->engine) | ||
| 97 | { | ||
| 98 | ENGINE_finish(dsa->engine); | ||
| 99 | dsa->engine = NULL; | ||
| 100 | } | ||
| 110 | dsa->meth = meth; | 101 | dsa->meth = meth; |
| 111 | if (meth->init) meth->init(dsa); | 102 | if (meth->init) meth->init(dsa); |
| 112 | return mtmp; | 103 | return 1; |
| 113 | } | ||
| 114 | #else | ||
| 115 | int DSA_set_method(DSA *dsa, ENGINE *engine) | ||
| 116 | { | ||
| 117 | ENGINE *mtmp; | ||
| 118 | DSA_METHOD *meth; | ||
| 119 | mtmp = dsa->engine; | ||
| 120 | meth = ENGINE_get_DSA(mtmp); | ||
| 121 | if (!ENGINE_init(engine)) | ||
| 122 | return 0; | ||
| 123 | if (meth->finish) meth->finish(dsa); | ||
| 124 | dsa->engine = engine; | ||
| 125 | meth = ENGINE_get_DSA(engine); | ||
| 126 | if (meth->init) meth->init(dsa); | ||
| 127 | /* SHOULD ERROR CHECK THIS!!! */ | ||
| 128 | ENGINE_finish(mtmp); | ||
| 129 | return 1; | ||
| 130 | } | 104 | } |
| 131 | #endif | ||
| 132 | 105 | ||
| 133 | |||
| 134 | #if 0 | ||
| 135 | DSA *DSA_new_method(DSA_METHOD *meth) | ||
| 136 | #else | ||
| 137 | DSA *DSA_new_method(ENGINE *engine) | 106 | DSA *DSA_new_method(ENGINE *engine) |
| 138 | #endif | ||
| 139 | { | 107 | { |
| 140 | DSA_METHOD *meth; | ||
| 141 | DSA *ret; | 108 | DSA *ret; |
| 142 | 109 | ||
| 143 | ret=(DSA *)OPENSSL_malloc(sizeof(DSA)); | 110 | ret=(DSA *)OPENSSL_malloc(sizeof(DSA)); |
| 144 | if (ret == NULL) | 111 | if (ret == NULL) |
| 145 | { | 112 | { |
| 146 | DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE); | 113 | DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); |
| 147 | return(NULL); | 114 | return(NULL); |
| 148 | } | 115 | } |
| 149 | if(engine) | 116 | ret->meth = DSA_get_default_method(); |
| 117 | if (engine) | ||
| 118 | { | ||
| 119 | if (!ENGINE_init(engine)) | ||
| 120 | { | ||
| 121 | DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); | ||
| 122 | OPENSSL_free(ret); | ||
| 123 | return NULL; | ||
| 124 | } | ||
| 150 | ret->engine = engine; | 125 | ret->engine = engine; |
| 126 | } | ||
| 151 | else | 127 | else |
| 128 | ret->engine = ENGINE_get_default_DSA(); | ||
| 129 | if(ret->engine) | ||
| 152 | { | 130 | { |
| 153 | if((ret->engine=ENGINE_get_default_DSA()) == NULL) | 131 | ret->meth = ENGINE_get_DSA(ret->engine); |
| 132 | if(!ret->meth) | ||
| 154 | { | 133 | { |
| 134 | DSAerr(DSA_F_DSA_NEW_METHOD, | ||
| 135 | ERR_R_ENGINE_LIB); | ||
| 136 | ENGINE_finish(ret->engine); | ||
| 155 | OPENSSL_free(ret); | 137 | OPENSSL_free(ret); |
| 156 | return NULL; | 138 | return NULL; |
| 157 | } | 139 | } |
| 158 | } | 140 | } |
| 159 | meth = ENGINE_get_DSA(ret->engine); | 141 | |
| 160 | ret->pad=0; | 142 | ret->pad=0; |
| 161 | ret->version=0; | 143 | ret->version=0; |
| 162 | ret->write_params=1; | 144 | ret->write_params=1; |
| @@ -172,11 +154,13 @@ DSA *DSA_new_method(ENGINE *engine) | |||
| 172 | ret->method_mont_p=NULL; | 154 | ret->method_mont_p=NULL; |
| 173 | 155 | ||
| 174 | ret->references=1; | 156 | ret->references=1; |
| 175 | ret->flags=meth->flags; | 157 | ret->flags=ret->meth->flags; |
| 176 | CRYPTO_new_ex_data(dsa_meth,ret,&ret->ex_data); | 158 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); |
| 177 | if ((meth->init != NULL) && !meth->init(ret)) | 159 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) |
| 178 | { | 160 | { |
| 179 | CRYPTO_free_ex_data(dsa_meth,ret,&ret->ex_data); | 161 | if (ret->engine) |
| 162 | ENGINE_finish(ret->engine); | ||
| 163 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); | ||
| 180 | OPENSSL_free(ret); | 164 | OPENSSL_free(ret); |
| 181 | ret=NULL; | 165 | ret=NULL; |
| 182 | } | 166 | } |
| @@ -186,7 +170,6 @@ DSA *DSA_new_method(ENGINE *engine) | |||
| 186 | 170 | ||
| 187 | void DSA_free(DSA *r) | 171 | void DSA_free(DSA *r) |
| 188 | { | 172 | { |
| 189 | DSA_METHOD *meth; | ||
| 190 | int i; | 173 | int i; |
| 191 | 174 | ||
| 192 | if (r == NULL) return; | 175 | if (r == NULL) return; |
| @@ -204,11 +187,12 @@ void DSA_free(DSA *r) | |||
| 204 | } | 187 | } |
| 205 | #endif | 188 | #endif |
| 206 | 189 | ||
| 207 | meth = ENGINE_get_DSA(r->engine); | 190 | if(r->meth->finish) |
| 208 | if(meth->finish) meth->finish(r); | 191 | r->meth->finish(r); |
| 209 | ENGINE_finish(r->engine); | 192 | if(r->engine) |
| 193 | ENGINE_finish(r->engine); | ||
| 210 | 194 | ||
| 211 | CRYPTO_free_ex_data(dsa_meth, r, &r->ex_data); | 195 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); |
| 212 | 196 | ||
| 213 | if (r->p != NULL) BN_clear_free(r->p); | 197 | if (r->p != NULL) BN_clear_free(r->p); |
| 214 | if (r->q != NULL) BN_clear_free(r->q); | 198 | if (r->q != NULL) BN_clear_free(r->q); |
| @@ -220,7 +204,23 @@ void DSA_free(DSA *r) | |||
| 220 | OPENSSL_free(r); | 204 | OPENSSL_free(r); |
| 221 | } | 205 | } |
| 222 | 206 | ||
| 223 | int DSA_size(DSA *r) | 207 | int DSA_up_ref(DSA *r) |
| 208 | { | ||
| 209 | int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA); | ||
| 210 | #ifdef REF_PRINT | ||
| 211 | REF_PRINT("DSA",r); | ||
| 212 | #endif | ||
| 213 | #ifdef REF_CHECK | ||
| 214 | if (i < 2) | ||
| 215 | { | ||
| 216 | fprintf(stderr, "DSA_up_ref, bad reference count\n"); | ||
| 217 | abort(); | ||
| 218 | } | ||
| 219 | #endif | ||
| 220 | return ((i > 1) ? 1 : 0); | ||
| 221 | } | ||
| 222 | |||
| 223 | int DSA_size(const DSA *r) | ||
| 224 | { | 224 | { |
| 225 | int ret,i; | 225 | int ret,i; |
| 226 | ASN1_INTEGER bs; | 226 | ASN1_INTEGER bs; |
| @@ -242,9 +242,8 @@ int DSA_size(DSA *r) | |||
| 242 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 242 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
| 243 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 243 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
| 244 | { | 244 | { |
| 245 | dsa_meth_num++; | 245 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, argl, argp, |
| 246 | return(CRYPTO_get_ex_new_index(dsa_meth_num-1, | 246 | new_func, dup_func, free_func); |
| 247 | &dsa_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 248 | } | 247 | } |
| 249 | 248 | ||
| 250 | int DSA_set_ex_data(DSA *d, int idx, void *arg) | 249 | int DSA_set_ex_data(DSA *d, int idx, void *arg) |
| @@ -257,8 +256,8 @@ void *DSA_get_ex_data(DSA *d, int idx) | |||
| 257 | return(CRYPTO_get_ex_data(&d->ex_data,idx)); | 256 | return(CRYPTO_get_ex_data(&d->ex_data,idx)); |
| 258 | } | 257 | } |
| 259 | 258 | ||
| 260 | #ifndef NO_DH | 259 | #ifndef OPENSSL_NO_DH |
| 261 | DH *DSA_dup_DH(DSA *r) | 260 | DH *DSA_dup_DH(const DSA *r) |
| 262 | { | 261 | { |
| 263 | /* DSA has p, q, g, optional pub_key, optional priv_key. | 262 | /* DSA has p, q, g, optional pub_key, optional priv_key. |
| 264 | * DH has p, optional length, g, optional pub_key, optional priv_key. | 263 | * DH has p, optional length, g, optional pub_key, optional priv_key. |
