diff --git a/libdevcrypto/Common.cpp b/libdevcrypto/Common.cpp index e763cc9b2..f039435ad 100644 --- a/libdevcrypto/Common.cpp +++ b/libdevcrypto/Common.cpp @@ -28,6 +28,7 @@ #include "Common.h" using namespace std; using namespace dev; +using namespace crypto; //#define ETH_ADDRESS_DEBUG 1 @@ -38,8 +39,8 @@ Address dev::toAddress(Secret _secret) KeyPair KeyPair::create() { - static std::mt19937_64 s_eng(time(0)); - std::uniform_int_distribution d(0, 255); + static mt19937_64 s_eng(time(0)); + uniform_int_distribution d(0, 255); for (int i = 0; i < 100; ++i) { @@ -57,8 +58,8 @@ KeyPair KeyPair::create() KeyPair::KeyPair(h256 _sec): m_secret(_sec) { - crypto::toPublic(m_secret, m_public); - if (crypto::verifySecret(m_secret, m_public)) + toPublic(m_secret, m_public); + if (verifySecret(m_secret, m_public)) m_address = right160(dev::sha3(m_public.ref())); #if ETH_ADDRESS_DEBUG @@ -106,7 +107,7 @@ bool dev::verify(Public _p, Signature _s, h256 _hash) return crypto::verify(_p, _s, bytesConstRef(_hash.data(), 32), true); } -h256 Sec::getNonce(bool _commit) +h256 Nonce::get(bool _commit) { // todo: atomic efface bit, periodic save, kdf, rr, rng static h256 seed; @@ -116,8 +117,7 @@ h256 Sec::getNonce(bool _commit) { if (!seed) { - static Sec sec; - + static Nonce nonce; bytes b = contents(seedFile); if (b.size() == 32) memcpy(seed.data(), b.data(), 32); @@ -139,7 +139,7 @@ h256 Sec::getNonce(bool _commit) return seed; } -Sec::~Sec() +Nonce::~Nonce() { - Sec::getNonce(true); + Nonce::get(true); } diff --git a/libdevcrypto/Common.h b/libdevcrypto/Common.h index e163fb1c4..167621ec0 100644 --- a/libdevcrypto/Common.h +++ b/libdevcrypto/Common.h @@ -110,13 +110,19 @@ private: Public m_public; Address m_address; }; - -struct Sec + +namespace crypto +{ +/** + * @brief Generator for nonce material + */ +struct Nonce { - static h256 getNonce(bool _commit = false); + static h256 get(bool _commit = false); private: - Sec() {} - ~Sec(); + Nonce() {} + ~Nonce(); }; +} } \ No newline at end of file diff --git a/libdevcrypto/EC.cpp b/libdevcrypto/EC.cpp index e6b4c19c8..73c36ffdc 100644 --- a/libdevcrypto/EC.cpp +++ b/libdevcrypto/EC.cpp @@ -56,7 +56,7 @@ void crypto::toPublic(Secret const& _s, Public& o_public) h256 crypto::kdf(Secret const& _priv, h256 const& _hash) { h256 s; - sha3mac(Sec::getNonce().ref(), _priv.ref(), s.ref()); + sha3mac(Nonce::get().ref(), _priv.ref(), s.ref()); assert(s); return sha3((_hash ^ s).asBytes()); }