diff options
author | Jack Lloyd <[email protected]> | 2016-08-11 11:01:29 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-08-11 11:01:29 -0400 |
commit | 25710f5375edb1af47699d128c04b4de0f2d0547 (patch) | |
tree | 4000bc0373ecc73d0f998006d3b9fc08188c9801 | |
parent | a6497c077feec6c12ad9ad0fe9c18fa8166911c7 (diff) | |
parent | a7967542e6e11ab399dca702669282208107e126 (diff) |
Merge GH #573: Add test for HMAC_DRBG reseed
-rw-r--r-- | src/tests/test_rng.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp index 2092f7545..ab5a38135 100644 --- a/src/tests/test_rng.cpp +++ b/src/tests/test_rng.cpp @@ -100,6 +100,47 @@ class HMAC_DRBG_Tests : public Text_Based_Test BOTAN_REGISTER_TEST("hmac_drbg", HMAC_DRBG_Tests); +class HMAC_DRBG_Reseed_Tests : public Test + { + public: + HMAC_DRBG_Reseed_Tests() : Test() {} + + std::vector<Test::Result> run() override + { + Test::Result result("HMAC_DRBG Reseed"); + + auto mac = Botan::MessageAuthenticationCode::create("HMAC(SHA-256)"); + if(!mac) + { + result.note_missing("HMAC(SHA-256)"); + return {result}; + } + + Botan::HMAC_DRBG rng(mac.release(), 17); + Botan::secure_vector<Botan::byte> seed_input( + {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF}); + Botan::secure_vector<Botan::byte> output_after_initialization( + {0x26,0x06,0x95,0xF4,0xB8,0x96,0x0D,0x0B,0x27,0x4E,0xA2,0x9E,0x8D,0x2B,0x5A,0x35}); + Botan::secure_vector<Botan::byte> output_without_reseed( + {0xC4,0x90,0x04,0x5B,0x35,0x4F,0x50,0x09,0x68,0x45,0xF0,0x4B,0x11,0x03,0x58,0xF0}); + result.test_eq("is_seeded",rng.is_seeded(),false); + + rng.initialize_with(seed_input.data(), seed_input.size()); + + Botan::secure_vector<Botan::byte> out(16); + + rng.randomize(out.data(), out.size()); + result.test_eq("out before reseed", out, output_after_initialization); + + // reseed must happend here + rng.randomize(out.data(), out.size()); + result.test_ne("out after reseed", out, output_without_reseed); + return {result}; + } + }; + +BOTAN_REGISTER_TEST("hmac_drbg_reseed", HMAC_DRBG_Reseed_Tests); + #endif } |