diff options
author | lloyd <[email protected]> | 2010-01-21 16:36:12 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-01-21 16:36:12 +0000 |
commit | 412a13fc607a57bd9986155d247353ba8e5fb203 (patch) | |
tree | cbdf63aaa7e9f28a748dedda286e79a138573f74 /src/pubkey | |
parent | 41bed2fa0c4d96faf805cd33850166972dcac114 (diff) | |
parent | 9b82bb5a720f32e3e7878550310b1151cac188b8 (diff) |
propagate from branch 'net.randombit.botan' (head 12382647ef0a28fcb11c824c77b670cc88a4f721)
to branch 'net.randombit.botan.c++0x' (head b586a3286d2c4d547ad3add5af9df1455bf4b87b)
Diffstat (limited to 'src/pubkey')
-rw-r--r-- | src/pubkey/dl_group/dl_group.cpp | 8 | ||||
-rw-r--r-- | src/pubkey/dsa/dsa_op.cpp | 21 | ||||
-rw-r--r-- | src/pubkey/ec_dompar/ec_dompar.cpp | 2 | ||||
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.cpp | 2 | ||||
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.h | 4 | ||||
-rw-r--r-- | src/pubkey/ecdsa/ecdsa.cpp | 15 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg.cpp | 4 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg.h | 2 | ||||
-rw-r--r-- | src/pubkey/elgamal/elg_op.cpp | 6 | ||||
-rw-r--r-- | src/pubkey/if_algo/if_op.cpp | 14 | ||||
-rw-r--r-- | src/pubkey/keypair/keypair.cpp | 8 | ||||
-rw-r--r-- | src/pubkey/nr/nr_op.cpp | 8 | ||||
-rw-r--r-- | src/pubkey/pk_codecs/pkcs8.cpp | 10 | ||||
-rw-r--r-- | src/pubkey/pk_codecs/x509_key.cpp | 6 | ||||
-rw-r--r-- | src/pubkey/pubkey.cpp | 4 | ||||
-rw-r--r-- | src/pubkey/rsa/rsa.cpp | 2 | ||||
-rw-r--r-- | src/pubkey/rw/rw.cpp | 2 |
17 files changed, 71 insertions, 47 deletions
diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp index 7940e69b2..55a83794c 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<byte> 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/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp index 5b921441d..5eb9e92be 100644 --- a/src/pubkey/dsa/dsa_op.cpp +++ b/src/pubkey/dsa/dsa_op.cpp @@ -1,11 +1,12 @@ /* * DSA Operations -* (C) 1999-2007 Jack Lloyd +* (C) 1999-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ #include <botan/dsa_op.h> +#include <botan/internal/async.h> namespace Botan { @@ -40,8 +41,14 @@ 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))); + + auto future_s_i = std_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); } @@ -55,11 +62,15 @@ SecureVector<byte> 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); - 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("Default_DSA_Op::sign: r or s was zero"); diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp index 0b5a6e681..e05b01465 100644 --- a/src/pubkey/ec_dompar/ec_dompar.cpp +++ b/src/pubkey/ec_dompar/ec_dompar.cpp @@ -553,7 +553,7 @@ EC_Domain_Params decode_ber_ec_dompar(SecureVector<byte> const& encoded) BER_Decoder dec(encoded); BER_Object obj = dec.get_next_object(); ASN1_Tag tag = obj.type_tag; - std::auto_ptr<EC_Domain_Params> p_result; + std::unique_ptr<EC_Domain_Params> 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 b7f58eecc..7d3c79868 100644 --- a/src/pubkey/ecc_key/ecc_key.cpp +++ b/src/pubkey/ecc_key/ecc_key.cpp @@ -165,7 +165,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<PointGFp>( new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr<PointGFp>( 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<byte> m_enc_public_point; // stores the public point - std::auto_ptr<EC_Domain_Params> mp_dom_pars; - std::auto_ptr<PointGFp> mp_public_point; + std::unique_ptr<EC_Domain_Params> mp_dom_pars; + std::unique_ptr<PointGFp> mp_public_point; EC_dompar_enc m_param_enc; }; diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp index 6116f7b13..dffd37e6f 100644 --- a/src/pubkey/ecdsa/ecdsa.cpp +++ b/src/pubkey/ecdsa/ecdsa.cpp @@ -19,7 +19,7 @@ namespace Botan { ECDSA_PrivateKey::ECDSA_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& dom_pars) { - mp_dom_pars = std::auto_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_pars)); generate_private_key(rng); try @@ -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<EC_Domain_Params>(new EC_Domain_Params(domain)); + mp_dom_pars = std::unique_ptr<EC_Domain_Params>(new EC_Domain_Params(domain)); m_private_value = x; - mp_public_point = std::auto_ptr<PointGFp>(new PointGFp (mp_dom_pars->get_base_point())); + mp_public_point = std::unique_ptr<PointGFp>(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); @@ -90,11 +90,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<EC_Domain_Params> 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) @@ -134,8 +133,8 @@ bool ECDSA_PublicKey::verify(const byte msg[], u32bit msg_len, ECDSA_PublicKey::ECDSA_PublicKey(const EC_Domain_Params& dom_par, const PointGFp& public_point) { - mp_dom_pars = std::auto_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr<PointGFp>(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr<PointGFp>(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 3e0f717e0..15c817fa7 100644 --- a/src/pubkey/eckaeg/eckaeg.cpp +++ b/src/pubkey/eckaeg/eckaeg.cpp @@ -62,8 +62,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<EC_Domain_Params>(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr<PointGFp>(new PointGFp(public_point)); + mp_dom_pars = std::unique_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_par)); + mp_public_point = std::unique_ptr<PointGFp>(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 7c4dfdb2d..b8c164967 100644 --- a/src/pubkey/eckaeg/eckaeg.h +++ b/src/pubkey/eckaeg/eckaeg.h @@ -90,7 +90,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<EC_Domain_Params>(new EC_Domain_Params(dom_pars)); + mp_dom_pars = std::unique_ptr<EC_Domain_Params>(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/elgamal/elg_op.cpp b/src/pubkey/elgamal/elg_op.cpp index 1e476ab7a..49db44251 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 <botan/elg_op.h> +#include <botan/internal/async.h> namespace Botan { @@ -33,8 +34,9 @@ SecureVector<byte> 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<byte> output(2*p.bytes()); a.binary_encode(output + (p.bytes() - a.bytes())); diff --git a/src/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp index 27aef453e..58618775b 100644 --- a/src/pubkey/if_algo/if_op.cpp +++ b/src/pubkey/if_algo/if_op.cpp @@ -1,12 +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 <botan/if_op.h> #include <botan/numthry.h> +#include <botan/internal/async.h> namespace Botan { @@ -38,8 +39,15 @@ 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 + */ + auto future_j1 = std_async([&]() { return powermod_d1_p(i); }); BigInt j2 = powermod_d2_q(i); + BigInt j1 = future_j1.get(); + j1 = reducer.reduce(sub_mul(j1, j2, c)); return mul_add(j1, q, j2); } 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<PK_Encryptor> enc(encryptor); - std::auto_ptr<PK_Decryptor> dec(decryptor); + std::unique_ptr<PK_Encryptor> enc(encryptor); + std::unique_ptr<PK_Decryptor> dec(decryptor); SecureVector<byte> 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<PK_Signer> sig(signer); - std::auto_ptr<PK_Verifier> ver(verifier); + std::unique_ptr<PK_Signer> sig(signer); + std::unique_ptr<PK_Verifier> ver(verifier); SecureVector<byte> message(16); rng.randomize(message, message.size()); diff --git a/src/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp index b5efa3d37..da104802d 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 <botan/nr_op.h> +#include <botan/internal/async.h> namespace Botan { @@ -37,7 +38,10 @@ SecureVector<byte> 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)); } diff --git a/src/pubkey/pk_codecs/pkcs8.cpp b/src/pubkey/pk_codecs/pkcs8.cpp index d0954df39..830f3a10d 100644 --- a/src/pubkey/pk_codecs/pkcs8.cpp +++ b/src/pubkey/pk_codecs/pkcs8.cpp @@ -89,7 +89,7 @@ SecureVector<byte> PKCS8_decode(DataSource& source, const User_Interface& ui, if(is_encrypted) { DataSource_Memory params(pbe_alg_id.parameters); - std::auto_ptr<PBE> pbe(get_pbe(pbe_alg_id.oid, params)); + std::unique_ptr<PBE> 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<byte> PKCS8_decode(DataSource& source, const User_Interface& ui, */ void encode(const Private_Key& key, Pipe& pipe, X509_Encoding encoding) { - std::auto_ptr<PKCS8_Encoder> encoder(key.pkcs8_encoder()); + std::unique_ptr<PKCS8_Encoder> 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> pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE))); + std::unique_ptr<PBE> 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<Private_Key> key(get_private_key(alg_name)); + std::unique_ptr<Private_Key> 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<PKCS8_Decoder> decoder(key->pkcs8_decoder(rng)); + std::unique_ptr<PKCS8_Decoder> decoder(key->pkcs8_decoder(rng)); if(!decoder.get()) throw Decoding_Error("Key does not support PKCS #8 decoding"); diff --git a/src/pubkey/pk_codecs/x509_key.cpp b/src/pubkey/pk_codecs/x509_key.cpp index fcfb2b165..4cd6371d8 100644 --- a/src/pubkey/pk_codecs/x509_key.cpp +++ b/src/pubkey/pk_codecs/x509_key.cpp @@ -24,7 +24,7 @@ namespace X509 { */ void encode(const Public_Key& key, Pipe& pipe, X509_Encoding encoding) { - std::auto_ptr<X509_Encoder> encoder(key.x509_encoder()); + std::unique_ptr<X509_Encoder> 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<Public_Key> key_obj(get_public_key(alg_name)); + std::unique_ptr<Public_Key> 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<X509_Decoder> decoder(key_obj->x509_decoder()); + std::unique_ptr<X509_Decoder> decoder(key_obj->x509_decoder()); if(!decoder.get()) throw Decoding_Error("Key does not support X.509 decoding"); diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp index dc0a505f5..69002207f 100644 --- a/src/pubkey/pubkey.cpp +++ b/src/pubkey/pubkey.cpp @@ -212,7 +212,7 @@ SecureVector<byte> PK_Signer::signature(RandomNumberGenerator& rng) } else throw Encoding_Error("PK_Signer: Unknown signature format " + - to_string(sig_format)); + std::to_string(sig_format)); } /* @@ -324,7 +324,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; } } 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"); |