From 7a62a8c05ddf02073108f4117a80065d2d8ae7ec Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 18 Nov 2009 08:54:45 +0000 Subject: Remove to_string, replacing with std::to_string Convert to_u32bit to use the new C++0x library func stoul instead of hand-written code. --- src/pubkey/rsa/rsa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pubkey/rsa') diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp index 83e6e1b17..38ea1eeca 100644 --- a/src/pubkey/rsa/rsa.cpp +++ b/src/pubkey/rsa/rsa.cpp @@ -60,7 +60,7 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng, { if(bits < 512) throw Invalid_Argument(algo_name() + ": Can't make a key that is only " + - to_string(bits) + " bits long"); + std::to_string(bits) + " bits long"); if(exp < 3 || exp % 2 == 0) throw Invalid_Argument(algo_name() + ": Invalid encryption exponent"); -- cgit v1.2.3 From d3e279ec353133e9f80f13a536aae15e49c2a206 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 9 Mar 2010 04:39:36 +0000 Subject: Add back async use for RSA, NR, DSA (was lost in mainline merge) --- src/pubkey/dsa/dsa.cpp | 19 +++++++++++++++---- src/pubkey/nr/nr.cpp | 6 +++++- src/pubkey/rsa/rsa.cpp | 4 +++- 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src/pubkey/rsa') 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 #include #include +#include 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 #include #include +#include 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 #include #include +#include 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)); -- cgit v1.2.3 From fcd3aba1ff6b8597b31165474573dbb339479c14 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 13 Oct 2010 03:34:49 +0000 Subject: Post-merge fixups --- src/engine/dyn_engine/dyn_engine.cpp | 2 +- src/hash/tiger/tiger.cpp | 2 +- src/pubkey/rsa/rsa.cpp | 1 + src/utils/parsing.h | 11 ++--------- 4 files changed, 5 insertions(+), 11 deletions(-) (limited to 'src/pubkey/rsa') diff --git a/src/engine/dyn_engine/dyn_engine.cpp b/src/engine/dyn_engine/dyn_engine.cpp index 83169f431..f48f1a06d 100644 --- a/src/engine/dyn_engine/dyn_engine.cpp +++ b/src/engine/dyn_engine/dyn_engine.cpp @@ -35,7 +35,7 @@ Dynamically_Loaded_Engine::Dynamically_Loaded_Engine( if(mod_version != 20100908) throw std::runtime_error("Incompatible version in " + library_path + " of " + - to_string(mod_version)); + std::to_string(mod_version)); creator_func creator = lib->resolve("create_engine"); diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp index 95d870857..32189952a 100644 --- a/src/hash/tiger/tiger.cpp +++ b/src/hash/tiger/tiger.cpp @@ -161,7 +161,7 @@ void Tiger::clear() std::string Tiger::name() const { return "Tiger(" + std::to_string(output_length()) + "," + - to_string(PASS) + ")"; + std::to_string(PASS) + ")"; } /* diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp index ebc06ddb7..2da366699 100644 --- a/src/pubkey/rsa/rsa.cpp +++ b/src/pubkey/rsa/rsa.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace Botan { diff --git a/src/utils/parsing.h b/src/utils/parsing.h index 12370bf2b..98dcd82b5 100644 --- a/src/utils/parsing.h +++ b/src/utils/parsing.h @@ -47,20 +47,13 @@ BOTAN_DLL std::vector parse_asn1_oid(const std::string& oid); BOTAN_DLL bool x500_name_cmp(const std::string& name1, const std::string& name2); -/** -* Convert a number to a string -* @param n the integer to convert to a string -* @param min_len the min length of the output string -* @return n convert to a string -*/ -BOTAN_DLL std::string to_string(u64bit n, size_t min_len = 0); - /** * Convert a string to a number * @param str the string to convert * @return number value of the string */ -BOTAN_DLL u32bit to_u32bit(const std::string& str); +inline u32bit to_u32bit(const std::string& str) + { return std::stoul(str); } /** * Convert a time specification to a number -- cgit v1.2.3