Browse Source

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 years ago
parent
commit
3fb37aa4bf
1 changed files with 8 additions and 4 deletions
  1. 8
    4
      onetimepad.cpp

+ 8
- 4
onetimepad.cpp View File

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


namespace CodeDweller {
using namespace std;


/* /*
class OneTimePad { // One Time Pad generator. class OneTimePad { // One Time Pad generator.
#include <windows.h> #include <windows.h>
#include <wincrypt.h> #include <wincrypt.h>


namespace CodeDweller {

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


#include <fstream> #include <fstream>


namespace CodeDweller {

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


void OneTimePad::addEntropy() { // Add strong entropy if available. void OneTimePad::addEntropy() { // Add strong entropy if available.
PadBuffer Fill = Entropy(); // Grab the entropy bits to add. 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( // time and then run an extra
PadGenerator.Encrypt(Fill.at(i))); // round per byte to increase the PadGenerator.Encrypt(Fill.at(i))); // round per byte to increase the
} // amount of guessing an attacker } // amount of guessing an attacker


void OneTimePad::addEntropy(PadBuffer Entropy) { // Add entropy from a given source. void OneTimePad::addEntropy(PadBuffer Entropy) { // Add entropy from a given source.
addLightweightEntropy(); // Start with some lightweight entropy. 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 and mix it in with one
PadGenerator.Encrypt(Entropy.at(i))); // extra round per byte to increase PadGenerator.Encrypt(Entropy.at(i))); // extra round per byte to increase
} // the amount of guessing an attacker } // the amount of guessing an attacker

Loading…
Cancel
Save