Crypto++ 8.2 Free C++ class library of cryptographic schemes

tea.h
Go to the documentation of this file.
1 // tea.h - originally written and placed in the public domain by Wei Dai
2
3 /// \file tea.h
4 /// \brief Classes for the TEA, BTEA and XTEA block ciphers
5
6 #ifndef CRYPTOPP_TEA_H
7 #define CRYPTOPP_TEA_H
8
9 #include "seckey.h"
10 #include "secblock.h"
11 #include "misc.h"
12
13 NAMESPACE_BEGIN(CryptoPP)
14
15 /// \brief TEA block cipher information
16 struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
17 {
18 /// \brief The algorithm name
19 /// \return the algorithm name
20 /// \details StaticAlgorithmName returns the algorithm's name as a static
21 /// member function.
22 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "TEA";}
23 };
24
25 /// \brief TEA block cipher
26 /// \sa <a href="http://www.cryptopp.com/wiki/TEA">TEA</a>
27 class TEA : public TEA_Info, public BlockCipherDocumentation
28 {
29 /// \brief TEA block cipher default operation
30 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
31 {
32 public:
33 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
34
35 protected:
36 FixedSizeSecBlock<word32, 4> m_k;
37 word32 m_limit;
38 };
39
40 /// \brief TEA block cipher encryption operation
41 class CRYPTOPP_NO_VTABLE Enc : public Base
42 {
43 public:
44 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
45 };
46
47 /// \brief TEA block cipher decryption operation
48 class CRYPTOPP_NO_VTABLE Dec : public Base
49 {
50 public:
51 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
52 };
53
54 public:
55 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
56 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
57 };
58
59 typedef TEA::Encryption TEAEncryption;
60 typedef TEA::Decryption TEADecryption;
61
62 /// \brief XTEA block cipher information
63 struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
64 {
65 /// \brief The algorithm name
66 /// \return the algorithm name
67 /// \details StaticAlgorithmName returns the algorithm's name as a static
68 /// member function.
69 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "XTEA";}
70 };
71
72 /// \brief XTEA block cipher
73 /// \sa <a href="http://www.cryptopp.com/wiki/TEA">XTEA</a>
74 class XTEA : public XTEA_Info, public BlockCipherDocumentation
75 {
76 /// \brief XTEA block cipher default operation
77 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
78 {
79 public:
80 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
81
82 protected:
83 FixedSizeSecBlock<word32, 4> m_k;
84 word32 m_limit;
85 };
86
87 /// \brief XTEA block cipher encryption operation
88 class CRYPTOPP_NO_VTABLE Enc : public Base
89 {
90 public:
91 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
92 };
93
94 /// \brief XTEA block cipher decryption operation
95 class CRYPTOPP_NO_VTABLE Dec : public Base
96 {
97 public:
98 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
99 };
100
101 public:
102 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
103 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
104 };
105
106 /// \brief BTEA block cipher information
107 struct BTEA_Info : public FixedKeyLength<16>
108 {
109 /// \brief The algorithm name
110 /// \return the algorithm name
111 /// \details StaticAlgorithmName returns the algorithm's name as a static
112 /// member function.
113 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "BTEA";}
114 };
115
116 /// \brief BTEA block cipher
117 /// \details Corrected Block TEA as described in "xxtea". This class hasn't been tested yet.
118 /// \sa <A HREF="http://www.movable-type.co.uk/scripts/xxtea.pdf">Correction to xtea</A> and
119 /// <a href="http://www.cryptopp.com/wiki/TEA">Corrected Block TEA</a>.
120 class BTEA : public BTEA_Info, public BlockCipherDocumentation
121 {
122 /// \brief BTEA block cipher default operation
123 class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>
124 {
125 public:
126 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
127 {
128 CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params);
129 m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
130 GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
131 }
132
133 unsigned int BlockSize() const {return m_blockSize;}
134
135 protected:
136 FixedSizeSecBlock<word32, 4> m_k;
137 unsigned int m_blockSize;
138 };
139
140 /// \brief BTEA block cipher encryption operation
141 class CRYPTOPP_NO_VTABLE Enc : public Base
142 {
143 public:
144 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
145 };
146
147 /// \brief BTEA block cipher decryption operation
148 class CRYPTOPP_NO_VTABLE Dec : public Base
149 {
150 public:
151 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
152 };
153
154 public:
155 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
156 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
157 };
158
159 NAMESPACE_END
160
161 #endif
FixedKeyLength
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:124
NameValuePairs::GetIntValueWithDefault
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Definition: cryptlib.h:424
misc.h
Utility functions for the Crypto++ library.
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:398
FixedKeyLength< 16 >::KEYLENGTH
static const int KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:129
BlockCipher
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1278
secblock.h
Classes and functions for secure memory allocations.
BTEA
BTEA block cipher.
Definition: tea.h:120
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
VariableRounds
Inherited by algorithms with variable number of rounds.
Definition: seckey.h:64
seckey.h
Classes and functions for implementing secret key algorithms.
XTEA_Info
XTEA block cipher information.
Definition: tea.h:63
BlockCipherFinal< ENCRYPTION, Enc >
XTEA
XTEA block cipher.
Definition: tea.h:74
TEA_Info
TEA block cipher information.
Definition: tea.h:16
TEA_Info::StaticAlgorithmName
static const char * StaticAlgorithmName()
The algorithm name.
Definition: tea.h:22
FixedSizeSecBlock< word32, 4 >
TEA
TEA block cipher.
Definition: tea.h:27
BIG_ENDIAN_ORDER
byte order is big-endian
Definition: cryptlib.h:147
Name::BlockSize
const char * BlockSize()
int, in bytes
Definition: argnames.h:27
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
BTEA_Info
BTEA block cipher information.
Definition: tea.h:107
CryptoPP
Crypto++ library namespace.
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
AlgorithmImpl
Base class information.
Definition: simple.h:39