port to GCC 4, reorganize implementations of SetKey
parent
28c392e082
commit
f05ea58bb3
7
3way.cpp
7
3way.cpp
|
|
@ -61,17 +61,16 @@ static inline word32 reverseBits(word32 a)
|
||||||
pi_gamma_pi(a0, a1, a2); \
|
pi_gamma_pi(a0, a1, a2); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreeWay::Base::UncheckedSetKey(CipherDir dir, const byte *uk, unsigned int length, unsigned int r)
|
void ThreeWay::Base::UncheckedSetKey(const byte *uk, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
AssertValidRounds(r);
|
|
||||||
|
|
||||||
m_rounds = r;
|
m_rounds = GetRoundsAndThrowIfInvalid(params, this);
|
||||||
|
|
||||||
for (unsigned int i=0; i<3; i++)
|
for (unsigned int i=0; i<3; i++)
|
||||||
m_k[i] = (word32)uk[4*i+3] | ((word32)uk[4*i+2]<<8) | ((word32)uk[4*i+1]<<16) | ((word32)uk[4*i]<<24);
|
m_k[i] = (word32)uk[4*i+3] | ((word32)uk[4*i+2]<<8) | ((word32)uk[4*i+1]<<16) | ((word32)uk[4*i]<<24);
|
||||||
|
|
||||||
if (dir == DECRYPTION)
|
if (!IsForwardTransformation())
|
||||||
{
|
{
|
||||||
theta(m_k[0], m_k[1], m_k[2]);
|
theta(m_k[0], m_k[1], m_k[2]);
|
||||||
mu(m_k[0], m_k[1], m_k[2]);
|
mu(m_k[0], m_k[1], m_k[2]);
|
||||||
|
|
|
||||||
2
3way.h
2
3way.h
|
|
@ -21,7 +21,7 @@ class ThreeWay : public ThreeWay_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<ThreeWay_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<ThreeWay_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *key, unsigned int length, unsigned int rounds);
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int m_rounds;
|
unsigned int m_rounds;
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ CXXFLAGS = -g
|
||||||
# Uncomment the following two lines to do a release build.
|
# Uncomment the following two lines to do a release build.
|
||||||
# Note that you must define NDEBUG for your own application if you define it for Crypto++.
|
# Note that you must define NDEBUG for your own application if you define it for Crypto++.
|
||||||
# Make sure you run the validation tests and test your own program thoroughly
|
# Make sure you run the validation tests and test your own program thoroughly
|
||||||
# after turning on -O2. The GCC optimizer may have bugs that cause it to generate incorrect code.
|
# after turning on -O3. The GCC optimizer may have bugs that cause it to generate incorrect code.
|
||||||
# Try removing -fdata-sections if you get "undefined external reference" errors.
|
# Try removing -fdata-sections if you get "undefined external reference" errors.
|
||||||
# CXXFLAGS = -O2 -DNDEBUG -ffunction-sections -fdata-sections
|
# CXXFLAGS = -O3 -DNDEBUG -ffunction-sections -fdata-sections
|
||||||
# LDFLAGS += -Wl,--gc-sections
|
# LDFLAGS += -Wl,--gc-sections
|
||||||
ARFLAGS = -cr # ar needs the dash on OpenBSD
|
ARFLAGS = -cr # ar needs the dash on OpenBSD
|
||||||
RANLIB = ranlib
|
RANLIB = ranlib
|
||||||
|
|
|
||||||
2
arc4.cpp
2
arc4.cpp
|
|
@ -21,7 +21,7 @@ ARC4_Base::~ARC4_Base()
|
||||||
m_x = m_y = 0;
|
m_x = m_y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC4_Base::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int keyLen, const byte *iv)
|
void ARC4_Base::UncheckedSetKey(const byte *key, unsigned int keyLen, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keyLen);
|
AssertValidKeyLength(keyLen);
|
||||||
|
|
||||||
|
|
|
||||||
2
arc4.h
2
arc4.h
|
|
@ -26,7 +26,7 @@ public:
|
||||||
typedef SymmetricCipherFinal<ARC4_Base> Decryption;
|
typedef SymmetricCipherFinal<ARC4_Base> Decryption;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv);
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
|
||||||
virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
|
virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
|
||||||
|
|
||||||
FixedSizeSecBlock<byte, 256> m_state;
|
FixedSizeSecBlock<byte, 256> m_state;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void Blowfish::Base::UncheckedSetKey(CipherDir dir, const byte *key_string, unsigned int keylength)
|
void Blowfish::Base::UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylength);
|
AssertValidKeyLength(keylength);
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ void Blowfish::Base::UncheckedSetKey(CipherDir dir, const byte *key_string, unsi
|
||||||
for (i=0; i<4*256-2; i+=2)
|
for (i=0; i<4*256-2; i+=2)
|
||||||
crypt_block(sbox+i, sbox+i+2);
|
crypt_block(sbox+i, sbox+i+2);
|
||||||
|
|
||||||
if (dir==DECRYPTION)
|
if (!IsForwardTransformation())
|
||||||
for (i=0; i<(ROUNDS+2)/2; i++)
|
for (i=0; i<(ROUNDS+2)/2; i++)
|
||||||
std::swap(pbox[i], pbox[ROUNDS+1-i]);
|
std::swap(pbox[i], pbox[ROUNDS+1-i]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class Blowfish : public Blowfish_Info, public BlockCipherDocumentation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *key_string, unsigned int keylength);
|
void UncheckedSetKey(const byte *key_string, unsigned int keylength, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void crypt_block(const word32 in[2], word32 out[2]) const;
|
void crypt_block(const word32 in[2], word32 out[2]) const;
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ inline void rotl128(word64 *x, unsigned int bits)
|
||||||
x[1] = (x[1] << bits) | temp;
|
x[1] = (x[1] << bits) | temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camellia::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int keylen)
|
void Camellia::Base::UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylen);
|
AssertValidKeyLength(keylen);
|
||||||
|
|
||||||
|
|
@ -171,7 +171,7 @@ void Camellia::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned in
|
||||||
ks[32] = KB[0]; ks[33] = KB[1];
|
ks[32] = KB[0]; ks[33] = KB[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir == DECRYPTION) // reverse key schedule order
|
if (!IsForwardTransformation()) // reverse key schedule order
|
||||||
{
|
{
|
||||||
std::swap(ks[0], ks[kslen-2]);
|
std::swap(ks[0], ks[kslen-2]);
|
||||||
std::swap(ks[1], ks[kslen-1]);
|
std::swap(ks[1], ks[kslen-1]);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class Camellia : public Camellia_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Camellia_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Camellia_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int keylen);
|
void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs ¶ms);
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
unsigned int BlockAlignment() const {return 8;}
|
unsigned int BlockAlignment() const {return 8;}
|
||||||
|
|
||||||
|
|
|
||||||
6
cast.cpp
6
cast.cpp
|
|
@ -94,7 +94,7 @@ void CAST128::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
|
||||||
t = l = r = 0;
|
t = l = r = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAST128::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned int keylength)
|
void CAST128::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylength);
|
AssertValidKeyLength(keylength);
|
||||||
|
|
||||||
|
|
@ -251,7 +251,7 @@ void CAST256::Base::Omega(int i, word32 kappa[8])
|
||||||
f2(kappa[7],kappa[0],t_m[7][i],t_r[7][i]);
|
f2(kappa[7],kappa[0],t_m[7][i],t_r[7][i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAST256::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned int keylength)
|
void CAST256::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylength);
|
AssertValidKeyLength(keylength);
|
||||||
|
|
||||||
|
|
@ -273,7 +273,7 @@ void CAST256::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned
|
||||||
K[8*i+7]=kappa[1];
|
K[8*i+7]=kappa[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir == DECRYPTION)
|
if (!IsForwardTransformation())
|
||||||
{
|
{
|
||||||
for(int j=0; j<6; ++j)
|
for(int j=0; j<6; ++j)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
4
cast.h
4
cast.h
|
|
@ -27,7 +27,7 @@ class CAST128 : public CAST128_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
|
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool reduced;
|
bool reduced;
|
||||||
|
|
@ -63,7 +63,7 @@ class CAST256 : public CAST256_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
|
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length = 8);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void CBC_MAC_Base::CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms)
|
void CBC_MAC_Base::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AccessCipher().SetKey(key, length, params);
|
AccessCipher().SetKey(key, length, params);
|
||||||
m_reg.CleanNew(AccessCipher().BlockSize());
|
m_reg.CleanNew(AccessCipher().BlockSize());
|
||||||
|
|
|
||||||
2
cbcmac.h
2
cbcmac.h
|
|
@ -12,7 +12,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticatio
|
||||||
public:
|
public:
|
||||||
CBC_MAC_Base() {}
|
CBC_MAC_Base() {}
|
||||||
|
|
||||||
void CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms);
|
void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms);
|
||||||
void Update(const byte *input, size_t length);
|
void Update(const byte *input, size_t length);
|
||||||
void TruncatedFinal(byte *mac, size_t size);
|
void TruncatedFinal(byte *mac, size_t size);
|
||||||
unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
|
unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
|
||||||
|
|
|
||||||
14
cryptlib.cpp
14
cryptlib.cpp
|
|
@ -47,6 +47,12 @@ Algorithm::Algorithm(bool checkSelfTestStatus)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleKeyingInterface::SetKey(const byte *key, size_t length, const NameValuePairs ¶ms)
|
||||||
|
{
|
||||||
|
this->ThrowIfInvalidKeyLength(length);
|
||||||
|
this->UncheckedSetKey(key, (unsigned int)length, params);
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleKeyingInterface::SetKeyWithRounds(const byte *key, size_t length, int rounds)
|
void SimpleKeyingInterface::SetKeyWithRounds(const byte *key, size_t length, int rounds)
|
||||||
{
|
{
|
||||||
SetKey(key, length, MakeParameters(Name::Rounds(), rounds));
|
SetKey(key, length, MakeParameters(Name::Rounds(), rounds));
|
||||||
|
|
@ -57,22 +63,22 @@ void SimpleKeyingInterface::SetKeyWithIV(const byte *key, size_t length, const b
|
||||||
SetKey(key, length, MakeParameters(Name::IV(), iv));
|
SetKey(key, length, MakeParameters(Name::IV(), iv));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleKeyingInterface::ThrowIfInvalidKeyLength(const Algorithm &algorithm, size_t length)
|
void SimpleKeyingInterface::ThrowIfInvalidKeyLength(size_t length)
|
||||||
{
|
{
|
||||||
if (!IsValidKeyLength(length))
|
if (!IsValidKeyLength(length))
|
||||||
throw InvalidKeyLength(algorithm.AlgorithmName(), length);
|
throw InvalidKeyLength(GetAlgorithm().AlgorithmName(), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleKeyingInterface::ThrowIfResynchronizable()
|
void SimpleKeyingInterface::ThrowIfResynchronizable()
|
||||||
{
|
{
|
||||||
if (IsResynchronizable())
|
if (IsResynchronizable())
|
||||||
throw InvalidArgument("SimpleKeyingInterface: this object requires an IV");
|
throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object requires an IV");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv)
|
void SimpleKeyingInterface::ThrowIfInvalidIV(const byte *iv)
|
||||||
{
|
{
|
||||||
if (!iv && !(IVRequirement() == INTERNALLY_GENERATED_IV || IVRequirement() == STRUCTURED_IV || !IsResynchronizable()))
|
if (!iv && !(IVRequirement() == INTERNALLY_GENERATED_IV || IVRequirement() == STRUCTURED_IV || !IsResynchronizable()))
|
||||||
throw InvalidArgument("SimpleKeyingInterface: this object cannot use a null IV");
|
throw InvalidArgument(GetAlgorithm().AlgorithmName() + ": this object cannot use a null IV");
|
||||||
}
|
}
|
||||||
|
|
||||||
const byte * SimpleKeyingInterface::GetIVAndThrowIfInvalid(const NameValuePairs ¶ms)
|
const byte * SimpleKeyingInterface::GetIVAndThrowIfInvalid(const NameValuePairs ¶ms)
|
||||||
|
|
|
||||||
18
cryptlib.dsp
18
cryptlib.dsp
|
|
@ -27,7 +27,7 @@ CFG=cryptlib - Win32 Debug
|
||||||
# PROP AllowPerConfigDependencies 0
|
# PROP AllowPerConfigDependencies 0
|
||||||
# PROP Scc_ProjName ""
|
# PROP Scc_ProjName ""
|
||||||
# PROP Scc_LocalPath ""
|
# PROP Scc_LocalPath ""
|
||||||
CPP=xicl6.exe
|
CPP=cl.exe
|
||||||
RSC=rc.exe
|
RSC=rc.exe
|
||||||
|
|
||||||
!IF "$(CFG)" == "cryptlib - Win32 DLL-Import Release"
|
!IF "$(CFG)" == "cryptlib - Win32 DLL-Import Release"
|
||||||
|
|
@ -49,7 +49,7 @@ RSC=rc.exe
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LIB32=xilink6.exe -lib
|
LIB32=link.exe -lib
|
||||||
# ADD BASE LIB32 /nologo
|
# ADD BASE LIB32 /nologo
|
||||||
# ADD LIB32 /nologo
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ LIB32=xilink6.exe -lib
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LIB32=xilink6.exe -lib
|
LIB32=link.exe -lib
|
||||||
# ADD BASE LIB32 /nologo
|
# ADD BASE LIB32 /nologo
|
||||||
# ADD LIB32 /nologo
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ LIB32=xilink6.exe -lib
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LIB32=xilink6.exe -lib
|
LIB32=link.exe -lib
|
||||||
# ADD BASE LIB32 /nologo
|
# ADD BASE LIB32 /nologo
|
||||||
# ADD LIB32 /nologo
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
|
@ -118,7 +118,7 @@ LIB32=xilink6.exe -lib
|
||||||
BSC32=bscmake.exe
|
BSC32=bscmake.exe
|
||||||
# ADD BASE BSC32 /nologo
|
# ADD BASE BSC32 /nologo
|
||||||
# ADD BSC32 /nologo
|
# ADD BSC32 /nologo
|
||||||
LIB32=xilink6.exe -lib
|
LIB32=link.exe -lib
|
||||||
# ADD BASE LIB32 /nologo
|
# ADD BASE LIB32 /nologo
|
||||||
# ADD LIB32 /nologo
|
# ADD LIB32 /nologo
|
||||||
|
|
||||||
|
|
@ -528,6 +528,10 @@ SOURCE=.\safer.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\salsa.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\seal.cpp
|
SOURCE=.\seal.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
@ -1012,6 +1016,10 @@ SOURCE=.\safer.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\salsa.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\seal.h
|
SOURCE=.\seal.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
|
||||||
19
cryptlib.h
19
cryptlib.h
|
|
@ -367,7 +367,7 @@ public:
|
||||||
|
|
||||||
//! set or reset the key of this object
|
//! set or reset the key of this object
|
||||||
/*! \param params is used to specify Rounds, BlockSize, etc */
|
/*! \param params is used to specify Rounds, BlockSize, etc */
|
||||||
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs) =0;
|
virtual void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs);
|
||||||
|
|
||||||
//! calls SetKey() with an NameValuePairs object that just specifies "Rounds"
|
//! calls SetKey() with an NameValuePairs object that just specifies "Rounds"
|
||||||
void SetKeyWithRounds(const byte *key, size_t length, int rounds);
|
void SetKeyWithRounds(const byte *key, size_t length, int rounds);
|
||||||
|
|
@ -400,15 +400,15 @@ public:
|
||||||
virtual void GetNextIV(byte *IV) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support GetNextIV()");}
|
virtual void GetNextIV(byte *IV) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support GetNextIV()");}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ThrowIfInvalidKeyLength(const Algorithm &algorithm, size_t length);
|
virtual const Algorithm & GetAlgorithm() const =0;
|
||||||
|
virtual void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) =0;
|
||||||
|
|
||||||
|
void ThrowIfInvalidKeyLength(size_t length);
|
||||||
void ThrowIfResynchronizable(); // to be called when no IV is passed
|
void ThrowIfResynchronizable(); // to be called when no IV is passed
|
||||||
void ThrowIfInvalidIV(const byte *iv); // check for NULL IV if it can't be used
|
void ThrowIfInvalidIV(const byte *iv); // check for NULL IV if it can't be used
|
||||||
const byte * GetIVAndThrowIfInvalid(const NameValuePairs ¶ms);
|
const byte * GetIVAndThrowIfInvalid(const NameValuePairs ¶ms);
|
||||||
|
|
||||||
inline void AssertValidKeyLength(size_t length) const
|
inline void AssertValidKeyLength(size_t length) const
|
||||||
{
|
{assert(IsValidKeyLength(length));}
|
||||||
assert(IsValidKeyLength(length));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! interface for the data processing part of block ciphers
|
//! interface for the data processing part of block ciphers
|
||||||
|
|
@ -451,6 +451,8 @@ public:
|
||||||
|
|
||||||
//! encrypt or decrypt multiple blocks, for bit-slicing implementations
|
//! encrypt or decrypt multiple blocks, for bit-slicing implementations
|
||||||
virtual void ProcessAndXorMultipleBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t numberOfBlocks) const;
|
virtual void ProcessAndXorMultipleBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, size_t numberOfBlocks) const;
|
||||||
|
|
||||||
|
inline CipherDir GetCipherDirection() const {return IsForwardTransformation() ? ENCRYPTION : DECRYPTION;}
|
||||||
};
|
};
|
||||||
|
|
||||||
//! interface for the data processing part of stream ciphers
|
//! interface for the data processing part of stream ciphers
|
||||||
|
|
@ -590,9 +592,8 @@ typedef HashTransformation HashFunction;
|
||||||
template <class T>
|
template <class T>
|
||||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyedTransformation : public T, public SimpleKeyingInterface
|
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyedTransformation : public T, public SimpleKeyingInterface
|
||||||
{
|
{
|
||||||
public:
|
protected:
|
||||||
void ThrowIfInvalidKeyLength(size_t length)
|
const Algorithm & GetAlgorithm() const {return *this;}
|
||||||
{SimpleKeyingInterface::ThrowIfInvalidKeyLength(*this, length);}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CRYPTOPP_DOXYGEN_PROCESSING
|
#ifdef CRYPTOPP_DOXYGEN_PROCESSING
|
||||||
|
|
|
||||||
|
|
@ -363,7 +363,10 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
|
||||||
while (buffer[0] != 0);
|
while (buffer[0] != 0);
|
||||||
is.clear();
|
is.clear();
|
||||||
is.ignore();
|
is.ignore();
|
||||||
|
|
||||||
|
if (!value.empty() && value[value.size()-1] == '\r')
|
||||||
|
value.resize(value.size()-1);
|
||||||
|
|
||||||
if (!value.empty() && value[value.size()-1] == '\\')
|
if (!value.empty() && value[value.size()-1] == '\\')
|
||||||
{
|
{
|
||||||
value.resize(value.size()-1);
|
value.resize(value.size()-1);
|
||||||
|
|
|
||||||
31
des.cpp
31
des.cpp
|
|
@ -264,7 +264,7 @@ static const int bytebit[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Set key (initialize key schedule array) */
|
/* Set key (initialize key schedule array) */
|
||||||
void RawDES::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
|
void RawDES::RawSetKey(CipherDir dir, const byte *key)
|
||||||
{
|
{
|
||||||
SecByteBlock buffer(56+56+8);
|
SecByteBlock buffer(56+56+8);
|
||||||
byte *const pc1m=buffer; /* place to modify pc1 into */
|
byte *const pc1m=buffer; /* place to modify pc1 into */
|
||||||
|
|
@ -345,12 +345,19 @@ void RawDES::RawProcessBlock(word32 &l_, word32 &r_) const
|
||||||
l_ = l; r_ = r;
|
l_ = l; r_ = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DES_EDE2::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
|
void DES::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
m_des1.UncheckedSetKey(dir, key);
|
RawSetKey(GetCipherDirection(), userKey);
|
||||||
m_des2.UncheckedSetKey(ReverseCipherDir(dir), key+8);
|
}
|
||||||
|
|
||||||
|
void DES_EDE2::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
|
||||||
|
{
|
||||||
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
|
m_des1.RawSetKey(GetCipherDirection(), userKey);
|
||||||
|
m_des2.RawSetKey(ReverseCipherDir(GetCipherDirection()), userKey+8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DES_EDE2::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
void DES_EDE2::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||||
|
|
@ -365,13 +372,13 @@ void DES_EDE2::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBloc
|
||||||
Block::Put(xorBlock, outBlock)(r)(l);
|
Block::Put(xorBlock, outBlock)(r)(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DES_EDE3::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
|
void DES_EDE3::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
m_des1.UncheckedSetKey(dir, key+(dir==ENCRYPTION?0:2*8));
|
m_des1.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 0 : 16));
|
||||||
m_des2.UncheckedSetKey(ReverseCipherDir(dir), key+8);
|
m_des2.RawSetKey(ReverseCipherDir(GetCipherDirection()), userKey + 8);
|
||||||
m_des3.UncheckedSetKey(dir, key+(dir==DECRYPTION?0:2*8));
|
m_des3.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 16 : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DES_EDE3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
void DES_EDE3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||||
|
|
@ -420,16 +427,16 @@ void DES::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by
|
||||||
Block::Put(xorBlock, outBlock)(r)(l);
|
Block::Put(xorBlock, outBlock)(r)(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DES_XEX3::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
|
void DES_XEX3::Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
if (!m_des.get())
|
if (!m_des.get())
|
||||||
m_des.reset(new DES::Encryption);
|
m_des.reset(new DES::Encryption);
|
||||||
|
|
||||||
memcpy(m_x1, key+(dir==ENCRYPTION?0:2*8), BLOCKSIZE);
|
memcpy(m_x1, key + (IsForwardTransformation() ? 0 : 16), BLOCKSIZE);
|
||||||
m_des->UncheckedSetKey(dir, key+8);
|
m_des->RawSetKey(GetCipherDirection(), key + 8);
|
||||||
memcpy(m_x3, key+(dir==DECRYPTION?0:2*8), BLOCKSIZE);
|
memcpy(m_x3, key + (IsForwardTransformation() ? 16 : 0), BLOCKSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DES_XEX3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
void DES_XEX3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||||
|
|
|
||||||
9
des.h
9
des.h
|
|
@ -12,7 +12,7 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||||
class CRYPTOPP_DLL RawDES
|
class CRYPTOPP_DLL RawDES
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length = 8);
|
void RawSetKey(CipherDir direction, const byte *userKey);
|
||||||
void RawProcessBlock(word32 &l, word32 &r) const;
|
void RawProcessBlock(word32 &l, word32 &r) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -38,6 +38,7 @@ class DES : public DES_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -63,7 +64,7 @@ class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
|
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -87,7 +88,7 @@ class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
|
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -111,7 +112,7 @@ class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
4
dmac.h
4
dmac.h
|
|
@ -16,7 +16,7 @@ public:
|
||||||
|
|
||||||
DMAC_Base() {}
|
DMAC_Base() {}
|
||||||
|
|
||||||
void CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms);
|
void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms);
|
||||||
void Update(const byte *input, size_t length);
|
void Update(const byte *input, size_t length);
|
||||||
void TruncatedFinal(byte *mac, size_t size);
|
void TruncatedFinal(byte *mac, size_t size);
|
||||||
unsigned int DigestSize() const {return DIGESTSIZE;}
|
unsigned int DigestSize() const {return DIGESTSIZE;}
|
||||||
|
|
@ -45,7 +45,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void DMAC_Base<T>::CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms)
|
void DMAC_Base<T>::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);
|
m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);
|
||||||
m_subkeys.resize(2*UnsignedMin((unsigned int)T::BLOCKSIZE, m_subkeylength));
|
m_subkeys.resize(2*UnsignedMin((unsigned int)T::BLOCKSIZE, m_subkeylength));
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#define _WIN32_WINNT 0x0400
|
#define _WIN32_WINNT 0x0400
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 14
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
#define _CRT_DEBUGGER_HOOK _crt_debugger_hook
|
#define _CRT_DEBUGGER_HOOK _crt_debugger_hook
|
||||||
#else
|
#else
|
||||||
|
|
@ -277,7 +277,7 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
|
||||||
char moduleFilenameBuf[MAX_PATH] = "";
|
char moduleFilenameBuf[MAX_PATH] = "";
|
||||||
if (moduleFilename == NULL)
|
if (moduleFilename == NULL)
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER // ifstream doesn't support wide filename on gcc 3.4.4 cygwin
|
#if (defined(_MSC_VER) && _MSC_VER >= 1400) // ifstream doesn't support wide filename on other compilers
|
||||||
wchar_t wideModuleFilename[MAX_PATH];
|
wchar_t wideModuleFilename[MAX_PATH];
|
||||||
if (GetModuleFileNameW(s_hModule, wideModuleFilename, MAX_PATH) > 0)
|
if (GetModuleFileNameW(s_hModule, wideModuleFilename, MAX_PATH) > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -363,7 +363,7 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 14
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
// first byte of _CRT_DEBUGGER_HOOK gets modified in memory by the debugger invisibly, so read it from file
|
// first byte of _CRT_DEBUGGER_HOOK gets modified in memory by the debugger invisibly, so read it from file
|
||||||
if (IsDebuggerPresent())
|
if (IsDebuggerPresent())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
2
gost.cpp
2
gost.cpp
|
|
@ -30,7 +30,7 @@ const byte GOST::Base::sBox[8][16]={
|
||||||
bool GOST::Base::sTableCalculated = false;
|
bool GOST::Base::sTableCalculated = false;
|
||||||
word32 GOST::Base::sTable[4][256];
|
word32 GOST::Base::sTable[4][256];
|
||||||
|
|
||||||
void GOST::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
|
void GOST::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
|
|
|
||||||
2
gost.h
2
gost.h
|
|
@ -21,7 +21,7 @@ class GOST : public GOST_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<GOST_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<GOST_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void PrecalculateSTable();
|
static void PrecalculateSTable();
|
||||||
|
|
|
||||||
2
hmac.cpp
2
hmac.cpp
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength)
|
void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylength);
|
AssertValidKeyLength(keylength);
|
||||||
|
|
||||||
|
|
|
||||||
2
hmac.h
2
hmac.h
|
|
@ -13,7 +13,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HMAC_Base : public VariableKeyLength<16, 0
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HMAC_Base() : m_innerHashKeyed(false) {}
|
HMAC_Base() : m_innerHashKeyed(false) {}
|
||||||
void UncheckedSetKey(const byte *userKey, unsigned int keylength);
|
void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
void Restart();
|
void Restart();
|
||||||
void Update(const byte *input, size_t length);
|
void Update(const byte *input, size_t length);
|
||||||
|
|
|
||||||
4
idea.cpp
4
idea.cpp
|
|
@ -78,7 +78,7 @@ inline void IDEA::Base::LookupMUL(IDEA::Word &a, IDEA::Word b)
|
||||||
}
|
}
|
||||||
#endif // IDEA_LARGECACHE
|
#endif // IDEA_LARGECACHE
|
||||||
|
|
||||||
void IDEA::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
|
void IDEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ void IDEA::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsig
|
||||||
|
|
||||||
EnKey(userKey);
|
EnKey(userKey);
|
||||||
|
|
||||||
if (direction==DECRYPTION)
|
if (!IsForwardTransformation())
|
||||||
DeKey();
|
DeKey();
|
||||||
|
|
||||||
#ifdef IDEA_LARGECACHE
|
#ifdef IDEA_LARGECACHE
|
||||||
|
|
|
||||||
2
idea.h
2
idea.h
|
|
@ -32,7 +32,7 @@ private:
|
||||||
unsigned int GetAlignment() const {return 2;}
|
unsigned int GetAlignment() const {return 2;}
|
||||||
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
|
||||||
|
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EnKey(const byte *);
|
void EnKey(const byte *);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class LR : public LR_Info<T>, public BlockCipherDocumentation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// VC60 workaround: have to define these functions within class definition
|
// VC60 workaround: have to define these functions within class definition
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
this->AssertValidKeyLength(length);
|
this->AssertValidKeyLength(length);
|
||||||
|
|
||||||
|
|
|
||||||
2
mars.cpp
2
mars.cpp
|
|
@ -38,7 +38,7 @@ static word32 gen_mask(word32 x)
|
||||||
};
|
};
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|
||||||
void MARS::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
|
void MARS::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
|
|
|
||||||
2
mars.h
2
mars.h
|
|
@ -21,7 +21,7 @@ class MARS : public MARS_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<MARS_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<MARS_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static const word32 Sbox[512];
|
static const word32 Sbox[512];
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const word32 MD5MAC_Base::T[12] =
|
||||||
0x96ce77b1,0x7c8e722e,0x0aab5a5f,0x18be4336,
|
0x96ce77b1,0x7c8e722e,0x0aab5a5f,0x18be4336,
|
||||||
0x21b4219d,0x4db987bc,0xbd279da2,0xc3d75bc7 };
|
0x21b4219d,0x4db987bc,0xbd279da2,0xc3d75bc7 };
|
||||||
|
|
||||||
void MD5MAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength)
|
void MD5MAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
const word32 zeros[4] = {0,0,0,0};
|
const word32 zeros[4] = {0,0,0,0};
|
||||||
|
|
||||||
|
|
|
||||||
2
md5mac.h
2
md5mac.h
|
|
@ -17,7 +17,7 @@ public:
|
||||||
|
|
||||||
MD5MAC_Base() {SetStateSize(DIGESTSIZE);}
|
MD5MAC_Base() {SetStateSize(DIGESTSIZE);}
|
||||||
|
|
||||||
void UncheckedSetKey(const byte *userKey, unsigned int keylength);
|
void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms);
|
||||||
void TruncatedFinal(byte *mac, size_t size);
|
void TruncatedFinal(byte *mac, size_t size);
|
||||||
unsigned int DigestSize() const {return DIGESTSIZE;}
|
unsigned int DigestSize() const {return DIGESTSIZE;}
|
||||||
|
|
||||||
|
|
|
||||||
3
mdc.h
3
mdc.h
|
|
@ -28,9 +28,8 @@ class MDC : public MDC_Info<T>
|
||||||
typedef typename T::HashWordType HashWordType;
|
typedef typename T::HashWordType HashWordType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
assert(direction == ENCRYPTION);
|
|
||||||
this->AssertValidKeyLength(length);
|
this->AssertValidKeyLength(length);
|
||||||
memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH);
|
memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH);
|
||||||
T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
|
T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,6 @@ void Modes_TestInstantiations()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CipherModeBase::SetKey(const byte *key, size_t length, const NameValuePairs ¶ms)
|
|
||||||
{
|
|
||||||
UncheckedSetKey(params, key, (unsigned int)length, GetIVAndThrowIfInvalid(params)); // the underlying cipher will check the key length
|
|
||||||
}
|
|
||||||
|
|
||||||
void CipherModeBase::GetNextIV(byte *IV)
|
void CipherModeBase::GetNextIV(byte *IV)
|
||||||
{
|
{
|
||||||
if (!IsForwardTransformation())
|
if (!IsForwardTransformation())
|
||||||
|
|
@ -102,12 +97,12 @@ void CTR_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv)
|
||||||
CopyOrZero(m_counterArray, iv, s);
|
CopyOrZero(m_counterArray, iv, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockOrientedCipherModeBase::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv)
|
void BlockOrientedCipherModeBase::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
m_cipher->SetKey(key, length, params);
|
m_cipher->SetKey(key, length, params);
|
||||||
ResizeBuffers();
|
ResizeBuffers();
|
||||||
if (IsResynchronizable())
|
if (IsResynchronizable())
|
||||||
Resynchronize(iv);
|
Resynchronize(GetIVAndThrowIfInvalid(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockOrientedCipherModeBase::ProcessData(byte *outString, const byte *inString, size_t length)
|
void BlockOrientedCipherModeBase::ProcessData(byte *outString, const byte *inString, size_t length)
|
||||||
|
|
|
||||||
9
modes.h
9
modes.h
|
|
@ -37,8 +37,6 @@ public:
|
||||||
size_t GetValidKeyLength(size_t n) const {return m_cipher->GetValidKeyLength(n);}
|
size_t GetValidKeyLength(size_t n) const {return m_cipher->GetValidKeyLength(n);}
|
||||||
bool IsValidKeyLength(size_t n) const {return m_cipher->IsValidKeyLength(n);}
|
bool IsValidKeyLength(size_t n) const {return m_cipher->IsValidKeyLength(n);}
|
||||||
|
|
||||||
void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs);
|
|
||||||
|
|
||||||
unsigned int OptimalDataAlignment() const {return BlockSize();}
|
unsigned int OptimalDataAlignment() const {return BlockSize();}
|
||||||
|
|
||||||
unsigned int IVSize() const {return BlockSize();}
|
unsigned int IVSize() const {return BlockSize();}
|
||||||
|
|
@ -56,7 +54,6 @@ protected:
|
||||||
{
|
{
|
||||||
m_register.New(m_cipher->BlockSize());
|
m_register.New(m_cipher->BlockSize());
|
||||||
}
|
}
|
||||||
virtual void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv) =0;
|
|
||||||
|
|
||||||
BlockCipher *m_cipher;
|
BlockCipher *m_cipher;
|
||||||
SecByteBlock m_register;
|
SecByteBlock m_register;
|
||||||
|
|
@ -171,7 +168,7 @@ private:
|
||||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
|
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv);
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
|
||||||
unsigned int MandatoryBlockSize() const {return BlockSize();}
|
unsigned int MandatoryBlockSize() const {return BlockSize();}
|
||||||
bool IsRandomAccess() const {return false;}
|
bool IsRandomAccess() const {return false;}
|
||||||
bool IsSelfInverting() const {return false;}
|
bool IsSelfInverting() const {return false;}
|
||||||
|
|
@ -225,9 +222,9 @@ public:
|
||||||
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";}
|
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv)
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
CBC_Encryption::UncheckedSetKey(params, key, length, iv);
|
CBC_Encryption::UncheckedSetKey(key, length, params);
|
||||||
m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), (byte *)NULL);
|
m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), (byte *)NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
panama.h
2
panama.h
|
|
@ -46,7 +46,7 @@ template <class T_Hash, class T_Info = T_Hash>
|
||||||
class HermeticHashFunctionMAC : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<MessageAuthenticationCode, VariableKeyLength<32, 0, UINT_MAX> > >, T_Info>
|
class HermeticHashFunctionMAC : public AlgorithmImpl<SimpleKeyingInterfaceImpl<TwoBases<MessageAuthenticationCode, VariableKeyLength<32, 0, UINT_MAX> > >, T_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs)
|
void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
m_key.Assign(key, length);
|
m_key.Assign(key, length);
|
||||||
Restart();
|
Restart();
|
||||||
|
|
|
||||||
14
rc2.cpp
14
rc2.cpp
|
|
@ -3,13 +3,18 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "rc2.h"
|
#include "rc2.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "argnames.h"
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void RC2::Base::UncheckedSetKey(CipherDir direction, const byte *key, unsigned int keyLen, unsigned int effectiveLen)
|
void RC2::Base::UncheckedSetKey(const byte *key, unsigned int keyLen, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keyLen);
|
AssertValidKeyLength(keyLen);
|
||||||
|
|
||||||
|
int effectiveLen = params.GetIntValueWithDefault(Name::EffectiveKeyLength(), DEFAULT_EFFECTIVE_KEYLENGTH);
|
||||||
|
if (effectiveLen > MAX_EFFECTIVE_KEYLENGTH)
|
||||||
|
throw InvalidArgument("RC2: effective key length parameter exceeds maximum");
|
||||||
|
|
||||||
static const unsigned char PITABLE[256] = {
|
static const unsigned char PITABLE[256] = {
|
||||||
217,120,249,196, 25,221,181,237, 40,233,253,121, 74,160,216,157,
|
217,120,249,196, 25,221,181,237, 40,233,253,121, 74,160,216,157,
|
||||||
198,126, 55,131, 43,118, 83,142, 98, 76,100,136, 68,139,251,162,
|
198,126, 55,131, 43,118, 83,142, 98, 76,100,136, 68,139,251,162,
|
||||||
|
|
@ -46,13 +51,6 @@ void RC2::Base::UncheckedSetKey(CipherDir direction, const byte *key, unsigned i
|
||||||
K[i] = L[2*i] + (L[2*i+1] << 8);
|
K[i] = L[2*i] + (L[2*i+1] << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RC2::Base::SetKeyWithEffectiveKeyLength(const byte *key, size_t length, unsigned int effectiveKeyLength)
|
|
||||||
{
|
|
||||||
if (effectiveKeyLength > MAX_EFFECTIVE_KEYLENGTH)
|
|
||||||
throw InvalidArgument("RC2: effective key length parameter exceeds maximum");
|
|
||||||
UncheckedSetKey(ENCRYPTION, key, (unsigned int)length, effectiveKeyLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef BlockGetAndPut<word16, LittleEndian> Block;
|
typedef BlockGetAndPut<word16, LittleEndian> Block;
|
||||||
|
|
||||||
void RC2::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
void RC2::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||||
|
|
|
||||||
24
rc2.h
24
rc2.h
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "seckey.h"
|
#include "seckey.h"
|
||||||
#include "secblock.h"
|
#include "secblock.h"
|
||||||
|
#include "algparam.h"
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
|
|
@ -22,18 +23,9 @@ class RC2 : public RC2_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *key, unsigned int length, unsigned int effectiveKeyLength);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
void SetKeyWithEffectiveKeyLength(const byte *key, size_t length, unsigned int effectiveKeyLength);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <class T>
|
|
||||||
static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m)
|
|
||||||
{
|
|
||||||
obj->ThrowIfInvalidKeyLength(length);
|
|
||||||
int effectiveKeyLength = param.GetIntValueWithDefault("EffectiveKeyLength", DEFAULT_EFFECTIVE_KEYLENGTH);
|
|
||||||
obj->SetKeyWithEffectiveKeyLength(key, length, effectiveKeyLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
FixedSizeSecBlock<word16, 64> K; // expanded key table
|
FixedSizeSecBlock<word16, 64> K; // expanded key table
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -54,16 +46,20 @@ public:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Encryption() {}
|
Encryption() {}
|
||||||
Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024)
|
Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
|
||||||
{SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);}
|
{SetKey(key, keyLen);}
|
||||||
|
Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
|
||||||
|
{SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
|
class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Decryption() {}
|
Decryption() {}
|
||||||
Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024)
|
Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
|
||||||
{SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);}
|
{SetKey(key, keyLen);}
|
||||||
|
Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
|
||||||
|
{SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
5
rc5.cpp
5
rc5.cpp
|
|
@ -6,12 +6,11 @@
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void RC5::Base::UncheckedSetKey(CipherDir direction, const byte *k, unsigned int keylen, unsigned int rounds)
|
void RC5::Base::UncheckedSetKey(const byte *k, unsigned int keylen, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylen);
|
AssertValidKeyLength(keylen);
|
||||||
AssertValidRounds(rounds);
|
|
||||||
|
|
||||||
r = rounds;
|
r = GetRoundsAndThrowIfInvalid(params, this);
|
||||||
sTable.New(2*(r+1));
|
sTable.New(2*(r+1));
|
||||||
|
|
||||||
static const RC5_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize
|
static const RC5_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize
|
||||||
|
|
|
||||||
2
rc5.h
2
rc5.h
|
|
@ -22,7 +22,7 @@ class RC5 : public RC5_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC5_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC5_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int r; // number of rounds
|
unsigned int r; // number of rounds
|
||||||
|
|
|
||||||
5
rc6.cpp
5
rc6.cpp
|
|
@ -7,12 +7,11 @@
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void RC6::Base::UncheckedSetKey(CipherDir direction, const byte *k, unsigned int keylen, unsigned int rounds)
|
void RC6::Base::UncheckedSetKey(const byte *k, unsigned int keylen, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylen);
|
AssertValidKeyLength(keylen);
|
||||||
AssertValidRounds(rounds);
|
|
||||||
|
|
||||||
r = rounds;
|
r = GetRoundsAndThrowIfInvalid(params, this);
|
||||||
sTable.New(2*(r+2));
|
sTable.New(2*(r+2));
|
||||||
|
|
||||||
static const RC6_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize
|
static const RC6_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize
|
||||||
|
|
|
||||||
2
rc6.h
2
rc6.h
|
|
@ -22,7 +22,7 @@ class RC6 : public RC6_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC6_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC6_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int r; // number of rounds
|
unsigned int r; // number of rounds
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ being unloaded from L1 cache, until that round is finished.
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void Rijndael::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned int keylen)
|
void Rijndael::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylen);
|
AssertValidKeyLength(keylen);
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ void Rijndael::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigne
|
||||||
rk += keylen/4;
|
rk += keylen/4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir == DECRYPTION)
|
if (!IsForwardTransformation())
|
||||||
{
|
{
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
rk = m_key;
|
rk = m_key;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class CRYPTOPP_DLL Rijndael : public Rijndael_Info, public BlockCipherDocumentat
|
||||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Rijndael_Info>
|
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Rijndael_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// VS2005 workaround: have to put these on seperate lines, or error C2487 is triggered in DLL build
|
// VS2005 workaround: have to put these on seperate lines, or error C2487 is triggered in DLL build
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "safer.h"
|
#include "safer.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "argnames.h"
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
|
|
@ -50,8 +51,11 @@ const byte SAFER::Base::log_tab[256] =
|
||||||
static const unsigned int BLOCKSIZE = 8;
|
static const unsigned int BLOCKSIZE = 8;
|
||||||
static const unsigned int MAX_ROUNDS = 13;
|
static const unsigned int MAX_ROUNDS = 13;
|
||||||
|
|
||||||
void SAFER::Base::UncheckedSetKey(CipherDir dir, const byte *userkey_1, unsigned int length, unsigned nof_rounds)
|
void SAFER::Base::UncheckedSetKey(const byte *userkey_1, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
|
bool strengthened = Strengthened();
|
||||||
|
unsigned int nof_rounds = params.GetIntValueWithDefault(Name::Rounds(), length == 8 ? (strengthened ? 8 : 6) : 10);
|
||||||
|
|
||||||
const byte *userkey_2 = length == 8 ? userkey_1 : userkey_1 + 8;
|
const byte *userkey_2 = length == 8 ? userkey_1 : userkey_1 + 8;
|
||||||
keySchedule.New(1 + BLOCKSIZE * (1 + 2 * nof_rounds));
|
keySchedule.New(1 + BLOCKSIZE * (1 + 2 * nof_rounds));
|
||||||
|
|
||||||
|
|
@ -69,6 +73,7 @@ void SAFER::Base::UncheckedSetKey(CipherDir dir, const byte *userkey_1, unsigned
|
||||||
ka[BLOCKSIZE] ^= ka[j] = rotlFixed(userkey_1[j], 5U);
|
ka[BLOCKSIZE] ^= ka[j] = rotlFixed(userkey_1[j], 5U);
|
||||||
kb[BLOCKSIZE] ^= kb[j] = *key++ = userkey_2[j];
|
kb[BLOCKSIZE] ^= kb[j] = *key++ = userkey_2[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i <= nof_rounds; i++)
|
for (i = 1; i <= nof_rounds; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < BLOCKSIZE + 1; j++)
|
for (j = 0; j < BLOCKSIZE + 1; j++)
|
||||||
|
|
|
||||||
47
safer.h
47
safer.h
|
|
@ -17,9 +17,11 @@ public:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned int GetAlignment() const {return 1;}
|
unsigned int GetAlignment() const {return 1;}
|
||||||
void UncheckedSetKey(CipherDir dir, const byte *userkey, unsigned int length, unsigned nof_rounds);
|
void UncheckedSetKey(const byte *userkey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool Strengthened() const =0;
|
||||||
|
|
||||||
bool strengthened;
|
|
||||||
SecByteBlock keySchedule;
|
SecByteBlock keySchedule;
|
||||||
static const byte exp_tab[256];
|
static const byte exp_tab[256];
|
||||||
static const byte log_tab[256];
|
static const byte log_tab[256];
|
||||||
|
|
@ -38,58 +40,39 @@ public:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class BASE, class INFO, bool STR>
|
||||||
|
class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
bool Strengthened() const {return STR;}
|
||||||
|
};
|
||||||
|
|
||||||
//! _
|
//! _
|
||||||
struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
|
struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
|
||||||
{
|
{
|
||||||
static const char *StaticAlgorithmName() {return "SAFER-K";}
|
static const char *StaticAlgorithmName() {return "SAFER-K";}
|
||||||
static unsigned int DefaultRounds(unsigned int keylength) {return keylength == 8 ? 6 : 10;}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-K">SAFER-K</a>
|
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-K">SAFER-K</a>
|
||||||
class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
|
class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
|
||||||
{
|
{
|
||||||
class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<SAFER_K_Info, SAFER::Enc>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Enc() {strengthened = false;}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CRYPTOPP_NO_VTABLE Dec : public BlockCipherImpl<SAFER_K_Info, SAFER::Dec>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Dec() {strengthened = false;}
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
|
typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_K_Info, false> > Encryption;
|
||||||
typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
|
typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_K_Info, false> > Decryption;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! _
|
//! _
|
||||||
struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
|
struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
|
||||||
{
|
{
|
||||||
static const char *StaticAlgorithmName() {return "SAFER-SK";}
|
static const char *StaticAlgorithmName() {return "SAFER-SK";}
|
||||||
static unsigned int DefaultRounds(unsigned int keylength) {return keylength == 8 ? 8 : 10;}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-SK">SAFER-SK</a>
|
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-SK">SAFER-SK</a>
|
||||||
class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
|
class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
|
||||||
{
|
{
|
||||||
class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<SAFER_SK_Info, SAFER::Enc>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Enc() {strengthened = true;}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CRYPTOPP_NO_VTABLE Dec : public BlockCipherImpl<SAFER_SK_Info, SAFER::Dec>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Dec() {strengthened = true;}
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
|
typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_SK_Info, true> > Encryption;
|
||||||
typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
|
typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_SK_Info, true> > Decryption;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SAFER_K::Encryption SAFER_K_Encryption;
|
typedef SAFER_K::Encryption SAFER_K_Encryption;
|
||||||
|
|
|
||||||
59
seckey.h
59
seckey.h
|
|
@ -32,17 +32,6 @@ class FixedRounds
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum {ROUNDS = R};
|
enum {ROUNDS = R};
|
||||||
|
|
||||||
protected:
|
|
||||||
template <class T>
|
|
||||||
static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m)
|
|
||||||
{
|
|
||||||
obj->ThrowIfInvalidKeyLength(length);
|
|
||||||
int rounds = param.GetIntValueWithDefault("Rounds", ROUNDS);
|
|
||||||
if (rounds != ROUNDS)
|
|
||||||
throw InvalidRounds(obj->StaticAlgorithmName(), rounds);
|
|
||||||
obj->UncheckedSetKey(dir, key, (unsigned int)length);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! to be inherited by ciphers with variable number of rounds
|
//! to be inherited by ciphers with variable number of rounds
|
||||||
|
|
@ -59,14 +48,17 @@ protected:
|
||||||
assert(rounds >= (unsigned int)MIN_ROUNDS && rounds <= (unsigned int)MAX_ROUNDS);
|
assert(rounds >= (unsigned int)MIN_ROUNDS && rounds <= (unsigned int)MAX_ROUNDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg)
|
||||||
static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m)
|
|
||||||
{
|
{
|
||||||
obj->ThrowIfInvalidKeyLength(length);
|
|
||||||
int rounds = param.GetIntValueWithDefault("Rounds", obj->StaticGetDefaultRounds(length));
|
|
||||||
if (rounds < (int)MIN_ROUNDS || rounds > (int)MAX_ROUNDS)
|
if (rounds < (int)MIN_ROUNDS || rounds > (int)MAX_ROUNDS)
|
||||||
throw InvalidRounds(obj->AlgorithmName(), rounds);
|
throw InvalidRounds(alg->AlgorithmName(), rounds);
|
||||||
obj->UncheckedSetKey(dir, key, (unsigned int)length, rounds);
|
}
|
||||||
|
|
||||||
|
inline unsigned int GetRoundsAndThrowIfInvalid(const NameValuePairs ¶m, const Algorithm *alg)
|
||||||
|
{
|
||||||
|
int rounds = param.GetIntValueWithDefault("Rounds", DEFAULT_ROUNDS);
|
||||||
|
ThrowIfInvalidRounds(rounds, alg);
|
||||||
|
return (unsigned int)rounds;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -123,20 +115,6 @@ public:
|
||||||
|
|
||||||
// ************** implementation helper for SimpledKeyed ***************
|
// ************** implementation helper for SimpledKeyed ***************
|
||||||
|
|
||||||
template <class T>
|
|
||||||
static inline void CheckedSetKey(T *obj, Empty empty, const byte *key, size_t length, const NameValuePairs ¶m)
|
|
||||||
{
|
|
||||||
obj->ThrowIfInvalidKeyLength(length);
|
|
||||||
obj->UncheckedSetKey(key, (unsigned int)length);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m)
|
|
||||||
{
|
|
||||||
obj->ThrowIfInvalidKeyLength(length);
|
|
||||||
obj->UncheckedSetKey(dir, key, (unsigned int)length);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! _
|
//! _
|
||||||
template <class BASE, class INFO = BASE>
|
template <class BASE, class INFO = BASE>
|
||||||
class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE
|
class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE
|
||||||
|
|
@ -147,9 +125,6 @@ public:
|
||||||
size_t DefaultKeyLength() const {return INFO::DEFAULT_KEYLENGTH;}
|
size_t DefaultKeyLength() const {return INFO::DEFAULT_KEYLENGTH;}
|
||||||
size_t GetValidKeyLength(size_t n) const {return INFO::StaticGetValidKeyLength(n);}
|
size_t GetValidKeyLength(size_t n) const {return INFO::StaticGetValidKeyLength(n);}
|
||||||
typename BASE::IV_Requirement IVRequirement() const {return (typename BASE::IV_Requirement)INFO::IV_REQUIREMENT;}
|
typename BASE::IV_Requirement IVRequirement() const {return (typename BASE::IV_Requirement)INFO::IV_REQUIREMENT;}
|
||||||
|
|
||||||
protected:
|
|
||||||
void AssertValidKeyLength(size_t length) {assert(GetValidKeyLength(length) == length);}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class INFO, class BASE = BlockCipher>
|
template <class INFO, class BASE = BlockCipher>
|
||||||
|
|
@ -166,29 +141,19 @@ class BlockCipherFinal : public ClonableImpl<BlockCipherFinal<DIR, BASE>, BASE>
|
||||||
public:
|
public:
|
||||||
BlockCipherFinal() {}
|
BlockCipherFinal() {}
|
||||||
BlockCipherFinal(const byte *key)
|
BlockCipherFinal(const byte *key)
|
||||||
{SetKey(key, this->DEFAULT_KEYLENGTH);}
|
{this->SetKey(key, this->DEFAULT_KEYLENGTH);}
|
||||||
BlockCipherFinal(const byte *key, size_t length)
|
BlockCipherFinal(const byte *key, size_t length)
|
||||||
{SetKey(key, length);}
|
{this->SetKey(key, length);}
|
||||||
BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
|
BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
|
||||||
{this->SetKeyWithRounds(key, length, rounds);}
|
{this->SetKeyWithRounds(key, length, rounds);}
|
||||||
|
|
||||||
bool IsForwardTransformation() const {return DIR == ENCRYPTION;}
|
bool IsForwardTransformation() const {return DIR == ENCRYPTION;}
|
||||||
|
|
||||||
void SetKey(const byte *key, size_t length, const NameValuePairs ¶m = g_nullNameValuePairs)
|
|
||||||
{
|
|
||||||
CheckedSetKey(this, DIR, key, length, param);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! _
|
//! _
|
||||||
template <class BASE, class INFO = BASE>
|
template <class BASE, class INFO = BASE>
|
||||||
class MessageAuthenticationCodeImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO>
|
class MessageAuthenticationCodeImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO>
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs)
|
|
||||||
{
|
|
||||||
CheckedSetKey(this, Empty(), key, length, params);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! _
|
//! _
|
||||||
|
|
@ -198,7 +163,7 @@ class MessageAuthenticationCodeFinal : public ClonableImpl<MessageAuthentication
|
||||||
public:
|
public:
|
||||||
MessageAuthenticationCodeFinal() {}
|
MessageAuthenticationCodeFinal() {}
|
||||||
MessageAuthenticationCodeFinal(const byte *key)
|
MessageAuthenticationCodeFinal(const byte *key)
|
||||||
{SetKey(key, this->DEFAULT_KEYLENGTH);}
|
{this->SetKey(key, this->DEFAULT_KEYLENGTH);}
|
||||||
MessageAuthenticationCodeFinal(const byte *key, size_t length)
|
MessageAuthenticationCodeFinal(const byte *key, size_t length)
|
||||||
{this->SetKey(key, length);}
|
{this->SetKey(key, length);}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -421,7 +421,7 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||||
c ^= k[4 * r + 2]; \
|
c ^= k[4 * r + 2]; \
|
||||||
d ^= k[4 * r + 3];}
|
d ^= k[4 * r + 3];}
|
||||||
|
|
||||||
void Serpent::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int keylen)
|
void Serpent::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylen);
|
AssertValidKeyLength(keylen);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class Serpent : public Serpent_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Serpent_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Serpent_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FixedSizeSecBlock<word32, 140> m_key;
|
FixedSizeSecBlock<word32, 140> m_key;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||||
#define P(a,b,c,d,e,f,g,h,k) \
|
#define P(a,b,c,d,e,f,g,h,k) \
|
||||||
h-=S0(a)+Maj(a,b,c);d-=h;h-=S1(e)+Ch(e,f,g)+*--k;
|
h-=S0(a)+Maj(a,b,c);d-=h;h-=S1(e)+Ch(e,f,g)+*--k;
|
||||||
|
|
||||||
void SHACAL2::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned int keylen)
|
void SHACAL2::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylen);
|
AssertValidKeyLength(keylen);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class SHACAL2 : public SHACAL2_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHACAL2_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHACAL2_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FixedSizeSecBlock<word32, 64> m_key;
|
FixedSizeSecBlock<word32, 64> m_key;
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,11 @@ static word64 SHARKTransform(word64 a)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHARK::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int keyLen, unsigned int rounds)
|
void SHARK::Base::UncheckedSetKey(const byte *key, unsigned int keyLen, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keyLen);
|
AssertValidKeyLength(keyLen);
|
||||||
AssertValidRounds(rounds);
|
|
||||||
|
|
||||||
m_rounds = rounds;
|
m_rounds = GetRoundsAndThrowIfInvalid(params, this);
|
||||||
m_roundKeys.New(m_rounds+1);
|
m_roundKeys.New(m_rounds+1);
|
||||||
|
|
||||||
// concatenate key enought times to fill a
|
// concatenate key enought times to fill a
|
||||||
|
|
@ -55,7 +54,7 @@ void SHARK::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int k
|
||||||
|
|
||||||
m_roundKeys[m_rounds] = SHARKTransform(m_roundKeys[m_rounds]);
|
m_roundKeys[m_rounds] = SHARKTransform(m_roundKeys[m_rounds]);
|
||||||
|
|
||||||
if (dir == DECRYPTION)
|
if (!IsForwardTransformation())
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
|
|
||||||
2
shark.h
2
shark.h
|
|
@ -25,7 +25,7 @@ class SHARK : public SHARK_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length, unsigned int rounds);
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶m);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int m_rounds;
|
unsigned int m_rounds;
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ const byte SKIPJACK::Base::fTable[256] = {
|
||||||
/**
|
/**
|
||||||
* Preprocess a user key into a table to save an XOR at each F-table access.
|
* Preprocess a user key into a table to save an XOR at each F-table access.
|
||||||
*/
|
*/
|
||||||
void SKIPJACK::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length)
|
void SKIPJACK::Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SKIPJACK_Info>
|
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SKIPJACK_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static const byte fTable[256];
|
static const byte fTable[256];
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ static void SquareTransform (word32 in[4], word32 out[4])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Square::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned int length)
|
void Square::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ void Square::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
/* produce the round keys */
|
/* produce the round keys */
|
||||||
if (dir == ENCRYPTION)
|
if (IsForwardTransformation())
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ROUNDS; i++)
|
for (int i = 0; i < ROUNDS; i++)
|
||||||
SquareTransform (roundkeys[i], roundkeys[i]);
|
SquareTransform (roundkeys[i], roundkeys[i]);
|
||||||
|
|
|
||||||
2
square.h
2
square.h
|
|
@ -21,7 +21,7 @@ class Square : public Square_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Square_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Square_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FixedSizeSecBlock<word32[4], ROUNDS+1> roundkeys;
|
FixedSizeSecBlock<word32[4], ROUNDS+1> roundkeys;
|
||||||
|
|
|
||||||
22
strciphr.h
22
strciphr.h
|
|
@ -135,7 +135,7 @@ public:
|
||||||
typedef typename BASE::PolicyInterface PolicyInterface;
|
typedef typename BASE::PolicyInterface PolicyInterface;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv);
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
unsigned int GetBufferByteSize(const PolicyInterface &policy) const {return policy.GetBytesPerIteration() * policy.GetIterationsToBuffer();}
|
unsigned int GetBufferByteSize(const PolicyInterface &policy) const {return policy.GetBytesPerIteration() * policy.GetIterationsToBuffer();}
|
||||||
|
|
||||||
|
|
@ -233,7 +233,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length) =0;
|
virtual void CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length) =0;
|
||||||
|
|
||||||
void UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv);
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
size_t m_leftOver;
|
size_t m_leftOver;
|
||||||
};
|
};
|
||||||
|
|
@ -266,23 +266,17 @@ class SymmetricCipherFinal : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE
|
||||||
public:
|
public:
|
||||||
SymmetricCipherFinal() {}
|
SymmetricCipherFinal() {}
|
||||||
SymmetricCipherFinal(const byte *key)
|
SymmetricCipherFinal(const byte *key)
|
||||||
{SetKey(key, this->DEFAULT_KEYLENGTH);}
|
{this->SetKey(key, this->DEFAULT_KEYLENGTH);}
|
||||||
SymmetricCipherFinal(const byte *key, size_t length)
|
SymmetricCipherFinal(const byte *key, size_t length)
|
||||||
{SetKey(key, length);}
|
{this->SetKey(key, length);}
|
||||||
SymmetricCipherFinal(const byte *key, size_t length, const byte *iv)
|
SymmetricCipherFinal(const byte *key, size_t length, const byte *iv)
|
||||||
{this->SetKeyWithIV(key, length, iv);}
|
{this->SetKeyWithIV(key, length, iv);}
|
||||||
|
|
||||||
void SetKey(const byte *key, size_t length, const NameValuePairs ¶ms = g_nullNameValuePairs)
|
|
||||||
{
|
|
||||||
this->ThrowIfInvalidKeyLength(length);
|
|
||||||
this->UncheckedSetKey(params, key, (unsigned int)length, this->GetIVAndThrowIfInvalid(params));
|
|
||||||
}
|
|
||||||
|
|
||||||
Clonable * Clone() const {return static_cast<SymmetricCipher *>(new SymmetricCipherFinal<BASE, INFO>(*this));}
|
Clonable * Clone() const {return static_cast<SymmetricCipher *>(new SymmetricCipherFinal<BASE, INFO>(*this));}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class S>
|
template <class S>
|
||||||
void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv)
|
void AdditiveCipherTemplate<S>::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
PolicyInterface &policy = this->AccessPolicy();
|
PolicyInterface &policy = this->AccessPolicy();
|
||||||
policy.CipherSetKey(params, key, length);
|
policy.CipherSetKey(params, key, length);
|
||||||
|
|
@ -290,17 +284,17 @@ void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs ¶ms, co
|
||||||
m_buffer.New(GetBufferByteSize(policy));
|
m_buffer.New(GetBufferByteSize(policy));
|
||||||
|
|
||||||
if (this->IsResynchronizable())
|
if (this->IsResynchronizable())
|
||||||
policy.CipherResynchronize(m_buffer, iv);
|
policy.CipherResynchronize(m_buffer, this->GetIVAndThrowIfInvalid(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class BASE>
|
template <class BASE>
|
||||||
void CFB_CipherTemplate<BASE>::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv)
|
void CFB_CipherTemplate<BASE>::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
PolicyInterface &policy = this->AccessPolicy();
|
PolicyInterface &policy = this->AccessPolicy();
|
||||||
policy.CipherSetKey(params, key, length);
|
policy.CipherSetKey(params, key, length);
|
||||||
|
|
||||||
if (this->IsResynchronizable())
|
if (this->IsResynchronizable())
|
||||||
policy.CipherResynchronize(iv);
|
policy.CipherResynchronize(this->GetIVAndThrowIfInvalid(params));
|
||||||
|
|
||||||
m_leftOver = policy.GetBytesPerIteration();
|
m_leftOver = policy.GetBytesPerIteration();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
tea.cpp
8
tea.cpp
|
|
@ -9,12 +9,12 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||||
static const word32 DELTA = 0x9e3779b9;
|
static const word32 DELTA = 0x9e3779b9;
|
||||||
typedef BlockGetAndPut<word32, BigEndian> Block;
|
typedef BlockGetAndPut<word32, BigEndian> Block;
|
||||||
|
|
||||||
void TEA::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds)
|
void TEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, userKey, KEYLENGTH);
|
GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, userKey, KEYLENGTH);
|
||||||
m_limit = rounds * DELTA;
|
m_limit = GetRoundsAndThrowIfInvalid(params, this) * DELTA;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
void TEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||||
|
|
@ -49,12 +49,12 @@ void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
|
||||||
Block::Put(xorBlock, outBlock)(y)(z);
|
Block::Put(xorBlock, outBlock)(y)(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XTEA::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds)
|
void XTEA::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(length);
|
AssertValidKeyLength(length);
|
||||||
|
|
||||||
GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, userKey, KEYLENGTH);
|
GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, userKey, KEYLENGTH);
|
||||||
m_limit = rounds * DELTA;
|
m_limit = GetRoundsAndThrowIfInvalid(params, this) * DELTA;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||||
|
|
|
||||||
12
tea.h
12
tea.h
|
|
@ -21,7 +21,7 @@ class TEA : public TEA_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FixedSizeSecBlock<word32, 4> m_k;
|
FixedSizeSecBlock<word32, 4> m_k;
|
||||||
|
|
@ -60,7 +60,7 @@ class XTEA : public XTEA_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FixedSizeSecBlock<word32, 4> m_k;
|
FixedSizeSecBlock<word32, 4> m_k;
|
||||||
|
|
@ -97,12 +97,10 @@ class BTEA : public BTEA_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info
|
class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template <class T>
|
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||||
static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m)
|
|
||||||
{
|
{
|
||||||
obj->ThrowIfInvalidKeyLength(length);
|
m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
|
||||||
obj->m_blockSize = param.GetIntValueWithDefault("BlockSize", 60*4);
|
GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
|
||||||
GetUserKey(BIG_ENDIAN_ORDER, obj->m_k.begin(), 4, key, KEYLENGTH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int BlockSize() const {return m_blockSize;}
|
unsigned int BlockSize() const {return m_blockSize;}
|
||||||
|
|
|
||||||
3
test.cpp
3
test.cpp
|
|
@ -749,6 +749,7 @@ bool Validate(int alg, bool thorough, const char *seed)
|
||||||
|
|
||||||
switch (alg)
|
switch (alg)
|
||||||
{
|
{
|
||||||
|
case 0: result = ValidateAll(thorough); break;
|
||||||
case 1: result = TestSettings(); break;
|
case 1: result = TestSettings(); break;
|
||||||
case 2: result = TestOS_RNG(); break;
|
case 2: result = TestOS_RNG(); break;
|
||||||
case 3: result = ValidateMD5(); break;
|
case 3: result = ValidateMD5(); break;
|
||||||
|
|
@ -812,7 +813,7 @@ bool Validate(int alg, bool thorough, const char *seed)
|
||||||
case 62: result = ValidateWhirlpool(); break;
|
case 62: result = ValidateWhirlpool(); break;
|
||||||
case 63: result = ValidateTTMAC(); break;
|
case 63: result = ValidateTTMAC(); break;
|
||||||
case 64: result = ValidateSalsa(); break;
|
case 64: result = ValidateSalsa(); break;
|
||||||
default: result = ValidateAll(thorough); break;
|
default: return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t endTime = time(NULL);
|
time_t endTime = time(NULL);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
NAMESPACE_BEGIN(CryptoPP)
|
NAMESPACE_BEGIN(CryptoPP)
|
||||||
|
|
||||||
void TTMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength)
|
void TTMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylength);
|
AssertValidKeyLength(keylength);
|
||||||
|
|
||||||
|
|
|
||||||
2
ttmac.h
2
ttmac.h
|
|
@ -18,7 +18,7 @@ public:
|
||||||
TTMAC_Base() {SetStateSize(DIGESTSIZE*2);}
|
TTMAC_Base() {SetStateSize(DIGESTSIZE*2);}
|
||||||
|
|
||||||
unsigned int DigestSize() const {return DIGESTSIZE;};
|
unsigned int DigestSize() const {return DIGESTSIZE;};
|
||||||
void UncheckedSetKey(const byte *userKey, unsigned int keylength);
|
void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs ¶ms);
|
||||||
void TruncatedFinal(byte *mac, size_t size);
|
void TruncatedFinal(byte *mac, size_t size);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ inline word32 Twofish::Base::h(word32 x, const word32 *key, unsigned int kLen)
|
||||||
return mds[0][GETBYTE(x,0)] ^ mds[1][GETBYTE(x,1)] ^ mds[2][GETBYTE(x,2)] ^ mds[3][GETBYTE(x,3)];
|
return mds[0][GETBYTE(x,0)] ^ mds[1][GETBYTE(x,1)] ^ mds[2][GETBYTE(x,2)] ^ mds[3][GETBYTE(x,3)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Twofish::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned int keylength)
|
void Twofish::Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &)
|
||||||
{
|
{
|
||||||
AssertValidKeyLength(keylength);
|
AssertValidKeyLength(keylength);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class Twofish : public Twofish_Info, public BlockCipherDocumentation
|
||||||
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Twofish_Info>
|
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Twofish_Info>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
|
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static word32 h0(word32 x, const word32 *key, unsigned int kLen);
|
static word32 h0(word32 x, const word32 *key, unsigned int kLen);
|
||||||
|
|
|
||||||
6
xormac.h
6
xormac.h
|
|
@ -23,7 +23,7 @@ public:
|
||||||
|
|
||||||
XMACC_Base() {SetStateSize(T::DIGESTSIZE);}
|
XMACC_Base() {SetStateSize(T::DIGESTSIZE);}
|
||||||
|
|
||||||
void CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms);
|
void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms);
|
||||||
void Resynchronize(const byte *IV)
|
void Resynchronize(const byte *IV)
|
||||||
{
|
{
|
||||||
GetWord(false, BIG_ENDIAN_ORDER, m_counter, IV);
|
GetWord(false, BIG_ENDIAN_ORDER, m_counter, IV);
|
||||||
|
|
@ -70,9 +70,9 @@ public:
|
||||||
{this->SetKey(key, this->KEYLENGTH, MakeParameters(Name::XMACC_Counter(), counter));}
|
{this->SetKey(key, this->KEYLENGTH, MakeParameters(Name::XMACC_Counter(), counter));}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T> void XMACC_Base<T>::CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms)
|
template <class T> void XMACC_Base<T>::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms)
|
||||||
{
|
{
|
||||||
this->ThrowIfInvalidKeyLength(length);
|
this->AssertValidKeyLength(length);
|
||||||
m_counter = 0xffffffff;
|
m_counter = 0xffffffff;
|
||||||
const byte *iv = NULL;
|
const byte *iv = NULL;
|
||||||
if (params.GetValue(Name::IV(), iv))
|
if (params.GetValue(Name::IV(), iv))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue