diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2006-12-10 02:12:23 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2006-12-10 02:12:23 +0000 |
commit | c3bad1afc1564f3bfac8434d45d6694811139333 (patch) | |
tree | ebfbbcf4dffdf4914b9ce879d3d2c93d3615f7ab /safer.h | |
parent | e553818e00684e8905ede16e53aa490c153b7e7a (diff) | |
download | cryptopp-c3bad1afc1564f3bfac8434d45d6694811139333.tar.gz |
port to GCC 4, reorganize implementations of SetKey
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@248 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'safer.h')
-rw-r--r-- | safer.h | 47 |
1 files changed, 15 insertions, 32 deletions
@@ -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 ¶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 @@ 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; |