瀏覽代碼

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 年之前
父節點
當前提交
c112f9db62
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7
    2
      onetimepad.cpp

+ 7
- 2
onetimepad.cpp 查看文件

@@ -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.

Loading…
取消
儲存