diff options
author | lloyd <[email protected]> | 2010-10-12 20:23:47 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-12 20:23:47 +0000 |
commit | 6385602fcccfd9c561b1c097095ddd2edf1a2357 (patch) | |
tree | 63374ebafd20b09ff4ad77d624a4b27c87b1062c /src/entropy | |
parent | ab1f661083053df745daf1e1b8f4859f5a92065d (diff) |
Use size_t instead of u32bit in entropy and rng
Diffstat (limited to 'src/entropy')
-rw-r--r-- | src/entropy/cryptoapi_rng/es_capi.cpp | 18 | ||||
-rw-r--r-- | src/entropy/dev_random/dev_random.cpp | 14 | ||||
-rw-r--r-- | src/entropy/dev_random/dev_random.h | 2 | ||||
-rw-r--r-- | src/entropy/egd/es_egd.cpp | 10 | ||||
-rw-r--r-- | src/entropy/egd/es_egd.h | 2 | ||||
-rw-r--r-- | src/entropy/entropy_src.h | 22 | ||||
-rw-r--r-- | src/entropy/hres_timer/hres_timer.cpp | 4 | ||||
-rw-r--r-- | src/entropy/proc_walk/es_ftw.cpp | 4 | ||||
-rw-r--r-- | src/entropy/unix_procs/es_unix.cpp | 18 | ||||
-rw-r--r-- | src/entropy/unix_procs/es_unix.h | 2 | ||||
-rw-r--r-- | src/entropy/unix_procs/unix_cmd.h | 6 | ||||
-rw-r--r-- | src/entropy/win32_stats/es_win32.cpp | 8 |
12 files changed, 55 insertions, 55 deletions
diff --git a/src/entropy/cryptoapi_rng/es_capi.cpp b/src/entropy/cryptoapi_rng/es_capi.cpp index f3a94ad34..1de76dabb 100644 --- a/src/entropy/cryptoapi_rng/es_capi.cpp +++ b/src/entropy/cryptoapi_rng/es_capi.cpp @@ -33,7 +33,7 @@ class CSP_Handle CryptReleaseContext(handle, 0); } - u32bit gen_random(byte out[], u32bit n) const + size_t gen_random(byte out[], size_t n) const { if(is_valid() && CryptGenRandom(handle, n, out)) return n; @@ -57,11 +57,11 @@ void Win32_CAPI_EntropySource::poll(Entropy_Accumulator& accum) { MemoryRegion<byte>& io_buffer = accum.get_io_buffer(32); - for(u32bit j = 0; j != prov_types.size(); ++j) + for(size_t i = 0; i != prov_types.size(); ++i) { - CSP_Handle csp(prov_types[j]); + CSP_Handle csp(prov_types[i]); - u32bit got = csp.gen_random(&io_buffer[0], io_buffer.size()); + size_t got = csp.gen_random(&io_buffer[0], io_buffer.size()); if(got) { @@ -78,12 +78,12 @@ Win32_CAPI_EntropySource::Win32_CAPI_EntropySource(const std::string& provs) { std::vector<std::string> capi_provs = split_on(provs, ':'); - for(u32bit j = 0; j != capi_provs.size(); ++j) + for(size_t i = 0; i != capi_provs.size(); ++i) { - if(capi_provs[j] == "RSA_FULL") prov_types.push_back(PROV_RSA_FULL); - if(capi_provs[j] == "INTEL_SEC") prov_types.push_back(PROV_INTEL_SEC); - if(capi_provs[j] == "FORTEZZA") prov_types.push_back(PROV_FORTEZZA); - if(capi_provs[j] == "RNG") prov_types.push_back(PROV_RNG); + if(capi_provs[i] == "RSA_FULL") prov_types.push_back(PROV_RSA_FULL); + if(capi_provs[i] == "INTEL_SEC") prov_types.push_back(PROV_INTEL_SEC); + if(capi_provs[i] == "FORTEZZA") prov_types.push_back(PROV_FORTEZZA); + if(capi_provs[i] == "RNG") prov_types.push_back(PROV_RNG); } if(prov_types.size() == 0) diff --git a/src/entropy/dev_random/dev_random.cpp b/src/entropy/dev_random/dev_random.cpp index a942806d0..b15240aba 100644 --- a/src/entropy/dev_random/dev_random.cpp +++ b/src/entropy/dev_random/dev_random.cpp @@ -26,8 +26,8 @@ void Device_EntropySource::Device_Reader::close() /** Read bytes from a device file */ -u32bit Device_EntropySource::Device_Reader::get(byte out[], u32bit length, - u32bit ms_wait_time) +size_t Device_EntropySource::Device_Reader::get(byte out[], size_t length, + size_t ms_wait_time) { if(fd < 0) return 0; @@ -54,7 +54,7 @@ u32bit Device_EntropySource::Device_Reader::get(byte out[], u32bit length, if(got <= 0) return 0; - return static_cast<u32bit>(got); + return static_cast<size_t>(got); } /** @@ -82,7 +82,7 @@ Open a file descriptor to each (available) device in fsnames Device_EntropySource::Device_EntropySource( const std::vector<std::string>& fsnames) { - for(u32bit i = 0; i != fsnames.size(); ++i) + for(size_t i = 0; i != fsnames.size(); ++i) { Device_Reader::fd_type fd = Device_Reader::open(fsnames[i]); if(fd > 0) @@ -104,14 +104,14 @@ Device_EntropySource::~Device_EntropySource() */ void Device_EntropySource::poll(Entropy_Accumulator& accum) { - u32bit go_get = std::min<u32bit>(accum.desired_remaining_bits() / 8, 48); + size_t go_get = std::min<size_t>(accum.desired_remaining_bits() / 8, 48); - u32bit read_wait_ms = std::max<u32bit>(go_get, 1000); + size_t read_wait_ms = std::max<size_t>(go_get, 1000); MemoryRegion<byte>& io_buffer = accum.get_io_buffer(go_get); for(size_t i = 0; i != devices.size(); ++i) { - u32bit got = devices[i].get(&io_buffer[0], io_buffer.size(), + size_t got = devices[i].get(&io_buffer[0], io_buffer.size(), read_wait_ms); if(got) diff --git a/src/entropy/dev_random/dev_random.h b/src/entropy/dev_random/dev_random.h index e20e74300..171adcc76 100644 --- a/src/entropy/dev_random/dev_random.h +++ b/src/entropy/dev_random/dev_random.h @@ -41,7 +41,7 @@ class Device_EntropySource : public EntropySource void close(); - u32bit get(byte out[], u32bit length, u32bit ms_wait_time); + size_t get(byte out[], size_t length, size_t ms_wait_time); static fd_type open(const std::string& pathname); private: diff --git a/src/entropy/egd/es_egd.cpp b/src/entropy/egd/es_egd.cpp index 7efcf204d..d2ce2706b 100644 --- a/src/entropy/egd/es_egd.cpp +++ b/src/entropy/egd/es_egd.cpp @@ -63,7 +63,7 @@ int EGD_EntropySource::EGD_Socket::open_socket(const std::string& path) /** * Attempt to read entropy from EGD */ -u32bit EGD_EntropySource::EGD_Socket::read(byte outbuf[], u32bit length) +size_t EGD_EntropySource::EGD_Socket::read(byte outbuf[], size_t length) { if(length == 0) return 0; @@ -79,7 +79,7 @@ u32bit EGD_EntropySource::EGD_Socket::read(byte outbuf[], u32bit length) { // 1 == EGD command for non-blocking read byte egd_read_command[2] = { - 1, static_cast<byte>(std::min<u32bit>(length, 255)) }; + 1, static_cast<byte>(std::min<size_t>(length, 255)) }; if(::write(m_fd, egd_read_command, 2) != 2) throw std::runtime_error("Writing entropy read command to EGD failed"); @@ -96,7 +96,7 @@ u32bit EGD_EntropySource::EGD_Socket::read(byte outbuf[], u32bit length) if(count != out_len) throw std::runtime_error("Reading entropy result from EGD failed"); - return static_cast<u32bit>(count); + return static_cast<size_t>(count); } catch(std::exception) { @@ -137,13 +137,13 @@ EGD_EntropySource::~EGD_EntropySource() */ void EGD_EntropySource::poll(Entropy_Accumulator& accum) { - u32bit go_get = std::min<u32bit>(accum.desired_remaining_bits() / 8, 32); + size_t go_get = std::min<size_t>(accum.desired_remaining_bits() / 8, 32); MemoryRegion<byte>& io_buffer = accum.get_io_buffer(go_get); for(size_t i = 0; i != sockets.size(); ++i) { - u32bit got = sockets[i].read(&io_buffer[0], io_buffer.size()); + size_t got = sockets[i].read(&io_buffer[0], io_buffer.size()); if(got) { diff --git a/src/entropy/egd/es_egd.h b/src/entropy/egd/es_egd.h index defe88a54..02c52b9a3 100644 --- a/src/entropy/egd/es_egd.h +++ b/src/entropy/egd/es_egd.h @@ -33,7 +33,7 @@ class EGD_EntropySource : public EntropySource EGD_Socket(const std::string& path); void close(); - u32bit read(byte outbuf[], u32bit length); + size_t read(byte outbuf[], size_t length); private: static int open_socket(const std::string& path); diff --git a/src/entropy/entropy_src.h b/src/entropy/entropy_src.h index fa61d9ea8..97ebe8bd9 100644 --- a/src/entropy/entropy_src.h +++ b/src/entropy/entropy_src.h @@ -24,7 +24,7 @@ class BOTAN_DLL Entropy_Accumulator * Initialize an Entropy_Accumulator * @param goal is how many bits we would like to collect */ - Entropy_Accumulator(u32bit goal) : + Entropy_Accumulator(size_t goal) : entropy_goal(goal), collected_bits(0) {} virtual ~Entropy_Accumulator() {} @@ -36,14 +36,14 @@ class BOTAN_DLL Entropy_Accumulator * @param size requested size for the I/O buffer * @return cached I/O buffer for repeated polls */ - MemoryRegion<byte>& get_io_buffer(u32bit size) + MemoryRegion<byte>& get_io_buffer(size_t size) { io_buffer.resize(size); return io_buffer; } /** * @return number of bits collected so far */ - u32bit bits_collected() const - { return static_cast<u32bit>(collected_bits); } + size_t bits_collected() const + { return static_cast<size_t>(collected_bits); } /** * @return if our polling goal has been achieved @@ -54,11 +54,11 @@ class BOTAN_DLL Entropy_Accumulator /** * @return how many bits we need to reach our polling goal */ - u32bit desired_remaining_bits() const + size_t desired_remaining_bits() const { if(collected_bits >= entropy_goal) return 0; - return static_cast<u32bit>(entropy_goal - collected_bits); + return static_cast<size_t>(entropy_goal - collected_bits); } /** @@ -68,7 +68,7 @@ class BOTAN_DLL Entropy_Accumulator * @param entropy_bits_per_byte is a best guess at how much * entropy per byte is in this input */ - void add(const void* bytes, u32bit length, double entropy_bits_per_byte) + void add(const void* bytes, size_t length, double entropy_bits_per_byte) { add_bytes(reinterpret_cast<const byte*>(bytes), length); collected_bits += entropy_bits_per_byte * length; @@ -86,10 +86,10 @@ class BOTAN_DLL Entropy_Accumulator add(&v, sizeof(T), entropy_bits_per_byte); } private: - virtual void add_bytes(const byte bytes[], u32bit length) = 0; + virtual void add_bytes(const byte bytes[], size_t length) = 0; SecureVector<byte> io_buffer; - u32bit entropy_goal; + size_t entropy_goal; double collected_bits; }; @@ -104,11 +104,11 @@ class BOTAN_DLL Entropy_Accumulator_BufferedComputation : public Entropy_Accumul * @param goal is how many bits we want to collect in this poll */ Entropy_Accumulator_BufferedComputation(BufferedComputation& sink, - u32bit goal) : + size_t goal) : Entropy_Accumulator(goal), entropy_sink(sink) {} private: - virtual void add_bytes(const byte bytes[], u32bit length) + virtual void add_bytes(const byte bytes[], size_t length) { entropy_sink.update(bytes, length); } diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp index e1b4928df..b0bbf6fa7 100644 --- a/src/entropy/hres_timer/hres_timer.cpp +++ b/src/entropy/hres_timer/hres_timer.cpp @@ -34,13 +34,13 @@ void High_Resolution_Timestamp::poll(Entropy_Accumulator& accum) #if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) if(CPUID::has_rdtsc()) // not availble on all x86 CPUs { - u32bit rtc_low = 0, rtc_high = 0; + size_t rtc_low = 0, rtc_high = 0; asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low)); rtc = (static_cast<u64bit>(rtc_high) << 32) | rtc_low; } #elif defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY) - u32bit rtc_low = 0, rtc_high = 0; + size_t rtc_low = 0, rtc_high = 0; asm volatile("mftbu %0; mftb %1" : "=r" (rtc_high), "=r" (rtc_low)); rtc = (static_cast<u64bit>(rtc_high) << 32) | rtc_low; diff --git a/src/entropy/proc_walk/es_ftw.cpp b/src/entropy/proc_walk/es_ftw.cpp index ce359f03f..5d58f9869 100644 --- a/src/entropy/proc_walk/es_ftw.cpp +++ b/src/entropy/proc_walk/es_ftw.cpp @@ -127,14 +127,14 @@ FTW_EntropySource::~FTW_EntropySource() void FTW_EntropySource::poll(Entropy_Accumulator& accum) { - const u32bit MAX_FILES_READ_PER_POLL = 1024; + const size_t MAX_FILES_READ_PER_POLL = 1024; if(!dir) dir = new Directory_Walker(path); MemoryRegion<byte>& io_buffer = accum.get_io_buffer(128); - for(u32bit i = 0; i != MAX_FILES_READ_PER_POLL; ++i) + for(size_t i = 0; i != MAX_FILES_READ_PER_POLL; ++i) { int fd = dir->next_fd(); diff --git a/src/entropy/unix_procs/es_unix.cpp b/src/entropy/unix_procs/es_unix.cpp index b96b740e9..b989e0213 100644 --- a/src/entropy/unix_procs/es_unix.cpp +++ b/src/entropy/unix_procs/es_unix.cpp @@ -45,7 +45,7 @@ Unix_EntropySource::Unix_EntropySource(const std::vector<std::string>& path) : /** * Add sources to the list */ -void Unix_EntropySource::add_sources(const Unix_Program srcs[], u32bit count) +void Unix_EntropySource::add_sources(const Unix_Program srcs[], size_t count) { sources.insert(sources.end(), srcs, srcs + count); std::sort(sources.begin(), sources.end(), Unix_Program_Cmp); @@ -70,11 +70,11 @@ void Unix_EntropySource::poll(Entropy_Accumulator& accum) "..", 0 }; - for(u32bit j = 0; stat_targets[j]; j++) + for(size_t i = 0; stat_targets[i]; i++) { struct stat statbuf; clear_mem(&statbuf, 1); - ::stat(stat_targets[j], &statbuf); + ::stat(stat_targets[i], &statbuf); accum.add(&statbuf, sizeof(statbuf), .005); } @@ -91,25 +91,25 @@ void Unix_EntropySource::poll(Entropy_Accumulator& accum) ::getrusage(RUSAGE_CHILDREN, &usage); accum.add(usage, .005); - const u32bit MINIMAL_WORKING = 16; + const size_t MINIMAL_WORKING = 16; MemoryRegion<byte>& io_buffer = accum.get_io_buffer(DEFAULT_BUFFERSIZE); - for(u32bit j = 0; j != sources.size(); j++) + for(size_t i = 0; i != sources.size(); i++) { - DataSource_Command pipe(sources[j].name_and_args, PATH); + DataSource_Command pipe(sources[i].name_and_args, PATH); - u32bit got_from_src = 0; + size_t got_from_src = 0; while(!pipe.end_of_data()) { - u32bit got_this_loop = pipe.read(&io_buffer[0], io_buffer.size()); + size_t got_this_loop = pipe.read(&io_buffer[0], io_buffer.size()); got_from_src += got_this_loop; accum.add(&io_buffer[0], got_this_loop, .005); } - sources[j].working = (got_from_src >= MINIMAL_WORKING) ? true : false; + sources[i].working = (got_from_src >= MINIMAL_WORKING) ? true : false; if(accum.polling_goal_achieved()) break; diff --git a/src/entropy/unix_procs/es_unix.h b/src/entropy/unix_procs/es_unix.h index 415cce9fe..9c217ebe7 100644 --- a/src/entropy/unix_procs/es_unix.h +++ b/src/entropy/unix_procs/es_unix.h @@ -24,7 +24,7 @@ class Unix_EntropySource : public EntropySource void poll(Entropy_Accumulator& accum); - void add_sources(const Unix_Program[], u32bit); + void add_sources(const Unix_Program[], size_t); Unix_EntropySource(const std::vector<std::string>& path); private: static std::vector<Unix_Program> get_default_sources(); diff --git a/src/entropy/unix_procs/unix_cmd.h b/src/entropy/unix_procs/unix_cmd.h index a4ad0c180..5185c1c8f 100644 --- a/src/entropy/unix_procs/unix_cmd.h +++ b/src/entropy/unix_procs/unix_cmd.h @@ -24,7 +24,7 @@ struct Unix_Program * @param n is the name and arguments of what we are going run * @param p is the priority level (lower prio numbers get polled first) */ - Unix_Program(const char* n, u32bit p) + Unix_Program(const char* n, size_t p) { name_and_args = n; priority = p; working = true; } /** @@ -35,7 +35,7 @@ struct Unix_Program /** * Priority: we scan from low to high */ - u32bit priority; + size_t priority; /** * Does this source seem to be working? @@ -63,7 +63,7 @@ class DataSource_Command : public DataSource void create_pipe(const std::vector<std::string>&); void shutdown_pipe(); - const u32bit MAX_BLOCK_USECS, KILL_WAIT; + const size_t MAX_BLOCK_USECS, KILL_WAIT; std::vector<std::string> arg_list; struct pipe_wrapper* pipe; diff --git a/src/entropy/win32_stats/es_win32.cpp b/src/entropy/win32_stats/es_win32.cpp index b3d7d27e5..fff11592d 100644 --- a/src/entropy/win32_stats/es_win32.cpp +++ b/src/entropy/win32_stats/es_win32.cpp @@ -75,12 +75,12 @@ void Win32_EntropySource::poll(Entropy_Accumulator& accum) if(!accum.polling_goal_achieved()) { - u32bit heap_lists_found = 0; + size_t heap_lists_found = 0; HEAPLIST32 heap_list; heap_list.dwSize = sizeof(HEAPLIST32); - const u32bit HEAP_LISTS_MAX = 32; - const u32bit HEAP_OBJS_PER_LIST = 128; + const size_t HEAP_LISTS_MAX = 32; + const size_t HEAP_OBJS_PER_LIST = 128; if(Heap32ListFirst(snapshot, &heap_list)) { @@ -91,7 +91,7 @@ void Win32_EntropySource::poll(Entropy_Accumulator& accum) if(++heap_lists_found > HEAP_LISTS_MAX) break; - u32bit heap_objs_found = 0; + size_t heap_objs_found = 0; HEAPENTRY32 heap_entry; heap_entry.dwSize = sizeof(HEAPENTRY32); if(Heap32First(&heap_entry, heap_list.th32ProcessID, |