aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_rng.cpp
diff options
context:
space:
mode:
authorDaniel Neus <[email protected]>2016-10-27 21:13:04 +0200
committerDaniel Neus <[email protected]>2016-10-28 11:38:02 +0200
commit728f23309d1423bcd4a55c20e0df93f5f7a1e744 (patch)
tree36bcf4a427fe36c09c6fee7668f8847d82f8517e /src/tests/test_rng.cpp
parent4e6785ff23305c05870074fd0420624cda8b99db (diff)
make max_number_of_bytes_per_request configurable
Diffstat (limited to 'src/tests/test_rng.cpp')
-rw-r--r--src/tests/test_rng.cpp61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/tests/test_rng.cpp b/src/tests/test_rng.cpp
index e815caf65..021273fe2 100644
--- a/src/tests/test_rng.cpp
+++ b/src/tests/test_rng.cpp
@@ -144,7 +144,10 @@ class HMAC_DRBG_Unit_Tests : public Test
bool is_seeded() const override { return true; }
- void clear() override {}
+ void clear() override
+ {
+ m_randomize_count = 0;
+ }
void randomize(byte[], size_t) override
{
@@ -239,6 +242,61 @@ class HMAC_DRBG_Unit_Tests : public Test
return result;
}
+ Test::Result test_max_number_of_bytes_per_request()
+ {
+ Test::Result result("HMAC_DRBG max_number_of_bytes_per_request");
+
+ std::string mac_string = "HMAC(SHA-256)";
+ auto mac = Botan::MessageAuthenticationCode::create(mac_string);
+ if(!mac)
+ {
+ result.note_missing(mac_string);
+ return result;
+ }
+
+ Request_Counting_RNG counting_rng;
+
+ result.test_throws("HMAC_DRBG does not accept 0 for max_number_of_bytes_per_request", [&mac_string, &counting_rng ]()
+ {
+ Botan::HMAC_DRBG rng(Botan::MessageAuthenticationCode::create(mac_string), counting_rng, 2, 0);
+ });
+
+ result.test_throws("HMAC_DRBG does not accept values higher than 64KB for max_number_of_bytes_per_request", [ &mac_string,
+ &counting_rng ]()
+ {
+ Botan::HMAC_DRBG rng(Botan::MessageAuthenticationCode::create(mac_string), counting_rng, 2, 64 * 1024 + 1);
+ });
+
+ // set reseed_interval to 1 so we can test that a long request is split
+ // into multiple, max_number_of_bytes_per_request long requests
+ // for each smaller request, reseed_check() calls counting_rng::randomize(),
+ // which we can compare with
+ Botan::HMAC_DRBG rng(std::move(mac), counting_rng, 1, 64);
+
+ rng.random_vec(63);
+ result.test_eq("one request", counting_rng.randomize_count(), 1);
+
+ rng.clear();
+ counting_rng.clear();
+
+ rng.random_vec(64);
+ result.test_eq("one request", counting_rng.randomize_count(), 1);
+
+ rng.clear();
+ counting_rng.clear();
+
+ rng.random_vec(65);
+ result.test_eq("two requests", counting_rng.randomize_count(), 2);
+
+ rng.clear();
+ counting_rng.clear();
+
+ rng.random_vec(1025);
+ result.test_eq("17 requests", counting_rng.randomize_count(), 17);
+
+ return result;
+ }
+
Test::Result test_broken_entropy_input()
{
Test::Result result("HMAC_DRBG Broken Entropy Input");
@@ -506,6 +564,7 @@ class HMAC_DRBG_Unit_Tests : public Test
std::vector<Test::Result> results;
results.push_back(test_reseed_kat());
results.push_back(test_reseed());
+ results.push_back(test_max_number_of_bytes_per_request());
results.push_back(test_broken_entropy_input());
results.push_back(test_check_nonce());
results.push_back(test_prediction_resistance());