Переглянути джерело

Moved #include outside of namespace declaration.

Use unsigned int in for-loops.


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@95 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 9 роки тому
джерело
коміт
3fb37aa4bf
1 змінених файлів з 8 додано та 4 видалено
  1. 8
    4
      onetimepad.cpp

+ 8
- 4
onetimepad.cpp Переглянути файл

@@ -4,7 +4,7 @@
#include "onetimepad.hpp"
#include "timing.hpp"

namespace CodeDweller {
using namespace std;

/*
class OneTimePad { // One Time Pad generator.
@@ -31,6 +31,8 @@ class OneTimePad {
#include <windows.h>
#include <wincrypt.h>

namespace CodeDweller {

PadBuffer OneTimePad::Entropy(int Length) { // Get a PadBuffer full of randomness.
PadBuffer Buffer(Length, 0); // Start by initializing the buffer.
HCRYPTPROV provider = 0; // We will need a handle for the source.
@@ -65,6 +67,8 @@ PadBuffer OneTimePad::Entropy(int Length) {

#include <fstream>

namespace CodeDweller {

PadBuffer OneTimePad::Entropy(int Length) { // Get Length bytes of strong entropy.
PadBuffer Buffer(Length, 0); // Initialize a buffer to hold them.
try { // Handle this in a try block.
@@ -107,7 +111,7 @@ void OneTimePad::addLightweightEntropy() {
CombinedFill = CombinedFill ^ LightweightEntropyBuffer; // Pick up some previous state entropy.
unsigned char* PrimerBuffer = (unsigned char*) &CombinedFill; // Treat the value as a bunch of bytes.
unsigned char* EntropyBuffer = (unsigned char*) &LightweightEntropyBuffer; // Likewise with the entropy buffer.
for(int i = 0; i < sizeof(msclock); i++) { // Fold bytes into the mangler one
for(int unsigned i = 0; i < sizeof(msclock); i++) { // Fold bytes into the mangler one
EntropyBuffer[i] += // byte at a time, capturing the
PadGenerator.Encrypt( // the results and using one extra
PadGenerator.Encrypt(PrimerBuffer[i])); // round per byte to increase the
@@ -116,7 +120,7 @@ void OneTimePad::addLightweightEntropy() {

void OneTimePad::addEntropy() { // Add strong entropy if available.
PadBuffer Fill = Entropy(); // Grab the entropy bits to add.
for(int i = 0; i < Fill.size(); i++) { // Pump them in one byte at a
for(int unsigned i = 0; i < Fill.size(); i++) { // Pump them in one byte at a
PadGenerator.Encrypt( // time and then run an extra
PadGenerator.Encrypt(Fill.at(i))); // round per byte to increase the
} // amount of guessing an attacker
@@ -124,7 +128,7 @@ void OneTimePad::addEntropy() {

void OneTimePad::addEntropy(PadBuffer Entropy) { // Add entropy from a given source.
addLightweightEntropy(); // Start with some lightweight entropy.
for(int i = 0; i < Entropy.size(); i++) { // Then loop through the provided
for(int unsigned i = 0; i < Entropy.size(); i++) { // Then loop through the provided
PadGenerator.Encrypt( // entropy and mix it in with one
PadGenerator.Encrypt(Entropy.at(i))); // extra round per byte to increase
} // the amount of guessing an attacker

Завантаження…
Відмінити
Зберегти