Integrated initialization vector
This commit is contained in:
parent
40a6b0c4ea
commit
e57456e9ae
@ -41,7 +41,7 @@ void ExampleFiles()
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//ExampleString();
|
ExampleString();
|
||||||
//ExampleFiles();
|
//ExampleFiles();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2,19 +2,22 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Cipher.h"
|
#include "Cipher.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "InitializationVector.h"
|
||||||
|
|
||||||
GhettoCipher::Cipher::Cipher(const Block& key)
|
GhettoCipher::Cipher::Cipher(const Block& key)
|
||||||
:
|
:
|
||||||
key { key }
|
key { key },
|
||||||
|
initializationVector(InitializationVector(key))
|
||||||
{
|
{
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GhettoCipher::Cipher::Cipher(const std::string& password)
|
GhettoCipher::Cipher::Cipher(const std::string& password)
|
||||||
|
:
|
||||||
|
key { PasswordToKey(password) },
|
||||||
|
initializationVector(InitializationVector(key))
|
||||||
{
|
{
|
||||||
key = PasswordToKey(password);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +64,7 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Encipher(const Flexblock& data, bo
|
|||||||
if ((i % ((blocks.size() > 1000)? 100 : 10) == 0) && (printProgress))
|
if ((i % ((blocks.size() > 1000)? 100 : 10) == 0) && (printProgress))
|
||||||
std::cout << "Encrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100 / blocks.size()) << "%)" << std::endl;
|
std::cout << "Encrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100 / blocks.size()) << "%)" << std::endl;
|
||||||
|
|
||||||
const Block& lastBlock = (i>0) ? blocks[i-1] : emptyBlock;
|
const Block& lastBlock = (i>0) ? blocks[i-1] : initializationVector;
|
||||||
blocks[i] = feistel.Encipher(blocks[i] ^ lastBlock);
|
blocks[i] = feistel.Encipher(blocks[i] ^ lastBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +91,7 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Decipher(const Flexblock& data, bo
|
|||||||
Feistel feistel(key);
|
Feistel feistel(key);
|
||||||
|
|
||||||
// We can't do this in-loop for decryption, because we are decrypting the blocks in-place.
|
// We can't do this in-loop for decryption, because we are decrypting the blocks in-place.
|
||||||
Block lastBlock = emptyBlock;
|
Block lastBlock = initializationVector;
|
||||||
|
|
||||||
for (std::size_t i = 0; i < blocks.size(); i++)
|
for (std::size_t i = 0; i < blocks.size(); i++)
|
||||||
{
|
{
|
||||||
@ -129,5 +132,3 @@ void GhettoCipher::Cipher::ZeroKeyMemory()
|
|||||||
#elif defined __GNUG__
|
#elif defined __GNUG__
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const GhettoCipher::Block GhettoCipher::Cipher::emptyBlock;
|
|
||||||
|
@ -36,6 +36,6 @@ namespace GhettoCipher
|
|||||||
void ZeroKeyMemory();
|
void ZeroKeyMemory();
|
||||||
|
|
||||||
// Initial value for cipher block chaining
|
// Initial value for cipher block chaining
|
||||||
static const Block emptyBlock;
|
const Block initializationVector;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ InitializationVector::InitializationVector(const Block& seed)
|
|||||||
for (std::size_t i = 0; i < BLOCK_SIZE; i++)
|
for (std::size_t i = 0; i < BLOCK_SIZE; i++)
|
||||||
ss << (mt() % 2 ? '1' : '0');
|
ss << (mt() % 2 ? '1' : '0');
|
||||||
|
|
||||||
// And create a bitset
|
// And create a block
|
||||||
iv = Block(ss.str());
|
iv = Block(ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user