From e172d412161a9cfef5cb199fd91ecc7d01267e39 Mon Sep 17 00:00:00 2001 From: Cekis Date: Sat, 30 Oct 2021 14:56:30 -0400 Subject: [PATCH] Progress on updating Crypto++ --- .../ours/library/crypto/src/CMakeLists.txt | 1 - .../crypto/src/shared/wrapper/MD5Hash.h | 6 +- .../src/shared/wrapper/TwofishCrypt.cpp | 93 ------------------- .../crypto/src/shared/wrapper/TwofishCrypt.h | 51 ++++++++-- .../src/shared/wrapper/TwofishDecryptor.h | 3 +- .../src/shared/wrapper/TwofishEncryptor.h | 8 +- 6 files changed, 50 insertions(+), 112 deletions(-) delete mode 100755 external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.cpp diff --git a/external/ours/library/crypto/src/CMakeLists.txt b/external/ours/library/crypto/src/CMakeLists.txt index 215b5967..b0c01c6f 100644 --- a/external/ours/library/crypto/src/CMakeLists.txt +++ b/external/ours/library/crypto/src/CMakeLists.txt @@ -29,7 +29,6 @@ set(SHARED_SOURCES shared/wrapper/Hash.h shared/wrapper/MD5Hash.cpp shared/wrapper/MD5Hash.h - shared/wrapper/TwofishCrypt.cpp shared/wrapper/TwofishCrypt.h shared/wrapper/TwofishDecryptor.cpp shared/wrapper/TwofishDecryptor.h diff --git a/external/ours/library/crypto/src/shared/wrapper/MD5Hash.h b/external/ours/library/crypto/src/shared/wrapper/MD5Hash.h index 97595d65..14abc12a 100755 --- a/external/ours/library/crypto/src/shared/wrapper/MD5Hash.h +++ b/external/ours/library/crypto/src/shared/wrapper/MD5Hash.h @@ -11,7 +11,9 @@ namespace CryptoPP { - class MD5; + namespace Weak1 { + class MD5; + } } namespace Crypto { @@ -35,7 +37,7 @@ private: MD5Hash(const MD5Hash & source); private: - CryptoPP::MD5 * md5; + CryptoPP::Weak1::MD5 * md5; }; //----------------------------------------------------------------------- diff --git a/external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.cpp b/external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.cpp deleted file mode 100755 index 9a272ae3..00000000 --- a/external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// TwofishCrypt.cpp -// copyright 2001 Verant Interactive -// Author: Justin Randall - -//----------------------------------------------------------------------- - -#include "FirstCrypto.h" -#include "twofish.h" -#include "TwofishCrypt.h" - -namespace Crypto { - -//----------------------------------------------------------------------- -/** - @brief default ctor -*/ -TwofishCrypt::TwofishCrypt() : -cipher(0) -{ -} - -//----------------------------------------------------------------------- - -TwofishCrypt::TwofishCrypt(const TwofishCrypt &) -{ -} - -//----------------------------------------------------------------------- -/** - @brief dtor - - Deletes the instance of the Twofish cipher -*/ -TwofishCrypt::~TwofishCrypt() -{ - delete cipher; -} - -//----------------------------------------------------------------------- -/** - @brief disabled assignment operator -*/ -TwofishCrypt & TwofishCrypt::operator = (const TwofishCrypt &) -{ - return *this; -} - -//----------------------------------------------------------------------- -/** - @brief return the blocksize of the cipher -*/ -const unsigned int TwofishCrypt::getBlockSize() const -{ - return BLOCKSIZE; -} - -//----------------------------------------------------------------------- -/** - @brief perform a cipher operation - - The cipher operation is determined by the instance of the - TwofishCrypt object (which is actually either a TwofishEncryptor or - TwofishDecryptor) - - The input block size must be greater than or equal to the cipher block - size. -*/ -void TwofishCrypt::process(const unsigned char * const inputBuffer, unsigned char * outputBuffer, const unsigned int size) -{ - static unsigned char block[BLOCKSIZE]; - - if(cipher && size >= BLOCKSIZE) - { - const unsigned int r = size & 3; // optimization -- safe is % BLOCKSIZE - if(r == 0) - { - unsigned int i; - for(i = 0; i < size; i += BLOCKSIZE) - { - memcpy(block, &inputBuffer[i], BLOCKSIZE); - cipher->ProcessBlock(block); - memcpy(&outputBuffer[i], block, BLOCKSIZE); - } - } - assert( r == 0 ); // size must be a 16 byte block for Twofish to do it's job! - } - assert(cipher != nullptr); // can't process data without a twofish encryptor or decryptor! -} - -//----------------------------------------------------------------------- - -}//namespace Crypto - diff --git a/external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.h b/external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.h index bcec162b..c16124f3 100755 --- a/external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.h +++ b/external/ours/library/crypto/src/shared/wrapper/TwofishCrypt.h @@ -7,6 +7,7 @@ //----------------------------------------------------------------------- +#include "assert.h" #include "CryptoBufferTransform.h" namespace CryptoPP @@ -20,23 +21,55 @@ namespace Crypto { /** @brief abstract base class for Twofish ciphers */ +template class TwofishCrypt { public: - TwofishCrypt(); - virtual ~TwofishCrypt() = 0; + TwofishCrypt() : cipher(0) + { + } - enum { BLOCKSIZE=16 }; - const unsigned int getBlockSize() const; - void process(const unsigned char * const inputBuffer, unsigned char * outputBuffer, const unsigned int size); + virtual ~TwofishCrypt() = 0; + + enum + { + BLOCKSIZE = 16 + }; + + const unsigned int getBlockSize() const + { + return BLOCKSIZE; + } + + void process(const unsigned char *const inputBuffer, unsigned char *outputBuffer, const unsigned int size) + { + static unsigned char block[BLOCKSIZE]; + + if (cipher && size >= BLOCKSIZE) + { + const unsigned int r = size & 3; // optimization -- safe is % BLOCKSIZE + if (r == 0) + { + unsigned int i; + for (i = 0; i < size; i += BLOCKSIZE) + { + memcpy(block, &inputBuffer[i], BLOCKSIZE); + cipher->ProcessAndXorBlock(block, NULLPTR, block); + memcpy(&outputBuffer[i], block, BLOCKSIZE); + } + } + assert(r == 0); // size must be a 16 byte block for Twofish to do it's job! + } + assert(cipher != nullptr); // can't process data without a twofish encryptor or decryptor! + } private: - TwofishCrypt & operator = (const TwofishCrypt & rhs); - TwofishCrypt(const TwofishCrypt & source); + TwofishCrypt &operator=(const TwofishCrypt &rhs); + TwofishCrypt(const TwofishCrypt &source); protected: - /** @brief assigned by a TwofishEncryptor or TwofishDecryptor */ - CryptoPP::Twofish * cipher; + /** @brief assigned by a TwofishEncryptor or TwofishDecryptor */ + T *cipher; }; //----------------------------------------------------------------------- diff --git a/external/ours/library/crypto/src/shared/wrapper/TwofishDecryptor.h b/external/ours/library/crypto/src/shared/wrapper/TwofishDecryptor.h index 9c5f7576..eb2099d2 100755 --- a/external/ours/library/crypto/src/shared/wrapper/TwofishDecryptor.h +++ b/external/ours/library/crypto/src/shared/wrapper/TwofishDecryptor.h @@ -7,13 +7,14 @@ //----------------------------------------------------------------------- +#include "twofish.h" #include "TwofishCrypt.h" namespace Crypto { //----------------------------------------------------------------------- - class TwofishDecryptor : public TwofishCrypt + class TwofishDecryptor : public TwofishCrypt { public: TwofishDecryptor(); diff --git a/external/ours/library/crypto/src/shared/wrapper/TwofishEncryptor.h b/external/ours/library/crypto/src/shared/wrapper/TwofishEncryptor.h index 437cb07c..70aea9e5 100755 --- a/external/ours/library/crypto/src/shared/wrapper/TwofishEncryptor.h +++ b/external/ours/library/crypto/src/shared/wrapper/TwofishEncryptor.h @@ -7,18 +7,14 @@ //----------------------------------------------------------------------- +#include "twofish.h" #include "TwofishCrypt.h" -namespace CryptoPP -{ - class TwofishEncryption; -} - namespace Crypto { //----------------------------------------------------------------------- -class TwofishEncryptor : public TwofishCrypt +class TwofishEncryptor : public TwofishCrypt { public: TwofishEncryptor();