diff options
author | lloyd <[email protected]> | 2010-03-09 04:39:36 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-09 04:39:36 +0000 |
commit | d3e279ec353133e9f80f13a536aae15e49c2a206 (patch) | |
tree | a794134b2ce5ae403bace660c689db2730c98424 /src/pubkey | |
parent | ac0ec9b832a337c91cb451e0b8d12b77fa27a20c (diff) |
Add back async use for RSA, NR, DSA (was lost in mainline merge)
Diffstat (limited to 'src/pubkey')
-rw-r--r-- | src/pubkey/dsa/dsa.cpp | 19 | ||||
-rw-r--r-- | src/pubkey/nr/nr.cpp | 6 | ||||
-rw-r--r-- | src/pubkey/rsa/rsa.cpp | 4 |
3 files changed, 23 insertions, 6 deletions
diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp index feac712b8..2b9a73015 100644 --- a/src/pubkey/dsa/dsa.cpp +++ b/src/pubkey/dsa/dsa.cpp @@ -8,6 +8,7 @@ #include <botan/dsa.h> #include <botan/numthry.h> #include <botan/keypair.h> +#include <future> namespace Botan { @@ -95,10 +96,14 @@ DSA_Signature_Operation::sign(const byte msg[], u32bit msg_len, k.randomize(rng, q.bits()); while(k >= q); + auto future_r = std::async(std::launch::async, + [&]() { return mod_q.reduce(powermod_g_p(k)); }); + BigInt i(msg, msg_len); - BigInt r = mod_q.reduce(powermod_g_p(k)); - BigInt s = mod_q.multiply(inverse_mod(k, q), mul_add(x, r, i)); + BigInt s = inverse_mod(k, q); + BigInt r = future_r.get(); + s = mod_q.multiply(s, mul_add(x, r, i)); if(r.is_zero() || s.is_zero()) throw Internal_Error("DSA signature gen failure: r or s was zero"); @@ -134,8 +139,14 @@ bool DSA_Verification_Operation::verify(const byte msg[], u32bit msg_len, return false; s = inverse_mod(s, q); - s = mod_p.multiply(powermod_g_p(mod_q.multiply(s, i)), - powermod_y_p(mod_q.multiply(s, r))); + + auto future_s_i = std::async(std::launch::async, + [&]() { return powermod_g_p(mod_q.multiply(s, i)); }); + + BigInt s_r = powermod_y_p(mod_q.multiply(s, r)); + BigInt s_i = future_s_i.get(); + + s = mod_p.multiply(s_i, s_r); return (mod_q.reduce(s) == r); } diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp index cf59615da..440fa22e4 100644 --- a/src/pubkey/nr/nr.cpp +++ b/src/pubkey/nr/nr.cpp @@ -8,6 +8,7 @@ #include <botan/nr.h> #include <botan/numthry.h> #include <botan/keypair.h> +#include <future> namespace Botan { @@ -143,7 +144,10 @@ NR_Verification_Operation::verify_mr(const byte msg[], u32bit msg_len) if(c.is_zero() || c >= q || d >= q) throw Invalid_Argument("NR verification: Invalid signature"); - BigInt i = mod_p.multiply(powermod_g_p(d), powermod_y_p(c)); + auto future_y_c = std::async(std::launch::async, powermod_y_p, c); + BigInt g_d = powermod_g_p(d); + + BigInt i = mod_p.multiply(g_d, future_y_c.get()); return BigInt::encode(mod_q.reduce(c - i)); } diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp index 200e92821..e27b2056d 100644 --- a/src/pubkey/rsa/rsa.cpp +++ b/src/pubkey/rsa/rsa.cpp @@ -9,6 +9,7 @@ #include <botan/parsing.h> #include <botan/numthry.h> #include <botan/keypair.h> +#include <future> namespace Botan { @@ -89,8 +90,9 @@ BigInt RSA_Private_Operation::private_op(const BigInt& m) const if(m >= n) throw Invalid_Argument("RSA private op - input is too large"); - BigInt j1 = powermod_d1_p(m); + auto future_j1 = std::async(std::launch::async, powermod_d1_p, m); BigInt j2 = powermod_d2_q(m); + BigInt j1 = future_j1.get(); j1 = mod_p.reduce(sub_mul(j1, j2, c)); |