diff options
author | Alessandro Ghedini <alessandro@ghedini.me> | 2016-03-04 15:43:46 +0000 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-03-08 09:07:32 -0500 |
commit | d188a53617de68a707fe9459d4f4245d9a57cd9c (patch) | |
tree | 5280ea92a3c2772e7c0446efa6fede7eba6e7eb4 /crypto/dsa | |
parent | f989cd8c0bb3c579d112294bf8e304647b334ee8 (diff) | |
download | openssl-d188a53617de68a707fe9459d4f4245d9a57cd9c.tar.gz |
Convert CRYPTO_LOCK_{DH,DSA,RSA} to new multi-threading API
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/dsa')
-rw-r--r-- | crypto/dsa/dsa_lib.c | 23 | ||||
-rw-r--r-- | crypto/dsa/dsa_ossl.c | 4 |
2 files changed, 20 insertions, 7 deletions
diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c index f7795b27bd..3b99b3c2eb 100644 --- a/crypto/dsa/dsa_lib.c +++ b/crypto/dsa/dsa_lib.c @@ -115,7 +115,7 @@ DSA *DSA_new_method(ENGINE *engine) ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE); - return (NULL); + return NULL; } ret->meth = DSA_get_default_method(); #ifndef OPENSSL_NO_ENGINE @@ -141,17 +141,25 @@ DSA *DSA_new_method(ENGINE *engine) ret->references = 1; ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; + CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); - if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { + + ret->lock = CRYPTO_THREAD_lock_new(); + if (ret->lock == NULL) { #ifndef OPENSSL_NO_ENGINE ENGINE_finish(ret->engine); #endif CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); OPENSSL_free(ret); + return NULL; + } + + if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { + DSA_free(ret); ret = NULL; } - return (ret); + return ret; } void DSA_free(DSA *r) @@ -161,7 +169,7 @@ void DSA_free(DSA *r) if (r == NULL) return; - i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA); + CRYPTO_atomic_add(&r->references, -1, &i, r->lock); REF_PRINT_COUNT("DSA", r); if (i > 0) return; @@ -175,6 +183,8 @@ void DSA_free(DSA *r) CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); + CRYPTO_THREAD_lock_free(r->lock); + BN_clear_free(r->p); BN_clear_free(r->q); BN_clear_free(r->g); @@ -185,7 +195,10 @@ void DSA_free(DSA *r) int DSA_up_ref(DSA *r) { - int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA); + int i; + + if (CRYPTO_atomic_add(&r->references, 1, &i, r->lock) <= 0) + return 0; REF_PRINT_COUNT("DSA", r); REF_ASSERT_ISNT(i < 2); diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c index 0874e89141..f8b4647f04 100644 --- a/crypto/dsa/dsa_ossl.c +++ b/crypto/dsa/dsa_ossl.c @@ -265,7 +265,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p, - CRYPTO_LOCK_DSA, dsa->p, ctx)) + dsa->lock, dsa->p, ctx)) goto err; } @@ -388,7 +388,7 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, - CRYPTO_LOCK_DSA, dsa->p, ctx); + dsa->lock, dsa->p, ctx); if (!mont) goto err; } |