diff options
author | Jack Lloyd <[email protected]> | 2016-10-12 15:32:14 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-10-12 15:32:14 -0400 |
commit | ed9e147695e4c5e800e83654baf365a634f3a2a7 (patch) | |
tree | 59bad402cff7d7af9baa5fd79081d677b60afc83 /src/lib/pubkey | |
parent | d59b164a2ad2bc2290265530ac1a5c7be7855975 (diff) |
Abstract out mutex type. Make threads optional.
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r-- | src/lib/pubkey/dsa/dsa.cpp | 15 | ||||
-rw-r--r-- | src/lib/pubkey/rsa/rsa.cpp | 11 |
2 files changed, 24 insertions, 2 deletions
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 <botan/rfc6979.h> #endif -#include <future> +#if defined(BOTAN_TARGET_OS_HAS_THREADS) + #include <future> +#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 <botan/workfactor.h> #include <botan/der_enc.h> #include <botan/ber_dec.h> -#include <future> #if defined(BOTAN_HAS_OPENSSL) #include <botan/internal/openssl.h> #endif +#if defined(BOTAN_TARGET_OS_HAS_THREADS) +#include <future> +#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)); |