~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to safer.h

  • Committer: weidai
  • Date: 2009-03-14 22:27:56 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:455
fix line ending

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
        class CRYPTOPP_NO_VTABLE Base : public BlockCipher
17
17
        {
18
18
        public:
19
 
                unsigned int GetAlignment() const {return 1;}
20
 
                void UncheckedSetKey(CipherDir dir, const byte *userkey, unsigned int length, unsigned nof_rounds);
21
 
 
22
 
                bool strengthened;
 
19
                unsigned int OptimalDataAlignment() const {return 1;}
 
20
                void UncheckedSetKey(const byte *userkey, unsigned int length, const NameValuePairs &params);
 
21
 
 
22
        protected:
 
23
                virtual bool Strengthened() const =0;
 
24
 
23
25
                SecByteBlock keySchedule;
24
26
                static const byte exp_tab[256];
25
27
                static const byte log_tab[256];
38
40
        };
39
41
};
40
42
 
 
43
template <class BASE, class INFO, bool STR>
 
44
class CRYPTOPP_NO_VTABLE SAFER_Impl : public BlockCipherImpl<INFO, BASE>
 
45
{
 
46
protected:
 
47
        bool Strengthened() const {return STR;}
 
48
};
 
49
 
41
50
//! _
42
51
struct SAFER_K_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
43
52
{
44
53
        static const char *StaticAlgorithmName() {return "SAFER-K";}
45
 
        static unsigned int DefaultRounds(unsigned int keylength) {return keylength == 8 ? 6 : 10;}
46
54
};
47
55
 
48
56
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-K">SAFER-K</a>
49
57
class SAFER_K : public SAFER_K_Info, public SAFER, public BlockCipherDocumentation
50
58
{
51
 
        class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<SAFER_K_Info, SAFER::Enc>
52
 
        {
53
 
        public:
54
 
                Enc() {strengthened = false;}
55
 
        };
56
 
 
57
 
        class CRYPTOPP_NO_VTABLE Dec : public BlockCipherImpl<SAFER_K_Info, SAFER::Dec>
58
 
        {
59
 
        public:
60
 
                Dec() {strengthened = false;}
61
 
        };
62
 
 
63
59
public:
64
 
        typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
65
 
        typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
 
60
        typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_K_Info, false> > Encryption;
 
61
        typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_K_Info, false> > Decryption;
66
62
};
67
63
 
68
64
//! _
69
65
struct SAFER_SK_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 8, 16, 8>, public VariableRounds<10, 1, 13>
70
66
{
71
67
        static const char *StaticAlgorithmName() {return "SAFER-SK";}
72
 
        static unsigned int DefaultRounds(unsigned int keylength) {return keylength == 8 ? 8 : 10;}
73
68
};
74
69
 
75
70
/// <a href="http://www.weidai.com/scan-mirror/cs.html#SAFER-SK">SAFER-SK</a>
76
71
class SAFER_SK : public SAFER_SK_Info, public SAFER, public BlockCipherDocumentation
77
72
{
78
 
        class CRYPTOPP_NO_VTABLE Enc : public BlockCipherImpl<SAFER_SK_Info, SAFER::Enc>
79
 
        {
80
 
        public:
81
 
                Enc() {strengthened = true;}
82
 
        };
83
 
 
84
 
        class CRYPTOPP_NO_VTABLE Dec : public BlockCipherImpl<SAFER_SK_Info, SAFER::Dec>
85
 
        {
86
 
        public:
87
 
                Dec() {strengthened = true;}
88
 
        };
89
 
 
90
73
public:
91
 
        typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
92
 
        typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
 
74
        typedef BlockCipherFinal<ENCRYPTION, SAFER_Impl<Enc, SAFER_SK_Info, true> > Encryption;
 
75
        typedef BlockCipherFinal<DECRYPTION, SAFER_Impl<Dec, SAFER_SK_Info, true> > Decryption;
93
76
};
94
77
 
95
78
typedef SAFER_K::Encryption SAFER_K_Encryption;