diff options
author | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-02-04 04:03:38 +0000 |
commit | 0dd060fed07b0060f94e3bae62e125a85c1bb877 (patch) | |
tree | ed4bc7a961e2b30f17ed5e80769c84b0c313c8b7 /src/lib/pubkey | |
parent | f9a7c85b74be0f4a7273e8e0591703af83036e81 (diff) |
Remove algo factory, engines, global RNG, global state, etc.
Convert all uses of Algorithm_Factory and the engines to using Algo_Registry
The shared pool of entropy sources remains but is moved to EntropySource.
With that and few remaining initializations (default OIDs and aliases)
moved elsewhere, the global state is empty and init and shutdown are no-ops.
Remove almost all of the headers and code for handling the global
state, except LibraryInitializer which remains as a compatability stub.
Update seeding for blinding so only one hacky almost-global RNG
instance needs to be setup instead of across all pubkey uses (it uses
either the system RNG or an AutoSeeded_RNG if the system RNG is not
available).
Diffstat (limited to 'src/lib/pubkey')
28 files changed, 131 insertions, 188 deletions
diff --git a/src/lib/pubkey/blinding.cpp b/src/lib/pubkey/blinding.cpp index 61da26a04..cd2b3d118 100644 --- a/src/lib/pubkey/blinding.cpp +++ b/src/lib/pubkey/blinding.cpp @@ -8,42 +8,50 @@ #include <botan/blinding.h> #include <botan/numthry.h> +#if defined(BOTAN_HAS_SYSTEM_RNG) + #include <botan/system_rng.h> +#else + #include <botan/auto_rng.h> +#endif + namespace Botan { -/* -* Blinder Constructor -*/ -Blinder::Blinder(const BigInt& e, const BigInt& d, const BigInt& n) +// TODO: use Montgomery + +Blinder::Blinder(const BigInt& modulus, + std::function<BigInt (const BigInt&)> fwd_func, + std::function<BigInt (const BigInt&)> inv_func) { - if(e < 1 || d < 1 || n < 1) - throw Invalid_Argument("Blinder: Arguments too small"); + m_reducer = Modular_Reducer(modulus); + +#if defined(BOTAN_HAS_SYSTEM_RNG) + auto& rng = system_rng(); +#else + AutoSeeded_RNG rng; +#endif + + const BigInt k(rng, modulus.bits() - 1); - reducer = Modular_Reducer(n); - this->e = e; - this->d = d; + m_e = fwd_func(k); + m_d = inv_func(k); } -/* -* Blind a number -*/ BigInt Blinder::blind(const BigInt& i) const { - if(!reducer.initialized()) - return i; + if(!m_reducer.initialized()) + throw std::runtime_error("Blinder not initialized, cannot blind"); - e = reducer.square(e); - d = reducer.square(d); - return reducer.multiply(i, e); + m_e = m_reducer.square(m_e); + m_d = m_reducer.square(m_d); + return m_reducer.multiply(i, m_e); } -/* -* Unblind a number -*/ BigInt Blinder::unblind(const BigInt& i) const { - if(!reducer.initialized()) - return i; - return reducer.multiply(i, d); + if(!m_reducer.initialized()) + throw std::runtime_error("Blinder not initialized, cannot unblind"); + + return m_reducer.multiply(i, m_d); } } diff --git a/src/lib/pubkey/blinding.h b/src/lib/pubkey/blinding.h index 1aa7687a9..e57c7888e 100644 --- a/src/lib/pubkey/blinding.h +++ b/src/lib/pubkey/blinding.h @@ -10,6 +10,7 @@ #include <botan/bigint.h> #include <botan/reducer.h> +#include <functional> namespace Botan { @@ -20,25 +21,20 @@ class BOTAN_DLL Blinder { public: BigInt blind(const BigInt& x) const; + BigInt unblind(const BigInt& x) const; - bool initialized() const { return reducer.initialized(); } + bool initialized() const { return m_reducer.initialized(); } Blinder() {} - /** - * Construct a blinder - * @param mask the forward (blinding) mask - * @param inverse_mask the inverse of mask (depends on algo) - * @param modulus of the group operations are performed in - */ - Blinder(const BigInt& mask, - const BigInt& inverse_mask, - const BigInt& modulus); + Blinder(const BigInt& modulus, + std::function<BigInt (const BigInt&)> fwd_func, + std::function<BigInt (const BigInt&)> inv_func); private: - Modular_Reducer reducer; - mutable BigInt e, d; + Modular_Reducer m_reducer; + mutable BigInt m_e, m_d; }; } diff --git a/src/lib/pubkey/dh/dh.cpp b/src/lib/pubkey/dh/dh.cpp index 8f44895ae..be411c5d8 100644 --- a/src/lib/pubkey/dh/dh.cpp +++ b/src/lib/pubkey/dh/dh.cpp @@ -11,12 +11,6 @@ #include <botan/pow_mod.h> #include <botan/blinding.h> -#if defined(BOTAN_HAS_SYSTEM_RNG) - #include <botan/system_rng.h> -#else - #include <botan/auto_rng.h> -#endif - namespace Botan { /* @@ -96,34 +90,31 @@ class DH_KA_Operation : public PK_Ops::Key_Agreement secure_vector<byte> agree(const byte w[], size_t w_len); private: - const BigInt& p; + const BigInt& m_p; - Fixed_Exponent_Power_Mod powermod_x_p; - Blinder blinder; + Fixed_Exponent_Power_Mod m_powermod_x_p; + Blinder m_blinder; }; DH_KA_Operation::DH_KA_Operation(const DH_PrivateKey& dh, const std::string&) : - p(dh.group_p()), powermod_x_p(dh.get_x(), p) + m_p(dh.group_p()), + m_powermod_x_p(dh.get_x(), m_p), + m_blinder(m_p, + [](const BigInt& k) { return k; }, + [this](const BigInt& k) { return m_powermod_x_p(inverse_mod(k, m_p)); }) { -#if defined(BOTAN_HAS_SYSTEM_RNG) - auto& rng = system_rng(); -#else - AutoSeeded_RNG rng; -#endif - BigInt k(rng, p.bits() - 1); - blinder = Blinder(k, powermod_x_p(inverse_mod(k, p)), p); } secure_vector<byte> DH_KA_Operation::agree(const byte w[], size_t w_len) { BigInt input = BigInt::decode(w, w_len); - if(input <= 1 || input >= p - 1) + if(input <= 1 || input >= m_p - 1) throw Invalid_Argument("DH agreement - invalid key provided"); - BigInt r = blinder.unblind(powermod_x_p(blinder.blind(input))); + BigInt r = m_blinder.unblind(m_powermod_x_p(m_blinder.blind(input))); - return BigInt::encode_1363(r, p.bytes()); + return BigInt::encode_1363(r, m_p.bytes()); } } diff --git a/src/lib/pubkey/dh/info.txt b/src/lib/pubkey/dh/info.txt index bb2707951..13ee41d5b 100644 --- a/src/lib/pubkey/dh/info.txt +++ b/src/lib/pubkey/dh/info.txt @@ -11,6 +11,5 @@ dh.cpp <requires> dl_algo dl_group -libstate numbertheory </requires> diff --git a/src/lib/pubkey/dl_group/info.txt b/src/lib/pubkey/dl_group/info.txt index b094c03f5..66f142062 100644 --- a/src/lib/pubkey/dl_group/info.txt +++ b/src/lib/pubkey/dl_group/info.txt @@ -3,7 +3,6 @@ define DL_GROUP 20131128 <requires> asn1 bigint -libstate numbertheory pem </requires> diff --git a/src/lib/pubkey/dlies/info.txt b/src/lib/pubkey/dlies/info.txt index b159cc546..ec1bac803 100644 --- a/src/lib/pubkey/dlies/info.txt +++ b/src/lib/pubkey/dlies/info.txt @@ -2,6 +2,5 @@ define DLIES 20131128 <requires> kdf -libstate mac </requires> diff --git a/src/lib/pubkey/dsa/info.txt b/src/lib/pubkey/dsa/info.txt index ad14494a2..6e0259ce2 100644 --- a/src/lib/pubkey/dsa/info.txt +++ b/src/lib/pubkey/dsa/info.txt @@ -4,7 +4,6 @@ define DSA 20131128 dl_algo dl_group keypair -libstate numbertheory rfc6979 </requires> diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index d024480bb..fc46675bd 100644 --- a/src/lib/pubkey/ec_group/ec_group.cpp +++ b/src/lib/pubkey/ec_group/ec_group.cpp @@ -10,7 +10,6 @@ #include <botan/ec_group.h> #include <botan/ber_dec.h> #include <botan/der_enc.h> -#include <botan/libstate.h> #include <botan/oids.h> #include <botan/pem.h> diff --git a/src/lib/pubkey/ec_group/info.txt b/src/lib/pubkey/ec_group/info.txt index 661f24473..c1cab112e 100644 --- a/src/lib/pubkey/ec_group/info.txt +++ b/src/lib/pubkey/ec_group/info.txt @@ -3,7 +3,6 @@ define ECC_GROUP 20131128 <requires> asn1 ec_gfp -libstate numbertheory oid_lookup pem diff --git a/src/lib/pubkey/ecdh/info.txt b/src/lib/pubkey/ecdh/info.txt index 9277aca9b..32d944728 100644 --- a/src/lib/pubkey/ecdh/info.txt +++ b/src/lib/pubkey/ecdh/info.txt @@ -5,6 +5,5 @@ alloc asn1 ec_group ecc_key -libstate numbertheory </requires> diff --git a/src/lib/pubkey/elgamal/elgamal.cpp b/src/lib/pubkey/elgamal/elgamal.cpp index d59fc1f6b..aacf8ec32 100644 --- a/src/lib/pubkey/elgamal/elgamal.cpp +++ b/src/lib/pubkey/elgamal/elgamal.cpp @@ -12,12 +12,6 @@ #include <botan/blinding.h> #include <botan/workfactor.h> -#if defined(BOTAN_HAS_SYSTEM_RNG) - #include <botan/system_rng.h> -#else - #include <botan/auto_rng.h> -#endif - namespace Botan { /* @@ -155,13 +149,9 @@ ElGamal_Decryption_Operation::ElGamal_Decryption_Operation(const ElGamal_Private powermod_x_p = Fixed_Exponent_Power_Mod(key.get_x(), p); mod_p = Modular_Reducer(p); -#if defined(BOTAN_HAS_SYSTEM_RNG) - auto& rng = system_rng(); -#else - AutoSeeded_RNG rng; -#endif - BigInt k(rng, p.bits() - 1); - blinder = Blinder(k, powermod_x_p(k), p); + blinder = Blinder(p, + [](const BigInt& k) { return k; }, + [this](const BigInt& k) { return powermod_x_p(k); }); } secure_vector<byte> diff --git a/src/lib/pubkey/elgamal/info.txt b/src/lib/pubkey/elgamal/info.txt index 4fe20e828..068949c66 100644 --- a/src/lib/pubkey/elgamal/info.txt +++ b/src/lib/pubkey/elgamal/info.txt @@ -4,6 +4,5 @@ define ELGAMAL 20131128 dl_algo dl_group keypair -libstate numbertheory </requires> diff --git a/src/lib/pubkey/gost_3410/info.txt b/src/lib/pubkey/gost_3410/info.txt index 63521d3dd..611449ebc 100644 --- a/src/lib/pubkey/gost_3410/info.txt +++ b/src/lib/pubkey/gost_3410/info.txt @@ -7,7 +7,6 @@ alloc asn1 ec_group ecc_key -libstate numbertheory rng </requires> diff --git a/src/lib/pubkey/if_algo/info.txt b/src/lib/pubkey/if_algo/info.txt index e4d2dbb5e..5ceec0a89 100644 --- a/src/lib/pubkey/if_algo/info.txt +++ b/src/lib/pubkey/if_algo/info.txt @@ -5,6 +5,5 @@ load_on dep <requires> asn1 bigint -libstate numbertheory </requires> diff --git a/src/lib/pubkey/info.txt b/src/lib/pubkey/info.txt index 4e95c3742..3ef346c30 100644 --- a/src/lib/pubkey/info.txt +++ b/src/lib/pubkey/info.txt @@ -29,14 +29,12 @@ pk_utils.h alloc asn1 bigint -engine filters kdf -libstate oid_lookup pbes2 pem pk_pad rng -algo_base +base </requires> diff --git a/src/lib/pubkey/keypair/info.txt b/src/lib/pubkey/keypair/info.txt index 10fb2013b..2bc9fce29 100644 --- a/src/lib/pubkey/keypair/info.txt +++ b/src/lib/pubkey/keypair/info.txt @@ -1,5 +1,4 @@ define KEYPAIR_TESTING 20131128 <requires> -libstate </requires> diff --git a/src/lib/pubkey/nr/info.txt b/src/lib/pubkey/nr/info.txt index 8c2816fe7..78ca6ef29 100644 --- a/src/lib/pubkey/nr/info.txt +++ b/src/lib/pubkey/nr/info.txt @@ -4,6 +4,5 @@ define NYBERG_RUEPPEL 20131128 dl_algo dl_group keypair -libstate numbertheory </requires> diff --git a/src/lib/pubkey/pk_algs.cpp b/src/lib/pubkey/pk_algs.cpp index 61380e68d..75264d56f 100644 --- a/src/lib/pubkey/pk_algs.cpp +++ b/src/lib/pubkey/pk_algs.cpp @@ -107,7 +107,7 @@ Public_Key* make_public_key(const AlgorithmIdentifier& alg_id, return new Curve25519_PublicKey(alg_id, key_bits); #endif - return nullptr; + throw Decoding_Error("Unhandled PK algorithm " + alg_name); } Private_Key* make_private_key(const AlgorithmIdentifier& alg_id, @@ -168,7 +168,7 @@ Private_Key* make_private_key(const AlgorithmIdentifier& alg_id, return new Curve25519_PrivateKey(alg_id, key_bits, rng); #endif - return nullptr; + throw Decoding_Error("Unhandled PK algorithm " + alg_name); } } diff --git a/src/lib/pubkey/pk_utils.h b/src/lib/pubkey/pk_utils.h new file mode 100644 index 000000000..2d643d862 --- /dev/null +++ b/src/lib/pubkey/pk_utils.h @@ -0,0 +1,36 @@ +/* +* Public Key Algos Utility Header +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_PK_UTILS_H__ +#define BOTAN_PK_UTILS_H__ + +#include <botan/internal/algo_registry.h> +#include <botan/pk_ops.h> +#include <botan/numthry.h> +#include <algorithm> + +namespace Botan { + +template<typename OP, typename T> +OP* make_pk_op(const typename T::Spec& spec) + { + if(auto* key = dynamic_cast<const typename T::Key_Type*>(&spec.key())) + return new T(*key, spec.padding()); + return nullptr; + } + +#define BOTAN_REGISTER_PK_OP(T, NAME, TYPE) BOTAN_REGISTER_NAMED_T(T, NAME, TYPE, (make_pk_op<T, TYPE>)) + +#define BOTAN_REGISTER_PK_ENCRYPTION_OP(NAME, TYPE) BOTAN_REGISTER_PK_OP(PK_Ops::Encryption, NAME, TYPE) +#define BOTAN_REGISTER_PK_DECRYPTION_OP(NAME, TYPE) BOTAN_REGISTER_PK_OP(PK_Ops::Decryption, NAME, TYPE) +#define BOTAN_REGISTER_PK_SIGNATURE_OP(NAME, TYPE) BOTAN_REGISTER_PK_OP(PK_Ops::Signature, NAME, TYPE) +#define BOTAN_REGISTER_PK_VERIFY_OP(NAME, TYPE) BOTAN_REGISTER_PK_OP(PK_Ops::Verification, NAME, TYPE) +#define BOTAN_REGISTER_PK_KEY_AGREE_OP(NAME, TYPE) BOTAN_REGISTER_PK_OP(PK_Ops::Key_Agreement, NAME, TYPE) + +} + +#endif diff --git a/src/lib/pubkey/pkcs8.cpp b/src/lib/pubkey/pkcs8.cpp index a1731c8ef..7b7b54891 100644 --- a/src/lib/pubkey/pkcs8.cpp +++ b/src/lib/pubkey/pkcs8.cpp @@ -12,7 +12,6 @@ #include <botan/oids.h> #include <botan/pem.h> #include <botan/pbes2.h> -#include <botan/libstate.h> #include <botan/scan_name.h> #include <botan/internal/pk_algs.h> @@ -44,7 +43,7 @@ secure_vector<byte> PKCS8_extract(DataSource& source, */ secure_vector<byte> PKCS8_decode( DataSource& source, - std::function<std::pair<bool,std::string> ()> get_passphrase, + std::function<std::string ()> get_passphrase, AlgorithmIdentifier& pk_alg_id) { AlgorithmIdentifier pbe_alg_id; @@ -77,49 +76,29 @@ secure_vector<byte> PKCS8_decode( throw Decoding_Error("PKCS #8 private key decoding failed: " + std::string(e.what())); } - if(!is_encrypted) - key = key_data; - - const size_t MAX_TRIES = 3; - - size_t tries = 0; - while(true) + try { - try { - if(MAX_TRIES && tries >= MAX_TRIES) - break; - - if(is_encrypted) - { - std::pair<bool, std::string> pass = get_passphrase(); - - if(pass.first == false) - break; - - if(OIDS::lookup(pbe_alg_id.oid) != "PBE-PKCS5v20") - throw std::runtime_error("Unknown PBE type " + pbe_alg_id.oid.as_string()); - - key = pbes2_decrypt(key_data, pass.second, pbe_alg_id.parameters); - } - - BER_Decoder(key) - .start_cons(SEQUENCE) - .decode_and_check<size_t>(0, "Unknown PKCS #8 version number") - .decode(pk_alg_id) - .decode(key, OCTET_STRING) - .discard_remaining() - .end_cons(); - - break; - } - catch(Decoding_Error) + if(is_encrypted) { - ++tries; + if(OIDS::lookup(pbe_alg_id.oid) != "PBE-PKCS5v20") + throw std::runtime_error("Unknown PBE type " + pbe_alg_id.oid.as_string()); + key = pbes2_decrypt(key_data, get_passphrase(), pbe_alg_id.parameters); } - } + else + key = key_data; - if(key.empty()) - throw Decoding_Error("PKCS #8 private key decoding failed"); + BER_Decoder(key) + .start_cons(SEQUENCE) + .decode_and_check<size_t>(0, "Unknown PKCS #8 version number") + .decode(pk_alg_id) + .decode(key, OCTET_STRING) + .discard_remaining() + .end_cons(); + } + catch(std::exception& e) + { + throw Decoding_Error("PKCS #8 private key decoding failed: " + std::string(e.what())); + } return key; } @@ -215,7 +194,7 @@ std::string PEM_encode(const Private_Key& key, */ Private_Key* load_key(DataSource& source, RandomNumberGenerator& rng, - std::function<std::pair<bool, std::string> ()> get_pass) + std::function<std::string ()> get_pass) { AlgorithmIdentifier alg_id; secure_vector<byte> pkcs8_key = PKCS8_decode(source, get_pass, alg_id); @@ -233,38 +212,12 @@ Private_Key* load_key(DataSource& source, */ Private_Key* load_key(const std::string& fsname, RandomNumberGenerator& rng, - std::function<std::pair<bool, std::string> ()> get_pass) + std::function<std::string ()> get_pass) { DataSource_Stream source(fsname, true); return PKCS8::load_key(source, rng, get_pass); } -namespace { - -class Single_Shot_Passphrase - { - public: - Single_Shot_Passphrase(const std::string& pass) : - passphrase(pass), first(true) {} - - std::pair<bool, std::string> operator()() - { - if(first) - { - first = false; - return std::make_pair(true, passphrase); - } - else - return std::make_pair(false, ""); - } - - private: - std::string passphrase; - bool first; - }; - -} - /* * Extract a private key and return it */ @@ -272,7 +225,7 @@ Private_Key* load_key(DataSource& source, RandomNumberGenerator& rng, const std::string& pass) { - return PKCS8::load_key(source, rng, Single_Shot_Passphrase(pass)); + return PKCS8::load_key(source, rng, [pass]() { return pass; }); } /* @@ -282,7 +235,7 @@ Private_Key* load_key(const std::string& fsname, RandomNumberGenerator& rng, const std::string& pass) { - return PKCS8::load_key(fsname, rng, Single_Shot_Passphrase(pass)); + return PKCS8::load_key(fsname, rng, [pass]() { return pass; }); } /* diff --git a/src/lib/pubkey/pkcs8.h b/src/lib/pubkey/pkcs8.h index 0840f4a46..ac037407e 100644 --- a/src/lib/pubkey/pkcs8.h +++ b/src/lib/pubkey/pkcs8.h @@ -89,7 +89,7 @@ PEM_encode(const Private_Key& key, BOTAN_DLL Private_Key* load_key( DataSource& source, RandomNumberGenerator& rng, - std::function<std::pair<bool, std::string> ()> get_passphrase); + std::function<std::string ()> get_passphrase); /** Load a key from a data source. * @param source the data source providing the encoded key @@ -112,7 +112,7 @@ BOTAN_DLL Private_Key* load_key(DataSource& source, BOTAN_DLL Private_Key* load_key( const std::string& filename, RandomNumberGenerator& rng, - std::function<std::pair<bool, std::string> ()> get_passphrase); + std::function<std::string ()> get_passphrase); /** Load a key from a file. * @param filename the path to the file containing the encoded key diff --git a/src/lib/pubkey/pubkey.cpp b/src/lib/pubkey/pubkey.cpp index 95d61ad4c..82797094a 100644 --- a/src/lib/pubkey/pubkey.cpp +++ b/src/lib/pubkey/pubkey.cpp @@ -10,7 +10,7 @@ #include <botan/ber_dec.h> #include <botan/bigint.h> #include <botan/parsing.h> -#include <botan/algo_registry.h> +#include <botan/internal/algo_registry.h> #include <botan/internal/bit_ops.h> #if defined(BOTAN_HAS_SYSTEM_RNG) diff --git a/src/lib/pubkey/rfc6979/rfc6979.cpp b/src/lib/pubkey/rfc6979/rfc6979.cpp index 5ba2f844a..9f9bbc9c0 100644 --- a/src/lib/pubkey/rfc6979/rfc6979.cpp +++ b/src/lib/pubkey/rfc6979/rfc6979.cpp @@ -8,7 +8,7 @@ #include <botan/rfc6979.h> #include <botan/hmac_drbg.h> #include <botan/scan_name.h> -#include <botan/algo_registry.h> +#include <botan/internal/algo_registry.h> namespace Botan { diff --git a/src/lib/pubkey/rsa/info.txt b/src/lib/pubkey/rsa/info.txt index 6171642bc..264ff7c62 100644 --- a/src/lib/pubkey/rsa/info.txt +++ b/src/lib/pubkey/rsa/info.txt @@ -3,6 +3,5 @@ define RSA 20131128 <requires> if_algo keypair -libstate numbertheory </requires> diff --git a/src/lib/pubkey/rsa/rsa.cpp b/src/lib/pubkey/rsa/rsa.cpp index 9393cb954..c371e20e0 100644 --- a/src/lib/pubkey/rsa/rsa.cpp +++ b/src/lib/pubkey/rsa/rsa.cpp @@ -13,12 +13,6 @@ #include <botan/reducer.h> #include <future> -#if defined(BOTAN_HAS_SYSTEM_RNG) - #include <botan/system_rng.h> -#else - #include <botan/auto_rng.h> -#endif - namespace Botan { /* @@ -84,15 +78,11 @@ class RSA_Private_Operation m_powermod_e_n(rsa.get_e(), rsa.get_n()), m_powermod_d1_p(rsa.get_d1(), rsa.get_p()), m_powermod_d2_q(rsa.get_d2(), rsa.get_q()), - m_mod_p(rsa.get_p()) + m_mod_p(rsa.get_p()), + m_blinder(n, + [this](const BigInt& k) { return m_powermod_e_n(k); }, + [this](const BigInt& k) { return inverse_mod(k, n); }) { -#if defined(BOTAN_HAS_SYSTEM_RNG) - auto& rng = system_rng(); -#else - AutoSeeded_RNG rng; -#endif - BigInt k(rng, n.bits() - 1); - m_blinder = Blinder(m_powermod_e_n(k), inverse_mod(k, n), n); } BigInt blinded_private_op(const BigInt& m) const diff --git a/src/lib/pubkey/rw/info.txt b/src/lib/pubkey/rw/info.txt index 486ede47f..7cf1d1780 100644 --- a/src/lib/pubkey/rw/info.txt +++ b/src/lib/pubkey/rw/info.txt @@ -3,6 +3,5 @@ define RW 20131128 <requires> if_algo keypair -libstate numbertheory </requires> diff --git a/src/lib/pubkey/rw/rw.cpp b/src/lib/pubkey/rw/rw.cpp index 3c7a6250b..32ba398b0 100644 --- a/src/lib/pubkey/rw/rw.cpp +++ b/src/lib/pubkey/rw/rw.cpp @@ -80,7 +80,10 @@ class RW_Signature_Operation : public PK_Ops::Signature c(rw.get_c()), powermod_d1_p(rw.get_d1(), rw.get_p()), powermod_d2_q(rw.get_d2(), rw.get_q()), - mod_p(rw.get_p()) + mod_p(rw.get_p()), + blinder(n, + [this](const BigInt& k) { return power_mod(k, e, n); }, + [this](const BigInt& k) { return inverse_mod(k, n); }) { } @@ -101,16 +104,8 @@ class RW_Signature_Operation : public PK_Ops::Signature secure_vector<byte> RW_Signature_Operation::sign(const byte msg[], size_t msg_len, - RandomNumberGenerator& rng) + RandomNumberGenerator&) { - rng.add_entropy(msg, msg_len); - - if(!blinder.initialized()) - { - BigInt k(rng, std::min<size_t>(160, n.bits() - 1)); - blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n); - } - BigInt i(msg, msg_len); if(i >= n || i % 16 != 12) diff --git a/src/lib/pubkey/x509_key.cpp b/src/lib/pubkey/x509_key.cpp index cd3da7a53..ccb94cea7 100644 --- a/src/lib/pubkey/x509_key.cpp +++ b/src/lib/pubkey/x509_key.cpp @@ -72,9 +72,9 @@ Public_Key* load_key(DataSource& source) return make_public_key(alg_id, key_bits); } - catch(Decoding_Error) + catch(Decoding_Error& e) { - throw Decoding_Error("X.509 public key decoding failed"); + throw Decoding_Error("X.509 public key decoding failed: " + std::string(e.what())); } } |