Changeset View
Changeset View
Standalone View
Standalone View
src/test/crypto_tests.cpp
Show First 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | for (std::vector<uint8_t>::iterator i(in.begin()); i != in.end(); ++i) { | ||||
std::vector<uint8_t> subout(sub.size() + AES_BLOCKSIZE); | std::vector<uint8_t> subout(sub.size() + AES_BLOCKSIZE); | ||||
int _size = enc.Encrypt(&sub[0], sub.size(), &subout[0]); | int _size = enc.Encrypt(&sub[0], sub.size(), &subout[0]); | ||||
if (_size != 0) { | if (_size != 0) { | ||||
subout.resize(_size); | subout.resize(_size); | ||||
std::vector<uint8_t> subdecrypted(subout.size()); | std::vector<uint8_t> subdecrypted(subout.size()); | ||||
_size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]); | _size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]); | ||||
subdecrypted.resize(_size); | subdecrypted.resize(_size); | ||||
BOOST_CHECK(decrypted.size() == in.size()); | BOOST_CHECK(decrypted.size() == in.size()); | ||||
BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + | BOOST_CHECK_MESSAGE(subdecrypted == sub, | ||||
std::string(" != ") + | HexStr(subdecrypted) + std::string(" != ") + | ||||
HexStr(sub)); | HexStr(sub)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, | void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, | ||||
bool pad, const std::string &hexin, | bool pad, const std::string &hexin, | ||||
const std::string &hexout) { | const std::string &hexout) { | ||||
std::vector<uint8_t> key = ParseHex(hexkey); | std::vector<uint8_t> key = ParseHex(hexkey); | ||||
Show All 26 Lines | for (std::vector<uint8_t>::iterator i(in.begin()); i != in.end(); ++i) { | ||||
std::vector<uint8_t> subout(sub.size() + AES_BLOCKSIZE); | std::vector<uint8_t> subout(sub.size() + AES_BLOCKSIZE); | ||||
int _size = enc.Encrypt(&sub[0], sub.size(), &subout[0]); | int _size = enc.Encrypt(&sub[0], sub.size(), &subout[0]); | ||||
if (_size != 0) { | if (_size != 0) { | ||||
subout.resize(_size); | subout.resize(_size); | ||||
std::vector<uint8_t> subdecrypted(subout.size()); | std::vector<uint8_t> subdecrypted(subout.size()); | ||||
_size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]); | _size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]); | ||||
subdecrypted.resize(_size); | subdecrypted.resize(_size); | ||||
BOOST_CHECK(decrypted.size() == in.size()); | BOOST_CHECK(decrypted.size() == in.size()); | ||||
BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + | BOOST_CHECK_MESSAGE(subdecrypted == sub, | ||||
std::string(" != ") + | HexStr(subdecrypted) + std::string(" != ") + | ||||
HexStr(sub)); | HexStr(sub)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void TestChaCha20(const std::string &hexkey, uint64_t nonce, uint64_t seek, | void TestChaCha20(const std::string &hexkey, uint64_t nonce, uint64_t seek, | ||||
const std::string &hexout) { | const std::string &hexout) { | ||||
std::vector<uint8_t> key = ParseHex(hexkey); | std::vector<uint8_t> key = ParseHex(hexkey); | ||||
ChaCha20 rng(key.data(), key.size()); | ChaCha20 rng(key.data(), key.size()); | ||||
▲ Show 20 Lines • Show All 413 Lines • Show Last 20 Lines |