Fixed issue that caused identical (m,k) to cause different ciphertexts on different platforms

This commit is contained in:
Leonetienne 2022-02-06 22:58:53 +01:00
parent c621357097
commit 730e2b00e0
5 changed files with 8 additions and 30 deletions

View File

@ -12,7 +12,7 @@ void ExampleString()
std::cout << "Example on how to encrypt & decrypt a string:" << std::endl; std::cout << "Example on how to encrypt & decrypt a string:" << std::endl;
// Get some string // Get some string
const std::string input = "I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!I am a super secret message!"; const std::string input = "I am a super secret message!";
std::cout << input << std::endl; std::cout << input << std::endl;
// Encrypt // Encrypt

View File

@ -1,34 +1,12 @@
#include "InitializationVector.h" #include "InitializationVector.h"
#include <random> #include <iostream>
#include <sstream> #include "Feistel.h"
// 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
>;
GhettoCipher::InitializationVector::InitializationVector(const Block& seed) GhettoCipher::InitializationVector::InitializationVector(const Block& seed)
{ {
// Since an initialization vector does not have to be a secret, // We'll generate our initialization vector by encrypting our seed with itself as a key
// we should be fine just using a mersenne twister seeded with // iv = E(M=seed, K=seed)
// for example the key to fill it up to fit BLOCK_SIZE. iv = Feistel(seed).Encipher(seed);
// Loosely seed mersenne twister with seed
// Here is nothing copied. Both Block::Get, and Hash<>::operator() take refs.
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++)
ss << (mt() % 2 ? '1' : '0');
// And create a block
iv = Block(ss.str());
} }
GhettoCipher::InitializationVector::operator GhettoCipher::Block() const GhettoCipher::InitializationVector::operator GhettoCipher::Block() const

View File

@ -1,2 +1,2 @@
#pragma once #pragma once
#define GHETTOCRYPT_VERSION 0.2 #define GHETTOCRYPT_VERSION 0.21

View File

@ -1,2 +1,2 @@
#pragma once #pragma once
#define GHETTOCRYPTCLI_VERSION 0.12 #define GHETTOCRYPTCLI_VERSION 0.121

Binary file not shown.