From e2a465b75d8baeac912e3f4d428ebc5e03fd76f1 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 27 Jun 2008 18:30:07 +0000 Subject: New structure for entropy sources + RNGs. The entropy sources are owned by Randpool, it will query them as needed (or if asked to do so). New function make_rng() that creates an RNG (X9.31 backed by a Randpool) and seeds it. Remove the entropy source related code from the Modules/Builtin_Modules classes. --- checks/dolook2.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'checks/dolook2.cpp') diff --git a/checks/dolook2.cpp b/checks/dolook2.cpp index f52d1fc09..a47efaff9 100644 --- a/checks/dolook2.cpp +++ b/checks/dolook2.cpp @@ -113,28 +113,31 @@ Filter* lookup_rng(const std::string& algname, RandomNumberGenerator* prng = 0; if(algname == "X9.31-RNG(TripleDES)") - prng = new ANSI_X931_RNG("TripleDES", new Fixed_Output_RNG); + prng = new ANSI_X931_RNG("TripleDES", new Fixed_Output_RNG(decode_hex(key))); else if(algname == "X9.31-RNG(AES-128)") - prng = new ANSI_X931_RNG("AES-128", new Fixed_Output_RNG); + prng = new ANSI_X931_RNG("AES-128", new Fixed_Output_RNG(decode_hex(key))); else if(algname == "X9.31-RNG(AES-192)") - prng = new ANSI_X931_RNG("AES-192", new Fixed_Output_RNG); + prng = new ANSI_X931_RNG("AES-192", new Fixed_Output_RNG(decode_hex(key))); else if(algname == "X9.31-RNG(AES-256)") - prng = new ANSI_X931_RNG("AES-256", new Fixed_Output_RNG); + prng = new ANSI_X931_RNG("AES-256", new Fixed_Output_RNG(decode_hex(key))); // these are used for benchmarking: AES-256/SHA-256 matches library // defaults, so benchmark reflects real-world performance (maybe) else if(algname == "Randpool") - prng = new Randpool("AES-256", "HMAC(SHA-256)"); + { + Randpool* randpool = new Randpool("AES-256", "HMAC(SHA-256)"); + randpool->add_entropy((const byte*)key.c_str(), key.length()); + prng = randpool; + } else if(algname == "X9.31-RNG") - prng = new ANSI_X931_RNG("AES-256", - new Randpool("AES-256", "HMAC(SHA-256)")); + { + Randpool* randpool = new Randpool("AES-256", "HMAC(SHA-256)"); + randpool->add_entropy((const byte*)key.c_str(), key.length()); + prng = new ANSI_X931_RNG("AES-256", randpool); + } if(prng) - { - SecureVector seed = decode_hex(key); - prng->add_entropy(seed.begin(), seed.size()); return new RNG_Filter(prng); - } return 0; } -- cgit v1.2.3