20#include <xrpl/basics/Buffer.h> 
   21#include <xrpl/basics/Slice.h> 
   22#include <xrpl/basics/base_uint.h> 
   23#include <xrpl/basics/contract.h> 
   24#include <xrpl/basics/strHex.h> 
   25#include <xrpl/beast/utility/rngfill.h> 
   26#include <xrpl/crypto/csprng.h> 
   27#include <xrpl/crypto/secure_erase.h> 
   28#include <xrpl/protocol/KeyType.h> 
   29#include <xrpl/protocol/PublicKey.h> 
   30#include <xrpl/protocol/SecretKey.h> 
   31#include <xrpl/protocol/Seed.h> 
   32#include <xrpl/protocol/detail/secp256k1.h> 
   33#include <xrpl/protocol/digest.h> 
   34#include <xrpl/protocol/tokens.h> 
   36#include <boost/utility/string_view.hpp> 
   64        LogicError(
"SecretKey::SecretKey: invalid size");
 
 
   80    *
out++ = (v >> 16) & 0xff;
 
   81    *
out++ = (v >> 8) & 0xff;
 
 
  116    Throw<std::runtime_error>(
"Unable to derive generator from seed");
 
 
  175        Throw<std::runtime_error>(
"Unable to derive generator from seed");
 
 
  182        secp256k1_pubkey pubkey;
 
  183        if (secp256k1_ec_pubkey_create(
 
  185            LogicError(
"derivePublicKey: secp256k1_ec_pubkey_create failed");
 
  189        if (secp256k1_ec_pubkey_serialize(
 
  194                SECP256K1_EC_COMPRESSED) != 1)
 
  195            LogicError(
"derivePublicKey: secp256k1_ec_pubkey_serialize failed");
 
 
  212            if (secp256k1_ec_seckey_tweak_add(
 
 
 
  233        LogicError(
"sign: secp256k1 required for digest signing");
 
  235    BOOST_ASSERT(sk.
size() == 32);
 
  236    secp256k1_ecdsa_signature sig_imp;
 
  237    if (secp256k1_ecdsa_sign(
 
  240            reinterpret_cast<unsigned char const*
>(
digest.data()),
 
  241            reinterpret_cast<unsigned char const*
>(sk.
data()),
 
  242            secp256k1_nonce_function_rfc6979,
 
  244        LogicError(
"sign: secp256k1_ecdsa_sign failed");
 
  246    unsigned char sig[72];
 
  247    size_t len = 
sizeof(sig);
 
  248    if (secp256k1_ecdsa_signature_serialize_der(
 
  250        LogicError(
"sign: secp256k1_ecdsa_signature_serialize_der failed");
 
 
  274            secp256k1_ecdsa_signature sig_imp;
 
  275            if (secp256k1_ecdsa_sign(
 
  278                    reinterpret_cast<unsigned char const*
>(
digest.data()),
 
  279                    reinterpret_cast<unsigned char const*
>(sk.
data()),
 
  280                    secp256k1_nonce_function_rfc6979,
 
  282                LogicError(
"sign: secp256k1_ecdsa_sign failed");
 
  284            unsigned char sig[72];
 
  285            size_t len = 
sizeof(sig);
 
  286            if (secp256k1_ecdsa_signature_serialize_der(
 
  289                    "sign: secp256k1_ecdsa_signature_serialize_der failed");
 
 
  327    LogicError(
"generateSecretKey: unknown key type");
 
 
  336            secp256k1_pubkey pubkey_imp;
 
  337            if (secp256k1_ec_pubkey_create(
 
  340                    reinterpret_cast<unsigned char const*
>(sk.
data())) != 1)
 
  342                    "derivePublicKey: secp256k1_ec_pubkey_create failed");
 
  344            unsigned char pubkey[33];
 
  346            if (secp256k1_ec_pubkey_serialize(
 
  351                    SECP256K1_EC_COMPRESSED) != 1)
 
  353                    "derivePublicKey: secp256k1_ec_pubkey_serialize failed");
 
  358            unsigned char buf[33];
 
  360            ed25519_publickey(sk.
data(), &buf[1]);
 
 
  399    if (result.size() != 32)
 
 
Like std::vector<char> but better.
 
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
 
std::uint8_t const * data() const noexcept
 
Slice slice() const noexcept
 
std::uint8_t const * data() const
 
std::string to_string() const
Convert the secret key to a hexadecimal string.
 
Seeds are used to generate deterministic secret keys.
 
const_iterator end() const noexcept
 
const_iterator begin() const noexcept
 
std::uint8_t const * data() const
 
An immutable linear range of bytes.
 
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
 
std::size_t size() const noexcept
Returns the number of bytes in the storage.
 
static constexpr std::size_t size()
 
Produces a sequence of secp256k1 key pairs.
 
uint256 calculateTweak(std::uint32_t seq) const
 
std::array< std::uint8_t, 33 > generator_
 
std::pair< PublicKey, SecretKey > operator()(std::size_t ordinal) const
Generate the nth key pair.
 
Generator(Seed const &seed)
 
void rngfill(void *const buffer, std::size_t const bytes, Generator &g)
 
void copy_uint32(std::uint8_t *out, std::uint32_t v)
 
uint256 deriveDeterministicRootKey(Seed const &seed)
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
secp256k1_context const * secp256k1Context()
 
sha512_half_hasher_s::result_type sha512Half_s(Args const &... args)
Returns the SHA512-Half of a series of objects.
 
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
 
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
 
csprng_engine & crypto_prng()
The default cryptographically secure PRNG.
 
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
 
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
 
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
 
std::string decodeBase58Token(std::string const &s, TokenType type)
 
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
 
std::string strHex(FwdIt begin, FwdIt end)
 
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
 
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
 
SecretKey randomSecretKey()
Create a secret key using secure random numbers.
 
Buffer signDigest(PublicKey const &pk, SecretKey const &sk, uint256 const &digest)
Generate a signature for a message digest.
 
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
 
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
 
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
 
void secure_erase(void *dest, std::size_t bytes)
Attempts to clear the given blob of memory.
 
Returns the SHA512-Half digest of a message.