aboutsummaryrefslogtreecommitdiffstats
path: root/src/entropy
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-06-17 21:48:55 +0000
committerlloyd <[email protected]>2010-06-17 21:48:55 +0000
commitc06b260b3328c5ce4be44c4f1a88feb55ee3dbc4 (patch)
tree41b05df5982b5b2e8a23b55972263d2172d6a9fd /src/entropy
parent0eecae9f21172c0a74ad62acaf77148c94a25be7 (diff)
parent3dde5683f69b9cb9f558bfb18087ce35fbbec78a (diff)
propagate from branch 'net.randombit.botan' (head 294e2082ce9231d6165276e2f2a4153a0116aca3)
to branch 'net.randombit.botan.c++0x' (head 0b695fad10f924601e07b009fcd781191fafcb28)
Diffstat (limited to 'src/entropy')
-rw-r--r--src/entropy/beos_stats/es_beos.cpp2
-rw-r--r--src/entropy/beos_stats/es_beos.h2
-rw-r--r--src/entropy/dev_random/dev_random.h3
-rw-r--r--src/entropy/egd/es_egd.cpp2
-rw-r--r--src/entropy/egd/es_egd.h2
-rw-r--r--src/entropy/entropy_src.h50
-rw-r--r--src/entropy/hres_timer/hres_timer.h4
-rw-r--r--src/entropy/proc_walk/es_ftw.cpp16
-rw-r--r--src/entropy/proc_walk/es_ftw.h10
-rw-r--r--src/entropy/unix_procs/unix_cmd.cpp10
-rw-r--r--src/entropy/unix_procs/unix_cmd.h6
-rw-r--r--src/entropy/win32_stats/es_win32.cpp2
-rw-r--r--src/entropy/win32_stats/es_win32.h2
13 files changed, 85 insertions, 26 deletions
diff --git a/src/entropy/beos_stats/es_beos.cpp b/src/entropy/beos_stats/es_beos.cpp
index 148d38b9b..2b4a7a24f 100644
--- a/src/entropy/beos_stats/es_beos.cpp
+++ b/src/entropy/beos_stats/es_beos.cpp
@@ -1,4 +1,4 @@
-/**
+/*
* BeOS EntropySource
* (C) 1999-2008 Jack Lloyd
*
diff --git a/src/entropy/beos_stats/es_beos.h b/src/entropy/beos_stats/es_beos.h
index be80ad340..31029a88c 100644
--- a/src/entropy/beos_stats/es_beos.h
+++ b/src/entropy/beos_stats/es_beos.h
@@ -1,4 +1,4 @@
-/**
+/*
* BeOS EntropySource
* (C) 1999-2008 Jack Lloyd
*
diff --git a/src/entropy/dev_random/dev_random.h b/src/entropy/dev_random/dev_random.h
index 3ffe536e3..e20e74300 100644
--- a/src/entropy/dev_random/dev_random.h
+++ b/src/entropy/dev_random/dev_random.h
@@ -14,6 +14,9 @@
namespace Botan {
+/**
+* Entropy source reading from kernel devices like /dev/random
+*/
class Device_EntropySource : public EntropySource
{
public:
diff --git a/src/entropy/egd/es_egd.cpp b/src/entropy/egd/es_egd.cpp
index bd8dc8590..29880a544 100644
--- a/src/entropy/egd/es_egd.cpp
+++ b/src/entropy/egd/es_egd.cpp
@@ -46,7 +46,7 @@ int EGD_EntropySource::EGD_Socket::open_socket(const std::string& path)
if(sizeof(addr.sun_path) < path.length() + 1)
throw std::invalid_argument("EGD socket path is too long");
- std::strcpy(addr.sun_path, path.c_str());
+ std::strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path));
int len = sizeof(addr.sun_family) + std::strlen(addr.sun_path) + 1;
diff --git a/src/entropy/egd/es_egd.h b/src/entropy/egd/es_egd.h
index 1a3618989..defe88a54 100644
--- a/src/entropy/egd/es_egd.h
+++ b/src/entropy/egd/es_egd.h
@@ -1,4 +1,4 @@
-/**
+/*
* EGD EntropySource
* (C) 1999-2007 Jack Lloyd
*
diff --git a/src/entropy/entropy_src.h b/src/entropy/entropy_src.h
index 4d01bce7c..fa61d9ea8 100644
--- a/src/entropy/entropy_src.h
+++ b/src/entropy/entropy_src.h
@@ -1,4 +1,4 @@
-/**
+/*
* EntropySource
* (C) 2008-2009 Jack Lloyd
*
@@ -20,23 +20,40 @@ namespace Botan {
class BOTAN_DLL Entropy_Accumulator
{
public:
+ /**
+ * Initialize an Entropy_Accumulator
+ * @param goal is how many bits we would like to collect
+ */
Entropy_Accumulator(u32bit goal) :
entropy_goal(goal), collected_bits(0) {}
virtual ~Entropy_Accumulator() {}
/**
- @return cached I/O buffer for repeated polls
+ * Get a cached I/O buffer (purely for minimizing allocation
+ * overhead to polls)
+ *
+ * @param size requested size for the I/O buffer
+ * @return cached I/O buffer for repeated polls
*/
MemoryRegion<byte>& get_io_buffer(u32bit 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); }
+ /**
+ * @return if our polling goal has been achieved
+ */
bool polling_goal_achieved() const
{ return (collected_bits >= entropy_goal); }
+ /**
+ * @return how many bits we need to reach our polling goal
+ */
u32bit desired_remaining_bits() const
{
if(collected_bits >= entropy_goal)
@@ -44,12 +61,25 @@ class BOTAN_DLL Entropy_Accumulator
return static_cast<u32bit>(entropy_goal - collected_bits);
}
+ /**
+ * Add entropy to the accumulator
+ * @param bytes the input bytes
+ * @param length specifies how many bytes the input is
+ * @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)
{
add_bytes(reinterpret_cast<const byte*>(bytes), length);
collected_bits += entropy_bits_per_byte * length;
}
+ /**
+ * Add entropy to the accumulator
+ * @param v is some value
+ * @param entropy_bits_per_byte is a best guess at how much
+ * entropy per byte is in this input
+ */
template<typename T>
void add(const T& v, double entropy_bits_per_byte)
{
@@ -63,9 +93,16 @@ class BOTAN_DLL Entropy_Accumulator
double collected_bits;
};
+/**
+* Entropy accumulator that puts the input into a BufferedComputation
+*/
class BOTAN_DLL Entropy_Accumulator_BufferedComputation : public Entropy_Accumulator
{
public:
+ /**
+ * @param sink the hash or MAC we are feeding the poll data into
+ * @param goal is how many bits we want to collect in this poll
+ */
Entropy_Accumulator_BufferedComputation(BufferedComputation& sink,
u32bit goal) :
Entropy_Accumulator(goal), entropy_sink(sink) {}
@@ -85,8 +122,17 @@ class BOTAN_DLL Entropy_Accumulator_BufferedComputation : public Entropy_Accumul
class BOTAN_DLL EntropySource
{
public:
+ /**
+ * @return name identifying this entropy source
+ */
virtual std::string name() const = 0;
+
+ /**
+ * Perform an entropy gathering poll
+ * @param accum is an accumulator object that will be given entropy
+ */
virtual void poll(Entropy_Accumulator& accum) = 0;
+
virtual ~EntropySource() {}
};
diff --git a/src/entropy/hres_timer/hres_timer.h b/src/entropy/hres_timer/hres_timer.h
index a602d5d7b..c693b8d4e 100644
--- a/src/entropy/hres_timer/hres_timer.h
+++ b/src/entropy/hres_timer/hres_timer.h
@@ -12,8 +12,8 @@
namespace Botan {
-/*
-* High Resolution Timestamp Source
+/**
+* Entropy source using high resolution timers
*/
class High_Resolution_Timestamp : public EntropySource
{
diff --git a/src/entropy/proc_walk/es_ftw.cpp b/src/entropy/proc_walk/es_ftw.cpp
index 5e2b17860..53e39d834 100644
--- a/src/entropy/proc_walk/es_ftw.cpp
+++ b/src/entropy/proc_walk/es_ftw.cpp
@@ -22,9 +22,23 @@
namespace Botan {
+/**
+* Returns file descriptors. Until it doesn't
+*/
+class File_Descriptor_Source
+ {
+ public:
+ /**
+ * @return next file descriptor, or -1 if done
+ */
+ virtual int next_fd() = 0;
+
+ virtual ~File_Descriptor_Source() {}
+ };
+
namespace {
-class Directory_Walker : public FTW_EntropySource::File_Descriptor_Source
+class Directory_Walker : public File_Descriptor_Source
{
public:
Directory_Walker(const std::string& root) { add_directory(root); }
diff --git a/src/entropy/proc_walk/es_ftw.h b/src/entropy/proc_walk/es_ftw.h
index d7a719818..3ba222d46 100644
--- a/src/entropy/proc_walk/es_ftw.h
+++ b/src/entropy/proc_walk/es_ftw.h
@@ -24,17 +24,9 @@ class FTW_EntropySource : public EntropySource
FTW_EntropySource(const std::string& root_dir);
~FTW_EntropySource();
-
- class File_Descriptor_Source
- {
- public:
- virtual int next_fd() = 0;
- virtual ~File_Descriptor_Source() {}
- };
private:
-
std::string path;
- File_Descriptor_Source* dir;
+ class File_Descriptor_Source* dir;
};
}
diff --git a/src/entropy/unix_procs/unix_cmd.cpp b/src/entropy/unix_procs/unix_cmd.cpp
index 34e7c314a..c92c84b4c 100644
--- a/src/entropy/unix_procs/unix_cmd.cpp
+++ b/src/entropy/unix_procs/unix_cmd.cpp
@@ -37,6 +37,7 @@ void do_exec(const std::vector<std::string>& arg_list,
{
const std::string full_path = paths[j] + "/" + arg_list[0];
const char* fsname = full_path.c_str();
+
::execl(fsname, fsname, arg1, arg2, arg3, arg4, NULL);
}
}
@@ -50,7 +51,9 @@ struct pipe_wrapper
{
int fd;
pid_t pid;
- pipe_wrapper() { fd = -1; pid = 0; }
+
+ pipe_wrapper(int f, pid_t p) : fd(f), pid(p) {}
+ ~pipe_wrapper() { ::close(fd); }
};
/**
@@ -152,9 +155,7 @@ void DataSource_Command::create_pipe(const std::vector<std::string>& paths)
}
else if(pid > 0)
{
- pipe = new pipe_wrapper;
- pipe->fd = pipe_fd[0];
- pipe->pid = pid;
+ pipe = new pipe_wrapper(pipe_fd[0], pid);
::close(pipe_fd[1]);
}
else
@@ -200,7 +201,6 @@ void DataSource_Command::shutdown_pipe()
}
}
- ::close(pipe->fd);
delete pipe;
pipe = 0;
}
diff --git a/src/entropy/unix_procs/unix_cmd.h b/src/entropy/unix_procs/unix_cmd.h
index 7decf587f..3abca8f37 100644
--- a/src/entropy/unix_procs/unix_cmd.h
+++ b/src/entropy/unix_procs/unix_cmd.h
@@ -1,4 +1,4 @@
-/**
+/*
* Unix Command Execution
* (C) 1999-2007 Jack Lloyd
*
@@ -20,6 +20,10 @@ namespace Botan {
*/
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)
{ name_and_args = n; priority = p; working = true; }
diff --git a/src/entropy/win32_stats/es_win32.cpp b/src/entropy/win32_stats/es_win32.cpp
index e9f564fee..b3d7d27e5 100644
--- a/src/entropy/win32_stats/es_win32.cpp
+++ b/src/entropy/win32_stats/es_win32.cpp
@@ -1,4 +1,4 @@
-/**
+/*
* Win32 EntropySource
* (C) 1999-2009 Jack Lloyd
*
diff --git a/src/entropy/win32_stats/es_win32.h b/src/entropy/win32_stats/es_win32.h
index 0aa9054e3..2e46c773d 100644
--- a/src/entropy/win32_stats/es_win32.h
+++ b/src/entropy/win32_stats/es_win32.h
@@ -1,4 +1,4 @@
-/**
+/*
* Win32 EntropySource
* (C) 1999-2009 Jack Lloyd
*