20 #include <ripple/beast/unit_test.h>
21 #include <ripple/beast/utility/rngfill.h>
22 #include <ripple/crypto/csprng.h>
23 #include <ripple/protocol/PublicKey.h>
24 #include <ripple/protocol/SecretKey.h>
25 #include <ripple/protocol/Seed.h>
30 #include <ripple/protocol/impl/secp256k1.h>
39 template <
class FwdIter,
class Container>
49 for (
int i = 0; i < 10; ++i)
51 for (
int i = 0; i < 6; ++i)
53 val[
'A' + i] = 10 + i;
54 val[
'a' + i] = 10 + i;
68 auto const hi(lut[(*first++)]);
69 auto const lo(lut[(*first++)]);
70 out.push_back((hi * 16) + lo);
111 testcase(
"secp256k1 canonicality");
114 makeCanonicalityTestVectors();
117 "34C19028C80D21F3F48C9354895F8D5BF0D5EE7FF457647CF655F5530A3022A7");
119 "025096EB12D3E924234E7162369C11D8BF877EDA238778E7A31FF0AAC5D0DBCF3"
122 "AA921417E7E5C299DA4EEC16D1CAA92F19B19F2A68511F68EC73BBB2F5236F3D");
124 "3045022100B49D07F0E934BA468C0EFC78117791408D1FB8B63A6492AD395AC2F3"
125 "60F246600220508739DB0A2EF81676E39F459C8BBB07A09C3E9F9BEB696294D524"
128 "3046022100B49D07F0E934BA468C0EFC78117791408D1FB8B63A6492AD395AC2F3"
129 "60F24660022100AF78C624F5D107E9891C60BA637444F71A129E47135D36D92AFD"
134 BEAST_EXPECT(canonicality);
140 BEAST_EXPECT(canonicality);
154 testcase(
"secp256k1 digest");
170 BEAST_EXPECT(sig.size() != 0);
177 if (
auto ptr = sig.data())
178 ptr[j % sig.size()]++;
206 BEAST_EXPECT(sig.size() != 0);
221 if (
auto ptr = sig.data())
222 ptr[j % sig.size()]++;
243 auto const sk2 = parseBase58<SecretKey>(
245 "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
248 BEAST_EXPECT(sk1 == *sk2);
255 auto const sk2 = parseBase58<SecretKey>(
257 "paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
260 BEAST_EXPECT(sk1 == *sk2);
266 BEAST_EXPECT(!parseBase58<SecretKey>(
280 s.erase(r(s) % s.size(), 1);
290 s.resize(s.size() + i, s[i % s.size()]);
327 BEAST_EXPECT(!si.empty());
330 BEAST_EXPECT(ski && keys[i] == *ski);
334 BEAST_EXPECT((keys[i] == keys[j]) == (i == j));
338 BEAST_EXPECT((si == sj) == (i == j));
342 BEAST_EXPECT(skj && keys[j] == *skj);
344 BEAST_EXPECT((*ski == *skj) == (i == j));
352 testcase(
"Miscellaneous operations");
358 BEAST_EXPECT(sk1 == sk2);
361 BEAST_EXPECT(sk3 != sk2);
363 BEAST_EXPECT(sk3 == sk2);
374 testcase(
"secp256k1");
static void hex_to_binary(FwdIter first, FwdIter last, Container &out)
static SecretKey hex_to_sk(std::string const &s)
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)
void testMiscOperations()
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, ripple)
boost::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
void testSigning(KeyType type)
An immutable linear range of bytes.
static PublicKey hex_to_pk(std::string const &s)
csprng_engine & crypto_prng()
The default cryptographically secure PRNG.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Like std::vector<char> but better.
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical)
Verify a signature on a message.
Integers of any length that is a multiple of 32-bits.
Buffer signDigest(PublicKey const &pk, SecretKey const &sk, uint256 const &digest)
Generate a signature for a message digest.
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
static Buffer hex_to_sig(std::string const &s)
boost::optional< ECDSACanonicality > ecdsaCanonicality(Slice const &sig)
Determine whether a signature is canonical.
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical)
Verify a secp256k1 signature on the digest of a message.
static uint256 hex_to_digest(std::string const &s)
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
void rngfill(void *buffer, std::size_t bytes, Generator &g)
SecretKey randomSecretKey()
Create a secret key using secure random numbers.