Crypto++  5.6.5
Free C++ class library of cryptographic schemes
tea.h
Go to the documentation of this file.
1 // tea.h - 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 //! \class TEA_Info
16 //! \brief TEA block cipher information
17 struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
18 {
19  CRYPTOPP_STATIC_CONSTEXPR char* const StaticAlgorithmName() {return "TEA";}
20 };
21 
22 //! \class TEA
23 //! \brief TEA block cipher
24 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">TEA</a>
25 class TEA : public TEA_Info, public BlockCipherDocumentation
26 {
27  //! \class Base
28  //! \brief TEA block cipher default operation
29  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
30  {
31  public:
32  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
33 
34  protected:
36  word32 m_limit;
37  };
38 
39  //! \class Enc
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  //! \class Dec
48  //! \brief TEA block cipher decryption operation
49  class CRYPTOPP_NO_VTABLE Dec : public Base
50  {
51  public:
52  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
53  };
54 
55 public:
58 };
59 
62 
63 //! \class XTEA_Info
64 //! \brief XTEA block cipher information
65 struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
66 {
67  CRYPTOPP_STATIC_CONSTEXPR char* const StaticAlgorithmName() {return "XTEA";}
68 };
69 
70 //! \class XTEA
71 //! \brief XTEA block cipher
72 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a>
73 class XTEA : public XTEA_Info, public BlockCipherDocumentation
74 {
75  //! \class Base
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:
84  word32 m_limit;
85  };
86 
87  //! \class Enc
88  //! \brief XTEA block cipher encryption operation
89  class CRYPTOPP_NO_VTABLE Enc : public Base
90  {
91  public:
92  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
93  };
94 
95  //! \class Dec
96  //! \brief XTEA block cipher decryption operation
97  class CRYPTOPP_NO_VTABLE Dec : public Base
98  {
99  public:
100  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
101  };
102 
103 public:
106 };
107 
108 //! \class BTEA_Info
109 //! \brief BTEA block cipher information
110 struct BTEA_Info : public FixedKeyLength<16>
111 {
112  CRYPTOPP_STATIC_CONSTEXPR char* const StaticAlgorithmName() {return "BTEA";}
113 };
114 
115 //! \class BTEA
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.weidai.com/scan-mirror/cs.html#TEA">Corrected Block TEA</a>.
120 {
121  //! \class Base
122  //! \brief BTEA block cipher default operation
123  class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public 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:
137  unsigned int m_blockSize;
138  };
139 
140  //! \class Enc
141  //! \brief BTEA block cipher encryption operation
142  class CRYPTOPP_NO_VTABLE Enc : public Base
143  {
144  public:
145  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
146  };
147 
148  //! \class Dec
149  //! \brief BTEA block cipher decryption operation
150  class CRYPTOPP_NO_VTABLE Dec : public Base
151  {
152  public:
153  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
154  };
155 
156 public:
159 };
160 
161 NAMESPACE_END
162 
163 #endif
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:121
Utility functions for the Crypto++ library.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:402
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1102
Classes and functions for secure memory allocations.
BTEA block cipher.
Definition: tea.h:119
Inherited by algorithms with fixed block size.
Definition: seckey.h:34
Inherited by algorithms with variable number of rounds.
Definition: seckey.h:60
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Definition: cryptlib.h:381
Classes and functions for implementing secret key algorithms.
XTEA block cipher information.
Definition: tea.h:65
XTEA block cipher.
Definition: tea.h:73
TEA block cipher information.
Definition: tea.h:17
TEA block cipher.
Definition: tea.h:25
byte order is big-endian
Definition: cryptlib.h:128
const char * BlockSize()
int, in bytes
Definition: argnames.h:27
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
BTEA block cipher information.
Definition: tea.h:110
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:278
Base class for identifying alogorithm.
Definition: simple.h:38