Crypto++  5.6.3
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  static const char *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 CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
28  {
29  public:
30  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
31 
32  protected:
34  word32 m_limit;
35  };
36 
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  class CRYPTOPP_NO_VTABLE Dec : public Base
44  {
45  public:
46  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
47  };
48 
49 public:
52 };
53 
56 
57 //! \class XTEA_Info
58 //! \brief XTEA block cipher information
59 struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
60 {
61  static const char *StaticAlgorithmName() {return "XTEA";}
62 };
63 
64 //! \class XTEA
65 //! \brief XTEA block cipher
66 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a>
67 class XTEA : public XTEA_Info, public BlockCipherDocumentation
68 {
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  class CRYPTOPP_NO_VTABLE Enc : public Base
80  {
81  public:
82  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
83  };
84 
85  class CRYPTOPP_NO_VTABLE Dec : public Base
86  {
87  public:
88  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
89  };
90 
91 public:
94 };
95 
96 //! \class BTEA_Info
97 //! \brief BTEA block cipher information
98 struct BTEA_Info : public FixedKeyLength<16>
99 {
100  static const char *StaticAlgorithmName() {return "BTEA";}
101 };
102 
103 //! \class BTEA
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.weidai.com/scan-mirror/cs.html#TEA">Corrected Block TEA</a>.
108 {
109  class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info
110  {
111  public:
112  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
113  {
114  CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params);
115  m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
116  GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
117  }
118 
119  unsigned int BlockSize() const {return m_blockSize;}
120 
121  protected:
123  unsigned int m_blockSize;
124  };
125 
126  class CRYPTOPP_NO_VTABLE Enc : public Base
127  {
128  public:
129  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
130  };
131 
132  class CRYPTOPP_NO_VTABLE Dec : public Base
133  {
134  public:
135  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
136  };
137 
138 public:
141 };
142 
143 NAMESPACE_END
144 
145 #endif
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:117
Utility functions for the Crypto++ library.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:396
static const int KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:122
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1081
Classes and functions for secure memory allocations.
BTEA block cipher.
Definition: tea.h:107
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:380
Classes and functions for implementing secret key algorithms.
XTEA block cipher information.
Definition: tea.h:59
XTEA block cipher.
Definition: tea.h:67
TEA block cipher information.
Definition: tea.h:17
TEA block cipher.
Definition: tea.h:25
byte order is big-endian
Definition: cryptlib.h:127
const char * BlockSize()
int, in bytes
Definition: argnames.h:26
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:303
BTEA block cipher information.
Definition: tea.h:98
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:277
Base class for identifying alogorithm.
Definition: simple.h:38