summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--3way.cpp7
-rw-r--r--3way.h2
-rw-r--r--GNUmakefile4
-rw-r--r--arc4.cpp2
-rw-r--r--arc4.h2
-rw-r--r--blowfish.cpp4
-rw-r--r--blowfish.h2
-rw-r--r--camellia.cpp4
-rw-r--r--camellia.h2
-rw-r--r--cast.cpp6
-rw-r--r--cast.h4
-rw-r--r--cbcmac.cpp2
-rw-r--r--cbcmac.h2
-rw-r--r--cryptlib.cpp14
-rw-r--r--cryptlib.dsp18
-rw-r--r--cryptlib.h19
-rw-r--r--datatest.cpp5
-rw-r--r--des.cpp31
-rw-r--r--des.h9
-rw-r--r--dmac.h4
-rw-r--r--fipstest.cpp6
-rw-r--r--gost.cpp2
-rw-r--r--gost.h2
-rw-r--r--hmac.cpp2
-rw-r--r--hmac.h2
-rw-r--r--idea.cpp4
-rw-r--r--idea.h2
-rw-r--r--lubyrack.h2
-rw-r--r--mars.cpp2
-rw-r--r--mars.h2
-rw-r--r--md5mac.cpp2
-rw-r--r--md5mac.h2
-rw-r--r--mdc.h3
-rw-r--r--modes.cpp9
-rw-r--r--modes.h9
-rw-r--r--panama.h2
-rw-r--r--rc2.cpp14
-rw-r--r--rc2.h24
-rw-r--r--rc5.cpp5
-rw-r--r--rc5.h2
-rw-r--r--rc6.cpp5
-rw-r--r--rc6.h2
-rw-r--r--rijndael.cpp4
-rw-r--r--rijndael.h2
-rw-r--r--safer.cpp7
-rw-r--r--safer.h47
-rw-r--r--seckey.h59
-rw-r--r--serpent.cpp2
-rw-r--r--serpent.h2
-rw-r--r--shacal2.cpp2
-rw-r--r--shacal2.h2
-rw-r--r--shark.cpp7
-rw-r--r--shark.h2
-rw-r--r--skipjack.cpp2
-rw-r--r--skipjack.h2
-rw-r--r--square.cpp4
-rw-r--r--square.h2
-rw-r--r--strciphr.h22
-rw-r--r--tea.cpp8
-rw-r--r--tea.h12
-rw-r--r--test.cpp3
-rw-r--r--ttmac.cpp2
-rw-r--r--ttmac.h2
-rw-r--r--twofish.cpp2
-rw-r--r--twofish.h2
-rw-r--r--xormac.h6
66 files changed, 203 insertions, 250 deletions
diff --git a/3way.cpp b/3way.cpp
index 0b7d4f2..725b682 100644
--- a/3way.cpp
+++ b/3way.cpp
@@ -61,17 +61,16 @@ static inline word32 reverseBits(word32 a)
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 &params)
{
AssertValidKeyLength(length);
- AssertValidRounds(r);
- m_rounds = r;
+ m_rounds = GetRoundsAndThrowIfInvalid(params, this);
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);
- if (dir == DECRYPTION)
+ if (!IsForwardTransformation())
{
theta(m_k[0], m_k[1], m_k[2]);
mu(m_k[0], m_k[1], m_k[2]);
diff --git a/3way.h b/3way.h
index 026af1c..33a619e 100644
--- a/3way.h
+++ b/3way.h
@@ -21,7 +21,7 @@ class ThreeWay : public ThreeWay_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<ThreeWay_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *key, unsigned int length, unsigned int rounds);
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
protected:
unsigned int m_rounds;
diff --git a/GNUmakefile b/GNUmakefile
index 7e7358d..baf650c 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -3,9 +3,9 @@ CXXFLAGS = -g
# 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++.
# 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.
-# CXXFLAGS = -O2 -DNDEBUG -ffunction-sections -fdata-sections
+# CXXFLAGS = -O3 -DNDEBUG -ffunction-sections -fdata-sections
# LDFLAGS += -Wl,--gc-sections
ARFLAGS = -cr # ar needs the dash on OpenBSD
RANLIB = ranlib
diff --git a/arc4.cpp b/arc4.cpp
index 2ee6857..b78b756 100644
--- a/arc4.cpp
+++ b/arc4.cpp
@@ -21,7 +21,7 @@ ARC4_Base::~ARC4_Base()
m_x = m_y = 0;
}
-void ARC4_Base::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int keyLen, const byte *iv)
+void ARC4_Base::UncheckedSetKey(const byte *key, unsigned int keyLen, const NameValuePairs &params)
{
AssertValidKeyLength(keyLen);
diff --git a/arc4.h b/arc4.h
index 510f03c..78f85cd 100644
--- a/arc4.h
+++ b/arc4.h
@@ -26,7 +26,7 @@ public:
typedef SymmetricCipherFinal<ARC4_Base> Decryption;
protected:
- void UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv);
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
FixedSizeSecBlock<byte, 256> m_state;
diff --git a/blowfish.cpp b/blowfish.cpp
index fa6c723..aaa637c 100644
--- a/blowfish.cpp
+++ b/blowfish.cpp
@@ -6,7 +6,7 @@
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);
@@ -35,7 +35,7 @@ void Blowfish::Base::UncheckedSetKey(CipherDir dir, const byte *key_string, unsi
for (i=0; i<4*256-2; i+=2)
crypt_block(sbox+i, sbox+i+2);
- if (dir==DECRYPTION)
+ if (!IsForwardTransformation())
for (i=0; i<(ROUNDS+2)/2; i++)
std::swap(pbox[i], pbox[ROUNDS+1-i]);
}
diff --git a/blowfish.h b/blowfish.h
index 9dae786..4707ce1 100644
--- a/blowfish.h
+++ b/blowfish.h
@@ -21,7 +21,7 @@ class Blowfish : public Blowfish_Info, public BlockCipherDocumentation
{
public:
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 &params);
private:
void crypt_block(const word32 in[2], word32 out[2]) const;
diff --git a/camellia.cpp b/camellia.cpp
index 4fff64c..05a1a27 100644
--- a/camellia.cpp
+++ b/camellia.cpp
@@ -56,7 +56,7 @@ inline void rotl128(word64 *x, unsigned int bits)
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);
@@ -171,7 +171,7 @@ void Camellia::Base::UncheckedSetKey(CipherDir dir, const byte *key, unsigned in
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[1], ks[kslen-1]);
diff --git a/camellia.h b/camellia.h
index 3e44efa..dd88720 100644
--- a/camellia.h
+++ b/camellia.h
@@ -25,7 +25,7 @@ class Camellia : public Camellia_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Camellia_Info>
{
public:
- void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int keylen);
+ void UncheckedSetKey(const byte *key, unsigned int keylen, const NameValuePairs &params);
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
unsigned int BlockAlignment() const {return 8;}
diff --git a/cast.cpp b/cast.cpp
index c1cc3eb..ef0a5ef 100644
--- a/cast.cpp
+++ b/cast.cpp
@@ -94,7 +94,7 @@ void CAST128::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock,
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);
@@ -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]);
}
-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);
@@ -273,7 +273,7 @@ void CAST256::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned
K[8*i+7]=kappa[1];
}
- if (dir == DECRYPTION)
+ if (!IsForwardTransformation())
{
for(int j=0; j<6; ++j)
{
diff --git a/cast.h b/cast.h
index 36c7465..98bb5d6 100644
--- a/cast.h
+++ b/cast.h
@@ -27,7 +27,7 @@ class CAST128 : public CAST128_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST128_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
bool reduced;
@@ -63,7 +63,7 @@ class CAST256 : public CAST256_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl<CAST256_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length = 8);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
protected:
diff --git a/cbcmac.cpp b/cbcmac.cpp
index 9fcab1e..e262535 100644
--- a/cbcmac.cpp
+++ b/cbcmac.cpp
@@ -6,7 +6,7 @@
NAMESPACE_BEGIN(CryptoPP)
-void CBC_MAC_Base::CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs &params)
+void CBC_MAC_Base::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs &params)
{
AccessCipher().SetKey(key, length, params);
m_reg.CleanNew(AccessCipher().BlockSize());
diff --git a/cbcmac.h b/cbcmac.h
index 1ec6313..30566d0 100644
--- a/cbcmac.h
+++ b/cbcmac.h
@@ -12,7 +12,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_MAC_Base : public MessageAuthenticatio
public:
CBC_MAC_Base() {}
- void CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs &params);
+ void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs &params);
void Update(const byte *input, size_t length);
void TruncatedFinal(byte *mac, size_t size);
unsigned int DigestSize() const {return const_cast<CBC_MAC_Base*>(this)->AccessCipher().BlockSize();}
diff --git a/cryptlib.cpp b/cryptlib.cpp
index fe0d764..642d5f2 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -47,6 +47,12 @@ Algorithm::Algorithm(bool checkSelfTestStatus)
}
}
+void SimpleKeyingInterface::SetKey(const byte *key, size_t length, const NameValuePairs &params)
+{
+ this->ThrowIfInvalidKeyLength(length);
+ this->UncheckedSetKey(key, (unsigned int)length, params);
+}
+
void SimpleKeyingInterface::SetKeyWithRounds(const byte *key, size_t length, int 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));
}
-void SimpleKeyingInterface::ThrowIfInvalidKeyLength(const Algorithm &algorithm, size_t length)
+void SimpleKeyingInterface::ThrowIfInvalidKeyLength(size_t length)
{
if (!IsValidKeyLength(length))
- throw InvalidKeyLength(algorithm.AlgorithmName(), length);
+ throw InvalidKeyLength(GetAlgorithm().AlgorithmName(), length);
}
void SimpleKeyingInterface::ThrowIfResynchronizable()
{
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)
{
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 &params)
diff --git a/cryptlib.dsp b/cryptlib.dsp
index bb2f098..de13a67 100644
--- a/cryptlib.dsp
+++ b/cryptlib.dsp
@@ -27,7 +27,7 @@ CFG=cryptlib - Win32 Debug
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
-CPP=xicl6.exe
+CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "cryptlib - Win32 DLL-Import Release"
@@ -49,7 +49,7 @@ RSC=rc.exe
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
@@ -72,7 +72,7 @@ LIB32=xilink6.exe -lib
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
@@ -95,7 +95,7 @@ LIB32=xilink6.exe -lib
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
@@ -118,7 +118,7 @@ LIB32=xilink6.exe -lib
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=xilink6.exe -lib
+LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
@@ -528,6 +528,10 @@ SOURCE=.\safer.cpp
# End Source File
# Begin Source File
+SOURCE=.\salsa.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\seal.cpp
# End Source File
# Begin Source File
@@ -1012,6 +1016,10 @@ SOURCE=.\safer.h
# End Source File
# Begin Source File
+SOURCE=.\salsa.h
+# End Source File
+# Begin Source File
+
SOURCE=.\seal.h
# End Source File
# Begin Source File
diff --git a/cryptlib.h b/cryptlib.h
index 5851d95..aaa8a31 100644
--- a/cryptlib.h
+++ b/cryptlib.h
@@ -367,7 +367,7 @@ public:
//! set or reset the key of this object
/*! \param params is used to specify Rounds, BlockSize, etc */
- virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs) =0;
+ virtual void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs);
//! calls SetKey() with an NameValuePairs object that just specifies "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()");}
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 &params) =0;
+
+ void ThrowIfInvalidKeyLength(size_t length);
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
const byte * GetIVAndThrowIfInvalid(const NameValuePairs &params);
-
inline void AssertValidKeyLength(size_t length) const
- {
- assert(IsValidKeyLength(length));
- }
+ {assert(IsValidKeyLength(length));}
};
//! interface for the data processing part of block ciphers
@@ -451,6 +451,8 @@ public:
//! encrypt or decrypt multiple blocks, for bit-slicing implementations
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
@@ -590,9 +592,8 @@ typedef HashTransformation HashFunction;
template <class T>
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyedTransformation : public T, public SimpleKeyingInterface
{
-public:
- void ThrowIfInvalidKeyLength(size_t length)
- {SimpleKeyingInterface::ThrowIfInvalidKeyLength(*this, length);}
+protected:
+ const Algorithm & GetAlgorithm() const {return *this;}
};
#ifdef CRYPTOPP_DOXYGEN_PROCESSING
diff --git a/datatest.cpp b/datatest.cpp
index 32b10fb..4a2d950 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -363,7 +363,10 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
while (buffer[0] != 0);
is.clear();
is.ignore();
-
+
+ if (!value.empty() && value[value.size()-1] == '\r')
+ value.resize(value.size()-1);
+
if (!value.empty() && value[value.size()-1] == '\\')
{
value.resize(value.size()-1);
diff --git a/des.cpp b/des.cpp
index af9308c..c176477 100644
--- a/des.cpp
+++ b/des.cpp
@@ -264,7 +264,7 @@ static const int bytebit[] = {
};
/* 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);
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;
}
-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);
- m_des1.UncheckedSetKey(dir, key);
- m_des2.UncheckedSetKey(ReverseCipherDir(dir), key+8);
+ RawSetKey(GetCipherDirection(), userKey);
+}
+
+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
@@ -365,13 +372,13 @@ void DES_EDE2::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBloc
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);
- m_des1.UncheckedSetKey(dir, key+(dir==ENCRYPTION?0:2*8));
- m_des2.UncheckedSetKey(ReverseCipherDir(dir), key+8);
- m_des3.UncheckedSetKey(dir, key+(dir==DECRYPTION?0:2*8));
+ m_des1.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 0 : 16));
+ m_des2.RawSetKey(ReverseCipherDir(GetCipherDirection()), userKey + 8);
+ m_des3.RawSetKey(GetCipherDirection(), userKey + (IsForwardTransformation() ? 16 : 0));
}
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);
}
-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);
if (!m_des.get())
m_des.reset(new DES::Encryption);
- memcpy(m_x1, key+(dir==ENCRYPTION?0:2*8), BLOCKSIZE);
- m_des->UncheckedSetKey(dir, key+8);
- memcpy(m_x3, key+(dir==DECRYPTION?0:2*8), BLOCKSIZE);
+ memcpy(m_x1, key + (IsForwardTransformation() ? 0 : 16), BLOCKSIZE);
+ m_des->RawSetKey(GetCipherDirection(), key + 8);
+ memcpy(m_x3, key + (IsForwardTransformation() ? 16 : 0), BLOCKSIZE);
}
void DES_XEX3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
diff --git a/des.h b/des.h
index 8400fa1..62f6288 100644
--- a/des.h
+++ b/des.h
@@ -12,7 +12,7 @@ NAMESPACE_BEGIN(CryptoPP)
class CRYPTOPP_DLL RawDES
{
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;
protected:
@@ -38,6 +38,7 @@ class DES : public DES_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
{
public:
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
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>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
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>
{
public:
- void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
protected:
@@ -111,7 +112,7 @@ class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
{
public:
- void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
protected:
diff --git a/dmac.h b/dmac.h
index fc4c283..d7522f7 100644
--- a/dmac.h
+++ b/dmac.h
@@ -16,7 +16,7 @@ public:
DMAC_Base() {}
- void CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs &params);
+ void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs &params);
void Update(const byte *input, size_t length);
void TruncatedFinal(byte *mac, size_t size);
unsigned int DigestSize() const {return DIGESTSIZE;}
@@ -45,7 +45,7 @@ public:
};
template <class T>
-void DMAC_Base<T>::CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs &params)
+void DMAC_Base<T>::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs &params)
{
m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE);
m_subkeys.resize(2*UnsignedMin((unsigned int)T::BLOCKSIZE, m_subkeylength));
diff --git a/fipstest.cpp b/fipstest.cpp
index 109e592..2248d10 100644
--- a/fipstest.cpp
+++ b/fipstest.cpp
@@ -11,7 +11,7 @@
#define _WIN32_WINNT 0x0400
#include <windows.h>
-#if defined(_MSC_VER) && _MSC_VER >= 14
+#if defined(_MSC_VER) && _MSC_VER >= 1400
#ifdef _M_IX86
#define _CRT_DEBUGGER_HOOK _crt_debugger_hook
#else
@@ -277,7 +277,7 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
char moduleFilenameBuf[MAX_PATH] = "";
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];
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
if (IsDebuggerPresent())
{
diff --git a/gost.cpp b/gost.cpp
index 1dc2be4..1775238 100644
--- a/gost.cpp
+++ b/gost.cpp
@@ -30,7 +30,7 @@ const byte GOST::Base::sBox[8][16]={
bool GOST::Base::sTableCalculated = false;
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);
diff --git a/gost.h b/gost.h
index 8b513d3..044c18d 100644
--- a/gost.h
+++ b/gost.h
@@ -21,7 +21,7 @@ class GOST : public GOST_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<GOST_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
static void PrecalculateSTable();
diff --git a/hmac.cpp b/hmac.cpp
index aa97aa4..dc9fc9b 100644
--- a/hmac.cpp
+++ b/hmac.cpp
@@ -8,7 +8,7 @@
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);
diff --git a/hmac.h b/hmac.h
index 072e8c6..f6b0fb1 100644
--- a/hmac.h
+++ b/hmac.h
@@ -13,7 +13,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE HMAC_Base : public VariableKeyLength<16, 0
{
public:
HMAC_Base() : m_innerHashKeyed(false) {}
- void UncheckedSetKey(const byte *userKey, unsigned int keylength);
+ void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
void Restart();
void Update(const byte *input, size_t length);
diff --git a/idea.cpp b/idea.cpp
index 85d933a..b0768fa 100644
--- a/idea.cpp
+++ b/idea.cpp
@@ -78,7 +78,7 @@ inline void IDEA::Base::LookupMUL(IDEA::Word &a, IDEA::Word b)
}
#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);
@@ -88,7 +88,7 @@ void IDEA::Base::UncheckedSetKey(CipherDir direction, const byte *userKey, unsig
EnKey(userKey);
- if (direction==DECRYPTION)
+ if (!IsForwardTransformation())
DeKey();
#ifdef IDEA_LARGECACHE
diff --git a/idea.h b/idea.h
index d7314a7..d823f8f 100644
--- a/idea.h
+++ b/idea.h
@@ -32,7 +32,7 @@ private:
unsigned int GetAlignment() const {return 2;}
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 &params);
private:
void EnKey(const byte *);
diff --git a/lubyrack.h b/lubyrack.h
index 424152a..af3a77b 100644
--- a/lubyrack.h
+++ b/lubyrack.h
@@ -27,7 +27,7 @@ class LR : public LR_Info<T>, public BlockCipherDocumentation
{
public:
// 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 &params)
{
this->AssertValidKeyLength(length);
diff --git a/mars.cpp b/mars.cpp
index 804c9b1..06811b5 100644
--- a/mars.cpp
+++ b/mars.cpp
@@ -38,7 +38,7 @@ static word32 gen_mask(word32 x)
};
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);
diff --git a/mars.h b/mars.h
index 22a9be7..ad0cd36 100644
--- a/mars.h
+++ b/mars.h
@@ -21,7 +21,7 @@ class MARS : public MARS_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<MARS_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
static const word32 Sbox[512];
diff --git a/md5mac.cpp b/md5mac.cpp
index 2c3b212..ea2d125 100644
--- a/md5mac.cpp
+++ b/md5mac.cpp
@@ -12,7 +12,7 @@ const word32 MD5MAC_Base::T[12] =
0x96ce77b1,0x7c8e722e,0x0aab5a5f,0x18be4336,
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};
diff --git a/md5mac.h b/md5mac.h
index fc83308..318dde8 100644
--- a/md5mac.h
+++ b/md5mac.h
@@ -17,7 +17,7 @@ public:
MD5MAC_Base() {SetStateSize(DIGESTSIZE);}
- void UncheckedSetKey(const byte *userKey, unsigned int keylength);
+ void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
void TruncatedFinal(byte *mac, size_t size);
unsigned int DigestSize() const {return DIGESTSIZE;}
diff --git a/mdc.h b/mdc.h
index 7091fe8..3512089 100644
--- a/mdc.h
+++ b/mdc.h
@@ -28,9 +28,8 @@ class MDC : public MDC_Info<T>
typedef typename T::HashWordType HashWordType;
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length)
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params)
{
- assert(direction == ENCRYPTION);
this->AssertValidKeyLength(length);
memcpy_s(m_key, m_key.size(), userKey, this->KEYLENGTH);
T::CorrectEndianess(Key(), Key(), this->KEYLENGTH);
diff --git a/modes.cpp b/modes.cpp
index 941a0dc..cdd4c26 100644
--- a/modes.cpp
+++ b/modes.cpp
@@ -24,11 +24,6 @@ void Modes_TestInstantiations()
}
#endif
-void CipherModeBase::SetKey(const byte *key, size_t length, const NameValuePairs &params)
-{
- UncheckedSetKey(params, key, (unsigned int)length, GetIVAndThrowIfInvalid(params)); // the underlying cipher will check the key length
-}
-
void CipherModeBase::GetNextIV(byte *IV)
{
if (!IsForwardTransformation())
@@ -102,12 +97,12 @@ void CTR_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv)
CopyOrZero(m_counterArray, iv, s);
}
-void BlockOrientedCipherModeBase::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv)
+void BlockOrientedCipherModeBase::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
m_cipher->SetKey(key, length, params);
ResizeBuffers();
if (IsResynchronizable())
- Resynchronize(iv);
+ Resynchronize(GetIVAndThrowIfInvalid(params));
}
void BlockOrientedCipherModeBase::ProcessData(byte *outString, const byte *inString, size_t length)
diff --git a/modes.h b/modes.h
index c4e875e..04e5016 100644
--- a/modes.h
+++ b/modes.h
@@ -37,8 +37,6 @@ public:
size_t GetValidKeyLength(size_t n) const {return m_cipher->GetValidKeyLength(n);}
bool IsValidKeyLength(size_t n) const {return m_cipher->IsValidKeyLength(n);}
- void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs);
-
unsigned int OptimalDataAlignment() const {return BlockSize();}
unsigned int IVSize() const {return BlockSize();}
@@ -56,7 +54,6 @@ protected:
{
m_register.New(m_cipher->BlockSize());
}
- virtual void UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv) =0;
BlockCipher *m_cipher;
SecByteBlock m_register;
@@ -171,7 +168,7 @@ private:
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase
{
public:
- void UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv);
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
unsigned int MandatoryBlockSize() const {return BlockSize();}
bool IsRandomAccess() const {return false;}
bool IsSelfInverting() const {return false;}
@@ -225,9 +222,9 @@ public:
static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";}
protected:
- void UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv)
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
- CBC_Encryption::UncheckedSetKey(params, key, length, iv);
+ CBC_Encryption::UncheckedSetKey(key, length, params);
m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), (byte *)NULL);
}
diff --git a/panama.h b/panama.h
index ff55c51..ce34c73 100644
--- a/panama.h
+++ b/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>
{
public:
- void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs)
+ void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs &params)
{
m_key.Assign(key, length);
Restart();
diff --git a/rc2.cpp b/rc2.cpp
index d15ce3d..48df2ef 100644
--- a/rc2.cpp
+++ b/rc2.cpp
@@ -3,13 +3,18 @@
#include "pch.h"
#include "rc2.h"
#include "misc.h"
+#include "argnames.h"
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 &params)
{
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] = {
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,
@@ -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);
}
-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;
void RC2::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
diff --git a/rc2.h b/rc2.h
index 4e86ec4..8a619ab 100644
--- a/rc2.h
+++ b/rc2.h
@@ -6,6 +6,7 @@
#include "seckey.h"
#include "secblock.h"
+#include "algparam.h"
NAMESPACE_BEGIN(CryptoPP)
@@ -22,18 +23,9 @@ class RC2 : public RC2_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *key, unsigned int length, unsigned int effectiveKeyLength);
- void SetKeyWithEffectiveKeyLength(const byte *key, size_t length, unsigned int effectiveKeyLength);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
- template <class T>
- static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs &param)
- {
- obj->ThrowIfInvalidKeyLength(length);
- int effectiveKeyLength = param.GetIntValueWithDefault("EffectiveKeyLength", DEFAULT_EFFECTIVE_KEYLENGTH);
- obj->SetKeyWithEffectiveKeyLength(key, length, effectiveKeyLength);
- }
-
FixedSizeSecBlock<word16, 64> K; // expanded key table
};
@@ -54,16 +46,20 @@ public:
{
public:
Encryption() {}
- Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024)
- {SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);}
+ Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
+ {SetKey(key, keyLen);}
+ Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
+ {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
};
class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
{
public:
Decryption() {}
- Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024)
- {SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);}
+ Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
+ {SetKey(key, keyLen);}
+ Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
+ {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
};
};
diff --git a/rc5.cpp b/rc5.cpp
index 3c8259a..2b730de 100644
--- a/rc5.cpp
+++ b/rc5.cpp
@@ -6,12 +6,11 @@
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 &params)
{
AssertValidKeyLength(keylen);
- AssertValidRounds(rounds);
- r = rounds;
+ r = GetRoundsAndThrowIfInvalid(params, this);
sTable.New(2*(r+1));
static const RC5_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize
diff --git a/rc5.h b/rc5.h
index 5dcc1aa..f842a9b 100644
--- a/rc5.h
+++ b/rc5.h
@@ -22,7 +22,7 @@ class RC5 : public RC5_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC5_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
unsigned int r; // number of rounds
diff --git a/rc6.cpp b/rc6.cpp
index 9a39d49..e58cb6a 100644
--- a/rc6.cpp
+++ b/rc6.cpp
@@ -7,12 +7,11 @@
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 &params)
{
AssertValidKeyLength(keylen);
- AssertValidRounds(rounds);
- r = rounds;
+ r = GetRoundsAndThrowIfInvalid(params, this);
sTable.New(2*(r+2));
static const RC6_WORD MAGIC_P = 0xb7e15163L; // magic constant P for wordsize
diff --git a/rc6.h b/rc6.h
index 2059a0c..df3d1ee 100644
--- a/rc6.h
+++ b/rc6.h
@@ -22,7 +22,7 @@ class RC6 : public RC6_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC6_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
unsigned int r; // number of rounds
diff --git a/rijndael.cpp b/rijndael.cpp
index 7131e01..5749c59 100644
--- a/rijndael.cpp
+++ b/rijndael.cpp
@@ -54,7 +54,7 @@ being unloaded from L1 cache, until that round is finished.
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);
@@ -103,7 +103,7 @@ void Rijndael::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigne
rk += keylen/4;
}
- if (dir == DECRYPTION)
+ if (!IsForwardTransformation())
{
unsigned int i, j;
rk = m_key;
diff --git a/rijndael.h b/rijndael.h
index bbe928c..a035da4 100644
--- a/rijndael.h
+++ b/rijndael.h
@@ -21,7 +21,7 @@ class CRYPTOPP_DLL Rijndael : public Rijndael_Info, public BlockCipherDocumentat
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Rijndael_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
// VS2005 workaround: have to put these on seperate lines, or error C2487 is triggered in DLL build
diff --git a/safer.cpp b/safer.cpp
index ef3f90a..d46ca64 100644
--- a/safer.cpp
+++ b/safer.cpp
@@ -3,6 +3,7 @@
#include "pch.h"
#include "safer.h"
#include "misc.h"
+#include "argnames.h"
NAMESPACE_BEGIN(CryptoPP)
@@ -50,8 +51,11 @@ const byte SAFER::Base::log_tab[256] =
static const unsigned int BLOCKSIZE = 8;
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 &params)
{
+ 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;
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);
kb[BLOCKSIZE] ^= kb[j] = *key++ = userkey_2[j];
}
+
for (i = 1; i <= nof_rounds; i++)
{
for (j = 0; j < BLOCKSIZE + 1; j++)
diff --git a/safer.h b/safer.h
index f551b4f..3b51c3f 100644
--- a/safer.h
+++ b/safer.h
@@ -17,9 +17,11 @@ public:
{
public:
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 &params);
+
+ protected:
+ virtual bool Strengthened() const =0;
- bool strengthened;
SecByteBlock keySchedule;
static const byte exp_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>
{
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>
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:
- typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
- typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
+ typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_K_Info, false> > Encryption;
+ 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>
{
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>
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:
- typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
- typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
+ typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_SK_Info, true> > Encryption;
+ typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_SK_Info, true> > Decryption;
};
typedef SAFER_K::Encryption SAFER_K_Encryption;
diff --git a/seckey.h b/seckey.h
index d7f90d2..b5e8824 100644
--- a/seckey.h
+++ b/seckey.h
@@ -32,17 +32,6 @@ class FixedRounds
{
public:
enum {ROUNDS = R};
-
-protected:
- template <class T>
- static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs &param)
- {
- 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
@@ -59,14 +48,17 @@ protected:
assert(rounds >= (unsigned int)MIN_ROUNDS && rounds <= (unsigned int)MAX_ROUNDS);
}
- template <class T>
- static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs &param)
+ inline void ThrowIfInvalidRounds(int rounds, const Algorithm *alg)
{
- obj->ThrowIfInvalidKeyLength(length);
- int rounds = param.GetIntValueWithDefault("Rounds", obj->StaticGetDefaultRounds(length));
if (rounds < (int)MIN_ROUNDS || rounds > (int)MAX_ROUNDS)
- throw InvalidRounds(obj->AlgorithmName(), rounds);
- obj->UncheckedSetKey(dir, key, (unsigned int)length, rounds);
+ throw InvalidRounds(alg->AlgorithmName(), rounds);
+ }
+
+ inline unsigned int GetRoundsAndThrowIfInvalid(const NameValuePairs &param, 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 ***************
-template <class T>
-static inline void CheckedSetKey(T *obj, Empty empty, const byte *key, size_t length, const NameValuePairs &param)
-{
- 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 &param)
-{
- obj->ThrowIfInvalidKeyLength(length);
- obj->UncheckedSetKey(dir, key, (unsigned int)length);
-}
-
//! _
template <class BASE, class INFO = BASE>
class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE
@@ -147,9 +125,6 @@ public:
size_t DefaultKeyLength() const {return INFO::DEFAULT_KEYLENGTH;}
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;}
-
-protected:
- void AssertValidKeyLength(size_t length) {assert(GetValidKeyLength(length) == length);}
};
template <class INFO, class BASE = BlockCipher>
@@ -166,29 +141,19 @@ class BlockCipherFinal : public ClonableImpl<BlockCipherFinal<DIR, BASE>, BASE>
public:
BlockCipherFinal() {}
BlockCipherFinal(const byte *key)
- {SetKey(key, this->DEFAULT_KEYLENGTH);}
+ {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
BlockCipherFinal(const byte *key, size_t length)
- {SetKey(key, length);}
+ {this->SetKey(key, length);}
BlockCipherFinal(const byte *key, size_t length, unsigned int rounds)
{this->SetKeyWithRounds(key, length, rounds);}
bool IsForwardTransformation() const {return DIR == ENCRYPTION;}
-
- void SetKey(const byte *key, size_t length, const NameValuePairs &param = g_nullNameValuePairs)
- {
- CheckedSetKey(this, DIR, key, length, param);
- }
};
//! _
template <class BASE, class INFO = BASE>
class MessageAuthenticationCodeImpl : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE, INFO>, INFO>
{
-public:
- void SetKey(const byte *key, size_t length, const NameValuePairs &params = g_nullNameValuePairs)
- {
- CheckedSetKey(this, Empty(), key, length, params);
- }
};
//! _
@@ -198,7 +163,7 @@ class MessageAuthenticationCodeFinal : public ClonableImpl<MessageAuthentication
public:
MessageAuthenticationCodeFinal() {}
MessageAuthenticationCodeFinal(const byte *key)
- {SetKey(key, this->DEFAULT_KEYLENGTH);}
+ {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
MessageAuthenticationCodeFinal(const byte *key, size_t length)
{this->SetKey(key, length);}
};
diff --git a/serpent.cpp b/serpent.cpp
index 5cef12d..6995646 100644
--- a/serpent.cpp
+++ b/serpent.cpp
@@ -421,7 +421,7 @@ NAMESPACE_BEGIN(CryptoPP)
c ^= k[4 * r + 2]; \
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);
diff --git a/serpent.h b/serpent.h
index c24d202..6aef38e 100644
--- a/serpent.h
+++ b/serpent.h
@@ -21,7 +21,7 @@ class Serpent : public Serpent_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Serpent_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
FixedSizeSecBlock<word32, 140> m_key;
diff --git a/shacal2.cpp b/shacal2.cpp
index 78e4a83..b0360e4 100644
--- a/shacal2.cpp
+++ b/shacal2.cpp
@@ -31,7 +31,7 @@ NAMESPACE_BEGIN(CryptoPP)
#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;
-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);
diff --git a/shacal2.h b/shacal2.h
index 552dafc..66c987f 100644
--- a/shacal2.h
+++ b/shacal2.h
@@ -21,7 +21,7 @@ class SHACAL2 : public SHACAL2_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHACAL2_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
FixedSizeSecBlock<word32, 64> m_key;
diff --git a/shark.cpp b/shark.cpp
index 0408d8e..56277ce 100644
--- a/shark.cpp
+++ b/shark.cpp
@@ -32,12 +32,11 @@ static word64 SHARKTransform(word64 a)
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 &params)
{
AssertValidKeyLength(keyLen);
- AssertValidRounds(rounds);
- m_rounds = rounds;
+ m_rounds = GetRoundsAndThrowIfInvalid(params, this);
m_roundKeys.New(m_rounds+1);
// 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]);
- if (dir == DECRYPTION)
+ if (!IsForwardTransformation())
{
unsigned int i;
diff --git a/shark.h b/shark.h
index ec483f8..398c7f5 100644
--- a/shark.h
+++ b/shark.h
@@ -25,7 +25,7 @@ class SHARK : public SHARK_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SHARK_Info>
{
public:
- void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length, unsigned int rounds);
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &param);
protected:
unsigned int m_rounds;
diff --git a/skipjack.cpp b/skipjack.cpp
index 0fb472d..2405fab 100644
--- a/skipjack.cpp
+++ b/skipjack.cpp
@@ -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.
*/
-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);
diff --git a/skipjack.h b/skipjack.h
index 5bf66e1..d6e4296 100644
--- a/skipjack.h
+++ b/skipjack.h
@@ -21,7 +21,7 @@ class SKIPJACK : public SKIPJACK_Info, public BlockCipherDocumentation
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<SKIPJACK_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
static const byte fTable[256];
diff --git a/square.cpp b/square.cpp
index 9d5466f..3686eac 100644
--- a/square.cpp
+++ b/square.cpp
@@ -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);
@@ -52,7 +52,7 @@ void Square::Base::UncheckedSetKey(CipherDir dir, const byte *userKey, unsigned
}
/* produce the round keys */
- if (dir == ENCRYPTION)
+ if (IsForwardTransformation())
{
for (int i = 0; i < ROUNDS; i++)
SquareTransform (roundkeys[i], roundkeys[i]);
diff --git a/square.h b/square.h
index a1da1cf..c728927 100644
--- a/square.h
+++ b/square.h
@@ -21,7 +21,7 @@ class Square : public Square_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Square_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
FixedSizeSecBlock<word32[4], ROUNDS+1> roundkeys;
diff --git a/strciphr.h b/strciphr.h
index 76d7b3d..e905d7b 100644
--- a/strciphr.h
+++ b/strciphr.h
@@ -135,7 +135,7 @@ public:
typedef typename BASE::PolicyInterface PolicyInterface;
protected:
- void UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv);
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
unsigned int GetBufferByteSize(const PolicyInterface &policy) const {return policy.GetBytesPerIteration() * policy.GetIterationsToBuffer();}
@@ -233,7 +233,7 @@ public:
protected:
virtual void CombineMessageAndShiftRegister(byte *output, byte *reg, const byte *message, size_t length) =0;
- void UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv);
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
size_t m_leftOver;
};
@@ -266,23 +266,17 @@ class SymmetricCipherFinal : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BASE
public:
SymmetricCipherFinal() {}
SymmetricCipherFinal(const byte *key)
- {SetKey(key, this->DEFAULT_KEYLENGTH);}
+ {this->SetKey(key, this->DEFAULT_KEYLENGTH);}
SymmetricCipherFinal(const byte *key, size_t length)
- {SetKey(key, length);}
+ {this->SetKey(key, length);}
SymmetricCipherFinal(const byte *key, size_t length, const byte *iv)
{this->SetKeyWithIV(key, length, iv);}
- void SetKey(const byte *key, size_t length, const NameValuePairs &params = 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));}
};
template <class S>
-void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv)
+void AdditiveCipherTemplate<S>::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
PolicyInterface &policy = this->AccessPolicy();
policy.CipherSetKey(params, key, length);
@@ -290,17 +284,17 @@ void AdditiveCipherTemplate<S>::UncheckedSetKey(const NameValuePairs &params, co
m_buffer.New(GetBufferByteSize(policy));
if (this->IsResynchronizable())
- policy.CipherResynchronize(m_buffer, iv);
+ policy.CipherResynchronize(m_buffer, this->GetIVAndThrowIfInvalid(params));
}
template <class BASE>
-void CFB_CipherTemplate<BASE>::UncheckedSetKey(const NameValuePairs &params, const byte *key, unsigned int length, const byte *iv)
+void CFB_CipherTemplate<BASE>::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
PolicyInterface &policy = this->AccessPolicy();
policy.CipherSetKey(params, key, length);
if (this->IsResynchronizable())
- policy.CipherResynchronize(iv);
+ policy.CipherResynchronize(this->GetIVAndThrowIfInvalid(params));
m_leftOver = policy.GetBytesPerIteration();
}
diff --git a/tea.cpp b/tea.cpp
index a971053..60921d4 100644
--- a/tea.cpp
+++ b/tea.cpp
@@ -9,12 +9,12 @@ NAMESPACE_BEGIN(CryptoPP)
static const word32 DELTA = 0x9e3779b9;
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 &params)
{
AssertValidKeyLength(length);
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
@@ -49,12 +49,12 @@ void TEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byt
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 &params)
{
AssertValidKeyLength(length);
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
diff --git a/tea.h b/tea.h
index c05c98a..d8ddded 100644
--- a/tea.h
+++ b/tea.h
@@ -21,7 +21,7 @@ class TEA : public TEA_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
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>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length, unsigned int rounds);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
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
{
public:
- template <class T>
- static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs &param)
+ void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
{
- obj->ThrowIfInvalidKeyLength(length);
- obj->m_blockSize = param.GetIntValueWithDefault("BlockSize", 60*4);
- GetUserKey(BIG_ENDIAN_ORDER, obj->m_k.begin(), 4, key, KEYLENGTH);
+ m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
+ GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
}
unsigned int BlockSize() const {return m_blockSize;}
diff --git a/test.cpp b/test.cpp
index 6a8f264..7a13bfc 100644
--- a/test.cpp
+++ b/test.cpp
@@ -749,6 +749,7 @@ bool Validate(int alg, bool thorough, const char *seed)
switch (alg)
{
+ case 0: result = ValidateAll(thorough); break;
case 1: result = TestSettings(); break;
case 2: result = TestOS_RNG(); 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 63: result = ValidateTTMAC(); break;
case 64: result = ValidateSalsa(); break;
- default: result = ValidateAll(thorough); break;
+ default: return false;
}
time_t endTime = time(NULL);
diff --git a/ttmac.cpp b/ttmac.cpp
index 7564079..d4ff381 100644
--- a/ttmac.cpp
+++ b/ttmac.cpp
@@ -6,7 +6,7 @@
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);
diff --git a/ttmac.h b/ttmac.h
index 2c8f216..a8ca6d5 100644
--- a/ttmac.h
+++ b/ttmac.h
@@ -18,7 +18,7 @@ public:
TTMAC_Base() {SetStateSize(DIGESTSIZE*2);}
unsigned int DigestSize() const {return DIGESTSIZE;};
- void UncheckedSetKey(const byte *userKey, unsigned int keylength);
+ void UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params);
void TruncatedFinal(byte *mac, size_t size);
protected:
diff --git a/twofish.cpp b/twofish.cpp
index 2371002..e78258d 100644
--- a/twofish.cpp
+++ b/twofish.cpp
@@ -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)];
}
-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);
diff --git a/twofish.h b/twofish.h
index 2ba283d..969fdb2 100644
--- a/twofish.h
+++ b/twofish.h
@@ -21,7 +21,7 @@ class Twofish : public Twofish_Info, public BlockCipherDocumentation
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<Twofish_Info>
{
public:
- void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
+ void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
protected:
static word32 h0(word32 x, const word32 *key, unsigned int kLen);
diff --git a/xormac.h b/xormac.h
index 18a2ae8..7c121d8 100644
--- a/xormac.h
+++ b/xormac.h
@@ -23,7 +23,7 @@ public:
XMACC_Base() {SetStateSize(T::DIGESTSIZE);}
- void CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs &params);
+ void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs &params);
void Resynchronize(const byte *IV)
{
GetWord(false, BIG_ENDIAN_ORDER, m_counter, IV);
@@ -70,9 +70,9 @@ public:
{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 &params)
+template <class T> void XMACC_Base<T>::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs &params)
{
- this->ThrowIfInvalidKeyLength(length);
+ this->AssertValidKeyLength(length);
m_counter = 0xffffffff;
const byte *iv = NULL;
if (params.GetValue(Name::IV(), iv))