Crypto++  7.0
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  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "TEA";}
19 };
20 
21 /// \brief TEA block cipher
22 /// \sa <a href="http://www.cryptopp.com/wiki/TEA">TEA</a>
23 class TEA : public TEA_Info, public BlockCipherDocumentation
24 {
25  /// \brief TEA block cipher default operation
26  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
27  {
28  public:
29  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
30 
31  protected:
33  word32 m_limit;
34  };
35 
36  /// \brief TEA block cipher encryption operation
37  class CRYPTOPP_NO_VTABLE Enc : public Base
38  {
39  public:
40  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
41  };
42 
43  /// \brief TEA block cipher decryption operation
44  class CRYPTOPP_NO_VTABLE Dec : public Base
45  {
46  public:
47  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
48  };
49 
50 public:
53 };
54 
57 
58 /// \brief XTEA block cipher information
59 struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
60 {
61  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "XTEA";}
62 };
63 
64 /// \brief XTEA block cipher
65 /// \sa <a href="http://www.cryptopp.com/wiki/TEA">XTEA</a>
66 class XTEA : public XTEA_Info, public BlockCipherDocumentation
67 {
68  /// \brief XTEA block cipher default operation
69  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
70  {
71  public:
72  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
73 
74  protected:
76  word32 m_limit;
77  };
78 
79  /// \brief XTEA block cipher encryption operation
80  class CRYPTOPP_NO_VTABLE Enc : public Base
81  {
82  public:
83  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
84  };
85 
86  /// \brief XTEA block cipher decryption operation
87  class CRYPTOPP_NO_VTABLE Dec : public Base
88  {
89  public:
90  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
91  };
92 
93 public:
96 };
97 
98 /// \brief BTEA block cipher information
99 struct BTEA_Info : public FixedKeyLength<16>
100 {
101  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "BTEA";}
102 };
103 
104 /// \brief BTEA block cipher
105 /// \details Corrected Block TEA as described in "xxtea". This class hasn't been tested yet.
106 /// \sa <a href="http://www.cryptopp.com/wiki/TEA">Corrected Block TEA</a>.
108 {
109  /// \brief BTEA block cipher default operation
110  class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info
111  {
112  public:
113  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
114  {
115  CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params);
116  m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
117  GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
118  }
119 
120  unsigned int BlockSize() const {return m_blockSize;}
121 
122  protected:
124  unsigned int m_blockSize;
125  };
126 
127  /// \brief BTEA block cipher encryption operation
128  class CRYPTOPP_NO_VTABLE Enc : public Base
129  {
130  public:
131  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
132  };
133 
134  /// \brief BTEA block cipher decryption operation
135  class CRYPTOPP_NO_VTABLE Dec : public Base
136  {
137  public:
138  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
139  };
140 
141 public:
144 };
145 
146 NAMESPACE_END
147 
148 #endif
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Definition: cryptlib.h:392
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:147
Utility functions for the Crypto++ library.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:420
static const int KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:152
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1229
Classes and functions for secure memory allocations.
BTEA block cipher.
Definition: tea.h:107
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
Inherited by algorithms with variable number of rounds.
Definition: seckey.h:87
Classes and functions for implementing secret key algorithms.
XTEA block cipher information.
Definition: tea.h:59
XTEA block cipher.
Definition: tea.h:66
TEA block cipher information.
Definition: tea.h:16
TEA block cipher.
Definition: tea.h:23
byte order is big-endian
Definition: cryptlib.h:144
const char * BlockSize()
int, in bytes
Definition: argnames.h:27
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:327
BTEA block cipher information.
Definition: tea.h:99
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:290
Base class information.
Definition: simple.h:36