From 327115405b0f483c2b432e2233f355a349b1f9d7 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 16:38:08 +0000 Subject: Replace the (deprecated) auto_ptr with unique_ptr. This was mostly a s/auto_ptr/unique_ptr/, except in the CVC code and one function in ECDSA, which relied on auto_ptr's move semantics (ugh) and had to be modified in various ways. --- src/pubkey/ec_dompar/ec_dompar.cpp | 2 +- src/pubkey/ecc_key/ecc_key.cpp | 2 +- src/pubkey/ecc_key/ecc_key.h | 4 ++-- src/pubkey/ecdsa/ecdsa.cpp | 11 +++++------ src/pubkey/eckaeg/eckaeg.cpp | 4 ++-- src/pubkey/eckaeg/eckaeg.h | 2 +- src/pubkey/keypair/keypair.cpp | 8 ++++---- src/pubkey/pubkey/pkcs8.cpp | 10 +++++----- src/pubkey/pubkey/x509_key.cpp | 6 +++--- 9 files changed, 24 insertions(+), 25 deletions(-) (limited to 'src/pubkey') diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp index 6cfcc0619..c4634877e 100644 --- a/src/pubkey/ec_dompar/ec_dompar.cpp +++ b/src/pubkey/ec_dompar/ec_dompar.cpp @@ -545,7 +545,7 @@ EC_Domain_Params decode_ber_ec_dompar(SecureVector const& encoded) BER_Decoder dec(encoded); BER_Object obj = dec.get_next_object(); ASN1_Tag tag = obj.type_tag; - std::auto_ptr p_result; + std::unique_ptr p_result; if(tag == OBJECT_ID) { diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp index 9af63bdcd..bebfc3705 100644 --- a/src/pubkey/ecc_key/ecc_key.cpp +++ b/src/pubkey/ecc_key/ecc_key.cpp @@ -166,7 +166,7 @@ void EC_PrivateKey::generate_private_key(RandomNumberGenerator& rng) BigInt tmp_private_value(0); tmp_private_value = BigInt::random_integer(rng, 1, mp_dom_pars->get_order()); - mp_public_point = std::auto_ptr( new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr( new PointGFp (mp_dom_pars->get_base_point())); mp_public_point->mult_this_secure(tmp_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h index 0ca9a0e75..9d5f57d9f 100644 --- a/src/pubkey/ecc_key/ecc_key.h +++ b/src/pubkey/ecc_key/ecc_key.h @@ -103,8 +103,8 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key SecureVector m_enc_public_point; // stores the public point - std::auto_ptr mp_dom_pars; - std::auto_ptr mp_public_point; + std::unique_ptr mp_dom_pars; + std::unique_ptr mp_public_point; EC_dompar_enc m_param_enc; }; diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index 9640c6397..3e3bbf38a 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -20,7 +20,7 @@ namespace Botan { ECDSA_PrivateKey::ECDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& dom_pars) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_pars)); generate_private_key(rng); try @@ -68,11 +68,10 @@ void ECDSA_PublicKey::set_domain_parameters(const EC_Domain_Params& dom_pars) throw Invalid_State("EC_PublicKey::set_domain_parameters(): point does not lie on provided curve"); } - std::auto_ptr p_tmp_pars(new EC_Domain_Params(dom_pars)); - ECDSA_Core tmp_ecdsa_core(*p_tmp_pars, BigInt(0), tmp_pp); + mp_dom_pars.reset(new EC_Domain_Params(dom_pars)); + ECDSA_Core tmp_ecdsa_core(*mp_dom_pars, BigInt(0), tmp_pp); mp_public_point.reset(new PointGFp(tmp_pp)); m_ecdsa_core = tmp_ecdsa_core; - mp_dom_pars = p_tmp_pars; } void ECDSA_PublicKey::set_all_values(const ECDSA_PublicKey& other) @@ -131,8 +130,8 @@ bool ECDSA_PublicKey::verify(const byte message[], ECDSA_PublicKey::ECDSA_PublicKey(const EC_Domain_Params& dom_par, const PointGFp& public_point) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr(new PointGFp(public_point)); m_param_enc = ENC_EXPLICIT; m_ecdsa_core = ECDSA_Core(*mp_dom_pars, BigInt(0), *mp_public_point); } diff --git a/src/pubkey/eckaeg/eckaeg.cpp b/src/pubkey/eckaeg/eckaeg.cpp index 0d094e2e1..1b315d101 100644 --- a/src/pubkey/eckaeg/eckaeg.cpp +++ b/src/pubkey/eckaeg/eckaeg.cpp @@ -63,8 +63,8 @@ void ECKAEG_PublicKey::X509_load_hook() ECKAEG_PublicKey::ECKAEG_PublicKey(EC_Domain_Params const& dom_par, PointGFp const& public_point) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr(new PointGFp(public_point)); if(mp_public_point->get_curve() != mp_dom_pars->get_curve()) { throw Invalid_Argument("ECKAEG_PublicKey(): curve of arg. point and curve of arg. domain parameters are different"); diff --git a/src/pubkey/eckaeg/eckaeg.h b/src/pubkey/eckaeg/eckaeg.h index 31b65740c..053a40e4f 100644 --- a/src/pubkey/eckaeg/eckaeg.h +++ b/src/pubkey/eckaeg/eckaeg.h @@ -89,7 +89,7 @@ class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey, ECKAEG_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& dom_pars) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_pars)); generate_private_key(rng); mp_public_point->check_invariants(); m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, m_private_value, *mp_public_point); diff --git a/src/pubkey/keypair/keypair.cpp b/src/pubkey/keypair/keypair.cpp index 486577fc5..7eaa33395 100644 --- a/src/pubkey/keypair/keypair.cpp +++ b/src/pubkey/keypair/keypair.cpp @@ -22,8 +22,8 @@ void check_key(RandomNumberGenerator& rng, if(encryptor->maximum_input_size() == 0) return; - std::auto_ptr enc(encryptor); - std::auto_ptr dec(decryptor); + std::unique_ptr enc(encryptor); + std::unique_ptr dec(decryptor); SecureVector message(enc->maximum_input_size() - 1); rng.randomize(message, message.size()); @@ -43,8 +43,8 @@ void check_key(RandomNumberGenerator& rng, void check_key(RandomNumberGenerator& rng, PK_Signer* signer, PK_Verifier* verifier) { - std::auto_ptr sig(signer); - std::auto_ptr ver(verifier); + std::unique_ptr sig(signer); + std::unique_ptr ver(verifier); SecureVector message(16); rng.randomize(message, message.size()); diff --git a/src/pubkey/pubkey/pkcs8.cpp b/src/pubkey/pubkey/pkcs8.cpp index 8a464ecfe..87f05da92 100644 --- a/src/pubkey/pubkey/pkcs8.cpp +++ b/src/pubkey/pubkey/pkcs8.cpp @@ -89,7 +89,7 @@ SecureVector PKCS8_decode(DataSource& source, const User_Interface& ui, if(is_encrypted) { DataSource_Memory params(pbe_alg_id.parameters); - std::auto_ptr pbe(get_pbe(pbe_alg_id.oid, params)); + std::unique_ptr pbe(get_pbe(pbe_alg_id.oid, params)); User_Interface::UI_Result result = User_Interface::OK; const std::string passphrase = @@ -138,7 +138,7 @@ SecureVector PKCS8_decode(DataSource& source, const User_Interface& ui, */ void encode(const Private_Key& key, Pipe& pipe, X509_Encoding encoding) { - std::auto_ptr encoder(key.pkcs8_encoder()); + std::unique_ptr encoder(key.pkcs8_encoder()); if(!encoder.get()) throw Encoding_Error("PKCS8::encode: Key does not support encoding"); @@ -175,7 +175,7 @@ void encrypt_key(const Private_Key& key, encode(key, raw_key, RAW_BER); raw_key.end_msg(); - std::auto_ptr pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE))); + std::unique_ptr pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE))); pbe->new_params(rng); pbe->set_key(pass); @@ -244,13 +244,13 @@ Private_Key* load_key(DataSource& source, throw PKCS8_Exception("Unknown algorithm OID: " + alg_id.oid.as_string()); - std::auto_ptr key(get_private_key(alg_name)); + std::unique_ptr key(get_private_key(alg_name)); if(!key.get()) throw PKCS8_Exception("Unknown PK algorithm/OID: " + alg_name + ", " + alg_id.oid.as_string()); - std::auto_ptr decoder(key->pkcs8_decoder(rng)); + std::unique_ptr decoder(key->pkcs8_decoder(rng)); if(!decoder.get()) throw Decoding_Error("Key does not support PKCS #8 decoding"); diff --git a/src/pubkey/pubkey/x509_key.cpp b/src/pubkey/pubkey/x509_key.cpp index 455e627f3..f1fc59410 100644 --- a/src/pubkey/pubkey/x509_key.cpp +++ b/src/pubkey/pubkey/x509_key.cpp @@ -24,7 +24,7 @@ namespace X509 { */ void encode(const Public_Key& key, Pipe& pipe, X509_Encoding encoding) { - std::auto_ptr encoder(key.x509_encoder()); + std::unique_ptr encoder(key.x509_encoder()); if(!encoder.get()) throw Encoding_Error("X509::encode: Key does not support encoding"); @@ -94,12 +94,12 @@ Public_Key* load_key(DataSource& source) throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string()); - std::auto_ptr key_obj(get_public_key(alg_name)); + std::unique_ptr key_obj(get_public_key(alg_name)); if(!key_obj.get()) throw Decoding_Error("Unknown PK algorithm/OID: " + alg_name + ", " + alg_id.oid.as_string()); - std::auto_ptr decoder(key_obj->x509_decoder()); + std::unique_ptr decoder(key_obj->x509_decoder()); if(!decoder.get()) throw Decoding_Error("Key does not support X.509 decoding"); -- cgit v1.2.3 From aa361909f881b791cdce67993f3ab0d6af47c140 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 17:40:48 +0000 Subject: In IF decryption, two large powmods are done, one mod p and one mod q. Spawn one of them off in a new thread and compute the other on the current thread. Performance on my Core2 shows a 60 to 90% improvement in overall speed in RSA private key operations. Will probably be even better once std::async is available (not currently in GCC) since it will probably use a thread pool which will amortize the thread creation/shutdown cost. --- src/pubkey/if_algo/if_op.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/pubkey') diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 27aef453e..a59c7d5f9 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include namespace Botan { @@ -38,8 +40,27 @@ BigInt Default_IF_Op::private_op(const BigInt& i) const if(q == 0) throw Internal_Error("Default_IF_Op::private_op: No private key"); - BigInt j1 = powermod_d1_p(i); + /* + * A simple std::bind(powermod_d1_p, i) would work instead of a + * lambda but GCC 4.5's std::result_of doesn't use decltype and gets + * confused + * + * Todo: use std::async() once it is in GCC + * auto future_j1 = std::async(std::bind(powermod_d1_p, i)); + * BigInt j2 = powermod_d2_q(i); + * BigInt j1 = future.get(); + */ + std::packaged_task task_j1([&]() { return powermod_d1_p(i); }); + auto future_j1 = task_j1.get_future(); + + std::thread thr_j1(std::move(task_j1)); + BigInt j2 = powermod_d2_q(i); + + BigInt j1 = future_j1.get(); + + thr_j1.join(); + j1 = reducer.reduce(sub_mul(j1, j2, c)); return mul_add(j1, q, j2); } -- cgit v1.2.3 From e25d4ec4612f74bfed1ffe34cc07a798c9e7a4ce Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 17:50:30 +0000 Subject: Use a thread to compute half of the DSA verification. 20-90% faster depending on key size on a Core2. --- src/pubkey/dsa/dsa_op.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/pubkey') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 5b921441d..114731eea 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -6,6 +6,8 @@ */ #include +#include +#include namespace Botan { @@ -40,8 +42,23 @@ bool Default_DSA_Op::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))); + + // Todo: use async() + + std::packaged_task task_s_i( + [&]() { return powermod_g_p(mod_q.multiply(s, i)); }); + + auto future_s_i = task_s_i.get_future(); + + std::thread thr_s_i(std::move(task_s_i)); + + BigInt s_r = powermod_y_p(mod_q.multiply(s, r)); + + BigInt s_i = future_s_i.get(); + + thr_s_i.join(); + + s = mod_p.multiply(s_i, s_r); return (mod_q.reduce(s) == r); } -- cgit v1.2.3 From 0467bf03eae3ace3412b5218210eb15b6c6bd30b Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 18:17:47 +0000 Subject: Also parallelize DSA signature generation, though due to critical path constraints there isn't that much parallelization to extract. Slightly faster; better for smaller key sizes as once a certain point is reached one thread is doing a lot more work than the other. --- src/pubkey/dsa/dsa_op.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/pubkey') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 114731eea..4c84667eb 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -75,8 +75,19 @@ SecureVector Default_DSA_Op::sign(const byte in[], u32bit length, const BigInt& q = group.get_q(); BigInt i(in, length); - BigInt r = mod_q.reduce(powermod_g_p(k)); - BigInt s = mod_q.multiply(inverse_mod(k, q), mul_add(x, r, i)); + std::packaged_task task_r( + [&]() { return mod_q.reduce(powermod_g_p(k)); }); + + auto future_r = task_r.get_future(); + + std::thread thr_r(std::move(task_r)); + + BigInt s = inverse_mod(k, q); + + BigInt r = future_r.get(); + thr_r.join(); + + s = mod_q.multiply(s, mul_add(x, r, i)); if(r.is_zero() || s.is_zero()) throw Internal_Error("Default_DSA_Op::sign: r or s was zero"); -- cgit v1.2.3 From d5310f79218a960fea4b8522d4529305971334ce Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 17 Nov 2009 21:45:09 +0000 Subject: Add a simple version of std::async as std_async in async.h and use it in the RSA and DSA ops. --- src/pubkey/dsa/dsa_op.cpp | 27 +++++---------------------- src/pubkey/if_algo/if_op.cpp | 21 ++++----------------- src/utils/async.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 src/utils/async.h (limited to 'src/pubkey') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 4c84667eb..03eaebfb0 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -1,13 +1,12 @@ /* * DSA Operations -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include -#include -#include +#include namespace Botan { @@ -43,21 +42,12 @@ bool Default_DSA_Op::verify(const byte msg[], u32bit msg_len, s = inverse_mod(s, q); - // Todo: use async() - - std::packaged_task task_s_i( + auto future_s_i = std_async( [&]() { return powermod_g_p(mod_q.multiply(s, i)); }); - auto future_s_i = task_s_i.get_future(); - - std::thread thr_s_i(std::move(task_s_i)); - BigInt s_r = powermod_y_p(mod_q.multiply(s, r)); - BigInt s_i = future_s_i.get(); - thr_s_i.join(); - s = mod_p.multiply(s_i, s_r); return (mod_q.reduce(s) == r); @@ -72,20 +62,13 @@ SecureVector Default_DSA_Op::sign(const byte in[], u32bit length, if(x == 0) throw Internal_Error("Default_DSA_Op::sign: No private key"); + auto future_r = std_async([&]() { return mod_q.reduce(powermod_g_p(k)); }); + const BigInt& q = group.get_q(); BigInt i(in, length); - std::packaged_task task_r( - [&]() { return mod_q.reduce(powermod_g_p(k)); }); - - auto future_r = task_r.get_future(); - - std::thread thr_r(std::move(task_r)); - BigInt s = inverse_mod(k, q); - BigInt r = future_r.get(); - thr_r.join(); s = mod_q.multiply(s, mul_add(x, r, i)); diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index a59c7d5f9..7974bf4f0 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -1,14 +1,13 @@ /* -* IF (RSA/RW) Operation -* (C) 1999-2007 Jack Lloyd +* Integer Factorization Scheme (RSA/RW) Operation +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include #include -#include -#include +#include namespace Botan { @@ -44,23 +43,11 @@ BigInt Default_IF_Op::private_op(const BigInt& i) const * A simple std::bind(powermod_d1_p, i) would work instead of a * lambda but GCC 4.5's std::result_of doesn't use decltype and gets * confused - * - * Todo: use std::async() once it is in GCC - * auto future_j1 = std::async(std::bind(powermod_d1_p, i)); - * BigInt j2 = powermod_d2_q(i); - * BigInt j1 = future.get(); */ - std::packaged_task task_j1([&]() { return powermod_d1_p(i); }); - auto future_j1 = task_j1.get_future(); - - std::thread thr_j1(std::move(task_j1)); - + auto future_j1 = std_async([&]() { return powermod_d1_p(i); }); BigInt j2 = powermod_d2_q(i); - BigInt j1 = future_j1.get(); - thr_j1.join(); - j1 = reducer.reduce(sub_mul(j1, j2, c)); return mul_add(j1, q, j2); } diff --git a/src/utils/async.h b/src/utils/async.h new file mode 100644 index 000000000..85702c114 --- /dev/null +++ b/src/utils/async.h @@ -0,0 +1,33 @@ +/** +* Standin for C++0x's std::async +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ASYNC_H__ +#define BOTAN_ASYNC_H__ + +#include +#include + +namespace Botan { + +/** +* A simple version of std::async (as it is not in GCC 4.5) +* Will be removed once GCC supports it natively +*/ +template +auto std_async(F f) -> std::unique_future + { + typedef decltype(f()) result_type; + std::packaged_task task(std::move(f)); + std::unique_future future = task.get_future(); + std::thread thread(std::move(task)); + thread.detach(); + return future; + } + +} + +#endif -- cgit v1.2.3 From 061733a4f765a4a40ae12108bc8e61a9bcf3a4d8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 18 Nov 2009 01:41:31 +0000 Subject: Use async in ElGamal encryption and Nyberg-Rueppel verification --- src/math/numbertheory/powm_fw.cpp | 35 +++++++++++++++++++++++++++++------ src/pubkey/elgamal/elg_op.cpp | 6 ++++-- src/pubkey/nr/nr_op.cpp | 8 ++++++-- 3 files changed, 39 insertions(+), 10 deletions(-) (limited to 'src/pubkey') diff --git a/src/math/numbertheory/powm_fw.cpp b/src/math/numbertheory/powm_fw.cpp index b764ee7aa..e4272f20d 100644 --- a/src/math/numbertheory/powm_fw.cpp +++ b/src/math/numbertheory/powm_fw.cpp @@ -77,17 +77,40 @@ BigInt Fixed_Window_Exponentiator::execute() const { const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits; - BigInt x = 1; - for(u32bit j = exp_nibbles; j > 0; --j) + if(exp_nibbles == 0) + return 1; + + BigInt x1 = 1; + + for(u32bit j = 0; j != exp_nibbles / 2; ++j) + { + for(u32bit k = 0; k != window_bits; ++k) + x1 = reducer.square(x1); + + u32bit nibble = exp.get_substring(window_bits*(exp_nibbles-1-j), + window_bits); + + if(nibble) + x1 = reducer.multiply(x1, g[nibble-1]); + } + + for(u32bit k = 0; k != window_bits; ++k) + x1 = reducer.square(x1); + BigInt x2 = 1; + + for(u32bit j = exp_nibbles / 2; j != exp_nibbles; ++j) { for(u32bit k = 0; k != window_bits; ++k) - x = reducer.square(x); + x2 = reducer.square(x2); + + u32bit nibble = exp.get_substring(window_bits*(exp_nibbles-1-j), + window_bits); - u32bit nibble = exp.get_substring(window_bits*(j-1), window_bits); if(nibble) - x = reducer.multiply(x, g[nibble-1]); + x2 = reducer.multiply(x2, g[nibble-1]); } - return x; + + return reducer.multiply(x1, x2); } /* diff --git a/src/pubkey/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index 1e476ab7a..db828a300 100644 --- a/src/pubkey/elgamal/elg_op.cpp +++ b/src/pubkey/elgamal/elg_op.cpp @@ -1,11 +1,12 @@ /* * ElGamal Operations -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include +#include namespace Botan { @@ -33,8 +34,9 @@ SecureVector Default_ELG_Op::encrypt(const byte in[], u32bit length, if(m >= p) throw Invalid_Argument("Default_ELG_Op::encrypt: Input is too large"); - BigInt a = powermod_g_p(k); + auto future_a = std_async([&]() { return powermod_g_p(k); }); BigInt b = mod_p.multiply(m, powermod_y_p(k)); + BigInt a = future_a.get(); SecureVector output(2*p.bytes()); a.binary_encode(output + (p.bytes() - a.bytes())); diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index b5efa3d37..49aa9fc00 100644 --- a/src/pubkey/nr/nr_op.cpp +++ b/src/pubkey/nr/nr_op.cpp @@ -1,11 +1,12 @@ /* * NR Operations -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include +#include namespace Botan { @@ -37,7 +38,10 @@ SecureVector Default_NR_Op::verify(const byte in[], u32bit length) const if(c.is_zero() || c >= q || d >= q) throw Invalid_Argument("Default_NR_Op::verify: Invalid signature"); - BigInt i = mod_p.multiply(powermod_g_p(d), powermod_y_p(c)); + auto future_y_c = std_async([&]() { return 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)); } -- cgit v1.2.3 From 6e45f118d112ee55b980a262b8b9ec67e66e9268 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 18 Nov 2009 07:20:44 +0000 Subject: auto_ptr is unique_ptr in C++0x --- src/pubkey/ecdsa/ecdsa.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pubkey') diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index aba571eb6..ea90010b1 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -37,10 +37,10 @@ ECDSA_PrivateKey::ECDSA_PrivateKey(RandomNumberGenerator& rng, ECDSA_PrivateKey::ECDSA_PrivateKey(const EC_Domain_Params& domain, const BigInt& x) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(domain)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(domain)); m_private_value = x; - mp_public_point = std::auto_ptr(new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr(new PointGFp (mp_dom_pars->get_base_point())); mp_public_point->mult_this_secure(m_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); -- cgit v1.2.3 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. --- checks/pk_bench.cpp | 16 ++++----- src/asn1/asn1_int.cpp | 4 +-- src/asn1/asn1_oid.cpp | 2 +- src/asn1/asn1_str.cpp | 2 +- src/asn1/asn1_tm.cpp | 47 +++++++++++++++----------- src/asn1/der_enc.cpp | 2 +- src/block/lion/lion.cpp | 2 +- src/block/misty1/misty1.cpp | 2 +- src/block/rc5/rc5.cpp | 2 +- src/block/safer/safer_sk.cpp | 2 +- src/cert/cvc/asn1_eac_tm.cpp | 66 ++++++++++++++++++------------------- src/cert/x509/pkcs10.cpp | 2 +- src/cert/x509/x509_crl.cpp | 2 +- src/cert/x509/x509cert.cpp | 2 +- src/engine/openssl/arc4_openssl.cpp | 2 +- src/filters/hex/hex.cpp | 2 +- src/filters/modes/cfb/cfb.cpp | 2 +- src/filters/modes/eax/eax.cpp | 2 +- src/filters/pipe.cpp | 2 +- src/hash/skein/skein_512.cpp | 2 +- src/hash/tiger/tiger.cpp | 6 ++-- src/math/numbertheory/dsa_gen.cpp | 6 ++-- src/math/numbertheory/make_prm.cpp | 4 +-- src/pubkey/dl_group/dl_group.cpp | 8 ++--- src/pubkey/pubkey.cpp | 4 +-- src/pubkey/rsa/rsa.cpp | 2 +- src/pubkey/rw/rw.cpp | 2 +- src/stream/arc4/arc4.cpp | 2 +- src/utils/charset.cpp | 2 +- src/utils/datastor/datastor.cpp | 2 +- src/utils/exceptn.cpp | 6 ++-- src/utils/parsing.cpp | 49 +-------------------------- src/utils/parsing.h | 6 ++-- src/utils/version.cpp | 6 ++-- 34 files changed, 115 insertions(+), 155 deletions(-) (limited to 'src/pubkey') diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 43d15010a..72c5f53f6 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -215,7 +215,7 @@ void benchmark_rsa(RandomNumberGenerator& rng, sig_timer, rng, 10000, seconds); } - const std::string rsa_keylen = "RSA-" + to_string(keylen); + const std::string rsa_keylen = "RSA-" + std::to_string(keylen); report.report(rsa_keylen, keygen_timer); report.report(rsa_keylen, verify_timer); @@ -266,7 +266,7 @@ void benchmark_rw(RandomNumberGenerator& rng, benchmark_sig_ver(*ver, *sig, verify_timer, sig_timer, rng, 10000, seconds); } - const std::string nm = "RW-" + to_string(keylen); + const std::string nm = "RW-" + std::to_string(keylen); report.report(nm, keygen_timer); report.report(nm, verify_timer); report.report(nm, sig_timer); @@ -301,7 +301,7 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, if(hashbits == 521) hashbits = 512; - const std::string padding = "EMSA1(SHA-" + to_string(hashbits) + ")"; + const std::string padding = "EMSA1(SHA-" + std::to_string(hashbits) + ")"; Timer keygen_timer("keygen"); Timer verify_timer(padding + " verify"); @@ -321,7 +321,7 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, sig_timer, rng, 1000, seconds); } - const std::string nm = "ECDSA-" + to_string(pbits); + const std::string nm = "ECDSA-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, verify_timer); @@ -387,7 +387,7 @@ void benchmark_eckaeg(RandomNumberGenerator& rng, } } - const std::string nm = "ECKAEG-" + to_string(pbits); + const std::string nm = "ECKAEG-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, kex_timer); } @@ -415,7 +415,7 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng, u32bit pbits = to_u32bit(split_on(domains[j], '/')[2]); u32bit qbits = (pbits <= 1024) ? 160 : 256; - const std::string padding = "EMSA1(SHA-" + to_string(qbits) + ")"; + const std::string padding = "EMSA1(SHA-" + std::to_string(qbits) + ")"; Timer keygen_timer("keygen"); Timer verify_timer(padding + " verify"); @@ -437,7 +437,7 @@ void benchmark_dsa_nr(RandomNumberGenerator& rng, sig_timer, rng, 1000, seconds); } - const std::string nm = algo_name + "-" + to_string(pbits); + const std::string nm = algo_name + "-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, verify_timer); report.report(nm, sig_timer); @@ -606,7 +606,7 @@ void benchmark_elg(RandomNumberGenerator& rng, benchmark_enc_dec(*enc, *dec, enc_timer, dec_timer, rng, 1000, seconds); } - const std::string nm = algo_name + "-" + to_string(pbits); + const std::string nm = algo_name + "-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, enc_timer); report.report(nm, dec_timer); diff --git a/src/asn1/asn1_int.cpp b/src/asn1/asn1_int.cpp index 5e18f3961..af01d8fa3 100644 --- a/src/asn1/asn1_int.cpp +++ b/src/asn1/asn1_int.cpp @@ -20,11 +20,11 @@ BER_Decoding_Error::BER_Decoding_Error(const std::string& str) : Decoding_Error("BER: " + str) {} BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag) : - BER_Decoding_Error(str + ": " + to_string(tag)) {} + BER_Decoding_Error(str + ": " + std::to_string(tag)) {} BER_Bad_Tag::BER_Bad_Tag(const std::string& str, ASN1_Tag tag1, ASN1_Tag tag2) : - BER_Decoding_Error(str + ": " + to_string(tag1) + "/" + to_string(tag2)) {} + BER_Decoding_Error(str + ": " + std::to_string(tag1) + "/" + std::to_string(tag2)) {} namespace ASN1 { diff --git a/src/asn1/asn1_oid.cpp b/src/asn1/asn1_oid.cpp index 531ceb9b2..c72ee7a1a 100644 --- a/src/asn1/asn1_oid.cpp +++ b/src/asn1/asn1_oid.cpp @@ -44,7 +44,7 @@ std::string OID::as_string() const std::string oid_str; for(u32bit j = 0; j != id.size(); ++j) { - oid_str += to_string(id[j]); + oid_str += std::to_string(id[j]); if(j != id.size() - 1) oid_str += '.'; } diff --git a/src/asn1/asn1_str.cpp b/src/asn1/asn1_str.cpp index 25782e239..892a44472 100644 --- a/src/asn1/asn1_str.cpp +++ b/src/asn1/asn1_str.cpp @@ -89,7 +89,7 @@ ASN1_String::ASN1_String(const std::string& str, ASN1_Tag t) : tag(t) tag != UTF8_STRING && tag != BMP_STRING) throw Invalid_Argument("ASN1_String: Unknown string type " + - to_string(tag)); + std::to_string(tag)); } /* diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp index c57d1bc73..9df10f4a3 100644 --- a/src/asn1/asn1_tm.cpp +++ b/src/asn1/asn1_tm.cpp @@ -103,11 +103,13 @@ void X509_Time::set_to(const std::string& time_str) void X509_Time::set_to(const std::string& t_spec, ASN1_Tag tag) { if(tag != GENERALIZED_TIME && tag != UTC_TIME) - throw Invalid_Argument("X509_Time: Invalid tag " + to_string(tag)); + throw Invalid_Argument("X509_Time: Invalid tag " + std::to_string(tag)); + if(tag == GENERALIZED_TIME && t_spec.size() != 13 && t_spec.size() != 15) throw Invalid_Argument("Invalid GeneralizedTime: " + t_spec); if(tag == UTC_TIME && t_spec.size() != 11 && t_spec.size() != 13) throw Invalid_Argument("Invalid UTCTime: " + t_spec); + if(t_spec[t_spec.size()-1] != 'Z') throw Invalid_Argument("Invalid time encoding: " + t_spec); @@ -179,21 +181,30 @@ std::string X509_Time::as_string() const if(time_is_set() == false) throw Invalid_State("X509_Time::as_string: No time set"); - std::string asn1rep; - if(tag == GENERALIZED_TIME) - asn1rep = to_string(year, 4); - else + u32bit full_year = year; + + if(tag == UTC_TIME) { if(year < 1950 || year >= 2050) throw Encoding_Error("X509_Time: The time " + readable_string() + " cannot be encoded as a UTCTime"); - u32bit asn1year = (year >= 2000) ? (year - 2000) : (year - 1900); - asn1rep = to_string(asn1year, 2); + + full_year = (year >= 2000) ? (year - 2000) : (year - 1900); } - asn1rep += to_string(month, 2) + to_string(day, 2); - asn1rep += to_string(hour, 2) + to_string(minute, 2) + to_string(second, 2); - asn1rep += "Z"; - return asn1rep; + + std::string repr = std::to_string(full_year*10000000000 + + month*100000000 + + day*1000000 + + hour*10000 + + minute*100 + + second) + "Z"; + + u32bit desired_size = (tag == UTC_TIME) ? 13 : 15; + + while(repr.size() < desired_size) + repr = "0" + repr; + + return repr; } /* @@ -212,14 +223,12 @@ std::string X509_Time::readable_string() const if(time_is_set() == false) throw Invalid_State("X509_Time::readable_string: No time set"); - std::string readable; - readable += to_string(year, 4) + "/"; - readable += to_string(month ) + "/"; - readable += to_string(day ) + " "; - readable += to_string(hour ) + ":"; - readable += to_string(minute, 2) + ":"; - readable += to_string(second, 2) + " UTC"; - return readable; + std::string output(24, 0); + + std::sprintf(&output[0], "%04d/%02d/%02d %02d:%02d:%02d UTC", + year, month, day, hour, minute, second); + + return output; } /* diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp index bee269431..1863e400d 100644 --- a/src/asn1/der_enc.cpp +++ b/src/asn1/der_enc.cpp @@ -24,7 +24,7 @@ SecureVector encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) { if((class_tag | 0xE0) != 0xE0) throw Encoding_Error("DER_Encoder: Invalid class tag " + - to_string(class_tag)); + std::to_string(class_tag)); SecureVector encoded_tag; if(type_tag <= 30) diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp index d8822b9f2..81252f5e3 100644 --- a/src/block/lion/lion.cpp +++ b/src/block/lion/lion.cpp @@ -81,7 +81,7 @@ std::string Lion::name() const { return "Lion(" + hash->name() + "," + cipher->name() + "," + - to_string(BLOCK_SIZE) + ")"; + std::to_string(BLOCK_SIZE) + ")"; } /* diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp index 8a92824cc..56cd7446c 100644 --- a/src/block/misty1/misty1.cpp +++ b/src/block/misty1/misty1.cpp @@ -255,7 +255,7 @@ MISTY1::MISTY1(u32bit rounds) : BlockCipher(8, 16) { if(rounds != 8) throw Invalid_Argument("MISTY1: Invalid number of rounds: " - + to_string(rounds)); + + std::to_string(rounds)); } } diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp index 0bd596b10..1b71de85a 100644 --- a/src/block/rc5/rc5.cpp +++ b/src/block/rc5/rc5.cpp @@ -99,7 +99,7 @@ void RC5::key_schedule(const byte key[], u32bit length) */ std::string RC5::name() const { - return "RC5(" + to_string(ROUNDS) + ")"; + return "RC5(" + std::to_string(ROUNDS) + ")"; } /* diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp index eb5c22fc9..fcbe84c8b 100644 --- a/src/block/safer/safer_sk.cpp +++ b/src/block/safer/safer_sk.cpp @@ -112,7 +112,7 @@ void SAFER_SK::key_schedule(const byte key[], u32bit) */ std::string SAFER_SK::name() const { - return "SAFER-SK(" + to_string(ROUNDS) + ")"; + return "SAFER-SK(" + std::to_string(ROUNDS) + ")"; } /* diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp index f361e6098..b0238ac4d 100644 --- a/src/cert/cvc/asn1_eac_tm.cpp +++ b/src/cert/cvc/asn1_eac_tm.cpp @@ -1,7 +1,7 @@ /* * EAC Time Types * (C) 2007 FlexSecure GmbH -* 2008 Jack Lloyd +* 2008-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -22,7 +22,7 @@ SecureVector enc_two_digit(u32bit in) { SecureVector result; in %= 100; - if (in < 10) + if(in < 10) result.append(0x00); else { @@ -84,7 +84,7 @@ EAC_Time::EAC_Time(u32bit y, u32bit m, u32bit d, ASN1_Tag t) */ void EAC_Time::set_to(const std::string& time_str) { - if (time_str == "") + if(time_str == "") { year = month = day = 0; return; @@ -93,28 +93,28 @@ void EAC_Time::set_to(const std::string& time_str) std::vector params; std::string current; - for (u32bit j = 0; j != time_str.size(); ++j) + for(u32bit j = 0; j != time_str.size(); ++j) { - if (Charset::is_digit(time_str[j])) + if(Charset::is_digit(time_str[j])) current += time_str[j]; else { - if (current != "") + if(current != "") params.push_back(current); current.clear(); } } - if (current != "") + if(current != "") params.push_back(current); - if (params.size() != 3) + if(params.size() != 3) throw Invalid_Argument("Invalid time specification " + time_str); year = to_u32bit(params[0]); month = to_u32bit(params[1]); day = to_u32bit(params[2]); - if (!passes_sanity_check()) + if(!passes_sanity_check()) throw Invalid_Argument("Invalid time specification " + time_str); } @@ -133,15 +133,10 @@ void EAC_Time::encode_into(DER_Encoder& der) const */ std::string EAC_Time::as_string() const { - if (time_is_set() == false) + if(time_is_set() == false) throw Invalid_State("EAC_Time::as_string: No time set"); - std::string asn1rep; - asn1rep = to_string(year, 2); - - asn1rep += to_string(month, 2) + to_string(day, 2); - - return asn1rep; + return std::to_string(year * 10000 + month * 100 + day); } /* @@ -157,15 +152,14 @@ bool EAC_Time::time_is_set() const */ std::string EAC_Time::readable_string() const { - if (time_is_set() == false) + if(time_is_set() == false) throw Invalid_State("EAC_Time::readable_string: No time set"); - std::string readable; - readable += to_string(year, 2) + "/"; - readable += to_string(month, 2) + "/"; - readable += to_string(day, 2) + " "; + std::string output(11, 0); + + std::sprintf(&output[0], "%04d/%02d/%02d", year, month, day); - return readable; + return output; } /* @@ -173,11 +167,11 @@ std::string EAC_Time::readable_string() const */ bool EAC_Time::passes_sanity_check() const { - if (year < 2000 || year > 2099) + if(year < 2000 || year > 2099) return false; - if (month == 0 || month > 12) + if(month == 0 || month > 12) return false; - if (day == 0 || day > 31) + if(day == 0 || day > 31) return false; return true; @@ -186,11 +180,11 @@ bool EAC_Time::passes_sanity_check() const /****************************************** * modification functions ******************************************/ - void EAC_Time::add_years(u32bit years) { year += years; } + void EAC_Time::add_months(u32bit months) { year += months/12; @@ -202,23 +196,22 @@ void EAC_Time::add_months(u32bit months) } } - /* * Compare this time against another */ s32bit EAC_Time::cmp(const EAC_Time& other) const { - if (time_is_set() == false) + if(time_is_set() == false) throw Invalid_State("EAC_Time::cmp: No time set"); const s32bit EARLIER = -1, LATER = 1, SAME_TIME = 0; - if (year < other.year) return EARLIER; - if (year > other.year) return LATER; - if (month < other.month) return EARLIER; - if (month > other.month) return LATER; - if (day < other.day) return EARLIER; - if (day > other.day) return LATER; + if(year < other.year) return EARLIER; + if(year > other.year) return LATER; + if(month < other.month) return EARLIER; + if(month > other.month) return LATER; + if(day < other.day) return EARLIER; + if(day > other.day) return LATER; return SAME_TIME; } @@ -230,22 +223,27 @@ bool operator==(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) == 0); } + bool operator!=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) != 0); } + bool operator<=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) <= 0); } + bool operator>=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) >= 0); } + bool operator>(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) > 0); } + bool operator<(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) < 0); diff --git a/src/cert/x509/pkcs10.cpp b/src/cert/x509/pkcs10.cpp index 5617cece4..5645552a0 100644 --- a/src/cert/x509/pkcs10.cpp +++ b/src/cert/x509/pkcs10.cpp @@ -45,7 +45,7 @@ void PKCS10_Request::force_decode() cert_req_info.decode(version); if(version != 0) throw Decoding_Error("Unknown version code in PKCS #10 request: " + - to_string(version)); + std::to_string(version)); X509_DN dn_subject; cert_req_info.decode(dn_subject); diff --git a/src/cert/x509/x509_crl.cpp b/src/cert/x509/x509_crl.cpp index f6a344dba..3613c1a91 100644 --- a/src/cert/x509/x509_crl.cpp +++ b/src/cert/x509/x509_crl.cpp @@ -44,7 +44,7 @@ void X509_CRL::force_decode() if(version != 0 && version != 1) throw X509_CRL_Error("Unknown X.509 CRL version " + - to_string(version+1)); + std::to_string(version+1)); AlgorithmIdentifier sig_algo_inner; tbs_crl.decode(sig_algo_inner); diff --git a/src/cert/x509/x509cert.cpp b/src/cert/x509/x509cert.cpp index 6a062b7ce..32c508a0c 100644 --- a/src/cert/x509/x509cert.cpp +++ b/src/cert/x509/x509cert.cpp @@ -80,7 +80,7 @@ void X509_Certificate::force_decode() .decode(dn_subject); if(version > 2) - throw Decoding_Error("Unknown X.509 cert version " + to_string(version)); + throw Decoding_Error("Unknown X.509 cert version " + std::to_string(version)); if(sig_algo != sig_algo_inner) throw Decoding_Error("Algorithm identifier mismatch"); diff --git a/src/engine/openssl/arc4_openssl.cpp b/src/engine/openssl/arc4_openssl.cpp index 793e1faff..15bb8f98e 100644 --- a/src/engine/openssl/arc4_openssl.cpp +++ b/src/engine/openssl/arc4_openssl.cpp @@ -40,7 +40,7 @@ std::string ARC4_OpenSSL::name() const { if(SKIP == 0) return "ARC4"; if(SKIP == 256) return "MARK-4"; - else return "RC4_skip(" + to_string(SKIP) + ")"; + else return "RC4_skip(" + std::to_string(SKIP) + ")"; } /* diff --git a/src/filters/hex/hex.cpp b/src/filters/hex/hex.cpp index 651899b73..56576a8a0 100644 --- a/src/filters/hex/hex.cpp +++ b/src/filters/hex/hex.cpp @@ -141,7 +141,7 @@ void Hex_Decoder::handle_bad_char(byte c) return; throw Decoding_Error("Hex_Decoder: Invalid hex character: " + - to_string(c)); + std::to_string(c)); } /* diff --git a/src/filters/modes/cfb/cfb.cpp b/src/filters/modes/cfb/cfb.cpp index a126bd995..672dbe7f5 100644 --- a/src/filters/modes/cfb/cfb.cpp +++ b/src/filters/modes/cfb/cfb.cpp @@ -22,7 +22,7 @@ void check_feedback(u32bit BLOCK_SIZE, u32bit FEEDBACK_SIZE, u32bit bits, { if(FEEDBACK_SIZE == 0 || FEEDBACK_SIZE > BLOCK_SIZE || bits % 8 != 0) throw Invalid_Argument(name + ": Invalid feedback size " + - to_string(bits)); + std::to_string(bits)); } } diff --git a/src/filters/modes/eax/eax.cpp b/src/filters/modes/eax/eax.cpp index e2ef178b6..4b712fa90 100644 --- a/src/filters/modes/eax/eax.cpp +++ b/src/filters/modes/eax/eax.cpp @@ -43,7 +43,7 @@ EAX_Base::EAX_Base(BlockCipher* ciph, mac = new CMAC(cipher->clone()); if(tag_size % 8 != 0 || TAG_SIZE == 0 || TAG_SIZE > mac->OUTPUT_LENGTH) - throw Invalid_Argument(name() + ": Bad tag size " + to_string(tag_size)); + throw Invalid_Argument(name() + ": Bad tag size " + std::to_string(tag_size)); state.resize(BLOCK_SIZE); buffer.resize(BLOCK_SIZE); diff --git a/src/filters/pipe.cpp b/src/filters/pipe.cpp index d43868e3f..ae0f6996d 100644 --- a/src/filters/pipe.cpp +++ b/src/filters/pipe.cpp @@ -19,7 +19,7 @@ Pipe::Invalid_Message_Number::Invalid_Message_Number(const std::string& where, message_id msg) { set_msg("Pipe::" + where + ": Invalid message number " + - to_string(msg)); + std::to_string(msg)); } namespace { diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp index e1ca08c15..5ae09f621 100644 --- a/src/hash/skein/skein_512.cpp +++ b/src/hash/skein/skein_512.cpp @@ -175,7 +175,7 @@ Skein_512::Skein_512(u32bit arg_output_bits, std::string Skein_512::name() const { - return "Skein-512(" + to_string(output_bits) + ")"; + return "Skein-512(" + std::to_string(output_bits) + ")"; } HashFunction* Skein_512::clone() const diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp index 4f4d4dc83..2d56aa1b3 100644 --- a/src/hash/tiger/tiger.cpp +++ b/src/hash/tiger/tiger.cpp @@ -143,7 +143,7 @@ void Tiger::clear() */ std::string Tiger::name() const { - return "Tiger(" + to_string(OUTPUT_LENGTH) + "," + to_string(PASS) + ")"; + return "Tiger(" + std::to_string(OUTPUT_LENGTH) + "," + std::to_string(PASS) + ")"; } /* @@ -154,10 +154,10 @@ Tiger::Tiger(u32bit hashlen, u32bit pass) : { if(OUTPUT_LENGTH != 16 && OUTPUT_LENGTH != 20 && OUTPUT_LENGTH != 24) throw Invalid_Argument("Tiger: Illegal hash output size: " + - to_string(OUTPUT_LENGTH)); + std::to_string(OUTPUT_LENGTH)); if(PASS < 3) throw Invalid_Argument("Tiger: Invalid number of passes: " - + to_string(PASS)); + + std::to_string(PASS)); clear(); } diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp index d5f6dc792..39a7cf5fa 100644 --- a/src/math/numbertheory/dsa_gen.cpp +++ b/src/math/numbertheory/dsa_gen.cpp @@ -47,15 +47,15 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, if(!fips186_3_valid_size(pbits, qbits)) throw Invalid_Argument( "FIPS 186-3 does not allow DSA domain parameters of " + - to_string(pbits) + "/" + to_string(qbits) + " bits long"); + std::to_string(pbits) + "/" + std::to_string(qbits) + " bits long"); if(seed_c.size() * 8 < qbits) throw Invalid_Argument( - "Generating a DSA parameter set with a " + to_string(qbits) + + "Generating a DSA parameter set with a " + std::to_string(qbits) + "long q requires a seed at least as many bits long"); std::unique_ptr hash( - af.make_hash_function("SHA-" + to_string(qbits))); + af.make_hash_function("SHA-" + std::to_string(qbits))); const u32bit HASH_SIZE = hash->OUTPUT_LENGTH; diff --git a/src/math/numbertheory/make_prm.cpp b/src/math/numbertheory/make_prm.cpp index b136b6d25..3eb01cd42 100644 --- a/src/math/numbertheory/make_prm.cpp +++ b/src/math/numbertheory/make_prm.cpp @@ -20,7 +20,7 @@ BigInt random_prime(RandomNumberGenerator& rng, { if(bits <= 1) throw Invalid_Argument("random_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); else if(bits == 2) return ((rng.next_byte() % 2) ? 2 : 3); else if(bits == 3) @@ -85,7 +85,7 @@ BigInt random_safe_prime(RandomNumberGenerator& rng, u32bit bits) { if(bits <= 64) throw Invalid_Argument("random_safe_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); BigInt p; do diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp index 13ea03016..1c18179e2 100644 --- a/src/pubkey/dl_group/dl_group.cpp +++ b/src/pubkey/dl_group/dl_group.cpp @@ -46,7 +46,7 @@ DL_Group::DL_Group(RandomNumberGenerator& rng, PrimeType type, u32bit pbits, u32bit qbits) { if(pbits < 512) - throw Invalid_Argument("DL_Group: prime size " + to_string(pbits) + + throw Invalid_Argument("DL_Group: prime size " + std::to_string(pbits) + " is too small"); if(type == Strong) @@ -237,7 +237,7 @@ SecureVector DL_Group::DER_encode(Format format) const .get_contents(); } - throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format)); } /* @@ -253,7 +253,7 @@ std::string DL_Group::PEM_encode(Format format) const else if(format == ANSI_X9_42) return PEM_Code::encode(encoding, "X942 DH PARAMETERS"); else - throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format)); } /* @@ -287,7 +287,7 @@ void DL_Group::BER_decode(DataSource& source, Format format) .discard_remaining(); } else - throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format)); initialize(new_p, new_q, new_g); } diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp index 4ddaa6fb6..5a5ca335e 100644 --- a/src/pubkey/pubkey.cpp +++ b/src/pubkey/pubkey.cpp @@ -216,7 +216,7 @@ SecureVector PK_Signer::signature(RandomNumberGenerator& rng) } else throw Encoding_Error("PK_Signer: Unknown signature format " + - to_string(sig_format)); + std::to_string(sig_format)); } /* @@ -328,7 +328,7 @@ bool PK_Verifier::check_signature(const byte sig[], u32bit length) } else throw Decoding_Error("PK_Verifier: Unknown signature format " + - to_string(sig_format)); + std::to_string(sig_format)); } catch(Invalid_Argument) { return false; } catch(Decoding_Error) { return false; } 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"); diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp index def0ae689..460c740ab 100644 --- a/src/pubkey/rw/rw.cpp +++ b/src/pubkey/rw/rw.cpp @@ -60,7 +60,7 @@ RW_PrivateKey::RW_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 < 2 || exp % 2 == 1) throw Invalid_Argument(algo_name() + ": Invalid encryption exponent"); diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp index 293a0a336..5d0c67d3e 100644 --- a/src/stream/arc4/arc4.cpp +++ b/src/stream/arc4/arc4.cpp @@ -81,7 +81,7 @@ std::string ARC4::name() const { if(SKIP == 0) return "ARC4"; if(SKIP == 256) return "MARK-4"; - else return "RC4_skip(" + to_string(SKIP) + ")"; + else return "RC4_skip(" + std::to_string(SKIP) + ")"; } /* diff --git a/src/utils/charset.cpp b/src/utils/charset.cpp index 53125cad1..e98cf601e 100644 --- a/src/utils/charset.cpp +++ b/src/utils/charset.cpp @@ -119,7 +119,7 @@ std::string transcode(const std::string& str, return ucs2_to_latin1(str); throw Invalid_Argument("Unknown transcoding operation from " + - to_string(from) + " to " + to_string(to)); + std::to_string(from) + " to " + std::to_string(to)); } /* diff --git a/src/utils/datastor/datastor.cpp b/src/utils/datastor/datastor.cpp index 5e7c94634..634b72872 100644 --- a/src/utils/datastor/datastor.cpp +++ b/src/utils/datastor/datastor.cpp @@ -124,7 +124,7 @@ void Data_Store::add(const std::string& key, const std::string& val) */ void Data_Store::add(const std::string& key, u32bit val) { - add(key, to_string(val)); + add(key, std::to_string(val)); } /* diff --git a/src/utils/exceptn.cpp b/src/utils/exceptn.cpp index 753d63424..2fa05f59d 100644 --- a/src/utils/exceptn.cpp +++ b/src/utils/exceptn.cpp @@ -15,7 +15,7 @@ namespace Botan { */ Invalid_Key_Length::Invalid_Key_Length(const std::string& name, u32bit length) { - set_msg(name + " cannot accept a key of length " + to_string(length)); + set_msg(name + " cannot accept a key of length " + std::to_string(length)); } /* @@ -32,7 +32,7 @@ Invalid_Block_Size::Invalid_Block_Size(const std::string& mode, */ Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, u32bit bad_len) { - set_msg("IV length " + to_string(bad_len) + " is invalid for " + mode); + set_msg("IV length " + std::to_string(bad_len) + " is invalid for " + mode); } /* @@ -56,7 +56,7 @@ Invalid_Algorithm_Name::Invalid_Algorithm_Name(const std::string& name) */ Config_Error::Config_Error(const std::string& err, u32bit line) { - set_msg("Config error at line " + to_string(line) + ": " + err); + set_msg("Config error at line " + std::to_string(line) + ": " + err); } } diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp index 63dfce64f..3412cf02b 100644 --- a/src/utils/parsing.cpp +++ b/src/utils/parsing.cpp @@ -12,53 +12,6 @@ namespace Botan { -/* -* Convert a string into an integer -*/ -u32bit to_u32bit(const std::string& number) - { - u32bit n = 0; - - for(auto i = number.begin(); i != number.end(); ++i) - { - const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; - - if(*i == ' ') - continue; - - byte digit = Charset::char2digit(*i); - - if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5)) - throw Decoding_Error("to_u32bit: Integer overflow"); - n *= 10; - n += digit; - } - return n; - } - -/* -* Convert an integer into a string -*/ -std::string to_string(u64bit n, u32bit min_len) - { - std::string lenstr; - if(n) - { - while(n > 0) - { - lenstr = Charset::digit2char(n % 10) + lenstr; - n /= 10; - } - } - else - lenstr = "0"; - - while(lenstr.size() < min_len) - lenstr = "0" + lenstr; - - return lenstr; - } - /* * Convert a string into a time duration */ @@ -282,7 +235,7 @@ std::string ipv4_to_string(u32bit ip) { if(i) str += "."; - str += to_string(get_byte(i, ip)); + str += std::to_string(get_byte(i, ip)); } return str; diff --git a/src/utils/parsing.h b/src/utils/parsing.h index 2c29d5b4d..cb8d61cee 100644 --- a/src/utils/parsing.h +++ b/src/utils/parsing.h @@ -23,10 +23,10 @@ BOTAN_DLL std::vector parse_asn1_oid(const std::string&); BOTAN_DLL bool x500_name_cmp(const std::string&, const std::string&); /* -* String/Integer Conversions +* Convert a string into an integer */ -BOTAN_DLL std::string to_string(u64bit, u32bit = 0); -BOTAN_DLL u32bit to_u32bit(const std::string&); +inline u32bit to_u32bit(const std::string& number) + { return stoul(number); } BOTAN_DLL u32bit timespec_to_u32bit(const std::string& timespec); diff --git a/src/utils/version.cpp b/src/utils/version.cpp index d540864b2..ef591b4d7 100644 --- a/src/utils/version.cpp +++ b/src/utils/version.cpp @@ -21,9 +21,9 @@ namespace Botan { */ std::string version_string() { - return to_string(version_major()) + "." + - to_string(version_minor()) + "." + - to_string(version_patch()); + return std::to_string(version_major()) + "." + + std::to_string(version_minor()) + "." + + std::to_string(version_patch()); } /* -- cgit v1.2.3 From 85b961ff87c1d6300451538c939c99a2ff74b505 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 16 Dec 2009 05:15:42 +0000 Subject: Post-merge fixes --- src/algo_factory/algo_cache.h | 2 +- src/libstate/libstate.cpp | 4 ++-- src/math/gfpmath/info.txt | 8 -------- src/pubkey/dsa/dsa_op.cpp | 2 +- src/pubkey/elgamal/elg_op.cpp | 2 +- src/pubkey/if_algo/if_op.cpp | 2 +- src/pubkey/nr/nr_op.cpp | 2 +- src/rng/hmac_rng/hmac_rng.cpp | 10 ---------- src/rng/randpool/randpool.cpp | 4 ++-- src/utils/info.txt | 1 + 10 files changed, 10 insertions(+), 27 deletions(-) (limited to 'src/pubkey') diff --git a/src/algo_factory/algo_cache.h b/src/algo_factory/algo_cache.h index 09bbc4b5a..bafea45e9 100644 --- a/src/algo_factory/algo_cache.h +++ b/src/algo_factory/algo_cache.h @@ -9,7 +9,7 @@ #define BOTAN_ALGORITHM_CACHE_TEMPLATE_H__ #include -#include +#include #include #include #include diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 06b05276f..1ca9415e5 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,9 +9,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include diff --git a/src/math/gfpmath/info.txt b/src/math/gfpmath/info.txt index 55ae8b5e6..b7b430805 100644 --- a/src/math/gfpmath/info.txt +++ b/src/math/gfpmath/info.txt @@ -7,15 +7,7 @@ gfp_modulus.h point_gfp.h -<<<<<<< variant A ->>>>>>> variant B - -####### Ancestor -define BIGINT_GFP - - -======= end curve_gfp.cpp gfp_element.cpp point_gfp.cpp diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 03eaebfb0..5eb9e92be 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/pubkey/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index db828a300..49db44251 100644 --- a/src/pubkey/elgamal/elg_op.cpp +++ b/src/pubkey/elgamal/elg_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 7974bf4f0..58618775b 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace Botan { diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index 49aa9fc00..da104802d 100644 --- a/src/pubkey/nr/nr_op.cpp +++ b/src/pubkey/nr/nr_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index 00a3a27d0..84cd647b7 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -6,18 +6,8 @@ */ #include -<<<<<<< variant A #include #include -#include ->>>>>>> variant B -#include -#include -####### Ancestor -#include -#include -#include -======= end #include namespace Botan { diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index 18a3b49a0..015cac491 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -6,8 +6,8 @@ */ #include -#include -#include +#include +#include #include #include diff --git a/src/utils/info.txt b/src/utils/info.txt index edeeb1cf9..bbfcd34be 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -14,6 +14,7 @@ version.cpp +async.h bit_ops.h bswap.h loadstor.h -- cgit v1.2.3 From 01a6b5d010f459e8eeb0ef2ce97ecaf885ae1809 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 24 Feb 2010 13:50:39 +0000 Subject: Post-merge fixups --- src/cert/cvc/cvc_ado.cpp | 2 +- src/cert/cvc/cvc_gen_cert.h | 2 +- src/cert/cvc/cvc_self.cpp | 4 ++-- src/math/gfpmath/point_gfp.cpp | 2 +- src/pubkey/gost_3410/gost_3410.cpp | 13 ++++++------- src/ssl/rec_wri.cpp | 2 +- src/ssl/tls_suites.cpp | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src/pubkey') diff --git a/src/cert/cvc/cvc_ado.cpp b/src/cert/cvc/cvc_ado.cpp index 782922354..fd5b80f13 100644 --- a/src/cert/cvc/cvc_ado.cpp +++ b/src/cert/cvc/cvc_ado.cpp @@ -51,7 +51,7 @@ MemoryVector EAC1_1_ADO::make_signed( RandomNumberGenerator& rng) { SecureVector concat_sig = - EAC1_1_obj::make_signature(signer.get(), tbs_bits, rng); + EAC1_1_obj::make_signature(signer, tbs_bits, rng); return DER_Encoder() .start_cons(ASN1_Tag(7), APPLICATION) diff --git a/src/cert/cvc/cvc_gen_cert.h b/src/cert/cvc/cvc_gen_cert.h index d64812e1e..ab6e22ff0 100644 --- a/src/cert/cvc/cvc_gen_cert.h +++ b/src/cert/cvc/cvc_gen_cert.h @@ -107,7 +107,7 @@ template MemoryVector EAC1_1_gen_CVC::make_sign const MemoryRegion& tbs_bits, RandomNumberGenerator& rng) // static { - SecureVector concat_sig = EAC1_1_obj::make_signature(signer.get(), tbs_bits, rng); + SecureVector concat_sig = EAC1_1_obj::make_signature(signer, tbs_bits, rng); return DER_Encoder() .start_cons(ASN1_Tag(33), APPLICATION) diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 8d782983d..5ec7d7d32 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -134,7 +134,7 @@ EAC1_1_Req create_cvc_req(Private_Key const& key, .encode(chr) .get_contents(); - MemoryVector signed_cert = EAC1_1_gen_CVC::make_signed(signer, EAC1_1_gen_CVC::build_cert_body(tbs), rng); + MemoryVector signed_cert = EAC1_1_gen_CVC::make_signed(*signer.get(), EAC1_1_gen_CVC::build_cert_body(tbs), rng); DataSource_Memory source(signed_cert); return EAC1_1_Req(source); @@ -158,7 +158,7 @@ EAC1_1_ADO create_ado_req(Private_Key const& key, SecureVector tbs_bits = req.BER_encode(); tbs_bits.append(DER_Encoder().encode(car).get_contents()); - MemoryVector signed_cert = EAC1_1_ADO::make_signed(signer, tbs_bits, rng); + MemoryVector signed_cert = EAC1_1_ADO::make_signed(*signer.get(), tbs_bits, rng); DataSource_Memory source(signed_cert); return EAC1_1_ADO(source); diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp index 00331f25b..4b2de7913 100644 --- a/src/math/gfpmath/point_gfp.cpp +++ b/src/math/gfpmath/point_gfp.cpp @@ -13,7 +13,7 @@ namespace Botan { // construct the point at infinity or a random point -nPointGFp::PointGFp(const CurveGFp& curve) : +PointGFp::PointGFp(const CurveGFp& curve) : mC(curve), mX(curve.get_p(), 0), mY(curve.get_p(), 1), diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp index c2ddabe63..21e2653c9 100644 --- a/src/pubkey/gost_3410/gost_3410.cpp +++ b/src/pubkey/gost_3410/gost_3410.cpp @@ -19,7 +19,7 @@ namespace Botan { GOST_3410_PrivateKey::GOST_3410_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& dom_pars) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_pars)); generate_private_key(rng); try @@ -35,10 +35,10 @@ GOST_3410_PrivateKey::GOST_3410_PrivateKey(RandomNumberGenerator& rng, GOST_3410_PrivateKey::GOST_3410_PrivateKey(const EC_Domain_Params& domain, const BigInt& x) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(domain)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(domain)); m_private_value = x; - mp_public_point = std::auto_ptr(new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr(new PointGFp (mp_dom_pars->get_base_point())); mp_public_point->mult_this_secure(m_private_value, mp_dom_pars->get_order(), mp_dom_pars->get_order()-1); @@ -173,9 +173,8 @@ void GOST_3410_PublicKey::set_domain_parameters(const EC_Domain_Params& dom_pars throw Invalid_State("EC_PublicKey::set_domain_parameters(): point does not lie on provided curve"); } - std::auto_ptr p_tmp_pars(new EC_Domain_Params(dom_pars)); mp_public_point.reset(new PointGFp(tmp_pp)); - mp_dom_pars = p_tmp_pars; + mp_dom_pars.reset(new EC_Domain_Params(dom_pars)); } void GOST_3410_PublicKey::set_all_values(const GOST_3410_PublicKey& other) @@ -242,8 +241,8 @@ bool GOST_3410_PublicKey::verify(const byte msg[], u32bit msg_len, GOST_3410_PublicKey::GOST_3410_PublicKey(const EC_Domain_Params& dom_par, const PointGFp& public_point) { - mp_dom_pars = std::auto_ptr(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr(new PointGFp(public_point)); m_param_enc = ENC_EXPLICIT; } diff --git a/src/ssl/rec_wri.cpp b/src/ssl/rec_wri.cpp index 258b4ec17..842b2698c 100644 --- a/src/ssl/rec_wri.cpp +++ b/src/ssl/rec_wri.cpp @@ -250,7 +250,7 @@ void Record_Writer::send_record(byte type, byte major, byte minor, */ void Record_Writer::alert(Alert_Level level, Alert_Type type) { - byte alert[2] = { level, type }; + byte alert[2] = { (byte)level, (byte)type }; send(ALERT, alert, sizeof(alert)); flush(); } diff --git a/src/ssl/tls_suites.cpp b/src/ssl/tls_suites.cpp index 26fa75428..a168dac0a 100644 --- a/src/ssl/tls_suites.cpp +++ b/src/ssl/tls_suites.cpp @@ -51,7 +51,7 @@ CipherSuite::CipherSuite(u16bit suite_code) if(suite_string == "") throw Invalid_Argument("Unknown ciphersuite: " + - to_string(suite_code)); + std::to_string(suite_code)); std::vector suite_info = split_on(suite_string, '/'); -- cgit v1.2.3 From 3e95540b28f3d828c4578381c318545f6ad49589 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 24 Feb 2010 13:55:53 +0000 Subject: Drop async.h and switch to using std::async which was added to GCC before the 4.5 release. --- src/pubkey/dsa/dsa_op.cpp | 7 ++++--- src/pubkey/elgamal/elg_op.cpp | 4 ++-- src/pubkey/if_algo/if_op.cpp | 9 ++------- src/pubkey/nr/nr_op.cpp | 4 ++-- src/utils/async.h | 33 --------------------------------- src/utils/info.txt | 1 - 6 files changed, 10 insertions(+), 48 deletions(-) delete mode 100644 src/utils/async.h (limited to 'src/pubkey') diff --git a/src/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 5eb9e92be..e83fd83b7 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { @@ -42,7 +42,7 @@ bool Default_DSA_Op::verify(const byte msg[], u32bit msg_len, s = inverse_mod(s, q); - auto future_s_i = std_async( + 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)); @@ -62,7 +62,8 @@ SecureVector Default_DSA_Op::sign(const byte in[], u32bit length, if(x == 0) throw Internal_Error("Default_DSA_Op::sign: No private key"); - auto future_r = std_async([&]() { return mod_q.reduce(powermod_g_p(k)); }); + auto future_r = std::async(std::launch::async, + [&]() { return mod_q.reduce(powermod_g_p(k)); }); const BigInt& q = group.get_q(); BigInt i(in, length); diff --git a/src/pubkey/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index 49db44251..4bde60bee 100644 --- a/src/pubkey/elgamal/elg_op.cpp +++ b/src/pubkey/elgamal/elg_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { @@ -34,7 +34,7 @@ SecureVector Default_ELG_Op::encrypt(const byte in[], u32bit length, if(m >= p) throw Invalid_Argument("Default_ELG_Op::encrypt: Input is too large"); - auto future_a = std_async([&]() { return powermod_g_p(k); }); + auto future_a = std::async(std::launch::async, powermod_g_p, k); BigInt b = mod_p.multiply(m, powermod_y_p(k)); BigInt a = future_a.get(); diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 58618775b..99f68400d 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace Botan { @@ -39,12 +39,7 @@ BigInt Default_IF_Op::private_op(const BigInt& i) const if(q == 0) throw Internal_Error("Default_IF_Op::private_op: No private key"); - /* - * A simple std::bind(powermod_d1_p, i) would work instead of a - * lambda but GCC 4.5's std::result_of doesn't use decltype and gets - * confused - */ - auto future_j1 = std_async([&]() { return powermod_d1_p(i); }); + auto future_j1 = std::async(std::launch::async, powermod_d1_p, i); BigInt j2 = powermod_d2_q(i); BigInt j1 = future_j1.get(); diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index da104802d..10890a127 100644 --- a/src/pubkey/nr/nr_op.cpp +++ b/src/pubkey/nr/nr_op.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { @@ -38,7 +38,7 @@ SecureVector Default_NR_Op::verify(const byte in[], u32bit length) const if(c.is_zero() || c >= q || d >= q) throw Invalid_Argument("Default_NR_Op::verify: Invalid signature"); - auto future_y_c = std_async([&]() { return 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()); diff --git a/src/utils/async.h b/src/utils/async.h deleted file mode 100644 index 1ffa2c4cb..000000000 --- a/src/utils/async.h +++ /dev/null @@ -1,33 +0,0 @@ -/** -* Standin for C++0x's std::async -* (C) 2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_ASYNC_H__ -#define BOTAN_ASYNC_H__ - -#include -#include - -namespace Botan { - -/** -* A simple version of std::async (as it is not in GCC 4.5) -* Will be removed once GCC supports it natively -*/ -template -auto std_async(F f) -> std::future - { - typedef decltype(f()) result_type; - std::packaged_task task(std::move(f)); - std::future future = task.get_future(); - std::thread thread(std::move(task)); - thread.detach(); - return future; - } - -} - -#endif diff --git a/src/utils/info.txt b/src/utils/info.txt index 2fb17fd80..2fb3e79a5 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -13,7 +13,6 @@ version.cpp -async.h bit_ops.h debug.h mlock.h -- cgit v1.2.3 From ac0ec9b832a337c91cb451e0b8d12b77fa27a20c Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 9 Mar 2010 04:14:30 +0000 Subject: Various updates: unique_ptr, using chrono, merge fixups, etc --- checks/pk_bench.cpp | 4 ++-- src/benchmark/benchmark.cpp | 8 ++++---- src/cert/cvc/cvc_self.cpp | 15 +++++++++++---- src/cms/cms_dalg.cpp | 2 +- src/cms/cms_ealg.cpp | 4 ++-- src/constructs/tss/tss.cpp | 2 +- src/pubkey/blinding.cpp | 6 ++++-- src/ssl/cert_ver.cpp | 2 +- src/ssl/s_kex.cpp | 2 +- src/wrap/python/core.cpp | 2 +- src/wrap/python/filter.cpp | 14 +++++++------- src/wrap/python/rsa.cpp | 8 ++++---- 12 files changed, 39 insertions(+), 30 deletions(-) (limited to 'src/pubkey') diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index a180778a6..c6f411379 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -374,7 +374,7 @@ void benchmark_gost_3410(RandomNumberGenerator& rng, if(hashbits == 521) hashbits = 512; - const std::string padding = "EMSA1(SHA-" + to_string(hashbits) + ")"; + const std::string padding = "EMSA1(SHA-" + std::to_string(hashbits) + ")"; Timer keygen_timer("keygen"); Timer verify_timer(padding + " verify"); @@ -394,7 +394,7 @@ void benchmark_gost_3410(RandomNumberGenerator& rng, sig_timer, rng, 1000, seconds); } - const std::string nm = "GOST-34.10-" + to_string(pbits); + const std::string nm = "GOST-34.10-" + std::to_string(pbits); report.report(nm, keygen_timer); report.report(nm, verify_timer); diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index 7a78461c2..348882b2a 100644 --- a/src/benchmark/benchmark.cpp +++ b/src/benchmark/benchmark.cpp @@ -162,7 +162,7 @@ algorithm_benchmark(const std::string& name, if(const BlockCipher* proto = af.prototype_block_cipher(name, provider)) { - std::auto_ptr block_cipher(proto->clone()); + std::unique_ptr block_cipher(proto->clone()); results = bench_block_cipher(block_cipher.get(), ns_per_provider, &buf[0], buf.size()); @@ -170,7 +170,7 @@ algorithm_benchmark(const std::string& name, else if(const StreamCipher* proto = af.prototype_stream_cipher(name, provider)) { - std::auto_ptr stream_cipher(proto->clone()); + std::unique_ptr stream_cipher(proto->clone()); results = bench_stream_cipher(stream_cipher.get(), ns_per_provider, &buf[0], buf.size()); @@ -178,14 +178,14 @@ algorithm_benchmark(const std::string& name, else if(const HashFunction* proto = af.prototype_hash_function(name, provider)) { - std::auto_ptr hash(proto->clone()); + std::unique_ptr hash(proto->clone()); results = bench_hash(hash.get(), ns_per_provider, &buf[0], buf.size()); } else if(const MessageAuthenticationCode* proto = af.prototype_mac(name, provider)) { - std::auto_ptr mac(proto->clone()); + std::unique_ptr mac(proto->clone()); results = bench_mac(mac.get(), ns_per_provider, &buf[0], buf.size()); } diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 0c765347f..9489ede85 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -168,7 +168,8 @@ EAC1_1_ADO create_ado_req(Private_Key const& key, PK_Signer signer(*priv_key, padding_and_hash); SecureVector tbs_bits = req.BER_encode(); tbs_bits.append(DER_Encoder().encode(car).get_contents()); - MemoryVector signed_cert = EAC1_1_ADO::make_signed(*signer.get(), tbs_bits, rng); + MemoryVector signed_cert = EAC1_1_ADO::make_signed(signer, + tbs_bits, rng); DataSource_Memory source(signed_cert); return EAC1_1_ADO(source); @@ -229,7 +230,7 @@ EAC1_1_CVC link_cvca(EAC1_1_CVC const& signer, AlgorithmIdentifier sig_algo = signer.signature_algorithm(); std::string padding_and_hash = padding_and_hash_from_oid(sig_algo.oid); PK_Signer pk_signer(*priv_key, padding_and_hash); - std::auto_ptr pk = signee.subject_public_key(); + std::unique_ptr pk = signee.subject_public_key(); ECDSA_PublicKey* subj_pk = dynamic_cast(pk.get()); subj_pk->set_parameter_encoding(EC_DOMPAR_ENC_EXPLICIT); @@ -259,11 +260,17 @@ EAC1_1_CVC sign_request(EAC1_1_CVC const& signer_cert, throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type"); } std::string chr_str = signee.get_chr().value(); - chr_str += to_string(seqnr, seqnr_len); + + std::string seqnr_string = std::to_string(seqnr); + + while(seqnr_string.size() < seqnr_len) + seqnr_string = '0' + seqnr_string; + + chr_str += seqnr_string; ASN1_Chr chr(chr_str); std::string padding_and_hash = padding_and_hash_from_oid(signee.signature_algorithm().oid); PK_Signer pk_signer(*priv_key, padding_and_hash); - std::auto_ptr pk = signee.subject_public_key(); + std::unique_ptr pk = signee.subject_public_key(); ECDSA_PublicKey* subj_pk = dynamic_cast(pk.get()); std::unique_ptr signer_pk = signer_cert.subject_public_key(); diff --git a/src/cms/cms_dalg.cpp b/src/cms/cms_dalg.cpp index 2a380b596..f727f2a3f 100644 --- a/src/cms/cms_dalg.cpp +++ b/src/cms/cms_dalg.cpp @@ -29,7 +29,7 @@ SecureVector hash_of(const SecureVector& content, Algorithm_Factory& af = global_state().algorithm_factory(); - std::auto_ptr hash_fn(af.make_hash_function(hash_name)); + std::unique_ptr hash_fn(af.make_hash_function(hash_name)); return hash_fn->process(content); } diff --git a/src/cms/cms_ealg.cpp b/src/cms/cms_ealg.cpp index 3ddf8a39e..b910b89d2 100644 --- a/src/cms/cms_ealg.cpp +++ b/src/cms/cms_ealg.cpp @@ -58,7 +58,7 @@ SecureVector hash_of(const SecureVector& content, const std::string& hash_name) { Algorithm_Factory& af = global_state().algorithm_factory(); - std::auto_ptr hash_fn(af.make_hash_function(hash_name)); + std::unique_ptr hash_fn(af.make_hash_function(hash_name)); return hash_fn->process(content); } @@ -97,7 +97,7 @@ void CMS_Encoder::encrypt(RandomNumberGenerator& rng, { const std::string cipher = choose_algo(user_cipher, "TripleDES"); - std::auto_ptr key(to.subject_public_key()); + std::unique_ptr key(to.subject_public_key()); const std::string algo = key->algo_name(); Key_Constraints constraints = to.constraints(); diff --git a/src/constructs/tss/tss.cpp b/src/constructs/tss/tss.cpp index 0782a27d1..101640f96 100644 --- a/src/constructs/tss/tss.cpp +++ b/src/constructs/tss/tss.cpp @@ -209,7 +209,7 @@ RTSS_Share::reconstruct(const std::vector& shares) byte hash_id = shares[0].contents[16]; - std::auto_ptr hash(get_rtss_hash_by_id(hash_id)); + std::unique_ptr hash(get_rtss_hash_by_id(hash_id)); if(shares[0].size() != secret_len + hash->OUTPUT_LENGTH + RTSS_HEADER_SIZE + 1) throw Decoding_Error("Bad RTSS length field in header"); diff --git a/src/pubkey/blinding.cpp b/src/pubkey/blinding.cpp index 819d0dd20..8da50249f 100644 --- a/src/pubkey/blinding.cpp +++ b/src/pubkey/blinding.cpp @@ -32,7 +32,7 @@ BigInt Blinder::choose_nonce(const BigInt& x, const BigInt& mod) { Algorithm_Factory& af = global_state().algorithm_factory(); - std::auto_ptr hash(af.make_hash_function("SHA-512")); + std::unique_ptr hash(af.make_hash_function("SHA-512")); u64bit ns_clock = get_nanoseconds_clock(); for(size_t i = 0; i != sizeof(ns_clock); ++i) @@ -41,7 +41,9 @@ BigInt Blinder::choose_nonce(const BigInt& x, const BigInt& mod) hash->update(BigInt::encode(x)); hash->update(BigInt::encode(mod)); - u64bit timestamp = system_time(); + auto timestamp = std::chrono::system_clock::to_time_t( + std::chrono::system_clock::now()); + for(size_t i = 0; i != sizeof(timestamp); ++i) hash->update(get_byte(i, timestamp)); diff --git a/src/ssl/cert_ver.cpp b/src/ssl/cert_ver.cpp index 7e17dbfab..0bf6c85be 100644 --- a/src/ssl/cert_ver.cpp +++ b/src/ssl/cert_ver.cpp @@ -80,7 +80,7 @@ bool Certificate_Verify::verify(const X509_Certificate& cert, { // FIXME: duplicate of Server_Key_Exchange::verify - std::auto_ptr key(cert.subject_public_key()); + std::unique_ptr key(cert.subject_public_key()); std::string padding = ""; Signature_Format format = IEEE_1363; diff --git a/src/ssl/s_kex.cpp b/src/ssl/s_kex.cpp index 94b17cb7e..3223adc5b 100644 --- a/src/ssl/s_kex.cpp +++ b/src/ssl/s_kex.cpp @@ -157,7 +157,7 @@ bool Server_Key_Exchange::verify(const X509_Certificate& cert, const MemoryRegion& s_random) const { - std::auto_ptr key(cert.subject_public_key()); + std::unique_ptr key(cert.subject_public_key()); std::string padding = ""; Signature_Format format = IEEE_1363; diff --git a/src/wrap/python/core.cpp b/src/wrap/python/core.cpp index b1be3b71f..67e17c4d5 100644 --- a/src/wrap/python/core.cpp +++ b/src/wrap/python/core.cpp @@ -178,7 +178,7 @@ std::string python_kdf2(const std::string& param, const std::string& masterkey, u32bit outputlength) { - std::auto_ptr kdf(get_kdf("KDF2(SHA-1)")); + std::unique_ptr kdf(get_kdf("KDF2(SHA-1)")); return make_string( kdf->derive_key(outputlength, diff --git a/src/wrap/python/filter.cpp b/src/wrap/python/filter.cpp index 48a3f84eb..0076f0c49 100644 --- a/src/wrap/python/filter.cpp +++ b/src/wrap/python/filter.cpp @@ -109,19 +109,19 @@ Filter* make_filter4(const std::string& name, name); } -void append_filter(Pipe& pipe, std::auto_ptr filter) +void append_filter(Pipe& pipe, std::unique_ptr filter) { pipe.append(filter.get()); filter.release(); } -void prepend_filter(Pipe& pipe, std::auto_ptr filter) +void prepend_filter(Pipe& pipe, std::unique_ptr filter) { pipe.prepend(filter.get()); filter.release(); } -void do_send(std::auto_ptr filter, const std::string& data) +void do_send(std::unique_ptr filter, const std::string& data) { printf("Sending %s to %p\n", data.c_str(), filter.get()); filter->send_str(data); @@ -131,7 +131,7 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(rallas_ovls, read_all_as_string, 0, 1) void export_filters() { - class_, boost::noncopyable> + class_, boost::noncopyable> ("__Internal_FilterObj", no_init); def("make_filter", make_filter1, @@ -145,7 +145,7 @@ void export_filters() // This might not work - Pipe will delete the filter, but Python // might have allocated the space with malloc() or who-knows-what -> bad - class_, + class_, bases, boost::noncopyable> ("FilterObj") .def("write", pure_virtual(&Py_Filter::write_str)) @@ -153,8 +153,8 @@ void export_filters() .def("start_msg", &Filter::start_msg, &FilterWrapper::default_start_msg) .def("end_msg", &Filter::end_msg, &FilterWrapper::default_end_msg); - implicitly_convertible, - std::auto_ptr >(); + implicitly_convertible, + std::unique_ptr >(); void (Pipe::*pipe_write_str)(const std::string&) = &Pipe::write; void (Pipe::*pipe_process_str)(const std::string&) = &Pipe::process_msg; diff --git a/src/wrap/python/rsa.cpp b/src/wrap/python/rsa.cpp index 900c3f93d..41d9bd4d1 100644 --- a/src/wrap/python/rsa.cpp +++ b/src/wrap/python/rsa.cpp @@ -55,7 +55,7 @@ class Py_RSA_PrivateKey std::string Py_RSA_PrivateKey::decrypt(const std::string& in, const std::string& padding) { - std::auto_ptr enc(get_pk_decryptor(*rsa_key, padding)); + std::unique_ptr enc(get_pk_decryptor(*rsa_key, padding)); const byte* in_bytes = reinterpret_cast(in.data()); @@ -66,7 +66,7 @@ std::string Py_RSA_PrivateKey::sign(const std::string& in, const std::string& padding, Python_RandomNumberGenerator& rng) { - std::auto_ptr sign(get_pk_signer(*rsa_key, padding)); + std::unique_ptr sign(get_pk_signer(*rsa_key, padding)); const byte* in_bytes = reinterpret_cast(in.data()); sign->update(in_bytes, in.size()); return make_string(sign->signature(rng.get_underlying_rng())); @@ -144,7 +144,7 @@ std::string Py_RSA_PublicKey::encrypt(const std::string& in, const std::string& padding, Python_RandomNumberGenerator& rng) { - std::auto_ptr enc(get_pk_encryptor(*rsa_key, padding)); + std::unique_ptr enc(get_pk_encryptor(*rsa_key, padding)); const byte* in_bytes = reinterpret_cast(in.data()); @@ -156,7 +156,7 @@ bool Py_RSA_PublicKey::verify(const std::string& in, const std::string& signature, const std::string& padding) { - std::auto_ptr ver(get_pk_verifier(*rsa_key, padding)); + std::unique_ptr ver(get_pk_verifier(*rsa_key, padding)); const byte* in_bytes = reinterpret_cast(in.data()); const byte* sig_bytes = reinterpret_cast(signature.data()); -- 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') 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