From f05ea58bb369988a61438411539ea955e0adf8c2 Mon Sep 17 00:00:00 2001 From: weidai Date: Sun, 10 Dec 2006 02:12:23 +0000 Subject: port to GCC 4, reorganize implementations of SetKey --- safer.h | 47 +++++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) (limited to 'safer.h') diff --git a/safer.h b/safer.h index f551b4fd..3b51c3fd 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 ¶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 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; -- cgit v1.2.1