Progress on updating Crypto++

This commit is contained in:
Cekis
2021-10-30 14:56:30 -04:00
parent 0139fd830a
commit e172d41216
6 changed files with 50 additions and 112 deletions
-1
View File
@@ -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
+4 -2
View File
@@ -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;
};
//-----------------------------------------------------------------------
@@ -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
@@ -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 <typename T>
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;
};
//-----------------------------------------------------------------------
@@ -7,13 +7,14 @@
//-----------------------------------------------------------------------
#include "twofish.h"
#include "TwofishCrypt.h"
namespace Crypto {
//-----------------------------------------------------------------------
class TwofishDecryptor : public TwofishCrypt
class TwofishDecryptor : public TwofishCrypt<CryptoPP::TwofishDecryption>
{
public:
TwofishDecryptor();
@@ -7,18 +7,14 @@
//-----------------------------------------------------------------------
#include "twofish.h"
#include "TwofishCrypt.h"
namespace CryptoPP
{
class TwofishEncryption;
}
namespace Crypto {
//-----------------------------------------------------------------------
class TwofishEncryptor : public TwofishCrypt
class TwofishEncryptor : public TwofishCrypt<CryptoPP::TwofishEncryption>
{
public:
TwofishEncryptor();