diff options
author | weidai <weidai11@users.noreply.github.com> | 2006-12-10 02:12:23 +0000 |
---|---|---|
committer | weidai <weidai11@users.noreply.github.com> | 2006-12-10 02:12:23 +0000 |
commit | f05ea58bb369988a61438411539ea955e0adf8c2 (patch) | |
tree | ebfbbcf4dffdf4914b9ce879d3d2c93d3615f7ab /safer.h | |
parent | 28c392e08234698cbe0e5fc3ffb3cfa5af1bc461 (diff) | |
download | cryptopp-git-f05ea58bb369988a61438411539ea955e0adf8c2.tar.gz |
port to GCC 4, reorganize implementations of SetKey
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; |