diff options
author | Adam Langley <agl@google.com> | 2015-04-13 21:04:14 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-04-14 23:10:27 +0300 |
commit | 683d7bd20a96a34d85341cd04b4c6309b0730852 (patch) | |
tree | e6f9f01d41862b133f97936b973f7e4e825bc802 /crypto/dsa | |
parent | ccdfbd9834511a473684caf4517bc5dcdf00fc58 (diff) |
Convert BN_MONT_CTX to new-style locking.
This introduces a per-RSA/DSA/DH lock. This is good for lock contention,
although pthread locks are depressingly bloated.
Change-Id: I07c4d1606fc35135fc141ebe6ba904a28c8f8a0c
Reviewed-on: https://boringssl-review.googlesource.com/4324
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/dsa')
-rw-r--r-- | crypto/dsa/dsa.c | 4 | ||||
-rw-r--r-- | crypto/dsa/dsa_impl.c | 11 |
2 files changed, 11 insertions, 4 deletions
diff --git a/crypto/dsa/dsa.c b/crypto/dsa/dsa.c index 5303714c..c5809562 100644 --- a/crypto/dsa/dsa.c +++ b/crypto/dsa/dsa.c @@ -70,6 +70,7 @@ #include <openssl/thread.h> #include "internal.h" +#include "../internal.h" extern const DSA_METHOD DSA_default_method; @@ -97,6 +98,8 @@ DSA *DSA_new_method(const ENGINE *engine) { dsa->write_params = 1; dsa->references = 1; + CRYPTO_MUTEX_init(&dsa->method_mont_p_lock); + if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, dsa, &dsa->ex_data)) { METHOD_unref(dsa->meth); OPENSSL_free(dsa); @@ -150,6 +153,7 @@ void DSA_free(DSA *dsa) { if (dsa->r != NULL) { BN_clear_free(dsa->r); } + CRYPTO_MUTEX_cleanup(&dsa->method_mont_p_lock); OPENSSL_free(dsa); } diff --git a/crypto/dsa/dsa_impl.c b/crypto/dsa/dsa_impl.c index aba7f854..c4df80bd 100644 --- a/crypto/dsa/dsa_impl.c +++ b/crypto/dsa/dsa_impl.c @@ -123,8 +123,9 @@ static int sign_setup(const DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BN_set_flags(&k, BN_FLG_CONSTTIME); - if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p, - CRYPTO_LOCK_DSA, dsa->p, ctx)) { + if (BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p, + (CRYPTO_MUTEX *)&dsa->method_mont_p_lock, dsa->p, + ctx) == NULL) { goto err; } @@ -365,12 +366,14 @@ static int verify(int *out_valid, const uint8_t *dgst, size_t digest_len, } mont = BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p, - CRYPTO_LOCK_DSA, dsa->p, ctx); + (CRYPTO_MUTEX *)&dsa->method_mont_p_lock, + dsa->p, ctx); if (!mont) { goto err; } - if (!BN_mod_exp2_mont(&t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx, mont)) { + if (!BN_mod_exp2_mont(&t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx, + mont)) { goto err; } |