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, | BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + | ||||
HexStr(subdecrypted) + std::string(" != ") + | 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, | BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + | ||||
HexStr(subdecrypted) + std::string(" != ") + | 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 345 Lines • ▼ Show 20 Lines | TestAES256CBC( | ||||
"f69f2445df4f9b17ad2b417be66c3710", | "f69f2445df4f9b17ad2b417be66c3710", | ||||
"b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644"); | "b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644"); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(chacha20_testvector) { | BOOST_AUTO_TEST_CASE(chacha20_testvector) { | ||||
// Test vector from RFC 7539 | // Test vector from RFC 7539 | ||||
TestChaCha20( | TestChaCha20( | ||||
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", | "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", | ||||
0x4a000000UL, 1, "224f51f3401bd9e12fde276fb8631ded8c131f823d2c06e27e4fc" | 0x4a000000UL, 1, | ||||
"aec9ef3cf788a3b0aa372600a92b57974cded2b9334794cba40c6" | "224f51f3401bd9e12fde276fb8631ded8c131f823d2c06e27e4fcaec9ef3cf788a3b0a" | ||||
"3e34cdea212c4cf07d41b769a6749f3f630f4122cafe28ec4dc47" | "a372600a92b57974cded2b9334794cba40c63e34cdea212c4cf07d41b769a6749f3f63" | ||||
"e26d4346d70b98c73f3e9c53ac40c5945398b6eda1a832c89c167" | "0f4122cafe28ec4dc47e26d4346d70b98c73f3e9c53ac40c5945398b6eda1a832c89c1" | ||||
"eacd901d7e2bf363"); | "67eacd901d7e2bf363"); | ||||
// Test vectors from | // Test vectors from | ||||
// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7 | // https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7 | ||||
TestChaCha20( | TestChaCha20( | ||||
"0000000000000000000000000000000000000000000000000000000000000000", 0, | "0000000000000000000000000000000000000000000000000000000000000000", 0, | ||||
0, "76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da4" | 0, | ||||
"76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da4" | |||||
"1597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586"); | "1597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586"); | ||||
TestChaCha20( | TestChaCha20( | ||||
"0000000000000000000000000000000000000000000000000000000000000001", 0, | "0000000000000000000000000000000000000000000000000000000000000001", 0, | ||||
0, "4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952ed432d41bbe" | 0, | ||||
"4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952ed432d41bbe" | |||||
"2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea817e9ad275ae546963"); | "2a0b6ea7566d2a5d1e7e20d42af2c53d792b1c43fea817e9ad275ae546963"); | ||||
TestChaCha20( | TestChaCha20( | ||||
"0000000000000000000000000000000000000000000000000000000000000000", | "0000000000000000000000000000000000000000000000000000000000000000", | ||||
0x0100000000000000ULL, 0, "de9cba7bf3d69ef5e786dc63973f653a0b49e015adbf" | 0x0100000000000000ULL, 0, | ||||
"f7134fcb7df137821031e85a050278a7084527214f73" | "de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df137821031e85a05" | ||||
"efc7fa5b5277062eb7a0433e445f41e3"); | "0278a7084527214f73efc7fa5b5277062eb7a0433e445f41e3"); | ||||
TestChaCha20( | TestChaCha20( | ||||
"0000000000000000000000000000000000000000000000000000000000000000", 1, | "0000000000000000000000000000000000000000000000000000000000000000", 1, | ||||
0, "ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd138e50d32111" | 0, | ||||
"ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd138e50d32111" | |||||
"e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d6bbdb0041b2f586b"); | "e4caf237ee53ca8ad6426194a88545ddc497a0b466e7d6bbdb0041b2f586b"); | ||||
TestChaCha20( | TestChaCha20( | ||||
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", | "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", | ||||
0x0706050403020100ULL, 0, | 0x0706050403020100ULL, 0, | ||||
"f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a454" | "f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a454" | ||||
"7b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc" | "7b733b46413042c9440049176905d3be59ea1c53f15916155c2be8241a38008b9a26bc" | ||||
"35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563e" | "35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc118be563e" | ||||
"b9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a4750" | "b9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a4750" | ||||
"32b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c507b138db853e3d" | "32b63fc385245fe054e3dd5a97a5f576fe064025d3ce042c566ab2c507b138db853e3d" | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |