diff options
Diffstat (limited to 'checks/hkdf.cpp')
-rw-r--r-- | checks/hkdf.cpp | 44 |
1 files changed, 6 insertions, 38 deletions
diff --git a/checks/hkdf.cpp b/checks/hkdf.cpp index ce93458d7..e63ff55fa 100644 --- a/checks/hkdf.cpp +++ b/checks/hkdf.cpp @@ -33,7 +33,7 @@ secure_vector<byte> hkdf(const std::string& algo, return key; } -void hkdf_test(const std::string& algo, +bool hkdf_test(const std::string& algo, const std::string& ikm, const std::string& salt, const std::string& info, @@ -50,40 +50,8 @@ void hkdf_test(const std::string& algo, if(got != okm) std::cout << "HKDF got " << got << " expected " << okm << std::endl; - } - -void run_tests(std::istream& src, - bool clear_between_cb, - const std::string& trigger_key, - std::function<void (std::map<std::string, std::string>)> cb) - { - std::map<std::string, std::string> vars; - - while(src.good()) - { - std::string line; - std::getline(src, line); - - if(line == "") - continue; - - // FIXME: strip # comments - - // FIXME: Do this right - - const std::string key = line.substr(0, line.find_first_of(' ')); - const std::string val = line.substr(line.find_last_of(' ') + 1, std::string::npos); - - vars[key] = val; - - if(key == trigger_key) - { - cb(vars); - if(clear_between_cb) - vars.clear(); - } - } + return (got == okm); } } @@ -93,10 +61,10 @@ void test_hkdf() // From RFC 5869 std::ifstream vec("checks/hkdf.vec"); - run_tests(vec, true, "OKM", - [](std::map<std::string, std::string> m) + run_tests_bb(vec, "HKDF", "OKM", true, + [](std::map<std::string, std::string> m) -> bool { - hkdf_test(m["Hash"], m["IKM"], m["salt"], m["info"], - m["OKM"], to_u32bit(m["L"])); + return hkdf_test(m["Hash"], m["IKM"], m["salt"], m["info"], + m["OKM"], to_u32bit(m["L"])); }); } |