|
|
@@ -1,6 +1,9 @@ |
|
|
|
// onetimepad.cpp |
|
|
|
// Copyright (C) 2006-2007 MicroNeil Research Corporation |
|
|
|
|
|
|
|
#include <cstdlib> |
|
|
|
#include <ctime> |
|
|
|
|
|
|
|
#include "onetimepad.hpp" |
|
|
|
#include "timing.hpp" |
|
|
|
|
|
|
@@ -137,7 +140,8 @@ void OneTimePad::addEntropy(PadBuffer Entropy) { |
|
|
|
PadBuffer OneTimePad::Pad(int Length) { // Grab a pad of a specific length. |
|
|
|
addLightweightEntropy(); // Add some lightweight entropy. |
|
|
|
PadBuffer Output; Output.reserve(Length); // Create a buffer the right size. |
|
|
|
unsigned char x; // Starting with an uninitialized |
|
|
|
srand(clock() + rand()); // Mix things up a tiny bit. |
|
|
|
unsigned char x = rand() % 256; // Starting with slightly random |
|
|
|
for(int i = 0; i < Length; i++) // char, fill the buffer with |
|
|
|
Output.push_back(x = PadGenerator.Encrypt(x)); // random bytes from the mangler. |
|
|
|
return Output; // Return the new pad. |
|
|
@@ -155,7 +159,8 @@ bool OneTimePad::isStrong() { return StrongEntropyFlag; } |
|
|
|
OneTimePad::OneTimePad() { // Initialize the one time pad. |
|
|
|
addLightweightEntropy(); // Add lightweight entropy. |
|
|
|
addEntropy(); // Add cryptographic entropy. |
|
|
|
unsigned char x; // Starting with an uninitialized |
|
|
|
srand(clock() + rand()); // Mix things up a tiny bit. |
|
|
|
unsigned char x = rand() % 256; // Starting with slightly random |
|
|
|
for(int i = 0; i < 1024; i++) { // character, run 1024 rounds to |
|
|
|
x = PadGenerator.Encrypt(x); // reduce the predictability of the |
|
|
|
} // initial Mangler state. |