/* * (C) 2014,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include "tests.h" #if defined(BOTAN_HAS_STREAM_CIPHER) #include #endif namespace Botan_Tests { #if defined(BOTAN_HAS_STREAM_CIPHER) class Stream_Cipher_Tests : public Text_Based_Test { public: Stream_Cipher_Tests(): Text_Based_Test(Test::data_dir("stream"), {"Key", "In", "Out"}, {"Nonce"}) {} 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 input = get_req_bin(vars, "In"); const std::vector expected = get_req_bin(vars, "Out"); const std::vector nonce = get_opt_bin(vars, "Nonce"); Test::Result result(algo); const std::vector providers = Botan::StreamCipher::providers(algo); if(providers.empty()) { result.note_missing("block cipher " + algo); return result; } for(auto&& provider: providers) { std::unique_ptr cipher(Botan::StreamCipher::create(algo, provider)); if(!cipher) { result.note_missing(algo + " from " + provider); continue; } result.test_eq(provider, cipher->name(), algo); cipher->set_key(key); if(nonce.size()) cipher->set_iv(nonce.data(), nonce.size()); std::vector buf = input; cipher->encrypt(buf); result.test_eq(provider, "encrypt", buf, expected); } return result; } }; BOTAN_REGISTER_TEST("stream", Stream_Cipher_Tests); #endif }