Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The War on RippleAddress #373

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ if not OSX:
'-pthread',
])

DEBUGFLAGS = ['-g', '-DDEBUG', '-D_DEBUG']
DEBUGFLAGS = [
'-g', '-DDEBUG', '-D_DEBUG', '-Wfatal-errors', '-Wno-unused-variable',
'-Wno-unused-function', '-Wno-unused-but-set-variable'
]

env.Append(CCFLAGS = ['-pthread', '-Wall', '-Wno-sign-compare', '-Wno-char-subscripts']+DEBUGFLAGS)
if not USING_CLANG:
Expand All @@ -342,7 +345,7 @@ else:
env.Append(CCFLAGS = more_warnings)

# add '-Wconversion' some day
env.Append(CXXFLAGS = ['-O3', '-fno-strict-aliasing', '-pthread', '-Wno-invalid-offsetof', '-Wformat']+more_warnings+DEBUGFLAGS)
env.Append(CXXFLAGS = ['-O0', '-fno-strict-aliasing', '-pthread', '-Wno-invalid-offsetof', '-Wformat']+more_warnings+DEBUGFLAGS)

# RTTI is required for Beast and CountedObject.
#
Expand Down
63 changes: 47 additions & 16 deletions src/ripple/types/api/base_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,53 @@ class base_uint

typedef Tag tag_type;

pointer data() { return reinterpret_cast<pointer>(pn); }
const_pointer data() const { return reinterpret_cast<const_pointer>(pn); }

iterator begin() { return data(); }
iterator end() { return data()+bytes; }
const_iterator begin() const { return data(); }
const_iterator end() const { return data()+bytes; }
const_iterator cbegin() const { return data(); }
const_iterator cend() const { return data()+bytes; }

reverse_iterator rbegin() { return end(); }
reverse_iterator rend() { return begin(); }
const_reverse_iterator rbegin() const { return end(); }
const_reverse_iterator rend() const { return begin(); }
const_reverse_iterator crbegin() const { return cend(); }
const_reverse_iterator crend() const { return cbegin(); }
pointer data () { return reinterpret_cast<pointer>(pn); }
const_pointer data () const { return reinterpret_cast<const_pointer>(pn); }

/** Forward iterators */
/** @{ */
iterator
begin () { return data (); }

iterator
end () { return data () + bytes; }
/** @} */

/** Constant forward iterators */
/** @{ */
const_iterator begin ()
const { return const_iterator (data ()); }

const_iterator end ()
const { return const_iterator (data () + bytes); }

const_iterator cbegin ()
const { return const_iterator (data ()); }

const_iterator cend ()
const { return const_iterator (data () + bytes); }
/** @} */

/** Reverse iterators */
/** @{ */
reverse_iterator rbegin () { return reverse_iterator (end ()); }
reverse_iterator rend () { return reverse_iterator (begin ()); }
/** @} */

/** Constant reverse iterators */
/** @{ */
const_reverse_iterator
rbegin () const { return const_reverse_iterator (cend()); }

const_reverse_iterator
rend () const { return const_reverse_iterator (cbegin()); }

const_reverse_iterator
crbegin () const { return const_reverse_iterator (cend()); }

const_reverse_iterator
crend () const { return const_reverse_iterator (cbegin()); }
/** @} */

