Implemented initialization vector
This commit is contained in:
parent
4064483cad
commit
40a6b0c4ea
@ -2,6 +2,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <GhettoCryptWrapper.h>
|
#include <GhettoCryptWrapper.h>
|
||||||
#include <SecureBitset.h>
|
#include <SecureBitset.h>
|
||||||
|
#include <Util.h>
|
||||||
|
#include <InitializationVector.h>
|
||||||
|
|
||||||
using namespace GhettoCipher;
|
using namespace GhettoCipher;
|
||||||
|
|
||||||
@ -39,7 +41,7 @@ void ExampleFiles()
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
ExampleString();
|
//ExampleString();
|
||||||
//ExampleFiles();
|
//ExampleFiles();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace GhettoCipher
|
namespace GhettoCipher
|
||||||
{
|
{
|
||||||
|
29
GhettoCrypt/InitializationVector.cpp
Normal file
29
GhettoCrypt/InitializationVector.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "InitializationVector.h"
|
||||||
|
#include <random>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace GhettoCipher;
|
||||||
|
|
||||||
|
InitializationVector::InitializationVector(const Block& seed)
|
||||||
|
{
|
||||||
|
// Since an initialization vector does not have to be a secret,
|
||||||
|
// we should be fine just using a mersenne twister seeded with
|
||||||
|
// for example the key to fill it up to fit BLOCK_SIZE.
|
||||||
|
|
||||||
|
// Loosely seed mersenne twister with seed
|
||||||
|
// Here is nothing copied. Both Block::Get, and Hash<>::operator() take refs.
|
||||||
|
std::mt19937 mt = std::mt19937(std::hash<std::bitset<BLOCK_SIZE>>()(seed.Get()));
|
||||||
|
|
||||||
|
// Now generate BLOCK_SIZE urandom bits
|
||||||
|
std::stringstream ss;
|
||||||
|
for (std::size_t i = 0; i < BLOCK_SIZE; i++)
|
||||||
|
ss << (mt() % 2 ? '1' : '0');
|
||||||
|
|
||||||
|
// And create a bitset
|
||||||
|
iv = Block(ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
InitializationVector::operator GhettoCipher::Block() const
|
||||||
|
{
|
||||||
|
return iv;
|
||||||
|
}
|
16
GhettoCrypt/InitializationVector.h
Normal file
16
GhettoCrypt/InitializationVector.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Block.h"
|
||||||
|
|
||||||
|
/** Will create a sudo-random Block based on a seed
|
||||||
|
*/
|
||||||
|
class InitializationVector
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InitializationVector(const GhettoCipher::Block& seed);
|
||||||
|
|
||||||
|
operator GhettoCipher::Block() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GhettoCipher::Block iv;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user