diff options
author | lloyd <[email protected]> | 2013-11-17 22:01:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-11-17 22:01:21 +0000 |
commit | 6162cefdbe4df65a4ab1046950874a7319158e06 (patch) | |
tree | eb9087835623d400f6b2a4d6d8385ae69f391063 | |
parent | e072b28e66a06a1a82678a2b5d8b946bf63f6289 (diff) |
Generalize the HKDF file reading
-rw-r--r-- | checks/hkdf.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/checks/hkdf.cpp b/checks/hkdf.cpp index 95960f62b..ce93458d7 100644 --- a/checks/hkdf.cpp +++ b/checks/hkdf.cpp @@ -52,33 +52,51 @@ void hkdf_test(const std::string& algo, std::cout << "HKDF got " << got << " expected " << okm << std::endl; } -} - -void test_hkdf() +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) { - // From RFC 5869 - std::ifstream vec("checks/hkdf.vec"); - std::map<std::string, std::string> vars; - while(vec.good()) + while(src.good()) { std::string line; - std::getline(vec, 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 == "OKM") + if(key == trigger_key) { - hkdf_test(vars["Hash"], vars["IKM"], vars["salt"], vars["info"], - vars["OKM"], to_u32bit(vars["L"])); - vars.clear(); + cb(vars); + + if(clear_between_cb) + vars.clear(); } } } + +} + +void test_hkdf() + { + // From RFC 5869 + std::ifstream vec("checks/hkdf.vec"); + + run_tests(vec, true, "OKM", + [](std::map<std::string, std::string> m) + { + hkdf_test(m["Hash"], m["IKM"], m["salt"], m["info"], + m["OKM"], to_u32bit(m["L"])); + }); + } |