Made the whole thing MUCH more secure, by adding an IV (initialization vector), implemeted RRKM (rolling round key mode) and redone key extrapolation

This commit is contained in:
Leonetienne
2022-02-06 21:54:43 +01:00
parent e57456e9ae
commit 8678d3cb1b
18 changed files with 427 additions and 65 deletions

View File

@@ -2,9 +2,18 @@
#include <random>
#include <sstream>
using namespace GhettoCipher;
// It would be REALLY BAD if another compiler/*version would use
// a mersenne twister with different attrbitutes. It would basically mean
// that E_machine1(M,K) != E_machine2(M,K), which would make them incompatible.
// We do NOT want this to happen, so let's be VERY specific about what mersenne twister setup we want.
// This is std::mt19937, as of msvc stl.
using Prng_MT = std::mersenne_twister_engine<
unsigned int,
32, 624, 397, 31, 0x9908b0df, 11, 0xffffffff,
7, 0x9d2c5680, 15,0xefc60000, 18, 1812433253
>;
InitializationVector::InitializationVector(const Block& seed)
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
@@ -12,8 +21,7 @@ InitializationVector::InitializationVector(const Block& seed)
// 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()));
Prng_MT mt = Prng_MT(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++)
@@ -23,7 +31,7 @@ InitializationVector::InitializationVector(const Block& seed)
iv = Block(ss.str());
}
InitializationVector::operator GhettoCipher::Block() const
GhettoCipher::InitializationVector::operator GhettoCipher::Block() const
{
return iv;
}