From ad6555f522ae16f6284e8dafa02f630b88bcf289 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 10 Jan 2014 23:07:16 +0000 Subject: Split up docs into the reference manual, the website, and everything else. Add `website` target to makefile. Some progress towards fixing minimized builds. TLS now hard requires ECDSA and GCM since otherwise a minimized build has only insecure options. Remove boost_thread dependency in command line tool --- src/tests/test_block.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/tests/test_block.cpp (limited to 'src/tests/test_block.cpp') diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp new file mode 100644 index 000000000..2ef5f8979 --- /dev/null +++ b/src/tests/test_block.cpp @@ -0,0 +1,79 @@ +#include "tests.h" + +#include +#include +#include +#include +#include + +using namespace Botan; + +namespace { + +size_t block_test(const std::string& algo, + const std::string& key_hex, + const std::string& in_hex, + const std::string& out_hex) + { + const secure_vector key = hex_decode_locked(key_hex); + const secure_vector pt = hex_decode_locked(in_hex); + const secure_vector ct = hex_decode_locked(out_hex); + + Algorithm_Factory& af = global_state().algorithm_factory(); + + const auto providers = af.providers_of(algo); + size_t fails = 0; + + for(auto provider: providers) + { + const BlockCipher* proto = af.prototype_block_cipher(algo, provider); + + if(!proto) + { + std::cout << "Unable to get " << algo << " from " << provider << "\n"; + ++fails; + continue; + } + + std::unique_ptr cipher(proto->clone()); + cipher->set_key(key); + secure_vector buf = pt; + + cipher->encrypt(buf); + + if(buf != ct) + { + std::cout << algo << " " << provider << " enc " << hex_encode(buf) << " != " << out_hex << "\n"; + ++fails; + buf = ct; + } + + cipher->decrypt(buf); + + if(buf != pt) + { + std::cout << algo << " " << provider << " dec " << hex_encode(buf) << " != " << out_hex << "\n"; + ++fails; + } + } + + return fails; + } + +} + +size_t test_block() + { + auto test_bc = [](const std::string& input) + { + std::ifstream vec(input); + + return run_tests_bb(vec, "BlockCipher", "Out", true, + [](std::map m) -> size_t + { + return block_test(m["BlockCipher"], m["Key"], m["In"], m["Out"]); + }); + }; + + return run_tests_in_dir(TEST_DATA_DIR "block", test_bc); + } -- cgit v1.2.3