// onetimepad.hpp // Copyright (C) 2006 - 2007 MicroNeil Research Corporation // // This module leverages the Mangler encryption engine to create // cryptographically strong one-time pads and random numbers upon request. // The engine is seeded by /dev/urandom on *nix machines and by CryptGenRandom // on win32 machines. Additionally, each call to get new data introduces a // small amount of entropy based on the jitter in timing between calls and the // amount of time the application has been running since the generator was // started. Additional entropy can be provided by the application or again from // one of the core entropy generators (/dev/urandom or CryptGenRandom). #ifndef onetimepad_included #define onetimepad_included #include #include "mangler.hpp" namespace CodeDweller { typedef std::vector PadBuffer; class OneTimePad { // One Time Pad generator. private: MANGLER PadGenerator; // MANGLER as a PRNG. void addLightweightEntropy(); // Add light weight entropy bits. PadBuffer Entropy(int Length = 1024); // System entropy source. void* fill(void* Object, int Size); // Internal method to fill an object. bool StrongEntropyFlag; // True if strong entropy is used. public: OneTimePad(); // Constructor initializes w/ Entropy. bool isStrong(); // True if strong entropy is available. PadBuffer Pad(int Length); // Get a pad of Length. void addEntropy(); // Add entropy from the system source. void addEntropy(PadBuffer Entropy); // Add entropy from this source. template // Fill any kind of object T& fill(T& Object) { // with random bytes. fill((void*) &Object, sizeof(Object)); // Get a void ptr to it, fill it, return Object; // and return it to the caller. } }; } #endif