From f05ea58bb369988a61438411539ea955e0adf8c2 Mon Sep 17 00:00:00 2001 From: weidai Date: Sun, 10 Dec 2006 02:12:23 +0000 Subject: [PATCH] port to GCC 4, reorganize implementations of SetKey --- 3way.cpp | 7 +++---- 3way.h | 2 +- GNUmakefile | 4 ++-- arc4.cpp | 2 +- arc4.h | 2 +- blowfish.cpp | 4 ++-- blowfish.h | 2 +- camellia.cpp | 4 ++-- camellia.h | 2 +- cast.cpp | 6 +++--- cast.h | 4 ++-- cbcmac.cpp | 2 +- cbcmac.h | 2 +- cryptlib.cpp | 14 +++++++++---- cryptlib.dsp | 18 +++++++++++----- cryptlib.h | 19 +++++++++-------- datatest.cpp | 5 ++++- des.cpp | 31 ++++++++++++++++----------- des.h | 9 ++++---- dmac.h | 4 ++-- fipstest.cpp | 6 +++--- gost.cpp | 2 +- gost.h | 2 +- hmac.cpp | 2 +- hmac.h | 2 +- idea.cpp | 4 ++-- idea.h | 2 +- lubyrack.h | 2 +- mars.cpp | 2 +- mars.h | 2 +- md5mac.cpp | 2 +- md5mac.h | 2 +- mdc.h | 3 +-- modes.cpp | 9 ++------ modes.h | 9 +++----- panama.h | 2 +- rc2.cpp | 14 ++++++------- rc2.h | 24 +++++++++------------ rc5.cpp | 5 ++--- rc5.h | 2 +- rc6.cpp | 5 ++--- rc6.h | 2 +- rijndael.cpp | 4 ++-- rijndael.h | 2 +- safer.cpp | 7 ++++++- safer.h | 47 +++++++++++++---------------------------- seckey.h | 59 +++++++++++----------------------------------------- serpent.cpp | 2 +- serpent.h | 2 +- shacal2.cpp | 2 +- shacal2.h | 2 +- shark.cpp | 7 +++---- shark.h | 2 +- skipjack.cpp | 2 +- skipjack.h | 2 +- square.cpp | 4 ++-- square.h | 2 +- strciphr.h | 22 +++++++------------- tea.cpp | 8 +++---- tea.h | 12 +++++------ test.cpp | 3 ++- ttmac.cpp | 2 +- ttmac.h | 2 +- twofish.cpp | 2 +- twofish.h | 2 +- xormac.h | 6 +++--- 66 files changed, 203 insertions(+), 250 deletions(-) diff --git a/3way.cpp b/3way.cpp index 0b7d4f232..725b682ea 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 ¶ms) { 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 026af1c06..33a619e2f 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 { 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: unsigned int m_rounds; diff --git a/GNUmakefile b/GNUmakefile index 7e7358dce..baf650c25 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 2ee6857e8..b78b75605 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 ¶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); diff --git a/arc4.h b/arc4.h index 510f03cd5..78f85cd00 100644 --- a/arc4.h +++ b/arc4.h @@ -26,7 +26,7 @@ class CRYPTOPP_NO_VTABLE ARC4_Base : public VariableKeyLength<16, 1, 256>, publi typedef SymmetricCipherFinal Decryption; 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;} FixedSizeSecBlock m_state; diff --git a/blowfish.cpp b/blowfish.cpp index fa6c7238d..aaa637cca 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 9dae78651..4707ce192 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 ¶ms); private: void crypt_block(const word32 in[2], word32 out[2]) const; diff --git a/camellia.cpp b/camellia.cpp index 4fff64c9f..05a1a2727 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 3e44efa01..dd887209e 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 { 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; unsigned int BlockAlignment() const {return 8;} diff --git a/cast.cpp b/cast.cpp index c1cc3eb86..ef0a5efdb 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 36c746549..98bb5d6b1 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: bool reduced; @@ -63,7 +63,7 @@ class CAST256 : public CAST256_Info, public BlockCipherDocumentation class CRYPTOPP_NO_VTABLE Base : public CAST, public BlockCipherImpl { 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; protected: diff --git a/cbcmac.cpp b/cbcmac.cpp index 9fcab1ef3..e262535da 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 ¶ms) +void CBC_MAC_Base::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms) { AccessCipher().SetKey(key, length, params); m_reg.CleanNew(AccessCipher().BlockSize()); diff --git a/cbcmac.h b/cbcmac.h index 1ec6313e0..30566d0ff 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 ¶ms); + void UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms); void Update(const byte *input, size_t length); void TruncatedFinal(byte *mac, size_t size); unsigned int DigestSize() const {return const_cast(this)->AccessCipher().BlockSize();} diff --git a/cryptlib.cpp b/cryptlib.cpp index fe0d764b7..642d5f2dd 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 ¶ms) +{ + 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 ¶ms) diff --git a/cryptlib.dsp b/cryptlib.dsp index bb2f09889..de13a676b 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 5851d9594..aaa8a31c9 100644 --- a/cryptlib.h +++ b/cryptlib.h @@ -367,7 +367,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyingInterface //! 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 ¶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" void SetKeyWithRounds(const byte *key, size_t length, int rounds); @@ -400,15 +400,15 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SimpleKeyingInterface 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 ¶ms) =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 ¶ms); - 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 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockTransformation : public Algorithm //! 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 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 32b10fbff..4a2d95044 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 af9308c11..c1764774d 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 8400fa1be..62f628824 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, public RawDES { public: + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 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 { 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; protected: @@ -87,7 +88,7 @@ class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { 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; protected: @@ -111,7 +112,7 @@ class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { 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; protected: diff --git a/dmac.h b/dmac.h index fc4c2839d..d7522f746 100644 --- a/dmac.h +++ b/dmac.h @@ -16,7 +16,7 @@ class CRYPTOPP_NO_VTABLE DMAC_Base : public SameKeyLengthAs, public MessageAu 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 TruncatedFinal(byte *mac, size_t size); unsigned int DigestSize() const {return DIGESTSIZE;} @@ -45,7 +45,7 @@ class DMAC : public MessageAuthenticationCodeFinal > }; template -void DMAC_Base::CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms) +void DMAC_Base::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms) { 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 109e592ba..2248d10c4 100644 --- a/fipstest.cpp +++ b/fipstest.cpp @@ -11,7 +11,7 @@ #define _WIN32_WINNT 0x0400 #include -#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 1dc2be40e..1775238db 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 8b513d37b..044c18d9e 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: static void PrecalculateSTable(); diff --git a/hmac.cpp b/hmac.cpp index aa97aa487..dc9fc9b2a 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 072e8c6ae..f6b0fb132 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 ¶ms); void Restart(); void Update(const byte *input, size_t length); diff --git a/idea.cpp b/idea.cpp index 85d933adf..b0768fad8 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 d7314a7f9..d823f8f63 100644 --- a/idea.h +++ b/idea.h @@ -32,7 +32,7 @@ class IDEA : public IDEA_Info, public BlockCipherDocumentation 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 ¶ms); private: void EnKey(const byte *); diff --git a/lubyrack.h b/lubyrack.h index 424152aaf..af3a77ba1 100644 --- a/lubyrack.h +++ b/lubyrack.h @@ -27,7 +27,7 @@ class LR : public LR_Info, 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 ¶ms) { this->AssertValidKeyLength(length); diff --git a/mars.cpp b/mars.cpp index 804c9b1e0..06811b533 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 22a9be788..ad0cd36bf 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: static const word32 Sbox[512]; diff --git a/md5mac.cpp b/md5mac.cpp index 2c3b21231..ea2d125d9 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 fc83308b3..318dde82a 100644 --- a/md5mac.h +++ b/md5mac.h @@ -17,7 +17,7 @@ class CRYPTOPP_NO_VTABLE MD5MAC_Base : public FixedKeyLength<16>, public Iterate 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); unsigned int DigestSize() const {return DIGESTSIZE;} diff --git a/mdc.h b/mdc.h index 7091fe8be..3512089ef 100644 --- a/mdc.h +++ b/mdc.h @@ -28,9 +28,8 @@ class MDC : public MDC_Info 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 ¶ms) { - 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 941a0dcc5..cdd4c2653 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 ¶ms) -{ - 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 ¶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); 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 c4e875ee2..04e501667 100644 --- a/modes.h +++ b/modes.h @@ -37,8 +37,6 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher 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 ¶ms = g_nullNameValuePairs); - unsigned int OptimalDataAlignment() const {return BlockSize();} unsigned int IVSize() const {return BlockSize();} @@ -56,7 +54,6 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CipherModeBase : public SymmetricCipher { 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; SecByteBlock m_register; @@ -171,7 +168,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CTR_ModePolicy : public ModePolicyCommonTe class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockOrientedCipherModeBase : public CipherModeBase { 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();} bool IsRandomAccess() const {return false;} bool IsSelfInverting() const {return false;} @@ -225,9 +222,9 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CBC_CTS_Encryption : public CBC_Encryption static const char * CRYPTOPP_API StaticAlgorithmName() {return "CBC/CTS";} 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); } diff --git a/panama.h b/panama.h index ff55c51b6..ce34c73d7 100644 --- a/panama.h +++ b/panama.h @@ -46,7 +46,7 @@ template class HermeticHashFunctionMAC : public AlgorithmImpl > >, T_Info> { 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); Restart(); diff --git a/rc2.cpp b/rc2.cpp index d15ce3d12..48df2ef45 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 ¶ms) { 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 Block; void RC2::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const diff --git a/rc2.h b/rc2.h index 4e86ec480..8a619ab1b 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 { 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 ¶ms); protected: - template - 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 K; // expanded key table }; @@ -54,16 +46,20 @@ class RC2 : public RC2_Info, public BlockCipherDocumentation { 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 { 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 3c8259ab9..2b730def7 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 ¶ms) { 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 5dcc1aaf0..f842a9bdf 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 { 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: unsigned int r; // number of rounds diff --git a/rc6.cpp b/rc6.cpp index 9a39d494e..e58cb6ac9 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 ¶ms) { 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 2059a0ce7..df3d1ee4e 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 { 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: unsigned int r; // number of rounds diff --git a/rijndael.cpp b/rijndael.cpp index 7131e016a..5749c59fd 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 bbe928cd1..a035da4c1 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); 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 ef3f90a94..d46ca6417 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 ¶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; 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 f551b4fd2..3b51c3fd6 100644 --- a/safer.h +++ b/safer.h @@ -17,9 +17,11 @@ class SAFER { 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 ¶ms); + + 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 @@ class SAFER }; }; +template +class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl +{ +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;} }; /// SAFER-K class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation { - class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl - { - public: - Enc() {strengthened = false;} - }; - - class CRYPTOPP_NO_VTABLE Dec : public BlockCipherImpl - { - public: - Dec() {strengthened = false;} - }; - public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; + typedef BlockCipherFinal > Encryption; + typedef BlockCipherFinal > 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;} }; /// SAFER-SK class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation { - class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl - { - public: - Enc() {strengthened = true;} - }; - - class CRYPTOPP_NO_VTABLE Dec : public BlockCipherImpl - { - public: - Dec() {strengthened = true;} - }; - public: - typedef BlockCipherFinal Encryption; - typedef BlockCipherFinal Decryption; + typedef BlockCipherFinal > Encryption; + typedef BlockCipherFinal > Decryption; }; typedef SAFER_K::Encryption SAFER_K_Encryption; diff --git a/seckey.h b/seckey.h index d7f90d24a..b5e8824f3 100644 --- a/seckey.h +++ b/seckey.h @@ -32,17 +32,6 @@ class FixedRounds { public: enum {ROUNDS = R}; - -protected: - template - 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 @@ -59,14 +48,17 @@ class VariableRounds assert(rounds >= (unsigned int)MIN_ROUNDS && rounds <= (unsigned int)MAX_ROUNDS); } - template - static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m) + 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 ¶m, const Algorithm *alg) + { + int rounds = param.GetIntValueWithDefault("Rounds", DEFAULT_ROUNDS); + ThrowIfInvalidRounds(rounds, alg); + return (unsigned int)rounds; } }; @@ -123,20 +115,6 @@ class SameKeyLengthAs // ************** implementation helper for SimpledKeyed *************** -template -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 -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 CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE @@ -147,9 +125,6 @@ class CRYPTOPP_NO_VTABLE SimpleKeyingInterfaceImpl : public BASE 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 @@ -166,29 +141,19 @@ class BlockCipherFinal : public ClonableImpl, 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 ¶m = g_nullNameValuePairs) - { - CheckedSetKey(this, DIR, key, length, param); - } }; //! _ template class MessageAuthenticationCodeImpl : public AlgorithmImpl, 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 ClonableImplDEFAULT_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 5cef12d0f..69956464f 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 c24d20250..6aef38e75 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: FixedSizeSecBlock m_key; diff --git a/shacal2.cpp b/shacal2.cpp index 78e4a8391..b0360e404 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 552dafcad..66c987fd7 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: FixedSizeSecBlock m_key; diff --git a/shark.cpp b/shark.cpp index 0408d8e1b..56277ce0a 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 ¶ms) { 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 ec483f8a3..398c7f5b5 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 { 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: unsigned int m_rounds; diff --git a/skipjack.cpp b/skipjack.cpp index 0fb472d1a..2405fab4b 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 5bf66e183..d6e4296fc 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: static const byte fTable[256]; diff --git a/square.cpp b/square.cpp index 9d5466fcc..3686eac24 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 a1da1cf56..c7289279b 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: FixedSizeSecBlock roundkeys; diff --git a/strciphr.h b/strciphr.h index 76d7b3d61..e905d7b19 100644 --- a/strciphr.h +++ b/strciphr.h @@ -135,7 +135,7 @@ class CRYPTOPP_NO_VTABLE AdditiveCipherTemplate : public BASE typedef typename BASE::PolicyInterface PolicyInterface; 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();} @@ -233,7 +233,7 @@ class CRYPTOPP_NO_VTABLE CFB_CipherTemplate : public BASE protected: 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; }; @@ -266,23 +266,17 @@ class SymmetricCipherFinal : public AlgorithmImplDEFAULT_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 ¶ms = g_nullNameValuePairs) - { - this->ThrowIfInvalidKeyLength(length); - this->UncheckedSetKey(params, key, (unsigned int)length, this->GetIVAndThrowIfInvalid(params)); - } - Clonable * Clone() const {return static_cast(new SymmetricCipherFinal(*this));} }; template -void AdditiveCipherTemplate::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv) +void AdditiveCipherTemplate::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) { PolicyInterface &policy = this->AccessPolicy(); policy.CipherSetKey(params, key, length); @@ -290,17 +284,17 @@ void AdditiveCipherTemplate::UncheckedSetKey(const NameValuePairs ¶ms, co m_buffer.New(GetBufferByteSize(policy)); if (this->IsResynchronizable()) - policy.CipherResynchronize(m_buffer, iv); + policy.CipherResynchronize(m_buffer, this->GetIVAndThrowIfInvalid(params)); } template -void CFB_CipherTemplate::UncheckedSetKey(const NameValuePairs ¶ms, const byte *key, unsigned int length, const byte *iv) +void CFB_CipherTemplate::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) { 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 a97105359..60921d4be 100644 --- a/tea.cpp +++ b/tea.cpp @@ -9,12 +9,12 @@ NAMESPACE_BEGIN(CryptoPP) static const word32 DELTA = 0x9e3779b9; typedef BlockGetAndPut 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); 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 ¶ms) { 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 c05c98a5c..d8ddded86 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 { 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: FixedSizeSecBlock m_k; @@ -60,7 +60,7 @@ class XTEA : public XTEA_Info, public BlockCipherDocumentation class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl { 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: FixedSizeSecBlock m_k; @@ -97,12 +97,10 @@ class BTEA : public BTEA_Info, public BlockCipherDocumentation class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl, BTEA_Info>, public BTEA_Info { public: - template - static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, size_t length, const NameValuePairs ¶m) + void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) { - 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 6a8f2646e..7a13bfc83 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 75640792f..d4ff38104 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 2c8f2166c..a8ca6d5c9 100644 --- a/ttmac.h +++ b/ttmac.h @@ -18,7 +18,7 @@ class CRYPTOPP_NO_VTABLE TTMAC_Base : public FixedKeyLength<20>, public Iterated 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 ¶ms); void TruncatedFinal(byte *mac, size_t size); protected: diff --git a/twofish.cpp b/twofish.cpp index 2371002ed..e78258d32 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 2ba283dad..969fdb2e8 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 { public: - void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length); + void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); protected: static word32 h0(word32 x, const word32 *key, unsigned int kLen); diff --git a/xormac.h b/xormac.h index 18a2ae8a7..7c121d8c8 100644 --- a/xormac.h +++ b/xormac.h @@ -23,7 +23,7 @@ class CRYPTOPP_NO_VTABLE XMACC_Base : public FixedKeyLength, MessageAuthenticationCodeImplSetKey(key, this->KEYLENGTH, MakeParameters(Name::XMACC_Counter(), counter));} }; -template void XMACC_Base::CheckedSetKey(void *, Empty empty, const byte *key, size_t length, const NameValuePairs ¶ms) +template void XMACC_Base::UncheckedSetKey(const byte *key, size_t length, const NameValuePairs ¶ms) { - this->ThrowIfInvalidKeyLength(length); + this->AssertValidKeyLength(length); m_counter = 0xffffffff; const byte *iv = NULL; if (params.GetValue(Name::IV(), iv))