aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-09-13 05:43:31 -0400
committerJack Lloyd <[email protected]>2019-09-13 05:50:27 -0400
commitd8f23de97ba48449befae12eda4f6853e74b6a74 (patch)
tree8065a954e8c82da111351added304214baafea65 /src/tests
parent71a92630ac1e3d995a017610e82a62ad6c54d246 (diff)
Add a variant of RandomNumberGenerator::random_vec
This avoids the unlock(rng.random_vec(...)) pattern which is pretty wasteful in terms of heap overhead.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_package_transform.cpp3
-rw-r--r--src/tests/test_rng.h7
-rw-r--r--src/tests/test_rsa.cpp2
-rw-r--r--src/tests/test_srp6.cpp3
4 files changed, 12 insertions, 3 deletions
diff --git a/src/tests/test_package_transform.cpp b/src/tests/test_package_transform.cpp
index f09251e1d..d72c3bbcb 100644
--- a/src/tests/test_package_transform.cpp
+++ b/src/tests/test_package_transform.cpp
@@ -30,7 +30,8 @@ class Package_Transform_Tests final : public Test
for(size_t input_len = 2; input_len != 256; ++input_len)
{
- std::vector<uint8_t> input = unlock(Test::rng().random_vec(input_len));
+ std::vector<uint8_t> input;
+ Test::rng().random_vec(input, input_len);
std::vector<uint8_t> output(input.size() + cipher->block_size());
// aont_package owns/deletes the passed cipher object, kind of a bogus API
diff --git a/src/tests/test_rng.h b/src/tests/test_rng.h
index 01fe89c92..080603a23 100644
--- a/src/tests/test_rng.h
+++ b/src/tests/test_rng.h
@@ -69,6 +69,13 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
m_buf.insert(m_buf.end(), in.begin(), in.end());
}
+ Fixed_Output_RNG(RandomNumberGenerator& rng, size_t len)
+ {
+ std::vector<uint8_t> output;
+ rng.random_vec(output, len);
+ m_buf.insert(m_buf.end(), output.begin(), output.end());
+ }
+
Fixed_Output_RNG() = default;
protected:
uint8_t random()
diff --git a/src/tests/test_rsa.cpp b/src/tests/test_rsa.cpp
index 3ac5d4733..725e3c313 100644
--- a/src/tests/test_rsa.cpp
+++ b/src/tests/test_rsa.cpp
@@ -284,7 +284,7 @@ class RSA_Blinding_Tests final : public Test
*/
const size_t rng_bytes = rsa.get_n().bytes() + (2*8*BOTAN_BLINDING_REINIT_INTERVAL);
- Botan_Tests::Fixed_Output_RNG fixed_rng(Botan::unlock(Test::rng().random_vec(rng_bytes)));
+ Botan_Tests::Fixed_Output_RNG fixed_rng(Test::rng(), rng_bytes);
Botan::PK_Decryptor_EME decryptor(rsa, fixed_rng, "Raw", "base");
for(size_t i = 1; i <= BOTAN_BLINDING_REINIT_INTERVAL ; ++i)
diff --git a/src/tests/test_srp6.cpp b/src/tests/test_srp6.cpp
index a25d857a2..8c84709cd 100644
--- a/src/tests/test_srp6.cpp
+++ b/src/tests/test_srp6.cpp
@@ -103,7 +103,8 @@ class SRP6_RT_Tests final : public Test
const std::string group_id = "modp/srp/1024";
const std::string hash_id = "SHA-256";
- const std::vector<uint8_t> salt = unlock(Test::rng().random_vec(16));
+ std::vector<uint8_t> salt;
+ Test::rng().random_vec(salt, 16);
const Botan::BigInt verifier = Botan::generate_srp6_verifier(username, password, salt, group_id, hash_id);