mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix C++ style issues.
* Restrict files to 80 columns. * Function names in GenerateDeterministicKey now start with lower case. * Remove deprecated boost::format calls.
This commit is contained in:
@@ -29,11 +29,12 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
Blob GenerateRootDeterministicPublicKey (const uint128& passPhrase);
|
||||
uint256 GenerateRootDeterministicPrivateKey (const uint128& passPhrase);
|
||||
Blob generateRootDeterministicPublicKey (const uint128& passPhrase);
|
||||
uint256 generateRootDeterministicPrivateKey (const uint128& passPhrase);
|
||||
|
||||
Blob GeneratePublicDeterministicKey (Blob const& generator, int n);
|
||||
uint256 GeneratePrivateDeterministicKey (Blob const& family, uint128 const& seed, int n);
|
||||
Blob generatePublicDeterministicKey (Blob const& generator, int n);
|
||||
uint256 generatePrivateDeterministicKey (
|
||||
Blob const& family, uint128 const& seed, int n);
|
||||
|
||||
} // ripple
|
||||
|
||||
|
||||
@@ -30,8 +30,10 @@ namespace ripple {
|
||||
|
||||
namespace openssl {
|
||||
|
||||
static EC_GROUP const* const secp256k1_group = EC_GROUP_new_by_curve_name (NID_secp256k1);
|
||||
static bignum const secp256k1_order = get_order (secp256k1_group);
|
||||
static EC_GROUP const* const secp256k1_group =
|
||||
EC_GROUP_new_by_curve_name (NID_secp256k1);
|
||||
static bignum const secp256k1_order =
|
||||
get_order (secp256k1_group);
|
||||
|
||||
} // namespace openssl
|
||||
|
||||
@@ -71,7 +73,7 @@ copy_uint32 (FwdIt out, std::uint32_t v)
|
||||
|
||||
// --> seed
|
||||
// <-- private root generator + public root generator
|
||||
static bignum GenerateRootDeterministicKey (uint128 const& seed)
|
||||
static bignum generateRootDeterministicKey (uint128 const& seed)
|
||||
{
|
||||
// find non-zero private key less than the curve's order
|
||||
bignum privKey;
|
||||
@@ -97,11 +99,11 @@ static bignum GenerateRootDeterministicKey (uint128 const& seed)
|
||||
|
||||
// --> seed
|
||||
// <-- private root generator + public root generator
|
||||
Blob GenerateRootDeterministicPublicKey (uint128 const& seed)
|
||||
Blob generateRootDeterministicPublicKey (uint128 const& seed)
|
||||
{
|
||||
bn_ctx ctx;
|
||||
|
||||
bignum privKey = GenerateRootDeterministicKey (seed);
|
||||
bignum privKey = generateRootDeterministicKey (seed);
|
||||
|
||||
// compute the corresponding public key point
|
||||
ec_point pubKey = multiply (secp256k1_group, privKey, ctx);
|
||||
@@ -111,9 +113,9 @@ Blob GenerateRootDeterministicPublicKey (uint128 const& seed)
|
||||
return serialize_ec_point (pubKey);
|
||||
}
|
||||
|
||||
uint256 GenerateRootDeterministicPrivateKey (uint128 const& seed)
|
||||
uint256 generateRootDeterministicPrivateKey (uint128 const& seed)
|
||||
{
|
||||
bignum key = GenerateRootDeterministicKey (seed);
|
||||
bignum key = generateRootDeterministicKey (seed);
|
||||
|
||||
return uint256_from_bignum_clear (key);
|
||||
}
|
||||
@@ -121,7 +123,7 @@ uint256 GenerateRootDeterministicPrivateKey (uint128 const& seed)
|
||||
// Take ripple address.
|
||||
// --> root public generator (consumes)
|
||||
// <-- root public generator in EC format
|
||||
static ec_point GenerateRootPubKey (bignum&& pubGenerator)
|
||||
static ec_point generateRootPubKey (bignum&& pubGenerator)
|
||||
{
|
||||
ec_point pubPoint = bn2point (secp256k1_group, pubGenerator.get());
|
||||
|
||||
@@ -155,10 +157,10 @@ static bignum makeHash (Blob const& pubGen, int seq, bignum const& order)
|
||||
}
|
||||
|
||||
// --> public generator
|
||||
Blob GeneratePublicDeterministicKey (Blob const& pubGen, int seq)
|
||||
Blob generatePublicDeterministicKey (Blob const& pubGen, int seq)
|
||||
{
|
||||
// publicKey(n) = rootPublicKey EC_POINT_+ Hash(pubHash|seq)*point
|
||||
ec_point rootPubKey = GenerateRootPubKey (bignum (pubGen));
|
||||
ec_point rootPubKey = generateRootPubKey (bignum (pubGen));
|
||||
|
||||
bn_ctx ctx;
|
||||
|
||||
@@ -175,10 +177,11 @@ Blob GeneratePublicDeterministicKey (Blob const& pubGen, int seq)
|
||||
}
|
||||
|
||||
// --> root private key
|
||||
uint256 GeneratePrivateDeterministicKey (Blob const& pubGen, uint128 const& seed, int seq)
|
||||
uint256 generatePrivateDeterministicKey (
|
||||
Blob const& pubGen, uint128 const& seed, int seq)
|
||||
{
|
||||
// privateKey(n) = (rootPrivateKey + Hash(pubHash|seq)) % order
|
||||
bignum rootPrivKey = GenerateRootDeterministicKey (seed);
|
||||
bignum rootPrivKey = generateRootDeterministicKey (seed);
|
||||
|
||||
bn_ctx ctx;
|
||||
|
||||
|
||||
@@ -40,14 +40,16 @@ public:
|
||||
seed1.SetHex ("71ED064155FFADFA38782C5E0158CB26");
|
||||
seed2.SetHex ("CF0C3BE4485961858C4198515AE5B965");
|
||||
|
||||
uint256 const priv1 = GenerateRootDeterministicPrivateKey (seed1);
|
||||
uint256 const priv2 = GenerateRootDeterministicPrivateKey (seed2);
|
||||
uint256 const priv1 = generateRootDeterministicPrivateKey (seed1);
|
||||
uint256 const priv2 = generateRootDeterministicPrivateKey (seed2);
|
||||
|
||||
unexpected (to_string (priv1) != "7CFBA64F771E93E817E15039215430B53F7401C34931D111EAB3510B22DBB0D8",
|
||||
"Incorrect private key for generator");
|
||||
unexpected (to_string (priv1) != "7CFBA64F771E93E817E15039215430B53F74"
|
||||
"01C34931D111EAB3510B22DBB0D8",
|
||||
"Incorrect private key for generator");
|
||||
|
||||
unexpected (to_string (priv2) != "98BC2EACB26EB021D1A6293C044D88BA2F0B6729A2772DEEBF2E21A263C1740B",
|
||||
"Incorrect private key for generator");
|
||||
unexpected (to_string (priv2) != "98BC2EACB26EB021D1A6293C044D88BA2F0B"
|
||||
"6729A2772DEEBF2E21A263C1740B",
|
||||
"Incorrect private key for generator");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user