6 #include "test/test_raven.h" 12 #include <boost/test/unit_test.hpp> 20 const std::vector<unsigned char> &correctKey = std::vector<unsigned char>(),
21 const std::vector<unsigned char> &correctIV = std::vector<unsigned char>())
26 if (!correctKey.empty())
27 BOOST_CHECK_MESSAGE(memcmp(crypt.
vchKey.data(), correctKey.data(), crypt.
vchKey.size()) == 0, \
28 HexStr(crypt.
vchKey.begin(), crypt.
vchKey.end()) + std::string(
" != ") +
HexStr(correctKey.begin(), correctKey.end()));
29 if (!correctIV.empty())
30 BOOST_CHECK_MESSAGE(memcmp(crypt.
vchIV.data(), correctIV.data(), crypt.
vchIV.size()) == 0,
31 HexStr(crypt.
vchIV.begin(), crypt.
vchIV.end()) + std::string(
" != ") +
HexStr(correctIV.begin(), correctIV.end()));
35 const std::vector<unsigned char> &correctKey = std::vector<unsigned char>(),
36 const std::vector<unsigned char> &correctIV = std::vector<unsigned char>())
38 TestPassphraseSingle(vchSalt, passphrase, rounds, correctKey, correctIV);
39 for (SecureString::const_iterator i(passphrase.begin()); i != passphrase.end(); ++i)
40 TestPassphraseSingle(vchSalt,
SecureString(i, passphrase.end()), rounds);
44 const std::vector<unsigned char> &vchPlaintext = std::vector<unsigned char>())
47 crypt.
Decrypt(vchCiphertext, vchDecrypted);
48 if (vchPlaintext.size())
53 const std::vector<unsigned char> &vchCiphertextCorrect = std::vector<unsigned char>())
55 std::vector<unsigned char> vchCiphertext;
56 crypt.
Encrypt(vchPlaintext, vchCiphertext);
58 if (!vchCiphertextCorrect.empty())
61 const std::vector<unsigned char> vchPlaintext2(vchPlaintext.begin(), vchPlaintext.end());
62 TestDecrypt(crypt, vchCiphertext, vchPlaintext2);
66 const std::vector<unsigned char> &vchCiphertextCorrect = std::vector<unsigned char>())
68 TestEncryptSingle(crypt,
CKeyingMaterial(vchPlaintextIn.begin(), vchPlaintextIn.end()), vchCiphertextCorrect);
69 for (std::vector<unsigned char>::const_iterator i(vchPlaintextIn.begin()); i != vchPlaintextIn.end(); ++i)
77 BOOST_TEST_MESSAGE(
"Running PassPhrase Test");
81 ParseHex(
"fc7aba077ad5f4c3a0988d8daa4810d0d4a0e3bcb53af662998898f33df0556a"), \
82 ParseHex(
"cf2f2691526dd1aa220896fb8bf7c369"));
85 std::vector<unsigned char> vchSalt(8);
87 uint32_t rounds = InsecureRand32();
95 BOOST_TEST_MESSAGE(
"Running Encrypt Test");
97 std::vector<unsigned char> vchSalt =
ParseHex(
"0000deadbeef0000");
103 for (
int i = 0; i != 100; i++)
113 BOOST_TEST_MESSAGE(
"Running Decrypt Test");
115 std::vector<unsigned char> vchSalt =
ParseHex(
"0000deadbeef0000");
128 for (
int i = 0; i != 100; i++)
bool SetKeyFromPassphrase(const SecureString &strKeyData, const std::vector< unsigned char > &chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
bool Encrypt(const CKeyingMaterial &vchPlaintext, std::vector< unsigned char > &vchCiphertext) const
Encryption/decryption context with key information.
static void TestEncrypt(const CCrypter &crypt, const std::vector< unsigned char > &vchPlaintextIn, const std::vector< unsigned char > &vchCiphertextCorrect=std::vector< unsigned char >())
BOOST_AUTO_TEST_CASE(passphrase_test)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
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 >())
bool Decrypt(const std::vector< unsigned char > &vchCiphertext, CKeyingMaterial &vchPlaintext) const
std::vector< unsigned char, secure_allocator< unsigned char > > vchKey
std::vector< unsigned char, secure_allocator< unsigned char > > vchIV
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 >())
const unsigned int WALLET_CRYPTO_SALT_SIZE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_AUTO_TEST_SUITE_END()
static void TestDecrypt(const CCrypter &crypt, const std::vector< unsigned char > &vchCiphertext, const std::vector< unsigned char > &vchPlaintext=std::vector< unsigned char >())
void GetRandBytes(unsigned char *buf, int num)
Functions to gather random data via the OpenSSL PRNG.
static void TestEncryptSingle(const CCrypter &crypt, const CKeyingMaterial &vchPlaintext, const std::vector< unsigned char > &vchCiphertextCorrect=std::vector< unsigned char >())
#define BOOST_CHECK(expr)
std::vector< unsigned char > ParseHex(const char *psz)