GCryptLib: Fix include paths

This commit is contained in:
Leonetienne 2022-05-16 22:35:28 +02:00
parent 9432325b4a
commit 7fe9dcc6dc
No known key found for this signature in database
GPG Key ID: C33879CD92E9708C
16 changed files with 483 additions and 455 deletions

View File

@ -1,8 +1,8 @@
#include <iostream> #include <iostream>
#include <GhettoCryptWrapper.h> #include <GCrypt/GhettoCryptWrapper.h>
#include <SecureBitset.h> #include <GCrypt/SecureBitset.h>
#include <Util.h> #include <GCrypt/Util.h>
#include <InitializationVector.h> #include <GCrypt/InitializationVector.h>
using namespace Leonetienne::GCrypt; using namespace Leonetienne::GCrypt;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "SecureBitset.h" #include "GCrypt/SecureBitset.h"
#include "Config.h" #include "GCrypt/Config.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {
typedef SecureBitset<BLOCK_SIZE> Block; typedef SecureBitset<BLOCK_SIZE> Block;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Feistel.h" #include "GCrypt/Feistel.h"
#include "Flexblock.h" #include "GCrypt/Flexblock.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {
/** Class to apply a block cipher to messages of arbitrary length in a distributed manner /** Class to apply a block cipher to messages of arbitrary length in a distributed manner

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "Keyset.h" #include "GCrypt/Keyset.h"
#include "Block.h" #include "GCrypt/Block.h"
#include "Halfblock.h" #include "GCrypt/Halfblock.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {
/** Class to perform a feistel block chipher /** Class to perform a feistel block chipher

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "SecureBitset.h"
#include <cstdint> #include <cstdint>
#include "Config.h" #include "GCrypt/SecureBitset.h"
#include "GCrypt/Config.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {
constexpr std::size_t HALFBLOCK_SIZE = (BLOCK_SIZE / 2); constexpr std::size_t HALFBLOCK_SIZE = (BLOCK_SIZE / 2);

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Config.h" #include "GCrypt/Config.h"
#include "Block.h" #include "GCrypt/Block.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {
/** Will create a sudo-random Block based on a seed /** Will create a sudo-random Block based on a seed

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include "Block.h" #include "GCrypt/Block.h"
#include "Config.h" #include "GCrypt/Config.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {
typedef std::array<Block, N_ROUNDS> Keyset; typedef std::array<Block, N_ROUNDS> Keyset;

View File

@ -3,12 +3,12 @@
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <cstring> #include <cstring>
#include "SecureBitset.h" #include "GCrypt/SecureBitset.h"
#include "Block.h" #include "GCrypt/Block.h"
#include "Flexblock.h" #include "GCrypt/Flexblock.h"
#include "Config.h" #include "GCrypt/Config.h"
#include "Cipher.h" #include "GCrypt/Cipher.h"
#include "InitializationVector.h" #include "GCrypt/InitializationVector.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {
//! Mod-operator that works with negative values //! Mod-operator that works with negative values

View File

@ -1,8 +1,8 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "Cipher.h" #include "GCrypt/Cipher.h"
#include "Util.h" #include "GCrypt/Util.h"
#include "InitializationVector.h" #include "GCrypt/InitializationVector.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {

View File

@ -1,7 +1,7 @@
#include <unordered_map> #include <unordered_map>
#include "Feistel.h" #include "GCrypt/Feistel.h"
#include "Util.h" #include "GCrypt/Util.h"
#include "Config.h" #include "GCrypt/Config.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {

View File

@ -1,6 +1,6 @@
#include "GhettoCryptWrapper.h" #include "GCrypt/GhettoCryptWrapper.h"
#include "Cipher.h" #include "GCrypt/Cipher.h"
#include "Util.h" #include "GCrypt/Util.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {

View File

@ -1,5 +1,5 @@
#include "InitializationVector.h" #include "GCrypt/InitializationVector.h"
#include "Feistel.h" #include "GCrypt/Feistel.h"
namespace Leonetienne::GCrypt { namespace Leonetienne::GCrypt {

View File

@ -1,3 +1,4 @@
/*
#include "CppUnitTest.h" #include "CppUnitTest.h"
#include "../GhettoCrypt/Cipher.h" #include "../GhettoCrypt/Cipher.h"
#include "../GhettoCrypt/Util.h" #include "../GhettoCrypt/Util.h"
@ -9,222 +10,223 @@ using namespace GhettoCipher;
namespace SimpleTests namespace SimpleTests
{ {
TEST_CLASS(EncryptEqualsDecrypt) TEST_CLASS(EncryptEqualsDecrypt)
{ {
public: public:
// Tests that encrypting a message of exactly BLOCK_SIZE yields the exact message back // Tests that encrypting a message of exactly BLOCK_SIZE yields the exact message back
TEST_METHOD(SingleBlock_NoPadding) TEST_METHOD(SingleBlock_NoPadding)
{ {
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
// Recode the ascii-string to bits // Recode the ascii-string to bits
const Flexblock cleartext_bits = const Flexblock cleartext_bits =
"1011110011010110000010110001111000111010111101001010100100011101" "1011110011010110000010110001111000111010111101001010100100011101"
"0101110101010010100000110100001000011000111010001001110101111111" "0101110101010010100000110100001000011000111010001001110101111111"
"1110110101100101110001010101011110001010000010111110011011010111" "1110110101100101110001010101011110001010000010111110011011010111"
"1100110100111000000011100101010100110010001110010011000010111001" "1100110100111000000011100101010100110010001110010011000010111001"
"0000010000010000011001111010011110111001000000000110101000110001" "0000010000010000011001111010011110111001000000000110101000110001"
"0110111110110110100000010100000011010001000011100100111001001011" "0110111110110110100000010100000011010001000011100100111001001011"
"1101100100000100010000001011100010010001101111100100101100010001" "1101100100000100010000001011100010010001101111100100101100010001"
"0000011110010110111010110110111110011110011010001100100111110101"; "0000011110010110111010110110111110011110011010001100100111110101";
// Encrypt our cleartext bits // Encrypt our cleartext bits
const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits); const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits);
// Decipher it again // Decipher it again
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( Assert::AreEqual(
cleartext_bits, cleartext_bits,
decryptedBits decryptedBits
); );
} }
// Tests that encrypting a message of less than BLOCK_SIZE yields the exact message plus zero-padding back // Tests that encrypting a message of less than BLOCK_SIZE yields the exact message plus zero-padding back
TEST_METHOD(SingleBlock_Padding) TEST_METHOD(SingleBlock_Padding)
{ {
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
// Recode the ascii-string to bits // Recode the ascii-string to bits
const Flexblock cleartext_bits = const Flexblock cleartext_bits =
"1011110011010110000010110001111000111010111101001010100100011101" "1011110011010110000010110001111000111010111101001010100100011101"
"0101110101010010100000110100001000011000111010001001110101111111" "0101110101010010100000110100001000011000111010001001110101111111"
"1110110101100101110001010101011110001010000010111110011011010111" "1110110101100101110001010101011110001010000010111110011011010111"
"1100110100111000000011100101010100110010001110010011000010111001" "1100110100111000000011100101010100110010001110010011000010111001"
"0000010000010000011001111010011110111001000000000110101000110001" "0000010000010000011001111010011110111001000000000110101000110001"
"0110111110110110100000010100000011010001000011100100111001001011" "0110111110110110100000010100000011010001000011100100111001001011"
"1101100100000100"; "1101100100000100";
const Flexblock cleartext_bits_EXPECTED_RESULT = const Flexblock cleartext_bits_EXPECTED_RESULT =
"1011110011010110000010110001111000111010111101001010100100011101" "1011110011010110000010110001111000111010111101001010100100011101"
"0101110101010010100000110100001000011000111010001001110101111111" "0101110101010010100000110100001000011000111010001001110101111111"
"1110110101100101110001010101011110001010000010111110011011010111" "1110110101100101110001010101011110001010000010111110011011010111"
"1100110100111000000011100101010100110010001110010011000010111001" "1100110100111000000011100101010100110010001110010011000010111001"
"0000010000010000011001111010011110111001000000000110101000110001" "0000010000010000011001111010011110111001000000000110101000110001"
"0110111110110110100000010100000011010001000011100100111001001011" "0110111110110110100000010100000011010001000011100100111001001011"
"1101100100000100000000000000000000000000000000000000000000000000" "1101100100000100000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000"; "0000000000000000000000000000000000000000000000000000000000000000";
// Encrypt our cleartext bits // Encrypt our cleartext bits
const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits); const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits);
// Decipher it again // Decipher it again
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( Assert::AreEqual(
cleartext_bits_EXPECTED_RESULT, cleartext_bits_EXPECTED_RESULT,
decryptedBits decryptedBits
); );
} }
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks // Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_METHOD(MultiBlock_NoPadding) TEST_METHOD(MultiBlock_NoPadding)
{ {
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
// Recode the ascii-string to bits // Recode the ascii-string to bits
const Flexblock cleartext_bits = const Flexblock cleartext_bits =
"1011110011010110000010110001111000111010111101001010100100011101" "1011110011010110000010110001111000111010111101001010100100011101"
"0101110101010010100000110100001000011000111010001001110101111111" "0101110101010010100000110100001000011000111010001001110101111111"
"1110110101100101110001010101011110001010000010111110011011010111" "1110110101100101110001010101011110001010000010111110011011010111"
"1100110100111000000011100101010100110010001110010011000010111001" "1100110100111000000011100101010100110010001110010011000010111001"
"0000010000010000011001111010011110111001000000000110101000110001" "0000010000010000011001111010011110111001000000000110101000110001"
"0110111110110110100000010100000011010001000011100100111001001011" "0110111110110110100000010100000011010001000011100100111001001011"
"1101100100000100010000001011100010010001101111100100101100010001" "1101100100000100010000001011100010010001101111100100101100010001"
"0000011110010110111010110110111110011110011010001100100111110101" "0000011110010110111010110110111110011110011010001100100111110101"
"1000010010000000000100101011110001000101101101100000010011111011" "1000010010000000000100101011110001000101101101100000010011111011"
"1011111010110100100111100111110011100001111101111110000110001100" "1011111010110100100111100111110011100001111101111110000110001100"
"0001000111000111101110000111011011101010100010100101100111010100" "0001000111000111101110000111011011101010100010100101100111010100"
"0101111110110010110000111111011001101110101101100100100011000100" "0101111110110010110000111111011001101110101101100100100011000100"
"1000110010101001000100001001101000011111101011111100100000100101" "1000110010101001000100001001101000011111101011111100100000100101"
"1100001100111001011111001101000111011101011101000110010110110110" "1100001100111001011111001101000111011101011101000110010110110110"
"0111001010011010010000010110000110010101101100101110111100100011" "0111001010011010010000010110000110010101101100101110111100100011"
"0010111110011100010100000101100101110101101011110100100000110110" "0010111110011100010100000101100101110101101011110100100000110110"
"1001101110101001001111111000010100011100100000101000111101101111" "1001101110101001001111111000010100011100100000101000111101101111"
"0101111011110001101010111010001000111010101111001101100100100100" "0101111011110001101010111010001000111010101111001101100100100100"
"1110110111001100011010110000101000011001011100101100111101110000" "1110110111001100011010110000101000011001011100101100111101110000"
"1010101111011110000111011011011110000111010110110111111010101010" "1010101111011110000111011011011110000111010110110111111010101010"
"0111100101111001010111101000001010100000111010111100111011111001" "0111100101111001010111101000001010100000111010111100111011111001"
"0110111000000110100011011100101101010101101000010010011111100100" "0110111000000110100011011100101101010101101000010010011111100100"
"0010111000001011101110000110010011101001111010100111110111110101" "0010111000001011101110000110010011101001111010100111110111110101"
"1110111000000000101011000100101010000110110111101010011001111010" "1110111000000000101011000100101010000110110111101010011001111010"
"1101011110001110000011010111001100001100101000000101000101000010" "1101011110001110000011010111001100001100101000000101000101000010"
"0101000011011111010010110010000010101100001110011000110111110111" "0101000011011111010010110010000010101100001110011000110111110111"
"1110010101011110111001100010110101101011100111100011101010001011" "1110010101011110111001100010110101101011100111100011101010001011"
"0101110010100110101100111100010000111101111100000111000110110110" "0101110010100110101100111100010000111101111100000111000110110110"
"1001100111000000011010100000011101011000010010011010001011110000" "1001100111000000011010100000011101011000010010011010001011110000"
"1100100111111001001000011100110000011110001100000000010000001001" "1100100111111001001000011100110000011110001100000000010000001001"
"1110000000110010000010011010100011011011000000000111110000110111" "1110000000110010000010011010100011011011000000000111110000110111"
"0101110011001101010110010100011001110110000110010001100110011111"; "0101110011001101010110010100011001110110000110010001100110011111";
// Encrypt our cleartext bits // Encrypt our cleartext bits
const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits); const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits);
// Decipher it again // Decipher it again
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( Assert::AreEqual(
cleartext_bits, cleartext_bits,
decryptedBits decryptedBits
); );
} }
// Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks // Tests that a decrypted ciphertext equals its plaintrext version, using a cleartext that requires A LOT of blocks
TEST_METHOD(MultiBlock_Padding) TEST_METHOD(MultiBlock_Padding)
{ {
// Instanciate our cipher and supply a key // Instanciate our cipher and supply a key
const Block key = PasswordToKey("1234"); const Block key = PasswordToKey("1234");
const Cipher cipher(key); const Cipher cipher(key);
// Recode the ascii-string to bits // Recode the ascii-string to bits
const Flexblock cleartext_bits = const Flexblock cleartext_bits =
"1011110011010110000010110001111000111010111101001010100100011101" "1011110011010110000010110001111000111010111101001010100100011101"
"0101110101010010100000110100001000011000111010001001110101111111" "0101110101010010100000110100001000011000111010001001110101111111"
"1110110101100101110001010101011110001010000010111110011011010111" "1110110101100101110001010101011110001010000010111110011011010111"
"1100110100111000000011100101010100110010001110010011000010111001" "1100110100111000000011100101010100110010001110010011000010111001"
"0000010000010000011001111010011110111001000000000110101000110001" "0000010000010000011001111010011110111001000000000110101000110001"
"0110111110110110100000010100000011010001000011100100111001001011" "0110111110110110100000010100000011010001000011100100111001001011"
"1101100100000100010000001011100010010001101111100100101100010001" "1101100100000100010000001011100010010001101111100100101100010001"
"0000011110010110111010110110111110011110011010001100100111110101" "0000011110010110111010110110111110011110011010001100100111110101"
"1000010010000000000100101011110001000101101101100000010011111011" "1000010010000000000100101011110001000101101101100000010011111011"
"1011111010110100100111100111110011100001111101111110000110001100" "1011111010110100100111100111110011100001111101111110000110001100"
"0001000111000111101110000111011011101010100010100101100111010100" "0001000111000111101110000111011011101010100010100101100111010100"
"0101111110110010110000111111011001101110101101100100100011000100" "0101111110110010110000111111011001101110101101100100100011000100"
"1000110010101001000100001001101000011111101011111100100000100101" "1000110010101001000100001001101000011111101011111100100000100101"
"1100001100111001011111001101000111011101011101000110010110110110" "1100001100111001011111001101000111011101011101000110010110110110"
"0111001010011010010000010110000110010101101100101110111100100011" "0111001010011010010000010110000110010101101100101110111100100011"
"0010111110011100010100000101100101110101101011110100100000110110" "0010111110011100010100000101100101110101101011110100100000110110"
"1001101110101001001111111000010100011100100000101000111101101111" "1001101110101001001111111000010100011100100000101000111101101111"
"0101111011110001101010111010001000111010101111001101100100100100" "0101111011110001101010111010001000111010101111001101100100100100"
"1110110111001100011010110000101000011001011100101100111101110000" "1110110111001100011010110000101000011001011100101100111101110000"
"1010101111011110000111011011011110000111010110110111111010101010" "1010101111011110000111011011011110000111010110110111111010101010"
"0111100101111001010111101000001010100000111010111100111011111001" "0111100101111001010111101000001010100000111010111100111011111001"
"0110111000000110100011011100101101010101101000010010011111100100" "0110111000000110100011011100101101010101101000010010011111100100"
"0010111000001011101110000110010011101001111010100111110111110101" "0010111000001011101110000110010011101001111010100111110111110101"
"1110111000000000101011000100101010000110110111101010011001111010" "1110111000000000101011000100101010000110110111101010011001111010"
"1101011110001110000011010111001100001100101000000101000101000010" "1101011110001110000011010111001100001100101000000101000101000010"
"0101000011011111010010110010000010101100001110011000110111110111" "0101000011011111010010110010000010101100001110011000110111110111"
"1110010101011110111001100010110101101011100111100011101010001011" "1110010101011110111001100010110101101011100111100011101010001011"
"0101110010100110101100111100010000111101111100000111000110110110" "0101110010100110101100111100010000111101111100000111000110110110"
"1001100111000000011010100000011101011000010010011010001011110000" "1001100111000000011010100000011101011000010010011010001011110000"
"1100100111111001001000011100110000011110001100000000010000001001" "1100100111111001001000011100110000011110001100000000010000001001"
"11100000001100100000100110101000110110110000000001111100001"; "11100000001100100000100110101000110110110000000001111100001";
const Flexblock cleartext_bits_EXPECTED_RESULT = const Flexblock cleartext_bits_EXPECTED_RESULT =
"1011110011010110000010110001111000111010111101001010100100011101" "1011110011010110000010110001111000111010111101001010100100011101"
"0101110101010010100000110100001000011000111010001001110101111111" "0101110101010010100000110100001000011000111010001001110101111111"
"1110110101100101110001010101011110001010000010111110011011010111" "1110110101100101110001010101011110001010000010111110011011010111"
"1100110100111000000011100101010100110010001110010011000010111001" "1100110100111000000011100101010100110010001110010011000010111001"
"0000010000010000011001111010011110111001000000000110101000110001" "0000010000010000011001111010011110111001000000000110101000110001"
"0110111110110110100000010100000011010001000011100100111001001011" "0110111110110110100000010100000011010001000011100100111001001011"
"1101100100000100010000001011100010010001101111100100101100010001" "1101100100000100010000001011100010010001101111100100101100010001"
"0000011110010110111010110110111110011110011010001100100111110101" "0000011110010110111010110110111110011110011010001100100111110101"
"1000010010000000000100101011110001000101101101100000010011111011" "1000010010000000000100101011110001000101101101100000010011111011"
"1011111010110100100111100111110011100001111101111110000110001100" "1011111010110100100111100111110011100001111101111110000110001100"
"0001000111000111101110000111011011101010100010100101100111010100" "0001000111000111101110000111011011101010100010100101100111010100"
"0101111110110010110000111111011001101110101101100100100011000100" "0101111110110010110000111111011001101110101101100100100011000100"
"1000110010101001000100001001101000011111101011111100100000100101" "1000110010101001000100001001101000011111101011111100100000100101"
"1100001100111001011111001101000111011101011101000110010110110110" "1100001100111001011111001101000111011101011101000110010110110110"
"0111001010011010010000010110000110010101101100101110111100100011" "0111001010011010010000010110000110010101101100101110111100100011"
"0010111110011100010100000101100101110101101011110100100000110110" "0010111110011100010100000101100101110101101011110100100000110110"
"1001101110101001001111111000010100011100100000101000111101101111" "1001101110101001001111111000010100011100100000101000111101101111"
"0101111011110001101010111010001000111010101111001101100100100100" "0101111011110001101010111010001000111010101111001101100100100100"
"1110110111001100011010110000101000011001011100101100111101110000" "1110110111001100011010110000101000011001011100101100111101110000"
"1010101111011110000111011011011110000111010110110111111010101010" "1010101111011110000111011011011110000111010110110111111010101010"
"0111100101111001010111101000001010100000111010111100111011111001" "0111100101111001010111101000001010100000111010111100111011111001"
"0110111000000110100011011100101101010101101000010010011111100100" "0110111000000110100011011100101101010101101000010010011111100100"
"0010111000001011101110000110010011101001111010100111110111110101" "0010111000001011101110000110010011101001111010100111110111110101"
"1110111000000000101011000100101010000110110111101010011001111010" "1110111000000000101011000100101010000110110111101010011001111010"
"1101011110001110000011010111001100001100101000000101000101000010" "1101011110001110000011010111001100001100101000000101000101000010"
"0101000011011111010010110010000010101100001110011000110111110111" "0101000011011111010010110010000010101100001110011000110111110111"
"1110010101011110111001100010110101101011100111100011101010001011" "1110010101011110111001100010110101101011100111100011101010001011"
"0101110010100110101100111100010000111101111100000111000110110110" "0101110010100110101100111100010000111101111100000111000110110110"
"1001100111000000011010100000011101011000010010011010001011110000" "1001100111000000011010100000011101011000010010011010001011110000"
"1100100111111001001000011100110000011110001100000000010000001001" "1100100111111001001000011100110000011110001100000000010000001001"
"1110000000110010000010011010100011011011000000000111110000100000" "1110000000110010000010011010100011011011000000000111110000100000"
"0000000000000000000000000000000000000000000000000000000000000000"; "0000000000000000000000000000000000000000000000000000000000000000";
// Encrypt our cleartext bits // Encrypt our cleartext bits
const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits); const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits);
// Decipher it again // Decipher it again
const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits);
// Assert that the decrypted text equals the plaintext // Assert that the decrypted text equals the plaintext
Assert::AreEqual( Assert::AreEqual(
cleartext_bits_EXPECTED_RESULT, cleartext_bits_EXPECTED_RESULT,
decryptedBits decryptedBits
); );
} }
}; };
} }
*/

View File

@ -1,81 +1,103 @@
#include "CppUnitTest.h" #include <GCrypt/GhettoCryptWrapper.h>
#include "../GhettoCrypt/GhettoCryptWrapper.h" #include <GCrypt/Flexblock.h>
#include "../GhettoCrypt/Flexblock.h" #include <GCrypt/Util.h>
#include "../GhettoCrypt/Util.h" #include "Catch2.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Leonetienne::GCrypt;
using namespace GhettoCipher;
// Tests that encrypting and decrypting strings using the wrapper works.
// This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated.
TEST_CASE(__FILE__"/Encrypting and decrypting strings works", "[Wrapper]") {
// Setup
const std::string plaintext = "Hello, World!";
const std::string password = "Der Affe will Zucker";
std::string ciphertext;
std::string decrypted;
// Encryption
ciphertext = GhettoCryptWrapper::EncryptString(plaintext, password);
// Decryption
decrypted = GhettoCryptWrapper::DecryptString(ciphertext, password);
// Assertion
REQUIRE(plaintext == decrypted);
}
/*
namespace SimpleTests namespace SimpleTests
{ {
TEST_CLASS(GCWrapper) TEST_CLASS(GCWrapper)
{ {
public: public:
// Tests that encrypting and decrypting strings using the wrapper works. // Tests that encrypting and decrypting strings using the wrapper works.
// This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated. // This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated.
TEST_METHOD(String) TEST_METHOD(String)
{ {
// Setup // Setup
const std::string plaintext = "Hello, World!"; const std::string plaintext = "Hello, World!";
const std::string password = "Der Affe will Zucker"; const std::string password = "Der Affe will Zucker";
std::string ciphertext; std::string ciphertext;
std::string decrypted; std::string decrypted;
// Encryption // Encryption
{ {
ciphertext = GhettoCryptWrapper::EncryptString(plaintext, password); ciphertext = GhettoCryptWrapper::EncryptString(plaintext, password);
} }
// Decryption // Decryption
{ {
decrypted = GhettoCryptWrapper::DecryptString(ciphertext, password); decrypted = GhettoCryptWrapper::DecryptString(ciphertext, password);
} }
// Assertion // Assertion
Assert::AreEqual( Assert::AreEqual(
plaintext, plaintext,
decrypted decrypted
); );
} }
// Tests that encrypting and decrypting files using the wrapper works. // Tests that encrypting and decrypting files using the wrapper works.
// This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated. // This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated.
TEST_METHOD(File) TEST_METHOD(File)
{ {
// Setup // Setup
#if defined _WIN64 #if defined _WIN64
const std::string testfile_dir = "../../SimpleTests/"; const std::string testfile_dir = "../../SimpleTests/";
#elif defined _WIN32 #elif defined _WIN32
const std::string testfile_dir = "../SimpleTests/"; const std::string testfile_dir = "../SimpleTests/";
#endif #endif
const std::string filename_plain = testfile_dir + "testfile.png"; const std::string filename_plain = testfile_dir + "testfile.png";
const std::string filename_encrypted = testfile_dir + "testfile.png.crypt"; const std::string filename_encrypted = testfile_dir + "testfile.png.crypt";
const std::string filename_decrypted = testfile_dir + "testfile.png.clear.png"; const std::string filename_decrypted = testfile_dir + "testfile.png.clear.png";
const std::string password = "Der Affe will Zucker"; const std::string password = "Der Affe will Zucker";
// Encryption // Encryption
{ {
GhettoCryptWrapper::EncryptFile(filename_plain, filename_encrypted, password); GhettoCryptWrapper::EncryptFile(filename_plain, filename_encrypted, password);
} }
// Decryption // Decryption
{ {
GhettoCryptWrapper::DecryptFile(filename_encrypted, filename_decrypted, password); GhettoCryptWrapper::DecryptFile(filename_encrypted, filename_decrypted, password);
} }
// Read in both the base, and the decrypted file // Read in both the base, and the decrypted file
const Flexblock plainfile = ReadFileToBits(filename_plain); const Flexblock plainfile = ReadFileToBits(filename_plain);
const Flexblock decryptfile = ReadFileToBits(filename_decrypted); const Flexblock decryptfile = ReadFileToBits(filename_decrypted);
// Assertion (If this fails, maybe check if the image is even readable by an image viewer) // Assertion (If this fails, maybe check if the image is even readable by an image viewer)
Assert::AreEqual( Assert::AreEqual(
PadStringToLength(plainfile, decryptfile.length(), '0', false), PadStringToLength(plainfile, decryptfile.length(), '0', false),
decryptfile decryptfile
); );
} }
}; };
} }
*/

View File

@ -1,3 +1,4 @@
/*
#include "CppUnitTest.h" #include "CppUnitTest.h"
#include "../GhettoCrypt/Util.h" #include "../GhettoCrypt/Util.h"
#include "../GhettoCrypt/Config.h" #include "../GhettoCrypt/Config.h"
@ -108,3 +109,4 @@ namespace SimpleTests
} }
}; };
} }
*/

2
GCryptLib/test/main.cpp Normal file
View File

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "Catch2.h"