Turned off optimizations for zero-memory methods for g++

This commit is contained in:
Leonetienne 2021-12-06 12:53:18 +01:00
parent 6133123387
commit b25640a268
4 changed files with 70 additions and 50 deletions

View File

@ -114,6 +114,9 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Decipher(const Flexblock& data, bo
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", off ) #pragma optimize("", off )
#elif defined __GNUG__
#pragma GCC push_options
#pragma GCC optimize ("O0")
#endif #endif
void GhettoCipher::Cipher::ZeroKeyMemory() void GhettoCipher::Cipher::ZeroKeyMemory()
{ {
@ -122,6 +125,8 @@ void GhettoCipher::Cipher::ZeroKeyMemory()
} }
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", on ) #pragma optimize("", on )
#elif defined __GNUG__
#pragma GCC pop_options
#endif #endif
const GhettoCipher::Block GhettoCipher::Cipher::emptyBlock; const GhettoCipher::Block GhettoCipher::Cipher::emptyBlock;

View File

@ -194,6 +194,9 @@ void GhettoCipher::Feistel::GenerateRoundKeys(const Block& seedKey)
// These pragmas only work for MSVC, as far as i know. Beware!!! // These pragmas only work for MSVC, as far as i know. Beware!!!
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", off ) #pragma optimize("", off )
#elif defined __GNUG__
#pragma GCC push_options
#pragma GCC optimize ("O0")
#endif #endif
void GhettoCipher::Feistel::ZeroKeyMemory() void GhettoCipher::Feistel::ZeroKeyMemory()
{ {
@ -204,4 +207,6 @@ void GhettoCipher::Feistel::ZeroKeyMemory()
} }
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", on ) #pragma optimize("", on )
#elif defined __GNUG__
#pragma GCC pop_options
#endif #endif

View File

@ -144,6 +144,9 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Decipher(const Flexblock& data, bo
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", off ) #pragma optimize("", off )
#elif defined __GNUG__
#pragma GCC push_options
#pragma GCC optimize ("O0")
#endif #endif
void GhettoCipher::Cipher::ZeroKeyMemory() void GhettoCipher::Cipher::ZeroKeyMemory()
{ {
@ -152,6 +155,8 @@ void GhettoCipher::Cipher::ZeroKeyMemory()
} }
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", on ) #pragma optimize("", on )
#elif defined __GNUG__
#pragma GCC pop_options
#endif #endif
const GhettoCipher::Block GhettoCipher::Cipher::emptyBlock; const GhettoCipher::Block GhettoCipher::Cipher::emptyBlock;
@ -352,6 +357,9 @@ void GhettoCipher::Feistel::GenerateRoundKeys(const Block& seedKey)
// These pragmas only work for MSVC, as far as i know. Beware!!! // These pragmas only work for MSVC, as far as i know. Beware!!!
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", off ) #pragma optimize("", off )
#elif defined __GNUG__
#pragma GCC push_options
#pragma GCC optimize ("O0")
#endif #endif
void GhettoCipher::Feistel::ZeroKeyMemory() void GhettoCipher::Feistel::ZeroKeyMemory()
{ {
@ -362,6 +370,8 @@ void GhettoCipher::Feistel::ZeroKeyMemory()
} }
#if defined _WIN32 || defined _WIN64 #if defined _WIN32 || defined _WIN64
#pragma optimize("", on ) #pragma optimize("", on )
#elif defined __GNUG__
#pragma GCC pop_options
#endif #endif

View File

@ -33,14 +33,40 @@
#pragma once #pragma once
#define GHETTOCRYPT_VERSION 0.1 #define GHETTOCRYPT_VERSION 0.1
/*** ./../GhettoCrypt/Config.h ***/ /*** ./../GhettoCrypt/GhettoCryptWrapper.h ***/
#pragma once #pragma once
#include <string>
namespace GhettoCipher namespace GhettoCipher
{ {
constexpr int BLOCK_SIZE = 512; /** This class is a wrapper to make working with the GhettoCipher super easy with a python-like syntax
constexpr int N_ROUNDS = 64; */
class GhettoCryptWrapper
{
public:
//! Will encrypt a string and return it hexadecimally encoded.
static std::string EncryptString(const std::string& cleartext, const std::string& password);
//! Will decrypt a hexadecimally encoded string.
static std::string DecryptString(const std::string& ciphertext, const std::string& password);
//! Will encrypt a file.
//! Returns false if anything goes wrong (like, file-access).
//! @filename_in The file to be read.
//! @filename_out The file the encrypted version should be saved in.
static bool EncryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport = false);
//! Will decrypt a file.
//! Returns false if anything goes wrong (like, file-access).
//! @filename_in The file to be read.
//! @filename_out The file the decrypted version should be saved in.
static bool DecryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport = false);
private:
// No instanciation! >:(
GhettoCryptWrapper();
};
} }
/*** ./../GhettoCrypt/Flexblock.h ***/ /*** ./../GhettoCrypt/Flexblock.h ***/
@ -54,6 +80,27 @@ namespace GhettoCipher
typedef std::string Flexblock; typedef std::string Flexblock;
} }
/*** ./../GhettoCrypt/Config.h ***/
#pragma once
namespace GhettoCipher
{
constexpr int BLOCK_SIZE = 512;
constexpr int N_ROUNDS = 64;
}
/*** ./../GhettoCrypt/Halfblock.h ***/
#pragma once
#include <bitset>
namespace GhettoCipher
{
constexpr int HALFBLOCK_SIZE = (BLOCK_SIZE / 2);
typedef std::bitset<HALFBLOCK_SIZE> Halfblock;
}
/*** ./../GhettoCrypt/Block.h ***/ /*** ./../GhettoCrypt/Block.h ***/
#pragma once #pragma once
@ -335,17 +382,6 @@ namespace GhettoCipher
typedef std::array<Block, N_ROUNDS> Keyset; typedef std::array<Block, N_ROUNDS> Keyset;
} }
/*** ./../GhettoCrypt/Halfblock.h ***/
#pragma once
#include <bitset>
namespace GhettoCipher
{
constexpr int HALFBLOCK_SIZE = (BLOCK_SIZE / 2);
typedef std::bitset<HALFBLOCK_SIZE> Halfblock;
}
/*** ./../GhettoCrypt/Feistel.h ***/ /*** ./../GhettoCrypt/Feistel.h ***/
#pragma once #pragma once
@ -406,42 +442,6 @@ namespace GhettoCipher
}; };
} }
/*** ./../GhettoCrypt/GhettoCryptWrapper.h ***/
#pragma once
#include <string>
namespace GhettoCipher
{
/** This class is a wrapper to make working with the GhettoCipher super easy with a python-like syntax
*/
class GhettoCryptWrapper
{
public:
//! Will encrypt a string and return it hexadecimally encoded.
static std::string EncryptString(const std::string& cleartext, const std::string& password);
//! Will decrypt a hexadecimally encoded string.
static std::string DecryptString(const std::string& ciphertext, const std::string& password);
//! Will encrypt a file.
//! Returns false if anything goes wrong (like, file-access).
//! @filename_in The file to be read.
//! @filename_out The file the encrypted version should be saved in.
static bool EncryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport = false);
//! Will decrypt a file.
//! Returns false if anything goes wrong (like, file-access).
//! @filename_in The file to be read.
//! @filename_out The file the decrypted version should be saved in.
static bool DecryptFile(const std::string& filename_in, const std::string& filename_out, const std::string& password, bool printProgressReport = false);
private:
// No instanciation! >:(
GhettoCryptWrapper();
};
}
/*** ./../GhettoCrypt/Cipher.h ***/ /*** ./../GhettoCrypt/Cipher.h ***/
#pragma once #pragma once