20 #include <ripple/crypto/csprng.h>
21 #include <ripple/protocol/PublicKey.h>
22 #include <ripple/protocol/SecretKey.h>
23 #include <ripple/protocol/Seed.h>
24 #include <ripple/beast/unit_test.h>
25 #include <ripple/beast/utility/rngfill.h>
30 #include <ripple/protocol/impl/secp256k1.h>
39 template <
class FwdIter,
class Container>
50 for (
int i = 0; i < 10; ++i)
52 for (
int i = 0; i < 6; ++i)
58 int operator[] (
int i)
68 auto const hi (lut[(*first++)]);
69 auto const lo (lut[(*first++)]);
70 out.push_back ((hi*16)+lo);
184 testcase (
"secp256k1 canonicality");
187 makeCanonicalityTestVectors();
189 auto const digest =
hex_to_digest(
"34C19028C80D21F3F48C9354895F8D5BF0D5EE7FF457647CF655F5530A3022A7");
190 auto const pk =
hex_to_pk(
"025096EB12D3E924234E7162369C11D8BF877EDA238778E7A31FF0AAC5D0DBCF37");
191 auto const sk =
hex_to_sk(
"AA921417E7E5C299DA4EEC16D1CAA92F19B19F2A68511F68EC73BBB2F5236F3D");
192 auto const sig =
hex_to_sig(
"3045022100B49D07F0E934BA468C0EFC78117791408D1FB8B63A6492AD395AC2F360F246600220508739DB0A2EF81676E39F459C8BBB07A09C3E9F9BEB696294D524D479D62740");
193 auto const non =
hex_to_sig(
"3046022100B49D07F0E934BA468C0EFC78117791408D1FB8B63A6492AD395AC2F360F24660022100AF78C624F5D107E9891C60BA637444F71A129E47135D36D92AFD39B856601A01");
197 BEAST_EXPECT(canonicality);
203 BEAST_EXPECT(canonicality);
216 testcase (
"secp256k1 digest");
236 BEAST_EXPECT(sig.size() != 0);
245 if (
auto ptr = sig.data())
246 ptr[j % sig.size()]++;
280 BEAST_EXPECT(sig.size() != 0);
297 if (
auto ptr = sig.data())
298 ptr[j % sig.size()]++;
321 auto const sk2 = parseBase58<SecretKey> (
323 "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
326 BEAST_EXPECT(sk1 == *sk2);
334 auto const sk2 = parseBase58<SecretKey> (
336 "paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
339 BEAST_EXPECT(sk1 == *sk2);
360 s.erase (r(s) % s.size(), 1);
369 s.resize (s.size() + i, s[i % s.size()]);
406 BEAST_EXPECT(!si.empty());
408 auto const ski = parseBase58<SecretKey> (
410 BEAST_EXPECT(ski && keys[i] == *ski);
414 BEAST_EXPECT((keys[i] == keys[j]) == (i == j));
420 BEAST_EXPECT((si == sj) == (i == j));
422 auto const skj = parseBase58<SecretKey> (
424 BEAST_EXPECT(skj && keys[j] == *skj);
426 BEAST_EXPECT((*ski == *skj) == (i == j));
433 testcase (
"Miscellaneous operations");
440 BEAST_EXPECT(sk1 == sk2);
443 BEAST_EXPECT(sk3 != sk2);
445 BEAST_EXPECT(sk3 == sk2);
455 testcase (
"secp256k1");
458 testcase (
"ed25519");
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.
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.