From 3750e96a5f17cc12e3dc03b73eb65f9791c2a0bc Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Mon, 13 Dec 2021 15:56:24 +0100 Subject: [PATCH] Added dontoptimize pragma to zerokeymemory in feistel class --- GhettoCrypt/Feistel.cpp | 12 ++++++ INCLUDE/GhettoCrypt.cpp | 12 ++++++ INCLUDE/GhettoCrypt.h | 82 ++++++++++++++++++++--------------------- 3 files changed, 65 insertions(+), 41 deletions(-) diff --git a/GhettoCrypt/Feistel.cpp b/GhettoCrypt/Feistel.cpp index 5bacd1e..6bfc66d 100644 --- a/GhettoCrypt/Feistel.cpp +++ b/GhettoCrypt/Feistel.cpp @@ -191,6 +191,13 @@ void GhettoCipher::Feistel::GenerateRoundKeys(const Block& seedKey) return; } +// These pragmas only work for MSVC and g++, 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() { for (Block& key : roundKeys) @@ -198,3 +205,8 @@ void GhettoCipher::Feistel::ZeroKeyMemory() return; } +#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 75c4940..8cf8680 100644 --- a/INCLUDE/GhettoCrypt.cpp +++ b/INCLUDE/GhettoCrypt.cpp @@ -355,6 +355,13 @@ void GhettoCipher::Feistel::GenerateRoundKeys(const Block& seedKey) return; } +// These pragmas only work for MSVC and g++, 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() { for (Block& key : roundKeys) @@ -362,6 +369,11 @@ void GhettoCipher::Feistel::ZeroKeyMemory() return; } +#if defined _WIN32 || defined _WIN64 +#pragma optimize("", on ) +#elif defined __GNUG__ +#pragma GCC pop_options +#endif /*** ./../GhettoCrypt/GhettoCryptWrapper.cpp ***/ diff --git a/INCLUDE/GhettoCrypt.h b/INCLUDE/GhettoCrypt.h index 4f4ff0f..e4b6816 100644 --- a/INCLUDE/GhettoCrypt.h +++ b/INCLUDE/GhettoCrypt.h @@ -28,42 +28,6 @@ #pragma once -/*** ./../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/Flexblock.h ***/ #pragma once @@ -75,6 +39,11 @@ namespace GhettoCipher typedef std::string Flexblock; } +/*** ./../GhettoCrypt/Version.h ***/ + +#pragma once +#define GHETTOCRYPT_VERSION 0.12 + /*** ./../GhettoCrypt/Config.h ***/ #pragma once @@ -683,11 +652,6 @@ namespace GhettoCipher } } -/*** ./../GhettoCrypt/Version.h ***/ - -#pragma once -#define GHETTOCRYPT_VERSION 0.12 - /*** ./../GhettoCrypt/Keyset.h ***/ #pragma once @@ -769,6 +733,42 @@ 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