Browse Source

rename nonce generator

cl-refactor
subtly 10 years ago
parent
commit
482a1241f7
  1. 18
      libdevcrypto/Common.cpp
  2. 14
      libdevcrypto/Common.h
  3. 2
      libdevcrypto/EC.cpp

18
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<uint16_t> d(0, 255);
static mt19937_64 s_eng(time(0));
uniform_int_distribution<uint16_t> 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);
}

14
libdevcrypto/Common.h

@ -111,12 +111,18 @@ private:
Address m_address;
};
struct Sec
namespace crypto
{
static h256 getNonce(bool _commit = false);
/**
* @brief Generator for nonce material
*/
struct Nonce
{
static h256 get(bool _commit = false);
private:
Sec() {}
~Sec();
Nonce() {}
~Nonce();
};
}
}

2
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());
}

Loading…
Cancel
Save