From 4ec179fa73b94d940138e0862a7025d815aa831e Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 16 Jun 2010 14:28:40 +0000 Subject: In the cipher KAT selftest, query if the IV length we got was supported before setting it. If it's not, then check if a 0 length IV is supported (eg, ECB mode). If neither is true, throw Invalid_IV_Length. --- src/selftest/selftest.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/selftest') diff --git a/src/selftest/selftest.cpp b/src/selftest/selftest.cpp index 215569cbb..93af4f1b7 100644 --- a/src/selftest/selftest.cpp +++ b/src/selftest/selftest.cpp @@ -49,8 +49,9 @@ algorithm_kat(const SCAN_Name& algo_name, const std::string input = search_map(vars, std::string("input")); const std::string output = search_map(vars, std::string("output")); - const std::string key = search_map(vars, std::string("key")); - const std::string iv = search_map(vars, std::string("iv")); + + SymmetricKey key(search_map(vars, std::string("key"))); + InitializationVector iv(search_map(vars, std::string("iv"))); for(u32bit i = 0; i != providers.size(); ++i) { @@ -96,10 +97,18 @@ algorithm_kat(const SCAN_Name& algo_name, } enc->set_key(key); - enc->set_iv(iv); + + if(enc->valid_iv_length(iv.length())) + enc->set_iv(iv); + else if(!enc->valid_iv_length(0)) + throw Invalid_IV_Length(algo, iv.length()); dec->set_key(key); - dec->set_iv(iv); + + if(dec->valid_iv_length(iv.length())) + dec->set_iv(iv); + else if(!dec->valid_iv_length(0)) + throw Invalid_IV_Length(algo, iv.length()); bool enc_ok = test_filter_kat(enc, input, output); bool dec_ok = test_filter_kat(dec, output, input); -- cgit v1.2.3