aboutsummaryrefslogtreecommitdiffstats
path: root/src/entropy/beos_stats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-01-27 00:16:49 +0000
committerlloyd <[email protected]>2009-01-27 00:16:49 +0000
commitc055f425107cf20c1b8b7c692d5133509dfad52e (patch)
treeea86b2f84a126ec253c1c487aaf46522a37d7019 /src/entropy/beos_stats
parent59471d5ad33fc136e0f2c02c9400f50e1515e904 (diff)
Check in a branch with a major redesign on how entropy polling is performed.
Combine the fast and slow polls, into a single poll() operation. Instead of being given a buffer to write output into, the EntropySource is passed an Entropy_Accumulator. This handles the RLE encoding that xor_into_buf used to do. It also contains a cached I/O buffer so entropy sources do not individually need to allocate memory for that with each poll. When data is added to the accumulator, the source specifies an estimate of the number of bits of entropy per byte, as a double. This is tracked in the accumulator. Once the estimated entropy hits a target (set by the constructor), the accumulator's member function predicate polling_goal_achieved flips to true. This signals to the PRNG that it can stop performing polling on sources, also polls that take a long time periodically check this flag and return immediately. The Win32 and BeOS entropy sources have been updated, but blindly; testing is needed. The test_es example program has been modified: now it polls twice and outputs the XOR of the two collected results. That helps show if the output is consistent across polls (not a good thing). I have noticed on the Unix entropy source, occasionally there are many 0x00 bytes in the output, which is not optimal. This also needs to be investigated. The RLE is not actually RLE anymore. It works well for non-random inputs (ASCII text, etc), but I noticed that when /dev/random output was fed into it, the output buffer would end up being RR01RR01RR01 where RR is a random byte and 00 is the byte count. The buffer sizing also needs to be examined carefully. It might be useful to choose a prime number for the size to XOR stuff into, to help ensure an even distribution of entropy across the entire buffer space. Or: feed it all into a hash function? This change should (perhaps with further modifications) help WRT the concerns Zack W raised about the RNG on the monotone-dev list.
Diffstat (limited to 'src/entropy/beos_stats')
-rw-r--r--src/entropy/beos_stats/es_beos.cpp43
-rw-r--r--src/entropy/beos_stats/es_beos.h3
2 files changed, 12 insertions, 34 deletions
diff --git a/src/entropy/beos_stats/es_beos.cpp b/src/entropy/beos_stats/es_beos.cpp
index b5a5e7fee..d7c0c6cd6 100644
--- a/src/entropy/beos_stats/es_beos.cpp
+++ b/src/entropy/beos_stats/es_beos.cpp
@@ -4,7 +4,6 @@
*/
#include <botan/es_beos.h>
-#include <botan/xor_buf.h>
#include <kernel/OS.h>
#include <kernel/image.h>
@@ -13,69 +12,49 @@
namespace Botan {
/**
-* BeOS Fast Poll
+* BeOS entropy poll
*/
-u32bit BeOS_EntropySource::fast_poll(byte buf[], u32bit length)
+void BeOS_EntropySource::poll(Entropy_Accumulator& accum)
{
- if(length == 0)
- return 0;
- length = std::min<u32bit>(length, 32);
-
- u32bit buf_i = 0;
-
system_info info_sys;
get_system_info(&info_sys);
- buf_i = xor_into_buf(buf, buf_i, length, info_sys);
+ accum.add(info_sys, 2);
- key_info info_key;
+ key_info info_key; // current state of the keyboard
get_key_info(&info_key);
- buf_i = xor_into_buf(buf, buf_i, length, key_info);
+ accum.add(info_key, 0);
- buf_i = xor_into_buf(buf, buf_i, length, idle_time());
+ accum.add(idle_time(), 0);
- return length;
- }
-
-/**
-* BeOS slow poll
-*/
-u32bit BeOS_EntropySource::slow_poll(byte buf[], u32bit length)
- {
- if(length == 0)
- return 0;
-
- u32bit buf_i = 0;
team_info info_team;
int32 cookie_team = 0;
while(get_next_team_info(&cookie_team, &info_team) == B_OK)
{
- buf_i = xor_into_buf(buf, buf_i, length, info_team);
+ accum.add(info_team, 2);
team_id id = info_team.team;
int32 cookie = 0;
thread_info info_thr;
while(get_next_thread_info(id, &cookie, &info_thr) == B_OK)
- buf_i = xor_into_buf(buf, buf_i, length, info_thr);
+ accum.add(info_thr, 1);
cookie = 0;
image_info info_img;
while(get_next_image_info(id, &cookie, &info_img) == B_OK)
- buf_i = xor_into_buf(buf, buf_i, length, info_img);
+ accum.add(info_img, 1);
cookie = 0;
sem_info info_sem;
while(get_next_sem_info(id, &cookie, &info_sem) == B_OK)
- buf_i = xor_into_buf(buf, buf_i, length, info_sem);
+ accum.add(info_sem, 1);
cookie = 0;
area_info info_area;
while(get_next_area_info(id, &cookie, &info_area) == B_OK)
- buf_i = xor_into_buf(buf, buf_i, length, info_area);
+ accum.add(info_area, 2);
}
-
- return length;
}
}
diff --git a/src/entropy/beos_stats/es_beos.h b/src/entropy/beos_stats/es_beos.h
index 686ac5c38..0ae670e94 100644
--- a/src/entropy/beos_stats/es_beos.h
+++ b/src/entropy/beos_stats/es_beos.h
@@ -18,8 +18,7 @@ class BOTAN_DLL BeOS_EntropySource : public EntropySource
private:
std::string name() const { return "BeOS Statistics"; }
- u32bit fast_poll(byte buf[], u32bit length);
- u32bit slow_poll(byte buf[], u32bit length);
+ void poll(Entropy_Accumulator& accum);
};
}