From c39a4cea7ac150d3e4cd0396b991c8ede6dad67e Mon Sep 17 00:00:00 2001 From: René Korthaus Date: Thu, 25 Aug 2016 17:14:21 +0200 Subject: Add unit test for HMAC_DRBG::randomize_with_ts_input() --- src/tests/test_rng.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/tests') diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index 3368ab52b..7b75eca01 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -441,6 +441,44 @@ class HMAC_DRBG_Unit_Tests : public Test return result; } + Test::Result test_randomize_with_ts_input() + { + Test::Result result("HMAC_DRBG Randomize With Timestamp Input"); + + auto mac = Botan::MessageAuthenticationCode::create("HMAC(SHA-256)"); + if(!mac) + { + result.note_missing("HMAC(SHA-256)"); + return result; + } + + const size_t reseed_interval = 1024; + const size_t request_bytes = 64; + const std::vector seed(128); + + // check that randomize_with_ts_input() creates different output based on a timestamp + // and possibly additional data, such as process id + Fixed_Output_RNG fixed_output_rng1(seed); + Botan::HMAC_DRBG rng1(std::move(mac), fixed_output_rng1, reseed_interval); + Botan::secure_vector output1(request_bytes); + rng1.randomize(output1.data(), output1.size()); + + mac = Botan::MessageAuthenticationCode::create("HMAC(SHA-256)"); + Fixed_Output_RNG fixed_output_rng2(seed); + Botan::HMAC_DRBG rng2(std::move(mac), fixed_output_rng2, reseed_interval); + Botan::secure_vector output2(request_bytes); + rng2.randomize(output2.data(), output2.size()); + + result.test_eq("equal output due to same seed", output1, output2); + + rng1.randomize_with_ts_input(output1.data(), output1.size()); + rng2.randomize_with_ts_input(output2.data(), output2.size()); + + result.test_ne("output differs due to different timestamp", output1, output2); + + return result; + } + std::vector run() override { std::vector results; @@ -450,6 +488,7 @@ class HMAC_DRBG_Unit_Tests : public Test results.push_back(test_check_nonce()); results.push_back(test_prediction_resistance()); results.push_back(test_fork_safety()); + results.push_back(test_randomize_with_ts_input()); return results; } }; -- cgit v1.2.3