aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-10-26 03:07:18 +0000
committerlloyd <[email protected]>2008-10-26 03:07:18 +0000
commita8ee54d459a42d98fdfe1e9ff4f0c011c2f41e10 (patch)
tree576d871ed243508e5458456d12ea99d240e8339c
parentb1344477a80c7410da9ce05dd3343c04d24f8095 (diff)
Move rng.{cpp,h} from core to rng/ topdir
Add a new class AutoSeeded_RNG that is a RandomNumberGenerator that wraps up the logic formerly in RandomNumberGenerator::make_rng. make_rng in fact now just returns a new AutoSeeded_RNG object. AutoSeeded_RNG is a bit more convenient because - No need to use auto_ptr - No need to dereference (same syntax everywhere - it's an underestimated advantage imo) Also move the code from timer/timer_base to timer/
-rw-r--r--checks/check.cpp40
-rw-r--r--doc/api.tex2
-rw-r--r--doc/examples/ca.cpp8
-rw-r--r--doc/examples/cms_dec.cpp5
-rw-r--r--doc/examples/cms_enc.cpp7
-rw-r--r--doc/examples/dh.cpp7
-rw-r--r--doc/examples/dsa_kgen.cpp9
-rw-r--r--doc/examples/dsa_sign.cpp7
-rw-r--r--doc/examples/eax_test.cpp3
-rw-r--r--doc/examples/ecdsa.cpp7
-rw-r--r--doc/examples/encrypt.cpp5
-rw-r--r--doc/examples/factor.cpp5
-rw-r--r--doc/examples/make_prime.cpp11
-rw-r--r--doc/examples/passhash.cpp5
-rw-r--r--doc/examples/pkcs10.cpp10
-rw-r--r--doc/examples/pqg_gen.cpp6
-rw-r--r--doc/examples/ressol.cpp9
-rw-r--r--doc/examples/row_encryptor.cpp6
-rw-r--r--doc/examples/rsa_dec.cpp5
-rw-r--r--doc/examples/rsa_enc.cpp7
-rw-r--r--doc/examples/rsa_kgen.cpp7
-rw-r--r--doc/examples/rsa_manykey.cpp4
-rw-r--r--doc/examples/self_sig.cpp9
-rw-r--r--src/core/botan.h4
-rw-r--r--src/core/info.txt9
-rw-r--r--src/rng/auto_rng/auto_rng.cpp (renamed from src/core/rng.cpp)69
-rw-r--r--src/rng/auto_rng/auto_rng.h42
-rw-r--r--src/rng/auto_rng/info.txt18
-rw-r--r--src/rng/info.txt8
-rw-r--r--src/rng/rng.cpp44
-rw-r--r--src/s2k/info.txt12
-rw-r--r--src/utils/timer/cpu_counter/info.txt2
-rw-r--r--src/utils/timer/gettimeofday/info.txt2
-rw-r--r--src/utils/timer/info.txt (renamed from src/utils/timer/timer_base/info.txt)0
-rw-r--r--src/utils/timer/posix_rt/info.txt2
-rw-r--r--src/utils/timer/timers.cpp (renamed from src/utils/timer/timer_base/timers.cpp)0
-rw-r--r--src/utils/timer/timers.h (renamed from src/utils/timer/timer_base/timers.h)0
-rw-r--r--src/utils/timer/win32_query_perf_ctr/info.txt2
38 files changed, 241 insertions, 157 deletions
diff --git a/checks/check.cpp b/checks/check.cpp
index 2105640f8..36762786a 100644
--- a/checks/check.cpp
+++ b/checks/check.cpp
@@ -140,12 +140,11 @@ int main(int argc, char* argv[])
const bool html = opts.is_set("html");
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
if(opts.is_set("benchmark"))
{
- benchmark("All", *rng, html, seconds);
+ benchmark("All", rng, html, seconds);
}
else if(opts.is_set("bench-algo"))
{
@@ -155,9 +154,9 @@ int main(int argc, char* argv[])
for(u32bit j = 0; j != algs.size(); j++)
{
const std::string alg = algs[j];
- u32bit found = bench_algo(alg, *rng, seconds);
+ u32bit found = bench_algo(alg, rng, seconds);
if(!found) // maybe it's a PK algorithm
- bench_pk(*rng, alg, html, seconds);
+ bench_pk(rng, alg, html, seconds);
}
}
else if(opts.is_set("bench-type"))
@@ -165,19 +164,19 @@ int main(int argc, char* argv[])
const std::string type = opts.value("bench-type");
if(type == "all")
- benchmark("All", *rng, html, seconds);
+ benchmark("All", rng, html, seconds);
else if(type == "block")
- benchmark("Block Cipher", *rng, html, seconds);
+ benchmark("Block Cipher", rng, html, seconds);
else if(type == "stream")
- benchmark("Stream Cipher", *rng, html, seconds);
+ benchmark("Stream Cipher", rng, html, seconds);
else if(type == "hash")
- benchmark("Hash", *rng, html, seconds);
+ benchmark("Hash", rng, html, seconds);
else if(type == "mac")
- benchmark("MAC", *rng, html, seconds);
+ benchmark("MAC", rng, html, seconds);
else if(type == "rng")
- benchmark("RNG", *rng, html, seconds);
+ benchmark("RNG", rng, html, seconds);
else if(type == "pk")
- bench_pk(*rng, "All", html, seconds);
+ bench_pk(rng, "All", html, seconds);
else
std::cerr << "Unknown --bench-type " << type << "\n";
}
@@ -204,15 +203,14 @@ int run_test_suite()
u32bit errors = 0;
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
-
- errors += do_validation_tests(VALIDATION_FILE, *rng);
- errors += do_validation_tests(EXPECTED_FAIL_FILE, *rng, false);
- errors += do_bigint_tests(BIGINT_VALIDATION_FILE, *rng);
- errors += do_gfpmath_tests(*rng);
- errors += do_pk_validation_tests(PK_VALIDATION_FILE, *rng);
- //errors += do_cvc_tests(*rng);
+ AutoSeeded_RNG rng;
+
+ errors += do_validation_tests(VALIDATION_FILE, rng);
+ errors += do_validation_tests(EXPECTED_FAIL_FILE, rng, false);
+ errors += do_bigint_tests(BIGINT_VALIDATION_FILE, rng);
+ errors += do_gfpmath_tests(rng);
+ errors += do_pk_validation_tests(PK_VALIDATION_FILE, rng);
+ //errors += do_cvc_tests(rng);
}
catch(Botan::Exception& e)
{
diff --git a/doc/api.tex b/doc/api.tex
index 68f34c6cc..965773876 100644
--- a/doc/api.tex
+++ b/doc/api.tex
@@ -985,7 +985,7 @@ cryptographic programs)
\begin{verbatim}
// everyone does:
-std::auto_ptr<RandomNumberGenerator> rng(RandomNumberGenerator::make_rng());
+AutoSeeded_RNG rng;
// Alice
RSA_PrivateKey priv_rsa(rng, 1024 /* bits */);
diff --git a/doc/examples/ca.cpp b/doc/examples/ca.cpp
index d0fd32d17..e4fb9eb02 100644
--- a/doc/examples/ca.cpp
+++ b/doc/examples/ca.cpp
@@ -14,7 +14,6 @@
*/
#include <botan/botan.h>
-#include <botan/rng.h>
#include <botan/x509_ca.h>
#include <botan/util.h>
using namespace Botan;
@@ -38,13 +37,12 @@ int main(int argc, char* argv[])
const std::string arg_ca_key = argv[3];
const std::string arg_req_file = argv[4];
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
X509_Certificate ca_cert(arg_ca_cert);
std::auto_ptr<PKCS8_PrivateKey> privkey(
- PKCS8::load_key(arg_ca_key, *rng, arg_passphrase)
+ PKCS8::load_key(arg_ca_key, rng, arg_passphrase)
);
X509_CA ca(ca_cert, *privkey);
@@ -59,7 +57,7 @@ int main(int argc, char* argv[])
X509_Time start_time(system_time());
X509_Time end_time(system_time() + 365 * 60 * 60 * 24);
- X509_Certificate new_cert = ca.sign_request(req, *rng,
+ X509_Certificate new_cert = ca.sign_request(req, rng,
start_time, end_time);
// send the new cert back to the requestor
diff --git a/doc/examples/cms_dec.cpp b/doc/examples/cms_dec.cpp
index 08d43e7b8..f35d63fa6 100644
--- a/doc/examples/cms_dec.cpp
+++ b/doc/examples/cms_dec.cpp
@@ -17,11 +17,10 @@ int main(int argc, char* argv[])
LibraryInitializer init;
try {
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
X509_Certificate mycert("mycert.pem");
- PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", *rng, "cut");
+ PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", rng, "cut");
X509_Certificate yourcert("yourcert.pem");
X509_Certificate cacert("cacert.pem");
diff --git a/doc/examples/cms_enc.cpp b/doc/examples/cms_enc.cpp
index 50babc650..48b3c5ddd 100644
--- a/doc/examples/cms_enc.cpp
+++ b/doc/examples/cms_enc.cpp
@@ -18,8 +18,7 @@ int main()
X509_Certificate cacert("cacert.pem");
X509_Certificate int_ca("int_ca.pem");
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
X509_Store store;
store.add_cert(mycert);
@@ -34,10 +33,10 @@ int main()
encoder.compress("Zlib");
encoder.digest();
- encoder.encrypt(*rng, mycert);
+ encoder.encrypt(rng, mycert);
/*
- PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", *rng, "cut");
+ PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", rng, "cut");
encoder.sign(store, *mykey);
*/
diff --git a/doc/examples/dh.cpp b/doc/examples/dh.cpp
index f2a43e7f6..af0c19fec 100644
--- a/doc/examples/dh.cpp
+++ b/doc/examples/dh.cpp
@@ -17,15 +17,14 @@ int main()
{
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
// Alice creates a DH key and sends (the public part) to Bob
- DH_PrivateKey private_a(*rng, DL_Group("modp/ietf/1024"));
+ DH_PrivateKey private_a(rng, DL_Group("modp/ietf/1024"));
DH_PublicKey public_a = private_a; // Bob gets this
// Bob creates a key with a matching group
- DH_PrivateKey private_b(*rng, public_a.get_domain());
+ DH_PrivateKey private_b(rng, public_a.get_domain());
// Bob sends the key back to Alice
DH_PublicKey public_b = private_b; // Alice gets this
diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp
index 258ad6cf6..fe70f93fb 100644
--- a/doc/examples/dsa_kgen.cpp
+++ b/doc/examples/dsa_kgen.cpp
@@ -44,18 +44,17 @@ int main(int argc, char* argv[])
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
- DL_Group group(*rng, DL_Group::DSA_Kosherizer, 2048, 256);
+ DL_Group group(rng, DL_Group::DSA_Kosherizer, 2048, 256);
- DSA_PrivateKey key(*rng, group);
+ DSA_PrivateKey key(rng, group);
pub << X509::PEM_encode(key);
if(argc == 1)
priv << PKCS8::PEM_encode(key);
else
- priv << PKCS8::PEM_encode(key, *rng, argv[1]);
+ priv << PKCS8::PEM_encode(key, rng, argv[1]);
}
catch(std::exception& e)
{
diff --git a/doc/examples/dsa_sign.cpp b/doc/examples/dsa_sign.cpp
index b45bd9d70..1ef81d424 100644
--- a/doc/examples/dsa_sign.cpp
+++ b/doc/examples/dsa_sign.cpp
@@ -48,11 +48,10 @@ int main(int argc, char* argv[])
return 1;
}
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
std::auto_ptr<PKCS8_PrivateKey> key(
- PKCS8::load_key(argv[1], *rng, passphrase)
+ PKCS8::load_key(argv[1], rng, passphrase)
);
DSA_PrivateKey* dsakey = dynamic_cast<DSA_PrivateKey*>(key.get());
@@ -71,7 +70,7 @@ int main(int argc, char* argv[])
signer.update(buf, got);
Pipe pipe(new Base64_Encoder);
- pipe.process_msg(signer.signature(*rng));
+ pipe.process_msg(signer.signature(rng));
sigfile << pipe.read_all_as_string() << std::endl;
}
catch(std::exception& e)
diff --git a/doc/examples/eax_test.cpp b/doc/examples/eax_test.cpp
index f0e6b8d33..ea20bd0a6 100644
--- a/doc/examples/eax_test.cpp
+++ b/doc/examples/eax_test.cpp
@@ -48,9 +48,6 @@ void eax_test(const std::string& algo,
plaintext_str.c_str(), ciphertext.c_str());
*/
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
-
SymmetricKey key(key_str);
InitializationVector iv(nonce_str);
diff --git a/doc/examples/ecdsa.cpp b/doc/examples/ecdsa.cpp
index db4a94f3f..ce199936d 100644
--- a/doc/examples/ecdsa.cpp
+++ b/doc/examples/ecdsa.cpp
@@ -12,12 +12,11 @@ int main()
{
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
EC_Domain_Params params = get_EC_Dom_Pars_by_oid("1.3.132.0.8");
- ECDSA_PrivateKey ecdsa(*rng, params);
+ ECDSA_PrivateKey ecdsa(rng, params);
ECDSA_PublicKey ecdsa_pub = ecdsa;
@@ -34,7 +33,7 @@ int main()
signer->update((const byte*)message, strlen(message));
- SecureVector<byte> sig = signer->signature(*rng);
+ SecureVector<byte> sig = signer->signature(rng);
std::cout << sig.size() << "\n";
diff --git a/doc/examples/encrypt.cpp b/doc/examples/encrypt.cpp
index 959461b63..8f61306be 100644
--- a/doc/examples/encrypt.cpp
+++ b/doc/examples/encrypt.cpp
@@ -119,12 +119,11 @@ int main(int argc, char* argv[])
const u32bit key_len = max_keylength_of(algo);
const u32bit iv_len = block_size_of(algo);
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
std::auto_ptr<S2K> s2k(get_s2k("PBKDF2(SHA-1)"));
s2k->set_iterations(8192);
- s2k->new_random_salt(*rng, 8);
+ s2k->new_random_salt(rng, 8);
SymmetricKey bc_key = s2k->derive_key(key_len, "BLK" + passphrase);
InitializationVector iv = s2k->derive_key(iv_len, "IVL" + passphrase);
diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp
index cf4d395d0..70dde1050 100644
--- a/doc/examples/factor.cpp
+++ b/doc/examples/factor.cpp
@@ -123,10 +123,9 @@ int main(int argc, char* argv[])
{
BigInt n(argv[1]);
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
- std::vector<BigInt> factors = factorize(n, *rng);
+ std::vector<BigInt> factors = factorize(n, rng);
std::sort(factors.begin(), factors.end());
std::cout << n << ": ";
diff --git a/doc/examples/make_prime.cpp b/doc/examples/make_prime.cpp
index 4d82907f9..4135bd197 100644
--- a/doc/examples/make_prime.cpp
+++ b/doc/examples/make_prime.cpp
@@ -1,4 +1,5 @@
#include <botan/numthry.h>
+#include <botan/auto_rng.h>
using namespace Botan;
@@ -9,7 +10,7 @@ using namespace Botan;
int main()
{
- RandomNumberGenerator* rng = RandomNumberGenerator::make_rng();
+ AutoSeeded_RNG rng;
std::set<BigInt> primes;
@@ -23,14 +24,14 @@ int main()
u32bit bits = 18;
- if(rng->next_byte() % 128 == 0)
- bits -= rng->next_byte() % (bits-2);
+ if(rng.next_byte() % 128 == 0)
+ bits -= rng.next_byte() % (bits-2);
bit_count[bits]++;
//std::cout << "random_prime(" << bits << ")\n";
- BigInt p = random_prime(*rng, bits);
+ BigInt p = random_prime(rng, bits);
if(p.bits() != bits)
{
@@ -39,7 +40,7 @@ int main()
return 1;
}
- primes.insert(random_prime(*rng, bits));
+ primes.insert(random_prime(rng, bits));
if(primes.size() != start_cnt)
std::cout << primes.size() << "\n";
diff --git a/doc/examples/passhash.cpp b/doc/examples/passhash.cpp
index 78ced1c66..3cba3738f 100644
--- a/doc/examples/passhash.cpp
+++ b/doc/examples/passhash.cpp
@@ -25,11 +25,10 @@ int main(int argc, char* argv[])
if(argc == 2)
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
std::cout << "H('" << argv[1] << "') = "
- << password_hash(argv[1], *rng) << '\n';
+ << password_hash(argv[1], rng) << '\n';
}
else
{
diff --git a/doc/examples/pkcs10.cpp b/doc/examples/pkcs10.cpp
index 3983d5891..18390da7c 100644
--- a/doc/examples/pkcs10.cpp
+++ b/doc/examples/pkcs10.cpp
@@ -8,6 +8,7 @@ Written by Jack Lloyd ([email protected]), April 7, 2003
This file is in the public domain
*/
#include <botan/init.h>
+#include <botan/auto_rng.h>
#include <botan/x509self.h>
#include <botan/rsa.h>
#include <botan/dsa.h>
@@ -28,16 +29,15 @@ int main(int argc, char* argv[])
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
- RSA_PrivateKey priv_key(*rng, 1024);
+ RSA_PrivateKey priv_key(rng, 1024);
// If you want a DSA key instead of RSA, comment out the above line and
// uncomment this one:
//DSA_PrivateKey priv_key(DL_Group("dsa/jce/1024"));
std::ofstream key_file("private.pem");
- key_file << PKCS8::PEM_encode(priv_key, *rng, argv[1]);
+ key_file << PKCS8::PEM_encode(priv_key, rng, argv[1]);
X509_Cert_Options opts;
@@ -57,7 +57,7 @@ int main(int argc, char* argv[])
opts.xmpp = "[email protected]";
- PKCS10_Request req = X509::create_cert_req(opts, priv_key, *rng);
+ PKCS10_Request req = X509::create_cert_req(opts, priv_key, rng);
std::ofstream req_file("req.pem");
req_file << req.PEM_encode();
diff --git a/doc/examples/pqg_gen.cpp b/doc/examples/pqg_gen.cpp
index 8683cb2df..5cb3703d6 100644
--- a/doc/examples/pqg_gen.cpp
+++ b/doc/examples/pqg_gen.cpp
@@ -6,6 +6,7 @@
#include <memory>
#include <botan/botan.h>
+#include <botan/auto_rng.h>
#include <botan/look_pk.h>
#include <botan/dsa.h>
#include <botan/numthry.h>
@@ -20,8 +21,7 @@ int main()
try {
LibraryInitializer init("use_engines");
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
std::ifstream in("PQGGen.rsp");
if(!in)
@@ -51,7 +51,7 @@ int main()
if(name == "H")
{
- bool result = check(*rng, inputs);
+ bool result = check(rng, inputs);
std::cout << "." << std::flush;
if(result == false)
{
diff --git a/doc/examples/ressol.cpp b/doc/examples/ressol.cpp
index ff49ef19d..47a6550b6 100644
--- a/doc/examples/ressol.cpp
+++ b/doc/examples/ressol.cpp
@@ -1,4 +1,5 @@
#include <botan/numthry.h>
+#include <botan/auto_rng.h>
using namespace Botan;
@@ -47,7 +48,7 @@ void test_ressol(const BigInt& p, RandomNumberGenerator& rng)
int main()
{
- RandomNumberGenerator* rng = RandomNumberGenerator::make_rng();
+ AutoSeeded_RNG rng;
#if 0
std::cout << ressol(8, 17) << "\n";
@@ -58,8 +59,8 @@ int main()
for(int j = 16; j != 1024; ++j)
{
std::cout << "Round " << j << "\n";
- BigInt p = random_prime(*rng, j);
- test_ressol(p, *rng);
+ BigInt p = random_prime(rng, j);
+ test_ressol(p, rng);
//printf("%d\n", j);
@@ -70,7 +71,7 @@ int main()
{
std::cout << "PRIME[" << j << "] == " << PRIMES[j] << std::endl;
//printf("%d - ", PRIMES[j]);
- test_ressol(PRIMES[j], *rng);
+ test_ressol(PRIMES[j], rng);
//printf("\n");
}
*/
diff --git a/doc/examples/row_encryptor.cpp b/doc/examples/row_encryptor.cpp
index dc15ee6c4..f78332335 100644
--- a/doc/examples/row_encryptor.cpp
+++ b/doc/examples/row_encryptor.cpp
@@ -88,9 +88,9 @@ int main()
{
LibraryInitializer init;
- std::auto_ptr<RandomNumberGenerator> rng(RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
- Row_Encryptor encryptor("secret passphrase", *rng);
+ Row_Encryptor encryptor("secret passphrase", rng);
std::vector<std::string> original_inputs;
@@ -104,7 +104,7 @@ int main()
// TODO: Maybe randomize the length slightly?
for(u32bit j = 0; j != 32; ++j)
- out << std::hex << (int)rng->next_byte();
+ out << std::hex << (int)rng.next_byte();
original_inputs.push_back(out.str());
}
diff --git a/doc/examples/rsa_dec.cpp b/doc/examples/rsa_dec.cpp
index ca93756f2..7459f41b6 100644
--- a/doc/examples/rsa_dec.cpp
+++ b/doc/examples/rsa_dec.cpp
@@ -34,11 +34,10 @@ int main(int argc, char* argv[])
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
std::auto_ptr<PKCS8_PrivateKey> key(
- PKCS8::load_key(argv[1], *rng, argv[3]));
+ PKCS8::load_key(argv[1], rng, argv[3]));
RSA_PrivateKey* rsakey = dynamic_cast<RSA_PrivateKey*>(key.get());
if(!rsakey)
diff --git a/doc/examples/rsa_enc.cpp b/doc/examples/rsa_enc.cpp
index aebe42e72..4f37af6d6 100644
--- a/doc/examples/rsa_enc.cpp
+++ b/doc/examples/rsa_enc.cpp
@@ -73,8 +73,7 @@ int main(int argc, char* argv[])
return 1;
}
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
std::auto_ptr<PK_Encryptor> encryptor(get_pk_encryptor(*rsakey,
"EME1(SHA-1)"));
@@ -90,7 +89,7 @@ int main(int argc, char* argv[])
statistically indepedent. Practically speaking I don't think this is
a problem.
*/
- SymmetricKey masterkey(*rng,
+ SymmetricKey masterkey(rng,
std::min(32U, encryptor->maximum_input_size()));
SymmetricKey cast_key = derive_key("CAST", masterkey, 16);
@@ -98,7 +97,7 @@ int main(int argc, char* argv[])
SymmetricKey iv = derive_key("IV", masterkey, 8);
SecureVector<byte> encrypted_key =
- encryptor->encrypt(masterkey.bits_of(), *rng);
+ encryptor->encrypt(masterkey.bits_of(), rng);
ciphertext << b64_encode(encrypted_key) << std::endl;
diff --git a/doc/examples/rsa_kgen.cpp b/doc/examples/rsa_kgen.cpp
index c3942971b..ed8e786fe 100644
--- a/doc/examples/rsa_kgen.cpp
+++ b/doc/examples/rsa_kgen.cpp
@@ -45,16 +45,15 @@ int main(int argc, char* argv[])
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
- RSA_PrivateKey key(*rng, bits);
+ RSA_PrivateKey key(rng, bits);
pub << X509::PEM_encode(key);
if(argc == 2)
priv << PKCS8::PEM_encode(key);
else
- priv << PKCS8::PEM_encode(key, *rng, argv[2]);
+ priv << PKCS8::PEM_encode(key, rng, argv[2]);
}
catch(std::exception& e)
{
diff --git a/doc/examples/rsa_manykey.cpp b/doc/examples/rsa_manykey.cpp
index 95be8c568..9d27634de 100644
--- a/doc/examples/rsa_manykey.cpp
+++ b/doc/examples/rsa_manykey.cpp
@@ -15,13 +15,13 @@ using namespace Botan;
int main()
{
- std::auto_ptr<RandomNumberGenerator> rng(RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
for(u32bit j = 512; j <= 8192; j += 256)
{
std::cout << j << "...";
- RSA_PrivateKey key(*rng, j);
+ RSA_PrivateKey key(rng, j);
std::ofstream priv(("rsa/" + to_string(j) + ".pem").c_str());
priv << PKCS8::PEM_encode(key);
diff --git a/doc/examples/self_sig.cpp b/doc/examples/self_sig.cpp
index 42a58b485..a4b0c928c 100644
--- a/doc/examples/self_sig.cpp
+++ b/doc/examples/self_sig.cpp
@@ -42,13 +42,12 @@ int main(int argc, char* argv[])
try
{
- std::auto_ptr<RandomNumberGenerator> rng(
- RandomNumberGenerator::make_rng());
+ AutoSeeded_RNG rng;
- RSA_PrivateKey key(*rng, 1024);
+ RSA_PrivateKey key(rng, 1024);
std::ofstream priv_key("private.pem");
- priv_key << PKCS8::PEM_encode(key, *rng, argv[1]);
+ priv_key << PKCS8::PEM_encode(key, rng, argv[1]);
X509_Cert_Options opts;
@@ -63,7 +62,7 @@ int main(int argc, char* argv[])
if(do_CA)
opts.CA_key();
- X509_Certificate cert = X509::create_self_signed_cert(opts, key, *rng);
+ X509_Certificate cert = X509::create_self_signed_cert(opts, key, rng);
std::ofstream cert_file("cert.pem");
cert_file << cert.PEM_encode();
diff --git a/src/core/botan.h b/src/core/botan.h
index 70261398a..97b7dc1a3 100644
--- a/src/core/botan.h
+++ b/src/core/botan.h
@@ -9,3 +9,7 @@
#include <botan/lookup.h>
#include <botan/version.h>
#include <botan/parsing.h>
+
+#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
+ #include <botan/auto_rng.h>
+#endif
diff --git a/src/core/info.txt b/src/core/info.txt
index 7528abba8..a4cdfbf2b 100644
--- a/src/core/info.txt
+++ b/src/core/info.txt
@@ -5,15 +5,12 @@ load_on auto
define CORE_MODULE
<requires>
-aes
-sha1
-sha2
-hmac
+rng
filters
hex
bigint
libstate
-timer_base
+timer
</requires>
<add>
@@ -31,8 +28,6 @@ exceptn.h
mem_pool.cpp
mem_pool.h
mutex.h
-rng.cpp
-rng.h
secmem.h
symkey.cpp
symkey.h
diff --git a/src/core/rng.cpp b/src/rng/auto_rng/auto_rng.cpp
index 05746f188..076630f6d 100644
--- a/src/core/rng.cpp
+++ b/src/rng/auto_rng/auto_rng.cpp
@@ -1,23 +1,20 @@
/*************************************************
-* Random Number Generator Base Source File *
-* (C) 1999-2008 Jack Lloyd *
+* Auto Seeded RNG Source File *
+* (C) 2008 Jack Lloyd *
*************************************************/
-#include <botan/rng.h>
-#include <botan/util.h>
+#include <botan/auto_rng.h>
+#include <botan/randpool.h>
#include <botan/parsing.h>
#include <botan/timers.h>
-
-#if defined(BOTAN_HAS_RANDPOOL)
- #include <botan/lookup.h>
- #include <botan/randpool.h>
+#include <botan/aes.h>
+#include <botan/hmac.h>
+#include <botan/sha2_32.h>
#if defined(BOTAN_HAS_X931_RNG)
#include <botan/x931_rng.h>
#endif
-#endif
-
#if defined(BOTAN_HAS_TIMER_HARDWARE)
#include <botan/tm_hard.h>
#elif defined(BOTAN_HAS_TIMER_POSIX)
@@ -58,41 +55,13 @@
namespace Botan {
-/*************************************************
-* Default fast poll for EntropySources *
-*************************************************/
-u32bit EntropySource::fast_poll(byte buf[], u32bit len)
- {
- return this->slow_poll(buf, len);
- }
+namespace {
-/*************************************************
-* Get a single random byte *
-*************************************************/
-byte RandomNumberGenerator::next_byte()
+/**
+* Add any known entropy sources to this RNG
+*/
+void add_entropy_sources(RandomNumberGenerator* rng)
{
- byte out;
- this->randomize(&out, 1);
- return out;
- }
-
-/*************************************************
-* Create and seed a new RNG object *
-*************************************************/
-RandomNumberGenerator* RandomNumberGenerator::make_rng()
- {
-#if defined(BOTAN_HAS_RANDPOOL)
-
- /* Randpool is required for make_rng to work */
- RandomNumberGenerator* rng = new Randpool(get_block_cipher("AES-256"),
- get_mac("HMAC(SHA-256)"));
-
-
- /* If X9.31 is available, wrap the Randpool algorithm in it */
-#if defined(BOTAN_HAS_X931_RNG)
- rng = new ANSI_X931_RNG(get_block_cipher("AES-256"), rng);
-#endif
-
#if defined(BOTAN_HAS_TIMER_HARDWARE)
rng->add_entropy_source(new Hardware_Timer);
#elif defined(BOTAN_HAS_TIMER_POSIX)
@@ -140,11 +109,21 @@ RandomNumberGenerator* RandomNumberGenerator::make_rng()
#if defined(BOTAN_HAS_ENTROPY_SRC_FTW)
rng->add_entropy_source(new FTW_EntropySource("/proc"));
#endif
+ }
- return rng;
+}
+
+AutoSeeded_RNG::AutoSeeded_RNG()
+ {
+ /* Randpool is required for make_rng to work */
+ rng = new Randpool(new AES_256, new HMAC(new SHA_256));
+
+ /* If X9.31 is available, wrap the Randpool algorithm in it */
+#if defined(BOTAN_HAS_X931_RNG)
+ rng = new ANSI_X931_RNG(new AES_256, rng);
#endif
- throw Algorithm_Not_Found("RandomNumberGenerator::make_rng - no RNG found");
+ add_entropy_sources(rng);
}
}
diff --git a/src/rng/auto_rng/auto_rng.h b/src/rng/auto_rng/auto_rng.h
new file mode 100644
index 000000000..bbc3703c1
--- /dev/null
+++ b/src/rng/auto_rng/auto_rng.h
@@ -0,0 +1,42 @@
+/*************************************************
+* Auto Seeded RNG Header File *
+* (C) 2008 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_AUTO_SEEDING_RNG_H__
+#define BOTAN_AUTO_SEEDING_RNG_H__
+
+#include <botan/rng.h>
+#include <botan/base.h>
+
+namespace Botan {
+
+/**
+* RNG that attempts to seed itself
+*/
+class BOTAN_DLL AutoSeeded_RNG : public RandomNumberGenerator
+ {
+ public:
+ void randomize(byte out[], u32bit len)
+ { rng->randomize(out, len); }
+ bool is_seeded() const
+ { return rng->is_seeded(); }
+ void clear() throw() { rng->clear(); }
+ std::string name() const
+ { return "AutoSeeded(" + rng->name() + ")"; }
+
+ void reseed() { rng->reseed(); }
+ void add_entropy_source(EntropySource* es)
+ { rng->add_entropy_source(es); }
+ void add_entropy(const byte in[], u32bit len)
+ { rng->add_entropy(in, len); }
+
+ AutoSeeded_RNG();
+ ~AutoSeeded_RNG() { delete rng; }
+ private:
+ RandomNumberGenerator* rng;
+ };
+
+}
+
+#endif
diff --git a/src/rng/auto_rng/info.txt b/src/rng/auto_rng/info.txt
new file mode 100644
index 000000000..c2b653220
--- /dev/null
+++ b/src/rng/auto_rng/info.txt
@@ -0,0 +1,18 @@
+realname "Auto-seeded Random Number Generator"
+
+define AUTO_SEEDING_RNG
+
+load_on auto
+
+<requires>
+randpool
+aes
+sha2
+hmac
+</requires>
+
+<add>
+auto_rng.h
+auto_rng.cpp
+</add>
+
diff --git a/src/rng/info.txt b/src/rng/info.txt
new file mode 100644
index 000000000..8b542b68f
--- /dev/null
+++ b/src/rng/info.txt
@@ -0,0 +1,8 @@
+realname "Random Number Generators"
+
+load_on auto
+
+<add>
+rng.cpp
+rng.h
+</add>
diff --git a/src/rng/rng.cpp b/src/rng/rng.cpp
new file mode 100644
index 000000000..01e909610
--- /dev/null
+++ b/src/rng/rng.cpp
@@ -0,0 +1,44 @@
+/*************************************************
+* Random Number Generator Base Source File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#include <botan/rng.h>
+
+#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
+ #include <botan/auto_rng.h>
+#endif
+
+namespace Botan {
+
+/*************************************************
+* Default fast poll for EntropySources *
+*************************************************/
+u32bit EntropySource::fast_poll(byte buf[], u32bit len)
+ {
+ return this->slow_poll(buf, len);
+ }
+
+/*************************************************
+* Get a single random byte *
+*************************************************/
+byte RandomNumberGenerator::next_byte()
+ {
+ byte out;
+ this->randomize(&out, 1);
+ return out;
+ }
+
+/*************************************************
+* Create and seed a new RNG object *
+*************************************************/
+RandomNumberGenerator* RandomNumberGenerator::make_rng()
+ {
+#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
+ return new AutoSeeded_RNG;
+#endif
+
+ throw Algorithm_Not_Found("RandomNumberGenerator::make_rng - no RNG found");
+ }
+
+}
diff --git a/src/s2k/info.txt b/src/s2k/info.txt
new file mode 100644
index 000000000..9c8bb0c45
--- /dev/null
+++ b/src/s2k/info.txt
@@ -0,0 +1,12 @@
+realname "String to Key Functions"
+
+load_on auto
+
+<requires>
+utils
+</requires>
+
+<add>
+s2k.cpp
+s2k.h
+</add>
diff --git a/src/utils/timer/cpu_counter/info.txt b/src/utils/timer/cpu_counter/info.txt
index eef6be5a2..025663a84 100644
--- a/src/utils/timer/cpu_counter/info.txt
+++ b/src/utils/timer/cpu_counter/info.txt
@@ -32,5 +32,5 @@ hppa
</arch>
<requires>
-timer_base
+timer
</requires>
diff --git a/src/utils/timer/gettimeofday/info.txt b/src/utils/timer/gettimeofday/info.txt
index c079dfd58..d3812eedf 100644
--- a/src/utils/timer/gettimeofday/info.txt
+++ b/src/utils/timer/gettimeofday/info.txt
@@ -27,6 +27,6 @@ tru64
</os>
<requires>
-timer_base
+timer
</requires>
diff --git a/src/utils/timer/timer_base/info.txt b/src/utils/timer/info.txt
index 3637d4c94..3637d4c94 100644
--- a/src/utils/timer/timer_base/info.txt
+++ b/src/utils/timer/info.txt
diff --git a/src/utils/timer/posix_rt/info.txt b/src/utils/timer/posix_rt/info.txt
index fb1870988..7501373bb 100644
--- a/src/utils/timer/posix_rt/info.txt
+++ b/src/utils/timer/posix_rt/info.txt
@@ -23,6 +23,6 @@ linux
</os>
<requires>
-timer_base
+timer
</requires>
diff --git a/src/utils/timer/timer_base/timers.cpp b/src/utils/timer/timers.cpp
index 4f482916f..4f482916f 100644
--- a/src/utils/timer/timer_base/timers.cpp
+++ b/src/utils/timer/timers.cpp
diff --git a/src/utils/timer/timer_base/timers.h b/src/utils/timer/timers.h
index 253f71f6b..253f71f6b 100644
--- a/src/utils/timer/timer_base/timers.h
+++ b/src/utils/timer/timers.h
diff --git a/src/utils/timer/win32_query_perf_ctr/info.txt b/src/utils/timer/win32_query_perf_ctr/info.txt
index 5ac05da95..e74259184 100644
--- a/src/utils/timer/win32_query_perf_ctr/info.txt
+++ b/src/utils/timer/win32_query_perf_ctr/info.txt
@@ -21,6 +21,6 @@ windows -> user32
</libs>
<requires>
-timer_base
+timer
</requires>