diff options
Diffstat (limited to 'src/rng')
-rw-r--r-- | src/rng/auto_rng/auto_rng.h | 6 | ||||
-rw-r--r-- | src/rng/hmac_rng/hmac_rng.cpp | 13 | ||||
-rw-r--r-- | src/rng/hmac_rng/hmac_rng.h | 9 | ||||
-rw-r--r-- | src/rng/randpool/randpool.cpp | 26 | ||||
-rw-r--r-- | src/rng/randpool/randpool.h | 12 | ||||
-rw-r--r-- | src/rng/rng.h | 14 | ||||
-rw-r--r-- | src/rng/x931_rng/x931_rng.cpp | 8 | ||||
-rw-r--r-- | src/rng/x931_rng/x931_rng.h | 8 |
8 files changed, 48 insertions, 48 deletions
diff --git a/src/rng/auto_rng/auto_rng.h b/src/rng/auto_rng/auto_rng.h index 28a603feb..520323e3e 100644 --- a/src/rng/auto_rng/auto_rng.h +++ b/src/rng/auto_rng/auto_rng.h @@ -20,7 +20,7 @@ namespace Botan { class BOTAN_DLL AutoSeeded_RNG : public RandomNumberGenerator { public: - void randomize(byte out[], u32bit len) + void randomize(byte out[], size_t len) { rng->randomize(out, len); } bool is_seeded() const { return rng->is_seeded(); } @@ -29,12 +29,12 @@ class BOTAN_DLL AutoSeeded_RNG : public RandomNumberGenerator std::string name() const { return rng->name(); } - void reseed(u32bit poll_bits = 256) { rng->reseed(poll_bits); } + void reseed(size_t poll_bits = 256) { rng->reseed(poll_bits); } void add_entropy_source(EntropySource* es) { rng->add_entropy_source(es); } - void add_entropy(const byte in[], u32bit len) + void add_entropy(const byte in[], size_t len) { rng->add_entropy(in, len); } AutoSeeded_RNG() { rng = &global_state().global_rng(); } diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index 6abdc66ce..a3456d9e0 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -22,8 +22,7 @@ void hmac_prf(MessageAuthenticationCode* prf, { prf->update(K); prf->update(label); - for(u32bit i = 0; i != 4; ++i) - prf->update(get_byte(i, counter)); + prf->update_be(counter); prf->final(&K[0]); ++counter; @@ -34,7 +33,7 @@ void hmac_prf(MessageAuthenticationCode* prf, /* * Generate a buffer of random bytes */ -void HMAC_RNG::randomize(byte out[], u32bit length) +void HMAC_RNG::randomize(byte out[], size_t length) { if(!is_seeded()) throw PRNG_Unseeded(name()); @@ -46,7 +45,7 @@ void HMAC_RNG::randomize(byte out[], u32bit length) { hmac_prf(prf, K, counter, "rng"); - const u32bit copied = std::min<u32bit>(K.size(), length); + const size_t copied = std::min<size_t>(K.size(), length); copy_mem(out, &K[0], copied); out += copied; @@ -57,7 +56,7 @@ void HMAC_RNG::randomize(byte out[], u32bit length) /* * Poll for entropy and reset the internal keys */ -void HMAC_RNG::reseed(u32bit poll_bits) +void HMAC_RNG::reseed(size_t poll_bits) { /* Using the terminology of E-t-E, XTR is the MAC function (normally @@ -72,7 +71,7 @@ void HMAC_RNG::reseed(u32bit poll_bits) if(!entropy_sources.empty()) { - u32bit poll_attempt = 0; + size_t poll_attempt = 0; while(!accum.polling_goal_achieved() && poll_attempt < poll_bits) { @@ -118,7 +117,7 @@ void HMAC_RNG::reseed(u32bit poll_bits) /* * Add user-supplied entropy to the extractor input */ -void HMAC_RNG::add_entropy(const byte input[], u32bit length) +void HMAC_RNG::add_entropy(const byte input[], size_t length) { extractor->update(input, length); user_input_len += length; diff --git a/src/rng/hmac_rng/hmac_rng.h b/src/rng/hmac_rng/hmac_rng.h index fc712b3ec..fc6a14f3a 100644 --- a/src/rng/hmac_rng/hmac_rng.h +++ b/src/rng/hmac_rng/hmac_rng.h @@ -27,14 +27,14 @@ and CMAC(AES-256) as the PRF. class BOTAN_DLL HMAC_RNG : public RandomNumberGenerator { public: - void randomize(byte buf[], u32bit len); + void randomize(byte buf[], size_t len); bool is_seeded() const { return seeded; } void clear(); std::string name() const; - void reseed(u32bit poll_bits); + void reseed(size_t poll_bits); void add_entropy_source(EntropySource* es); - void add_entropy(const byte[], u32bit); + void add_entropy(const byte[], size_t); /** * @param extractor a MAC used for extracting the entropy @@ -52,7 +52,8 @@ class BOTAN_DLL HMAC_RNG : public RandomNumberGenerator bool seeded; SecureVector<byte> K, io_buffer; - u32bit counter, user_input_len; + size_t user_input_len; + u32bit counter; }; } diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index bce3f8ac3..d99ae5463 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -29,7 +29,7 @@ enum RANDPOOL_PRF_TAG { /* * Generate a buffer of random bytes */ -void Randpool::randomize(byte out[], u32bit length) +void Randpool::randomize(byte out[], size_t length) { if(!is_seeded()) throw PRNG_Unseeded(name()); @@ -37,7 +37,7 @@ void Randpool::randomize(byte out[], u32bit length) update_buffer(); while(length) { - const u32bit copied = std::min<u32bit>(length, buffer.size()); + const size_t copied = std::min<size_t>(length, buffer.size()); copy_mem(out, &buffer[0], copied); out += copied; length -= copied; @@ -50,7 +50,7 @@ void Randpool::randomize(byte out[], u32bit length) */ void Randpool::update_buffer() { - for(u32bit i = 0; i != counter.size(); ++i) + for(size_t i = 0; i != counter.size(); ++i) if(++counter[i]) break; @@ -58,7 +58,7 @@ void Randpool::update_buffer() mac->update(counter); SecureVector<byte> mac_val = mac->final(); - for(u32bit i = 0; i != mac_val.size(); ++i) + for(size_t i = 0; i != mac_val.size(); ++i) buffer[i % buffer.size()] ^= mac_val[i]; cipher->encrypt(buffer); @@ -71,7 +71,7 @@ void Randpool::update_buffer() */ void Randpool::mix_pool() { - const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; + const size_t BLOCK_SIZE = cipher->BLOCK_SIZE; mac->update(static_cast<byte>(MAC_KEY)); mac->update(pool); @@ -83,7 +83,7 @@ void Randpool::mix_pool() xor_buf(pool, buffer, BLOCK_SIZE); cipher->encrypt(pool); - for(u32bit i = 1; i != POOL_BLOCKS; ++i) + for(size_t i = 1; i != POOL_BLOCKS; ++i) { const byte* previous_block = &pool[BLOCK_SIZE*(i-1)]; byte* this_block = &pool[BLOCK_SIZE*i]; @@ -97,13 +97,13 @@ void Randpool::mix_pool() /* * Reseed the internal state */ -void Randpool::reseed(u32bit poll_bits) +void Randpool::reseed(size_t poll_bits) { Entropy_Accumulator_BufferedComputation accum(*mac, poll_bits); if(!entropy_sources.empty()) { - u32bit poll_attempt = 0; + size_t poll_attempt = 0; while(!accum.polling_goal_achieved() && poll_attempt < poll_bits) { @@ -124,7 +124,7 @@ void Randpool::reseed(u32bit poll_bits) /* * Add user-supplied entropy */ -void Randpool::add_entropy(const byte input[], u32bit length) +void Randpool::add_entropy(const byte input[], size_t length) { SecureVector<byte> mac_val = mac->process(input, length); xor_buf(pool, mac_val, mac_val.size()); @@ -168,15 +168,15 @@ std::string Randpool::name() const */ Randpool::Randpool(BlockCipher* cipher_in, MessageAuthenticationCode* mac_in, - u32bit pool_blocks, - u32bit iter_before_reseed) : + size_t pool_blocks, + size_t iter_before_reseed) : ITERATIONS_BEFORE_RESEED(iter_before_reseed), POOL_BLOCKS(pool_blocks), cipher(cipher_in), mac(mac_in) { - const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE; - const u32bit OUTPUT_LENGTH = mac->OUTPUT_LENGTH; + const size_t BLOCK_SIZE = cipher->BLOCK_SIZE; + const size_t OUTPUT_LENGTH = mac->OUTPUT_LENGTH; if(OUTPUT_LENGTH < BLOCK_SIZE || !cipher->valid_keylength(OUTPUT_LENGTH) || diff --git a/src/rng/randpool/randpool.h b/src/rng/randpool/randpool.h index 471bb791a..ed224221c 100644 --- a/src/rng/randpool/randpool.h +++ b/src/rng/randpool/randpool.h @@ -21,14 +21,14 @@ namespace Botan { class BOTAN_DLL Randpool : public RandomNumberGenerator { public: - void randomize(byte[], u32bit); + void randomize(byte[], size_t); bool is_seeded() const { return seeded; } void clear(); std::string name() const; - void reseed(u32bit bits_to_collect); + void reseed(size_t bits_to_collect); void add_entropy_source(EntropySource* es); - void add_entropy(const byte input[], u32bit length); + void add_entropy(const byte input[], size_t length); /** * @param cipher a block cipher to use @@ -39,15 +39,15 @@ class BOTAN_DLL Randpool : public RandomNumberGenerator */ Randpool(BlockCipher* cipher, MessageAuthenticationCode* mac, - u32bit pool_blocks = 32, - u32bit iterations_before_reseed = 128); + size_t pool_blocks = 32, + size_t iterations_before_reseed = 128); ~Randpool(); private: void update_buffer(); void mix_pool(); - u32bit ITERATIONS_BEFORE_RESEED, POOL_BLOCKS; + size_t ITERATIONS_BEFORE_RESEED, POOL_BLOCKS; BlockCipher* cipher; MessageAuthenticationCode* mac; diff --git a/src/rng/rng.h b/src/rng/rng.h index e024eeb59..95e1f12cb 100644 --- a/src/rng/rng.h +++ b/src/rng/rng.h @@ -30,9 +30,9 @@ class BOTAN_DLL RandomNumberGenerator * @param output the byte array to hold the random output. * @param length the length of the byte array output. */ - virtual void randomize(byte output[], u32bit length) = 0; + virtual void randomize(byte output[], size_t length) = 0; - SecureVector<byte> random_vec(u32bit bytes) + SecureVector<byte> random_vec(size_t bytes) { SecureVector<byte> output(bytes); randomize(&output[0], output.size()); @@ -66,7 +66,7 @@ class BOTAN_DLL RandomNumberGenerator * @param bits_to_collect is the number of bits of entropy to attempt to gather from the entropy sources */ - virtual void reseed(u32bit bits_to_collect) = 0; + virtual void reseed(size_t bits_to_collect) = 0; /** * Add this entropy source to the RNG object @@ -79,7 +79,7 @@ class BOTAN_DLL RandomNumberGenerator * @param in a byte array containg the entropy to be added * @param length the length of the byte array in */ - virtual void add_entropy(const byte in[], u32bit length) = 0; + virtual void add_entropy(const byte in[], size_t length) = 0; RandomNumberGenerator() {} virtual ~RandomNumberGenerator() {} @@ -95,13 +95,13 @@ class BOTAN_DLL RandomNumberGenerator class BOTAN_DLL Null_RNG : public RandomNumberGenerator { public: - void randomize(byte[], u32bit) { throw PRNG_Unseeded("Null_RNG"); } + void randomize(byte[], size_t) { throw PRNG_Unseeded("Null_RNG"); } void clear() {} std::string name() const { return "Null_RNG"; } - void reseed(u32bit) {} + void reseed(size_t) {} bool is_seeded() const { return false; } - void add_entropy(const byte[], u32bit) {} + void add_entropy(const byte[], size_t) {} void add_entropy_source(EntropySource* es) { delete es; } }; diff --git a/src/rng/x931_rng/x931_rng.cpp b/src/rng/x931_rng/x931_rng.cpp index 1d5e57f6e..6da1e214d 100644 --- a/src/rng/x931_rng/x931_rng.cpp +++ b/src/rng/x931_rng/x931_rng.cpp @@ -14,7 +14,7 @@ namespace Botan { /* * Generate a buffer of random bytes */ -void ANSI_X931_RNG::randomize(byte out[], u32bit length) +void ANSI_X931_RNG::randomize(byte out[], size_t length) { if(!is_seeded()) throw PRNG_Unseeded(name()); @@ -24,7 +24,7 @@ void ANSI_X931_RNG::randomize(byte out[], u32bit length) if(position == R.size()) update_buffer(); - const u32bit copied = std::min<u32bit>(length, R.size() - position); + const size_t copied = std::min<size_t>(length, R.size() - position); copy_mem(out, &R[position], copied); out += copied; @@ -70,7 +70,7 @@ void ANSI_X931_RNG::rekey() /* * Reseed the internal state */ -void ANSI_X931_RNG::reseed(u32bit poll_bits) +void ANSI_X931_RNG::reseed(size_t poll_bits) { prng->reseed(poll_bits); rekey(); @@ -87,7 +87,7 @@ void ANSI_X931_RNG::add_entropy_source(EntropySource* src) /* * Add some entropy to the underlying PRNG */ -void ANSI_X931_RNG::add_entropy(const byte input[], u32bit length) +void ANSI_X931_RNG::add_entropy(const byte input[], size_t length) { prng->add_entropy(input, length); rekey(); diff --git a/src/rng/x931_rng/x931_rng.h b/src/rng/x931_rng/x931_rng.h index 345ee3ca9..41fa9328b 100644 --- a/src/rng/x931_rng/x931_rng.h +++ b/src/rng/x931_rng/x931_rng.h @@ -19,14 +19,14 @@ namespace Botan { class BOTAN_DLL ANSI_X931_RNG : public RandomNumberGenerator { public: - void randomize(byte[], u32bit); + void randomize(byte[], size_t); bool is_seeded() const; void clear(); std::string name() const; - void reseed(u32bit poll_bits); + void reseed(size_t poll_bits); void add_entropy_source(EntropySource*); - void add_entropy(const byte[], u32bit); + void add_entropy(const byte[], size_t); /** * @param cipher the block cipher to use in this PRNG @@ -43,7 +43,7 @@ class BOTAN_DLL ANSI_X931_RNG : public RandomNumberGenerator BlockCipher* cipher; RandomNumberGenerator* prng; SecureVector<byte> V, R; - u32bit position; + size_t position; }; } |