12 #include <boost/test/unit_test.hpp>
21 const std::vector<unsigned char>& correctKey = std::vector<unsigned char>(),
22 const std::vector<unsigned char>& correctIV=std::vector<unsigned char>())
27 if(!correctKey.empty())
28 BOOST_CHECK_MESSAGE(memcmp(crypt.
vchKey.data(), correctKey.data(), crypt.
vchKey.size()) == 0, \
30 if(!correctIV.empty())
31 BOOST_CHECK_MESSAGE(memcmp(crypt.
vchIV.data(), correctIV.data(), crypt.
vchIV.size()) == 0,
36 const std::vector<unsigned char>& correctKey = std::vector<unsigned char>(),
37 const std::vector<unsigned char>& correctIV=std::vector<unsigned char>())
39 TestPassphraseSingle(vchSalt, passphrase, rounds, correctKey, correctIV);
40 for(SecureString::const_iterator i(passphrase.begin()); i != passphrase.end(); ++i)
41 TestPassphraseSingle(vchSalt,
SecureString(i, passphrase.end()), rounds);
45 const std::vector<unsigned char>& vchPlaintext = std::vector<unsigned char>())
48 crypt.
Decrypt(vchCiphertext, vchDecrypted);
49 if (vchPlaintext.size())
54 const std::vector<unsigned char>& vchCiphertextCorrect = std::vector<unsigned char>())
56 std::vector<unsigned char> vchCiphertext;
57 crypt.
Encrypt(vchPlaintext, vchCiphertext);
59 if (!vchCiphertextCorrect.empty())
62 const std::vector<unsigned char> vchPlaintext2(vchPlaintext.begin(), vchPlaintext.end());
63 TestDecrypt(crypt, vchCiphertext, vchPlaintext2);
67 const std::vector<unsigned char>& vchCiphertextCorrect = std::vector<unsigned char>())
69 TestEncryptSingle(crypt,
CKeyingMaterial(vchPlaintextIn.begin(), vchPlaintextIn.end()), vchCiphertextCorrect);
70 for(std::vector<unsigned char>::const_iterator i(vchPlaintextIn.begin()); i != vchPlaintextIn.end(); ++i)
80 ParseHex(
"fc7aba077ad5f4c3a0988d8daa4810d0d4a0e3bcb53af662998898f33df0556a"), \
81 ParseHex(
"cf2f2691526dd1aa220896fb8bf7c369"));
84 std::vector<unsigned char> vchSalt(8);
93 std::vector<unsigned char> vchSalt =
ParseHex(
"0000deadbeef0000");
99 for (
int i = 0; i != 100; i++)
108 std::vector<unsigned char> vchSalt =
ParseHex(
"0000deadbeef0000");
121 for (
int i = 0; i != 100; i++)
constexpr unsigned char * end()
constexpr unsigned char * begin()
Encryption/decryption context with key information.
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext) const
std::vector< unsigned char, secure_allocator< unsigned char > > vchKey
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext) const
std::vector< unsigned char, secure_allocator< unsigned char > > vchIV
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
static void TestDecrypt(const CCrypter &crypt, const std::vector< unsigned char > &vchCiphertext, const std::vector< unsigned char > &vchPlaintext=std::vector< unsigned char >())
static void TestPassphrase(const std::vector< unsigned char > &vchSalt, const SecureString &passphrase, uint32_t rounds, const std::vector< unsigned char > &correctKey=std::vector< unsigned char >(), const std::vector< unsigned char > &correctIV=std::vector< unsigned char >())
static void TestEncryptSingle(const CCrypter &crypt, const CKeyingMaterial &vchPlaintext, const std::vector< unsigned char > &vchCiphertextCorrect=std::vector< unsigned char >())
static void TestEncrypt(const CCrypter &crypt, const std::vector< unsigned char > &vchPlaintextIn, const std::vector< unsigned char > &vchCiphertextCorrect=std::vector< unsigned char >())
static void TestPassphraseSingle(const std::vector< unsigned char > &vchSalt, const SecureString &passphrase, uint32_t rounds, const std::vector< unsigned char > &correctKey=std::vector< unsigned char >(), const std::vector< unsigned char > &correctIV=std::vector< unsigned char >())
BOOST_AUTO_TEST_SUITE_END()
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
const unsigned int WALLET_CRYPTO_SALT_SIZE
BOOST_AUTO_TEST_CASE(bnb_search_test)
#define BOOST_CHECK(expr)
void GetRandBytes(Span< unsigned char > bytes) noexcept
Overall design of the RNG and entropy sources.
uint256 GetRandHash() noexcept
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
static uint32_t InsecureRand32()
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.