20 #include <ripple/basics/contract.h>
21 #include <ripple/basics/strHex.h>
22 #include <ripple/protocol/PublicKey.h>
23 #include <ripple/protocol/digest.h>
24 #include <ripple/protocol/impl/secp256k1.h>
25 #include <boost/multiprecision/cpp_int.hpp>
56 if (buf.
size() < 3 || buf[0] != 0x02)
58 auto const len = buf[1];
60 if (len > buf.
size() || len < 1 || len > 33)
63 if ((buf[0] & 0x80) != 0)
71 if ((buf[1] & 0x80) == 0)
93 for (
int i = 0; i < slice.
size(); ++i)
95 s +=
"0123456789ABCDEF"[((slice[i] & 0xf0) >> 4)];
96 s +=
"0123456789ABCDEF"[((slice[i] & 0x0f) >> 0)];
117 boost::multiprecision::number<boost::multiprecision::cpp_int_backend<
120 boost::multiprecision::signed_magnitude,
121 boost::multiprecision::unchecked,
124 static uint264
const G(
125 "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
129 if ((sig.
size() < 8) || (sig.
size() > 72))
131 if ((sig[0] != 0x30) || (sig[1] != (sig.
size() - 2)))
136 if (!r || !s || !p.
empty())
149 auto const Sp = G - S;
158 if (sig.
size() != 64)
162 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xDE, 0xF9, 0xDE, 0xA2, 0xF7,
164 0x9C, 0xD6, 0x58, 0x12, 0x63, 0x1A, 0x5C, 0xF5, 0xD3, 0xED,
168 auto const le = sig.
data() + 32;
180 LogicError(
"PublicKey::PublicKey invalid type");
209 if (slice.
size() == 33)
211 if (slice[0] == 0xED)
214 if (slice[0] == 0x02 || slice[0] == 0x03)
226 bool mustBeFullyCanonical) noexcept
229 LogicError(
"sign: secp256k1 required for digest signing");
233 if (mustBeFullyCanonical &&
237 secp256k1_pubkey pubkey_imp;
238 if (secp256k1_ec_pubkey_parse(
241 reinterpret_cast<unsigned char const*
>(publicKey.data()),
242 publicKey.size()) != 1)
245 secp256k1_ecdsa_signature sig_imp;
246 if (secp256k1_ecdsa_signature_parse_der(
249 reinterpret_cast<unsigned char const*
>(sig.data()),
254 secp256k1_ecdsa_signature sig_norm;
255 if (secp256k1_ecdsa_signature_normalize(
258 return secp256k1_ecdsa_verify(
261 reinterpret_cast<unsigned char const*
>(
digest.data()),
264 return secp256k1_ecdsa_verify(
267 reinterpret_cast<unsigned char const*
>(
digest.data()),
276 bool mustBeFullyCanonical) noexcept
283 publicKey,
sha512Half(m), sig, mustBeFullyCanonical);
294 return ed25519_sign_open(
295 m.data(), m.size(), publicKey.data() + 1, sig.data()) ==
std::uint8_t const * data() const noexcept
std::size_t size() const noexcept
Returns the number of bytes in the storage.
T reverse_copy(T... args)
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)
NodeID calcNodeID(PublicKey const &pk)
Calculate the 160-bit node ID from a node public key.
base_uint< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
static std::string sliceToHex(Slice const &slice)
An immutable linear range of bytes.
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a signature on a message.
static std::optional< Slice > sigPart(Slice &buf)
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
std::string decodeBase58Token(std::string const &s, TokenType type)
Decode a token of given type encoded using Base58Check and the XRPL alphabet.
Slice slice() const noexcept
bool empty() const noexcept
Return true if the byte range is empty.
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
secp256k1_context const * secp256k1Context()
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
static constexpr std::size_t bytes
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
std::size_t size() const noexcept
T lexicographical_compare(T... args)
std::optional< ECDSACanonicality > ecdsaCanonicality(Slice const &sig)
Determine whether a signature is canonical.
PublicKey & operator=(PublicKey const &other)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a secp256k1 signature on the digest of a message.
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
std::string strHex(FwdIt begin, FwdIt end)
static bool ed25519Canonical(Slice const &sig)
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.