/* * (C) 2014,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include "tests.h" #if defined(BOTAN_HAS_MODES) #include #endif namespace Botan_Tests { #if defined(BOTAN_HAS_MODES) class Cipher_Mode_Tests : public Text_Based_Test { public: Cipher_Mode_Tests() : Text_Based_Test(Test::data_dir("modes"), {"Key", "Nonce", "In", "Out"}) {} Test::Result run_one_test(const std::string& algo, const VarMap& vars) override { const std::vector key = get_req_bin(vars, "Key"); const std::vector nonce = get_opt_bin(vars, "Nonce"); const std::vector input = get_req_bin(vars, "In"); const std::vector expected = get_req_bin(vars, "Out"); Test::Result result(algo); std::unique_ptr enc(Botan::get_cipher_mode(algo, Botan::ENCRYPTION)); std::unique_ptr dec(Botan::get_cipher_mode(algo, Botan::DECRYPTION)); if(!enc || !dec) { result.note_missing(algo); return result; } result.test_eq("mode not authenticated", enc->authenticated(), false); enc->set_key(key); enc->start(nonce); Botan::secure_vector buf(input.begin(), input.end()); // TODO: should first update if possible enc->finish(buf); result.test_eq("encrypt", buf, expected); buf.assign(expected.begin(), expected.end()); dec->set_key(key); dec->start(nonce); dec->finish(buf); result.test_eq("decrypt", buf, input); return result; } }; BOTAN_REGISTER_TEST("modes", Cipher_Mode_Tests); #endif }