~zooko/cryptopp/trunk

« back to all changes in this revision

Viewing changes to safer.h

  • Committer: weidai
  • Date: 2006-12-09 17:18:13 UTC
  • Revision ID: svn-v4:57ff6487-cd31-0410-9ec3-f628ee90f5f0:trunk/c5:247
add Salsa20 cipher

Show diffs side-by-side

added added

removed removed

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