aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-05-25 21:14:40 +0000
committerlloyd <[email protected]>2008-05-25 21:14:40 +0000
commit25609cd77358c4de86a9100dcd49b1d8ad07f19a (patch)
treec63ec72513883260e3124065dfd709b282a351eb
parent89e20a742ada5000c8a78fbbf0bf8bd3b13565eb (diff)
Make the two parameters of Randpool (which underlying block cipher and MAC
to use) explicit arguments to the constructor instead of being hardcoded.
-rw-r--r--checks/dolook2.cpp5
-rw-r--r--checks/pk.cpp13
-rw-r--r--include/randpool.h2
-rw-r--r--src/libstate.cpp3
-rw-r--r--src/randpool.cpp13
5 files changed, 22 insertions, 14 deletions
diff --git a/checks/dolook2.cpp b/checks/dolook2.cpp
index 1b7123b30..1571e5db2 100644
--- a/checks/dolook2.cpp
+++ b/checks/dolook2.cpp
@@ -113,9 +113,10 @@ void RNG_Filter::write(const byte[], u32bit length)
Filter* lookup_rng(const std::string& algname)
{
if(algname == "X9.31-RNG")
- return new RNG_Filter(new ANSI_X931_RNG("AES-256", new Randpool));
+ return new RNG_Filter(new ANSI_X931_RNG("AES-256",
+ new Randpool("AES-256", "HMAC(SHA-256)")));
if(algname == "Randpool")
- return new RNG_Filter(new Randpool);
+ return new RNG_Filter(new Randpool("AES-256", "HMAC(SHA-256)"));
return 0;
}
diff --git a/checks/pk.cpp b/checks/pk.cpp
index 0deab355c..fdb22624d 100644
--- a/checks/pk.cpp
+++ b/checks/pk.cpp
@@ -195,7 +195,9 @@ u32bit do_pk_validation_tests(const std::string& filename)
std::cout << std::endl;
- global_state().set_prng(new ANSI_X931_RNG("AES-128", new Randpool));
+ global_state().set_prng(new ANSI_X931_RNG("AES-128",
+ new Randpool("AES-256",
+ "HMAC(SHA-256)")));
for(u32bit j = 0; j != 2; j++)
global_state().seed_prng(true, 384);
@@ -250,7 +252,10 @@ void validate_encryption(PK_Encryptor* e, PK_Decryptor* d,
failure = true;
}
- global_state().set_prng(new ANSI_X931_RNG("AES-128", new Randpool));
+ global_state().set_prng(new ANSI_X931_RNG("AES-128",
+ new Randpool("AES-256",
+ "HMAC(SHA-256)")));
+
for(u32bit j = 0; j != 2; j++)
global_state().seed_prng(true, 384);
@@ -291,7 +296,9 @@ void validate_signature(PK_Verifier* v, PK_Signer* s, const std::string& algo,
failure = true;
}
- global_state().set_prng(new ANSI_X931_RNG("AES-128", new Randpool));
+ global_state().set_prng(new ANSI_X931_RNG("AES-128",
+ new Randpool("AES-256",
+ "HMAC(SHA-256)")));
for(u32bit j = 0; j != 2; j++)
global_state().seed_prng(true, 384);
diff --git a/include/randpool.h b/include/randpool.h
index 24f0a8270..c64eae903 100644
--- a/include/randpool.h
+++ b/include/randpool.h
@@ -21,7 +21,7 @@ class BOTAN_DLL Randpool : public RandomNumberGenerator
void clear() throw();
std::string name() const;
- Randpool();
+ Randpool(const std::string&, const std::string&);
~Randpool();
private:
void add_randomness(const byte[], u32bit);
diff --git a/src/libstate.cpp b/src/libstate.cpp
index b988625ce..7751216cb 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -273,7 +273,8 @@ void Library_State::initialize(const InitializerOptions& args,
for(u32bit j = 0; j != sources.size(); ++j)
add_entropy_source(sources[j]);
- set_prng(new ANSI_X931_RNG("AES-256", new Randpool));
+ set_prng(new ANSI_X931_RNG("AES-256",
+ new Randpool("AES-256", "HMAC(SHA-256)")));
if(args.seed_rng())
{
diff --git a/src/randpool.cpp b/src/randpool.cpp
index 46968eee1..be50ce2be 100644
--- a/src/randpool.cpp
+++ b/src/randpool.cpp
@@ -147,13 +147,12 @@ std::string Randpool::name() const
/*************************************************
* Randpool Constructor *
*************************************************/
-Randpool::Randpool() : ITERATIONS_BEFORE_RESEED(8), POOL_BLOCKS(32)
+Randpool::Randpool(const std::string& cipher_name,
+ const std::string& mac_name) :
+ ITERATIONS_BEFORE_RESEED(8), POOL_BLOCKS(32)
{
- const std::string CIPHER_NAME = "AES-256";
- const std::string MAC_NAME = "HMAC(SHA-256)";
-
- cipher = get_block_cipher(CIPHER_NAME);
- mac = get_mac(MAC_NAME);
+ cipher = get_block_cipher(cipher_name);
+ mac = get_mac(mac_name);
const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;
const u32bit OUTPUT_LENGTH = mac->OUTPUT_LENGTH;
@@ -165,7 +164,7 @@ Randpool::Randpool() : ITERATIONS_BEFORE_RESEED(8), POOL_BLOCKS(32)
delete cipher;
delete mac;
throw Internal_Error("Randpool: Invalid algorithm combination " +
- CIPHER_NAME + "/" + MAC_NAME);
+ cipher_name + "/" + mac_name);
}
buffer.create(BLOCK_SIZE);