Browse Source

Initialized OneTimePad as per instructions from Pete. Reason: Using an

uninitialized variable gave many valgrind errors.


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@101 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 9 years ago
parent
commit
c112f9db62
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      onetimepad.cpp

+ 7
- 2
onetimepad.cpp View File

// onetimepad.cpp // onetimepad.cpp
// Copyright (C) 2006-2007 MicroNeil Research Corporation // Copyright (C) 2006-2007 MicroNeil Research Corporation


#include <cstdlib>
#include <ctime>

#include "onetimepad.hpp" #include "onetimepad.hpp"
#include "timing.hpp" #include "timing.hpp"


PadBuffer OneTimePad::Pad(int Length) { // Grab a pad of a specific length. PadBuffer OneTimePad::Pad(int Length) { // Grab a pad of a specific length.
addLightweightEntropy(); // Add some lightweight entropy. addLightweightEntropy(); // Add some lightweight entropy.
PadBuffer Output; Output.reserve(Length); // Create a buffer the right size. 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 for(int i = 0; i < Length; i++) // char, fill the buffer with
Output.push_back(x = PadGenerator.Encrypt(x)); // random bytes from the mangler. Output.push_back(x = PadGenerator.Encrypt(x)); // random bytes from the mangler.
return Output; // Return the new pad. return Output; // Return the new pad.
OneTimePad::OneTimePad() { // Initialize the one time pad. OneTimePad::OneTimePad() { // Initialize the one time pad.
addLightweightEntropy(); // Add lightweight entropy. addLightweightEntropy(); // Add lightweight entropy.
addEntropy(); // Add cryptographic 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 for(int i = 0; i < 1024; i++) { // character, run 1024 rounds to
x = PadGenerator.Encrypt(x); // reduce the predictability of the x = PadGenerator.Encrypt(x); // reduce the predictability of the
} // initial Mangler state. } // initial Mangler state.

Loading…
Cancel
Save