From ed9e147695e4c5e800e83654baf365a634f3a2a7 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 12 Oct 2016 15:32:14 -0400 Subject: Abstract out mutex type. Make threads optional. --- src/lib/pubkey/dsa/dsa.cpp | 15 ++++++++++++++- src/lib/pubkey/rsa/rsa.cpp | 11 ++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/lib/pubkey') diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp index 15dc45373..9c8ae0821 100644 --- a/src/lib/pubkey/dsa/dsa.cpp +++ b/src/lib/pubkey/dsa/dsa.cpp @@ -17,7 +17,9 @@ #include #endif -#include +#if defined(BOTAN_TARGET_OS_HAS_THREADS) + #include +#endif namespace Botan { @@ -124,11 +126,17 @@ DSA_Signature_Operation::raw_sign(const byte msg[], size_t msg_len, const BigInt k = BigInt::random_integer(rng, 1, m_q); #endif +#if defined(BOTAN_TARGET_OS_HAS_THREADS) auto future_r = std::async(std::launch::async, [&]() { return m_mod_q.reduce(m_powermod_g_p(k)); }); BigInt s = inverse_mod(k, m_q); const BigInt r = future_r.get(); +#else + BigInt s = inverse_mod(k, m_q); + const BigInt r = m_mod_q.reduce(m_powermod_g_p(k)); +#endif + s = m_mod_q.multiply(s, mul_add(m_x, r, i)); // With overwhelming probability, a bug rather than actual zero r/s @@ -184,11 +192,16 @@ bool DSA_Verification_Operation::verify(const byte msg[], size_t msg_len, s = inverse_mod(s, m_q); +#if defined(BOTAN_TARGET_OS_HAS_THREADS) auto future_s_i = std::async(std::launch::async, [&]() { return m_powermod_g_p(m_mod_q.multiply(s, i)); }); BigInt s_r = m_powermod_y_p(m_mod_q.multiply(s, r)); BigInt s_i = future_s_i.get(); +#else + BigInt s_r = m_powermod_y_p(m_mod_q.multiply(s, r)); + BigInt s_i = m_powermod_g_p(m_mod_q.multiply(s, i)); +#endif s = m_mod_p.multiply(s_i, s_r); diff --git a/src/lib/pubkey/rsa/rsa.cpp b/src/lib/pubkey/rsa/rsa.cpp index b40f485e3..d201ca277 100644 --- a/src/lib/pubkey/rsa/rsa.cpp +++ b/src/lib/pubkey/rsa/rsa.cpp @@ -14,12 +14,16 @@ #include #include #include -#include #if defined(BOTAN_HAS_OPENSSL) #include #endif +#if defined(BOTAN_TARGET_OS_HAS_THREADS) +#include +#endif + + namespace Botan { size_t RSA_PublicKey::estimated_strength() const @@ -218,9 +222,14 @@ class RSA_Private_Operation BigInt private_op(const BigInt& m) const { +#if defined(BOTAN_TARGET_OS_HAS_THREADS) auto future_j1 = std::async(std::launch::async, m_powermod_d1_p, m); BigInt j2 = m_powermod_d2_q(m); BigInt j1 = future_j1.get(); +#else + BigInt j1 = m_powermod_d1_p(m); + BigInt j2 = m_powermod_d2_q(m); +#endif j1 = m_mod_p.reduce(sub_mul(j1, j2, m_c)); -- cgit v1.2.3