From b25640a2681a9528f52ae70dc96e1da9d700de2b Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Mon, 6 Dec 2021 12:53:18 +0100 Subject: [PATCH] Turned off optimizations for zero-memory methods for g++ --- GhettoCrypt/Cipher.cpp | 5 ++ GhettoCrypt/Feistel.cpp | 5 ++ INCLUDE/GhettoCrypt.cpp | 10 ++++ INCLUDE/GhettoCrypt.h | 100 ++++++++++++++++++++-------------------- 4 files changed, 70 insertions(+), 50 deletions(-) diff --git a/GhettoCrypt/Cipher.cpp b/GhettoCrypt/Cipher.cpp index d9eb784..335a9d2 100644 --- a/GhettoCrypt/Cipher.cpp +++ b/GhettoCrypt/Cipher.cpp @@ -114,6 +114,9 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Decipher(const Flexblock& data, bo #if defined _WIN32 || defined _WIN64 #pragma optimize("", off ) +#elif defined __GNUG__ +#pragma GCC push_options +#pragma GCC optimize ("O0") #endif void GhettoCipher::Cipher::ZeroKeyMemory() { @@ -122,6 +125,8 @@ void GhettoCipher::Cipher::ZeroKeyMemory() } #if defined _WIN32 || defined _WIN64 #pragma optimize("", on ) +#elif defined __GNUG__ +#pragma GCC pop_options #endif const GhettoCipher::Block GhettoCipher::Cipher::emptyBlock; diff --git a/GhettoCrypt/Feistel.cpp b/GhettoCrypt/Feistel.cpp index f3d1bcf..b1340a5 100644 --- a/GhettoCrypt/Feistel.cpp +++ b/GhettoCrypt/Feistel.cpp @@ -194,6 +194,9 @@ void GhettoCipher::Feistel::GenerateRoundKeys(const Block& seedKey) // These pragmas only work for MSVC, as far as i know. Beware!!! #if defined _WIN32 || defined _WIN64 #pragma optimize("", off ) +#elif defined __GNUG__ +#pragma GCC push_options +#pragma GCC optimize ("O0") #endif void GhettoCipher::Feistel::ZeroKeyMemory() { @@ -204,4 +207,6 @@ void GhettoCipher::Feistel::ZeroKeyMemory() } #if defined _WIN32 || defined _WIN64 #pragma optimize("", on ) +#elif defined __GNUG__ +#pragma GCC pop_options #endif diff --git a/INCLUDE/GhettoCrypt.cpp b/INCLUDE/GhettoCrypt.cpp index 9b47b6a..cbe3b0c 100644 --- a/INCLUDE/GhettoCrypt.cpp +++ b/INCLUDE/GhettoCrypt.cpp @@ -144,6 +144,9 @@ GhettoCipher::Flexblock GhettoCipher::Cipher::Decipher(const Flexblock& data, bo #if defined _WIN32 || defined _WIN64 #pragma optimize("", off ) +#elif defined __GNUG__ +#pragma GCC push_options +#pragma GCC optimize ("O0") #endif void GhettoCipher::Cipher::ZeroKeyMemory() { @@ -152,6 +155,8 @@ void GhettoCipher::Cipher::ZeroKeyMemory() } #if defined _WIN32 || defined _WIN64 #pragma optimize("", on ) +#elif defined __GNUG__ +#pragma GCC pop_options #endif 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!!! #if defined _WIN32 || defined _WIN64 #pragma optimize("", off ) +#elif defined __GNUG__ +#pragma GCC push_options +#pragma GCC optimize ("O0") #endif void GhettoCipher::Feistel::ZeroKeyMemory() { @@ -362,6 +370,8 @@ void GhettoCipher::Feistel::ZeroKeyMemory() } #if defined _WIN32 || defined _WIN64 #pragma optimize("", on ) +#elif defined __GNUG__ +#pragma GCC pop_options #endif diff --git a/INCLUDE/GhettoCrypt.h b/INCLUDE/GhettoCrypt.h index 64b6767..e24566a 100644 --- a/INCLUDE/GhettoCrypt.h +++ b/INCLUDE/GhettoCrypt.h @@ -33,14 +33,40 @@ #pragma once #define GHETTOCRYPT_VERSION 0.1 -/*** ./../GhettoCrypt/Config.h ***/ +/*** ./../GhettoCrypt/GhettoCryptWrapper.h ***/ #pragma once +#include namespace GhettoCipher { - constexpr int BLOCK_SIZE = 512; - constexpr int N_ROUNDS = 64; + /** 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/Flexblock.h ***/ @@ -54,6 +80,27 @@ namespace GhettoCipher 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 + +namespace GhettoCipher +{ + constexpr int HALFBLOCK_SIZE = (BLOCK_SIZE / 2); + typedef std::bitset Halfblock; +} + /*** ./../GhettoCrypt/Block.h ***/ #pragma once @@ -335,17 +382,6 @@ namespace GhettoCipher typedef std::array Keyset; } -/*** ./../GhettoCrypt/Halfblock.h ***/ - -#pragma once -#include - -namespace GhettoCipher -{ - constexpr int HALFBLOCK_SIZE = (BLOCK_SIZE / 2); - typedef std::bitset Halfblock; -} - /*** ./../GhettoCrypt/Feistel.h ***/ #pragma once @@ -406,42 +442,6 @@ namespace GhettoCipher }; } -/*** ./../GhettoCrypt/GhettoCryptWrapper.h ***/ - -#pragma once -#include - -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 ***/ #pragma once