/** Value hashing function.
The seed prevents crafted inputs from causing degenarate parent containers.
Expand Down
9 changes: 6 additions & 3 deletions src/ripple_app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,12 @@ class ApplicationImp
void ApplicationImp::startNewLedger ()
{
// New stuff.
RippleAddress rootSeedMaster = RippleAddress::createSeedGeneric ("masterpassphrase");
RippleAddress rootGeneratorMaster = RippleAddress::createGeneratorPublic (rootSeedMaster);
RippleAddress rootAddress = RippleAddress::createAccountPublic (rootGeneratorMaster, 0);
RippleAddressSeed rootSeedMaster (
RippleAddressSeed::createSeedGeneric ("masterpassphrase"));
RippleAddressGenerator rootGeneratorMaster (
RippleAddressGenerator::createGeneratorPublic (rootSeedMaster));
RippleAddress rootAddress (
RippleAddress::createAccountPublic (rootGeneratorMaster, 0));

// Print enough information to be able to claim root account.
m_journal.info << "Root master seed: " << rootSeedMaster.humanSeed ();
Expand Down
2 changes: 1 addition & 1 deletion src/ripple_app/main/LocalCredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool LocalCredentials::nodeIdentityCreate ()
//
// Generate the public and private key
//
RippleAddress naSeed = RippleAddress::createSeedRandom ();
RippleAddressSeed naSeed = RippleAddressSeed::createSeedRandom ();
RippleAddress naNodePublic = RippleAddress::createNodePublic (naSeed);
RippleAddress naNodePrivate = RippleAddress::createNodePrivate (naSeed);

Expand Down
11 changes: 7 additions & 4 deletions src/ripple_app/misc/SerializedTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,14 @@ class SerializedTransaction_test : public beast::unit_test::suite
public:
void run()
{
RippleAddress seed;
RippleAddressSeed seed;
seed.setSeedRandom ();
RippleAddress generator = RippleAddress::createGeneratorPublic (seed);
RippleAddress publicAcct = RippleAddress::createAccountPublic (generator, 1);
RippleAddress privateAcct = RippleAddress::createAccountPrivate (generator, seed, 1);
RippleAddressGenerator generator (
RippleAddressGenerator::createGeneratorPublic (seed));
RippleAddress publicAcct (
RippleAddress::createAccountPublic (generator, 1));
RippleAddress privateAcct (
RippleAddress::createAccountPrivate (generator, seed, 1));

SerializedTransaction j (ttACCOUNT_SET);
j.setSourceAccount (publicAcct);
Expand Down
10 changes: 6 additions & 4 deletions src/ripple_app/peers/UniqueNodeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,11 +1670,13 @@ class UniqueNodeListImp
{
std::string strRefered = smMatch[1];
std::string strComment = smMatch[2];
RippleAddress naValidator;

if (naValidator.setSeedGeneric (strRefered))
RippleAddressSeed naSeed;
RippleAddress naValidator;

if (naSeed.setSeedGeneric (strRefered))
{
WriteLog (lsWARNING, UniqueNodeList) << str (boost::format ("Bad validator: domain or public key required: %s %s") % strRefered % strComment);
WriteLog (lsWARNING, UniqueNodeList) <<
str (boost::format ("Bad validator: domain or public key required: %s %s") % strRefered % strComment);
}
else if (naValidator.setNodePublic (strRefered))
{
Expand Down
8 changes: 6 additions & 2 deletions src/ripple_core/functional/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,15 @@ class Config
int PATH_SEARCH_MAX;

// Validation
RippleAddress VALIDATION_SEED, VALIDATION_PUB, VALIDATION_PRIV;
RippleAddressSeed VALIDATION_SEED;
RippleAddress VALIDATION_PUB;
RippleAddress VALIDATION_PRIV;

// Node/Cluster
std::vector<std::string> CLUSTER_NODES;
RippleAddress NODE_SEED, NODE_PUB, NODE_PRIV;
RippleAddressSeed NODE_SEED;
RippleAddress NODE_PUB;
RippleAddress NODE_PRIV;

// Fee schedule (All below values are in fee units)
std::uint64_t FEE_DEFAULT; // Default fee.
Expand Down
19 changes: 16 additions & 3 deletions src/ripple_data/crypto/Base58Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ class CBase58Data
unsigned char nVersion;
Blob vchData;

CBase58Data ();
~CBase58Data ();

void SetData (int version, Blob const& vchDataIn)
{
nVersion = version;
vchData = vchDataIn;
}

template <size_t Bits, class Tag>
template <size_t Bits, class Tag = void>
void SetData (int version, base_uint<Bits, Tag> const& from)
{
nVersion = version;
Expand All @@ -67,6 +65,16 @@ class CBase58Data
}

public:
// Temporarily moved here.
CBase58Data ();
~CBase58Data ();

template <size_t Bits, class Tag = void>
CBase58Data (int version, base_uint<Bits, Tag> const& from)
: nVersion (version), vchData (std::begin (from), std::end(from))
{
}

bool SetString (std::string const& str, unsigned char version,
Base58::Alphabet const& alphabet);

Expand All @@ -89,6 +97,11 @@ class CBase58Data
return 0;
}

Blob const& getData () const
{
return vchData;
}

friend std::size_t hash_value (const CBase58Data& b58);
};

Expand Down
2 changes: 1 addition & 1 deletion src/ripple_data/crypto/CKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CKey_test : public beast::unit_test::suite
unexpected (to_string (priv2) != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B",
"Incorrect private key for generator");

RippleAddress nSeed;
RippleAddressSeed nSeed;
nSeed.setSeed (seed1);

unexpected (nSeed.humanSeed () != "shHM53KPZ87Gwdqarm1bAmPeXg8Tn",
Expand Down
20 changes: 13 additions & 7 deletions src/ripple_data/crypto/CKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,32 @@ class CKey
static uint128 PassPhraseToKey (const std::string& passPhrase);
static EC_KEY* GenerateRootDeterministicKey (const uint128& passPhrase);
static EC_KEY* GenerateRootPubKey (BIGNUM* pubGenerator);
static EC_KEY* GeneratePublicDeterministicKey (const RippleAddress& generator, int n);
static EC_KEY* GeneratePrivateDeterministicKey (const RippleAddress& family, const BIGNUM* rootPriv, int n);
static EC_KEY* GeneratePrivateDeterministicKey (const RippleAddress& family, uint256 const& rootPriv, int n);

CKey (const uint128& passPhrase) : fSet (false)
static EC_KEY* GeneratePublicDeterministicKey (
RippleAddressGenerator const& generator, int n);
static EC_KEY* GeneratePrivateDeterministicKey (
RippleAddressGenerator const& family, const BIGNUM* rootPriv, int n);
static EC_KEY* GeneratePrivateDeterministicKey (
RippleAddressGenerator const& family, uint256 const& rootPriv, int n);

CKey (const uint128& passPhrase)
: fSet (false)
{
pkey = GenerateRootDeterministicKey (passPhrase);
fSet = true;
assert (pkey);
}

CKey (const RippleAddress& generator, int n) : fSet (false)
CKey (const RippleAddressGenerator& generator, int n)
: fSet (false)
{
// public deterministic key
pkey = GeneratePublicDeterministicKey (generator, n);
fSet = true;
assert (pkey);
}

CKey (const RippleAddress& base, const BIGNUM* rootPrivKey, int n) : fSet (false)
CKey (const RippleAddressGenerator& base, const BIGNUM* rootPrivKey, int n)
: fSet (false)
{
// private deterministic key
pkey = GeneratePrivateDeterministicKey (base, rootPrivKey, n);
Expand Down
11 changes: 7 additions & 4 deletions src/ripple_data/crypto/CKeyDeterministic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ EC_KEY* CKey::GenerateRootPubKey (BIGNUM* pubGenerator)
}

// --> public generator
static BIGNUM* makeHash (const RippleAddress& pubGen, int seq, BIGNUM* order)
static BIGNUM* makeHash (RippleAddressGenerator const& pubGen, int seq, BIGNUM* order)
{
int subSeq = 0;
BIGNUM* ret = nullptr;
Expand All @@ -212,7 +212,8 @@ static BIGNUM* makeHash (const RippleAddress& pubGen, int seq, BIGNUM* order)
}

// --> public generator
EC_KEY* CKey::GeneratePublicDeterministicKey (const RippleAddress& pubGen, int seq)
EC_KEY* CKey::GeneratePublicDeterministicKey (
RippleAddressGenerator const& pubGen, int seq)
{
// publicKey(n) = rootPublicKey EC_POINT_+ Hash(pubHash|seq)*point
BIGNUM* generator = BN_bin2bn (
Expand Down Expand Up @@ -285,14 +286,16 @@ EC_KEY* CKey::GeneratePublicDeterministicKey (const RippleAddress& pubGen, int s
return success ? pkey : nullptr;
}

EC_KEY* CKey::GeneratePrivateDeterministicKey (const RippleAddress& pubGen, uint256 const& u, int seq)
EC_KEY* CKey::GeneratePrivateDeterministicKey (
RippleAddressGenerator const& pubGen, uint256 const& u, int seq)
{
CBigNum bn (u);
return GeneratePrivateDeterministicKey (pubGen, static_cast<BIGNUM*> (&bn), seq);
}

// --> root private key
EC_KEY* CKey::GeneratePrivateDeterministicKey (const RippleAddress& pubGen, const BIGNUM* rootPrivKey, int seq)
EC_KEY* CKey::GeneratePrivateDeterministicKey (
RippleAddressGenerator const& pubGen, const BIGNUM* rootPrivKey, int seq)
{
// privateKey(n) = (rootPrivateKey + Hash(pubHash|seq)) % order
BN_CTX* ctx = BN_CTX_new ();
Expand Down
4 changes: 2 additions & 2 deletions src/ripple_data/crypto/RFC1751.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,14 @@ int RFC1751::getKeyFromEnglish (std::string& strKey, const std::string& strHuman

/** Convert to human from a 128 bit key in big-endian format
*/
void RFC1751::getEnglishFromKey (std::string& strHuman, const std::string& strKey)
std::string RFC1751::getEnglishFromKey (const std::string& strKey)
{
std::string strFirst, strSecond;

btoe (strFirst, strKey.substr (0, 8));
btoe (strSecond, strKey.substr (8, 8));

strHuman = strFirst + " " + strSecond;
return (strFirst + " " + strSecond);
}

beast::String RFC1751::getWordFromBlob (void const* data, size_t bytes)
Expand Down
2 changes: 1 addition & 1 deletion src/ripple_data/crypto/RFC1751.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RFC1751
public:
static int getKeyFromEnglish (std::string& strKey, const std::string& strHuman);

static void getEnglishFromKey (std::string& strHuman, const std::string& strKey);
static std::string getEnglishFromKey (const std::string& strKey);

/** Chooses a single dictionary word from the data.

Expand Down
Loading