diff options
-rw-r--r-- | checks/bench.cpp | 4 | ||||
-rw-r--r-- | checks/bigint.cpp | 4 | ||||
-rw-r--r-- | checks/dolook2.cpp | 4 | ||||
-rw-r--r-- | checks/pk.cpp | 8 | ||||
-rw-r--r-- | checks/pk_bench.cpp | 16 | ||||
-rw-r--r-- | checks/validate.cpp | 4 | ||||
-rw-r--r-- | include/botan.h | 1 | ||||
-rw-r--r-- | include/libstate.h | 1 | ||||
-rw-r--r-- | include/rng.h | 32 | ||||
-rw-r--r-- | src/big_rand.cpp | 4 | ||||
-rw-r--r-- | src/dsa_gen.cpp | 5 | ||||
-rw-r--r-- | src/eme1.cpp | 4 | ||||
-rw-r--r-- | src/eme_pkcs.cpp | 4 | ||||
-rw-r--r-- | src/emsa4.cpp | 4 | ||||
-rw-r--r-- | src/keypair.cpp | 6 | ||||
-rw-r--r-- | src/libstate.cpp | 10 | ||||
-rw-r--r-- | src/pbes1.cpp | 4 | ||||
-rw-r--r-- | src/pbes2.cpp | 6 | ||||
-rw-r--r-- | src/rng.cpp | 65 | ||||
-rw-r--r-- | src/s2k.cpp | 4 | ||||
-rw-r--r-- | src/symkey.cpp | 4 |
21 files changed, 53 insertions, 141 deletions
diff --git a/checks/bench.cpp b/checks/bench.cpp index 089b229f2..48db9d8cf 100644 --- a/checks/bench.cpp +++ b/checks/bench.cpp @@ -5,7 +5,7 @@ #include <string> #include <exception> -#include <botan/rng.h> +#include <botan/libstate.h> #include <botan/filters.h> using namespace Botan_types; using Botan::u64bit; @@ -31,7 +31,7 @@ double bench_filter(std::string name, Botan::Filter* filter, static const u32bit BUFFERSIZE = 32*1024; byte buf[BUFFERSIZE]; - Botan::Global_RNG::randomize(buf, BUFFERSIZE); + Botan::global_state().randomize(buf, BUFFERSIZE); u32bit iterations = 0; u64bit start = get_clock(), clocks_used = 0; diff --git a/checks/bigint.cpp b/checks/bigint.cpp index e4fec12b4..6a4d5ac94 100644 --- a/checks/bigint.cpp +++ b/checks/bigint.cpp @@ -7,7 +7,7 @@ #include <botan/bigint.h> #include <botan/exceptn.h> #include <botan/numthry.h> -#include <botan/rng.h> +#include <botan/libstate.h> using namespace Botan; #include "common.h" @@ -264,7 +264,7 @@ u32bit check_mod(const std::vector<std::string>& args) /* Won't work for us, just pick one at random */ while(b_word == 0) for(u32bit j = 0; j != 2*sizeof(word); j++) - b_word = (b_word << 4) ^ Global_RNG::random(); + b_word = (b_word << 4) ^ global_state().random(); b = b_word; diff --git a/checks/dolook2.cpp b/checks/dolook2.cpp index b6c9ba339..b49d48a5e 100644 --- a/checks/dolook2.cpp +++ b/checks/dolook2.cpp @@ -8,7 +8,7 @@ #include <botan/filters.h> #include <botan/randpool.h> #include <botan/x931_rng.h> -#include <botan/rng.h> +#include <botan/libstate.h> using namespace Botan; /* A weird little hack to fit S2K algorithms into the validation suite @@ -49,7 +49,7 @@ class RNG_Filter : public Filter void write(const byte[], u32bit); RNG_Filter(RandomNumberGenerator* r) : rng(r), buffer(1024) { - Global_RNG::randomize(buffer, buffer.size()); + global_state().randomize(buffer, buffer.size()); rng->add_entropy(buffer, buffer.size()); } ~RNG_Filter() { delete rng; } diff --git a/checks/pk.cpp b/checks/pk.cpp index f2c2401fd..afd8d61e4 100644 --- a/checks/pk.cpp +++ b/checks/pk.cpp @@ -21,7 +21,7 @@ #include <botan/numthry.h> #include <botan/x931_rng.h> -#include <botan/rng.h> +#include <botan/libstate.h> using namespace Botan; #include "common.h" @@ -194,7 +194,7 @@ u32bit do_pk_validation_tests(const std::string& filename) global_state().set_prng(new ANSI_X931_RNG); for(u32bit j = 0; j != 2; j++) - Global_RNG::seed(true, 384); + global_state().seed_prng(true, 384); do_pk_keygen_tests(); do_x509_tests(); @@ -249,7 +249,7 @@ void validate_encryption(PK_Encryptor* e, PK_Decryptor* d, global_state().set_prng(new ANSI_X931_RNG); for(u32bit j = 0; j != 2; j++) - Global_RNG::seed(true, 384); + global_state().seed_prng(true, 384); validate_decryption(d, algo, out, message, failure); delete e; @@ -290,7 +290,7 @@ void validate_signature(PK_Verifier* v, PK_Signer* s, const std::string& algo, global_state().set_prng(new ANSI_X931_RNG); for(u32bit j = 0; j != 2; j++) - Global_RNG::seed(true, 384); + global_state().seed_prng(true, 384); delete v; delete s; diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index c06f12abf..51a454f4a 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -8,7 +8,7 @@ #include <botan/pkcs8.h> #include <botan/look_pk.h> -#include <botan/rng.h> +#include <botan/libstate.h> using namespace Botan; @@ -219,7 +219,7 @@ void bench_enc(PK_Encryptor* enc, const std::string& algo_name, while(clocks_used < seconds * ticks) { runs++; - Global_RNG::randomize(msg, MSG_SIZE); + global_state().randomize(msg, MSG_SIZE); u64bit start = get_clock(); enc->encrypt(msg, MSG_SIZE); @@ -237,7 +237,7 @@ void bench_dec(PK_Encryptor* enc, PK_Decryptor* dec, { static const u32bit MSG_SIZE = 16; byte msg[MSG_SIZE]; - Global_RNG::randomize(msg, MSG_SIZE); + global_state().randomize(msg, MSG_SIZE); SecureVector<byte> output; u32bit runs = 0; @@ -250,7 +250,7 @@ void bench_dec(PK_Encryptor* enc, PK_Decryptor* dec, { runs++; - Global_RNG::randomize(msg, MSG_SIZE); + global_state().randomize(msg, MSG_SIZE); msg[0] |= 0x80; // make sure it works with "Raw" padding encrypted_msg = enc->encrypt(msg, MSG_SIZE); @@ -286,7 +286,7 @@ void bench_sig(PK_Signer* sig, const std::string& algo_name, while(clocks_used < seconds * ticks) { runs++; - Global_RNG::randomize(msg, MSG_SIZE); + global_state().randomize(msg, MSG_SIZE); u64bit start = get_clock(); sig->update(msg, MSG_SIZE); sig->signature(); @@ -304,7 +304,7 @@ void bench_ver(PK_Signer* sig, PK_Verifier* ver, { static const u32bit MSG_SIZE = 16; byte msg[MSG_SIZE]; - Global_RNG::randomize(msg, MSG_SIZE); + global_state().randomize(msg, MSG_SIZE); sig->update(msg, MSG_SIZE); SecureVector<byte> signature = sig->signature(); @@ -317,7 +317,7 @@ void bench_ver(PK_Signer* sig, PK_Verifier* ver, // feel free to tweak, but make sure this always runs when runs == 0 if(runs % 100 == 0) { - Global_RNG::randomize(msg, MSG_SIZE); + global_state().randomize(msg, MSG_SIZE); sig->update(msg, MSG_SIZE); signature = sig->signature(); } @@ -352,7 +352,7 @@ void bench_kas(PK_Key_Agreement* kas, const std::string& algo_name, while(clocks_used < seconds * ticks) { runs++; - Global_RNG::randomize(key, REMOTE_KEY_SIZE); + global_state().randomize(key, REMOTE_KEY_SIZE); u64bit start = get_clock(); kas->derive_key(0, key, REMOTE_KEY_SIZE); diff --git a/checks/validate.cpp b/checks/validate.cpp index d634d3bb3..269b353a4 100644 --- a/checks/validate.cpp +++ b/checks/validate.cpp @@ -10,7 +10,7 @@ #include <botan/filters.h> #include <botan/exceptn.h> -#include <botan/rng.h> +#include <botan/libstate.h> using namespace Botan_types; #define EXTRA_TESTS 0 @@ -31,7 +31,7 @@ u32bit random_word(u32bit max) /* normal version */ u32bit r = 0; for(u32bit j = 0; j != 4; j++) - r = (r << 8) | Botan::Global_RNG::random(); + r = (r << 8) | Botan::global_state().random(); return ((r % max) + 1); // return between 1 and max inclusive #endif } diff --git a/include/botan.h b/include/botan.h index 007bf411e..bdd591569 100644 --- a/include/botan.h +++ b/include/botan.h @@ -7,6 +7,5 @@ #include <botan/config.h> #include <botan/init.h> #include <botan/lookup.h> -#include <botan/rng.h> #include <botan/version.h> #include <botan/parsing.h> diff --git a/include/libstate.h b/include/libstate.h index 0b2a2959f..5534d4ac1 100644 --- a/include/libstate.h +++ b/include/libstate.h @@ -48,6 +48,7 @@ class Library_State bool rng_is_seeded() const { return rng->is_seeded(); } void randomize(byte[], u32bit); + byte random(); void set_prng(RandomNumberGenerator*); void add_entropy_source(EntropySource*, bool = true); diff --git a/include/rng.h b/include/rng.h deleted file mode 100644 index 207da51b5..000000000 --- a/include/rng.h +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************* -* Global RNG Header File * -* (C) 1999-2007 The Botan Project * -*************************************************/ - -#ifndef BOTAN_GLOBAL_RNG_H__ -#define BOTAN_GLOBAL_RNG_H__ - -#include <botan/base.h> - -namespace Botan { - -/************************************************* -* RNG Access and Seeding Functions * -*************************************************/ -namespace Global_RNG { - -void randomize(byte[], u32bit); -byte random(); - -void add_entropy(const byte[], u32bit); -void add_entropy(EntropySource&, bool = true); - -u32bit seed(bool = true, u32bit = 256); - -void add_es(EntropySource*, bool = true); - -} - -} - -#endif diff --git a/src/big_rand.cpp b/src/big_rand.cpp index 7dac05e67..4d3abe1a2 100644 --- a/src/big_rand.cpp +++ b/src/big_rand.cpp @@ -6,7 +6,7 @@ #include <botan/bigint.h> #include <botan/parsing.h> #include <botan/numthry.h> -#include <botan/rng.h> +#include <botan/libstate.h> namespace Botan { @@ -36,7 +36,7 @@ void BigInt::randomize(u32bit bitsize) else { SecureVector<byte> array((bitsize + 7) / 8); - Global_RNG::randomize(array, array.size()); + global_state().randomize(array, array.size()); if(bitsize % 8) array[0] &= 0xFF >> (8 - (bitsize % 8)); array[0] |= 0x80 >> ((bitsize % 8) ? (8 - bitsize % 8) : 0); diff --git a/src/dsa_gen.cpp b/src/dsa_gen.cpp index 15a0b5ff8..3b1e52ad5 100644 --- a/src/dsa_gen.cpp +++ b/src/dsa_gen.cpp @@ -5,10 +5,9 @@ #include <botan/dl_group.h> #include <botan/numthry.h> -#include <botan/libstate.h> #include <botan/lookup.h> #include <botan/parsing.h> -#include <botan/rng.h> +#include <botan/libstate.h> #include <algorithm> #include <memory> @@ -121,7 +120,7 @@ SecureVector<byte> DL_Group::generate_dsa_primes(BigInt& p, BigInt& q, while(true) { - Global_RNG::randomize(seed, seed.size()); + global_state().randomize(seed, seed.size()); if(generate_dsa_primes(p, q, pbits, qbits, seed)) return seed; diff --git a/src/eme1.cpp b/src/eme1.cpp index bf914d248..ed8a8e4fd 100644 --- a/src/eme1.cpp +++ b/src/eme1.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/eme.h> -#include <botan/rng.h> +#include <botan/libstate.h> #include <botan/lookup.h> #include <botan/look_pk.h> #include <memory> @@ -26,7 +26,7 @@ SecureVector<byte> EME1::pad(const byte in[], u32bit in_length, out.clear(); - Global_RNG::randomize(out, HASH_LENGTH); + global_state().randomize(out, HASH_LENGTH); out.copy(HASH_LENGTH, Phash, Phash.size()); out[out.size() - in_length - 1] = 0x01; diff --git a/src/eme_pkcs.cpp b/src/eme_pkcs.cpp index 043d955c2..55ceeea99 100644 --- a/src/eme_pkcs.cpp +++ b/src/eme_pkcs.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/eme.h> -#include <botan/rng.h> +#include <botan/libstate.h> namespace Botan { @@ -26,7 +26,7 @@ SecureVector<byte> EME_PKCS1v15::pad(const byte in[], u32bit inlen, out[0] = 0x02; for(u32bit j = 1; j != olen - inlen - 1; ++j) while(out[j] == 0) - out[j] = Global_RNG::random(); + out[j] = global_state().random(); out.copy(olen - inlen, in, inlen); return out; diff --git a/src/emsa4.cpp b/src/emsa4.cpp index 5b2719f58..071439007 100644 --- a/src/emsa4.cpp +++ b/src/emsa4.cpp @@ -7,7 +7,7 @@ #include <botan/lookup.h> #include <botan/look_pk.h> #include <botan/bit_ops.h> -#include <botan/rng.h> +#include <botan/libstate.h> namespace Botan { @@ -43,7 +43,7 @@ SecureVector<byte> EMSA4::encoding_of(const MemoryRegion<byte>& msg, const u32bit output_length = (output_bits + 7) / 8; SecureVector<byte> salt(SALT_SIZE); - Global_RNG::randomize(salt, SALT_SIZE); + global_state().randomize(salt, SALT_SIZE); for(u32bit j = 0; j != 8; ++j) hash->update(0); diff --git a/src/keypair.cpp b/src/keypair.cpp index b40b8c395..6401131ea 100644 --- a/src/keypair.cpp +++ b/src/keypair.cpp @@ -5,7 +5,7 @@ #include <botan/keypair.h> #include <botan/look_pk.h> -#include <botan/rng.h> +#include <botan/libstate.h> #include <memory> namespace Botan { @@ -24,7 +24,7 @@ void check_key(PK_Encryptor* encryptor, PK_Decryptor* decryptor) std::auto_ptr<PK_Decryptor> dec(decryptor); SecureVector<byte> message(enc->maximum_input_size() - 1); - Global_RNG::randomize(message, message.size()); + global_state().randomize(message, message.size()); SecureVector<byte> ciphertext = enc->encrypt(message); if(ciphertext == message) @@ -44,7 +44,7 @@ void check_key(PK_Signer* signer, PK_Verifier* verifier) std::auto_ptr<PK_Verifier> ver(verifier); SecureVector<byte> message(16); - Global_RNG::randomize(message, message.size()); + global_state().randomize(message, message.size()); SecureVector<byte> signature; diff --git a/src/libstate.cpp b/src/libstate.cpp index 7f0c41b83..5e440c103 100644 --- a/src/libstate.cpp +++ b/src/libstate.cpp @@ -142,6 +142,16 @@ void Library_State::randomize(byte out[], u32bit length) } /************************************************* +* Get a byte from the global PRNG * +*************************************************/ +byte Library_State::random() + { + byte out; + rng->randomize(&out, 1); + return out; + } + +/************************************************* * Add a new entropy source to use * *************************************************/ void Library_State::add_entropy_source(EntropySource* src, bool last_in_list) diff --git a/src/pbes1.cpp b/src/pbes1.cpp index 69f2ebc10..cdd2a87fd 100644 --- a/src/pbes1.cpp +++ b/src/pbes1.cpp @@ -8,7 +8,7 @@ #include <botan/ber_dec.h> #include <botan/parsing.h> #include <botan/lookup.h> -#include <botan/rng.h> +#include <botan/libstate.h> #include <algorithm> #include <memory> @@ -86,7 +86,7 @@ void PBE_PKCS5v15::new_params() { iterations = 2048; salt.create(8); - Global_RNG::randomize(salt, salt.size()); + global_state().randomize(salt, salt.size()); } /************************************************* diff --git a/src/pbes2.cpp b/src/pbes2.cpp index 400e66572..029310fff 100644 --- a/src/pbes2.cpp +++ b/src/pbes2.cpp @@ -8,7 +8,7 @@ #include <botan/ber_dec.h> #include <botan/parsing.h> #include <botan/lookup.h> -#include <botan/rng.h> +#include <botan/libstate.h> #include <botan/asn1_obj.h> #include <botan/oids.h> #include <algorithm> @@ -87,8 +87,8 @@ void PBE_PKCS5v20::new_params() key_length = max_keylength_of(cipher_algo); salt.create(8); iv.create(block_size_of(cipher_algo)); - Global_RNG::randomize(salt, salt.size()); - Global_RNG::randomize(iv, iv.size()); + global_state().randomize(salt, salt.size()); + global_state().randomize(iv, iv.size()); } /************************************************* diff --git a/src/rng.cpp b/src/rng.cpp deleted file mode 100644 index be8891921..000000000 --- a/src/rng.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************* -* Global RNG Source File * -* (C) 1999-2007 The Botan Project * -*************************************************/ - -#include <botan/rng.h> -#include <botan/libstate.h> - -namespace Botan { - -namespace Global_RNG { - -/************************************************* -* Get random bits from the global RNG * -*************************************************/ -void randomize(byte output[], u32bit size) - { - global_state().randomize(output, size); - } - -/************************************************* -* Get random bits from the global RNG * -*************************************************/ -byte random() - { - byte ret = 0; - randomize(&ret, 1); - return ret; - } - -/************************************************* -* Add entropy to the global RNG * -*************************************************/ -void add_entropy(const byte entropy[], u32bit size) - { - global_state().add_entropy(entropy, size); - } - -/************************************************* -* Add entropy to the global RNG * -*************************************************/ -void add_entropy(EntropySource& src, bool slow_poll) - { - global_state().add_entropy(src, slow_poll); - } - -/************************************************* -* Add an EntropySource to the RNG seed list * -*************************************************/ -void add_es(EntropySource* src, bool last) - { - global_state().add_entropy_source(src, last); - } - -/************************************************* -* Seed the global RNG * -*************************************************/ -u32bit seed(bool slow_poll, u32bit bits_to_get) - { - return global_state().seed_prng(slow_poll, bits_to_get); - } - -} - -} diff --git a/src/s2k.cpp b/src/s2k.cpp index 94022b0d5..8860f5d4c 100644 --- a/src/s2k.cpp +++ b/src/s2k.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/s2k.h> -#include <botan/rng.h> +#include <botan/libstate.h> namespace Botan { @@ -47,7 +47,7 @@ void S2K::change_salt(const MemoryRegion<byte>& new_salt) void S2K::new_random_salt(u32bit length) { salt.create(length); - Global_RNG::randomize(salt, length); + global_state().randomize(salt, length); } } diff --git a/src/symkey.cpp b/src/symkey.cpp index b1f0786b0..d6302afbc 100644 --- a/src/symkey.cpp +++ b/src/symkey.cpp @@ -7,7 +7,7 @@ #include <botan/bit_ops.h> #include <botan/pipe.h> #include <botan/hex.h> -#include <botan/rng.h> +#include <botan/libstate.h> #include <algorithm> namespace Botan { @@ -18,7 +18,7 @@ namespace Botan { void OctetString::change(u32bit length) { bits.create(length); - Global_RNG::randomize(bits, length); + global_state().randomize(bits, length); } /************************************************* |