Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/crypto/dh
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2015-04-13 21:04:14 +0300
committerAdam Langley <agl@google.com>2015-04-14 23:10:27 +0300
commit683d7bd20a96a34d85341cd04b4c6309b0730852 (patch)
treee6f9f01d41862b133f97936b973f7e4e825bc802 /crypto/dh
parentccdfbd9834511a473684caf4517bc5dcdf00fc58 (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/dh')
-rw-r--r--crypto/dh/dh.c4
-rw-r--r--crypto/dh/dh_impl.c9
2 files changed, 9 insertions, 4 deletions
diff --git a/crypto/dh/dh.c b/crypto/dh/dh.c
index 7a50da7b..86804bf8 100644
--- a/crypto/dh/dh.c
+++ b/crypto/dh/dh.c
@@ -66,6 +66,7 @@
#include <openssl/thread.h>
#include "internal.h"
+#include "../internal.h"
extern const DH_METHOD DH_default_method;
@@ -90,6 +91,8 @@ DH *DH_new_method(const ENGINE *engine) {
}
METHOD_ref(dh->meth);
+ CRYPTO_MUTEX_init(&dh->method_mont_p_lock);
+
dh->references = 1;
if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, dh, &dh->ex_data)) {
OPENSSL_free(dh);
@@ -131,6 +134,7 @@ void DH_free(DH *dh) {
if (dh->counter != NULL) BN_clear_free(dh->counter);
if (dh->pub_key != NULL) BN_clear_free(dh->pub_key);
if (dh->priv_key != NULL) BN_clear_free(dh->priv_key);
+ CRYPTO_MUTEX_cleanup(&dh->method_mont_p_lock);
OPENSSL_free(dh);
}
diff --git a/crypto/dh/dh_impl.c b/crypto/dh/dh_impl.c
index 5c4d6372..81d777d0 100644
--- a/crypto/dh/dh_impl.c
+++ b/crypto/dh/dh_impl.c
@@ -62,6 +62,7 @@
#include "internal.h"
+
#define OPENSSL_DH_MAX_MODULUS_BITS 10000
static int generate_parameters(DH *ret, int prime_bits, int generator, BN_GENCB *cb) {
@@ -207,8 +208,8 @@ static int generate_key(DH *dh) {
pub_key = dh->pub_key;
}
- mont =
- BN_MONT_CTX_set_locked(&dh->method_mont_p, CRYPTO_LOCK_DH, dh->p, ctx);
+ mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
+ dh->p, ctx);
if (!mont) {
goto err;
}
@@ -282,8 +283,8 @@ static int compute_key(DH *dh, unsigned char *out, const BIGNUM *pub_key) {
goto err;
}
- mont =
- BN_MONT_CTX_set_locked(&dh->method_mont_p, CRYPTO_LOCK_DH, dh->p, ctx);
+ mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
+ dh->p, ctx);
if (!mont) {
goto err;
}