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 //! _
16 struct TEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
17 {
18  static const char *StaticAlgorithmName() {return "TEA";}
19 };
20 
21 /// <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">TEA</a>
22 class TEA : public TEA_Info, public BlockCipherDocumentation
23 {
24  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<TEA_Info>
25  {
26  public:
27  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
28 
29  protected:
31  word32 m_limit;
32  };
33 
34  class CRYPTOPP_NO_VTABLE Enc : public Base
35  {
36  public:
37  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
38  };
39 
40  class CRYPTOPP_NO_VTABLE Dec : public Base
41  {
42  public:
43  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
44  };
45 
46 public:
49 };
50 
53 
54 //! _
55 struct XTEA_Info : public FixedBlockSize<8>, public FixedKeyLength<16>, public VariableRounds<32>
56 {
57  static const char *StaticAlgorithmName() {return "XTEA";}
58 };
59 
60 /// <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a>
61 class XTEA : public XTEA_Info, public BlockCipherDocumentation
62 {
63  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<XTEA_Info>
64  {
65  public:
66  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
67 
68  protected:
70  word32 m_limit;
71  };
72 
73  class CRYPTOPP_NO_VTABLE Enc : public Base
74  {
75  public:
76  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
77  };
78 
79  class CRYPTOPP_NO_VTABLE Dec : public Base
80  {
81  public:
82  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
83  };
84 
85 public:
88 };
89 
90 //! _
91 struct BTEA_Info : public FixedKeyLength<16>
92 {
93  static const char *StaticAlgorithmName() {return "BTEA";}
94 };
95 
96 //! <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">corrected Block TEA</a> (as described in "xxtea").
97 /*! This class hasn't been tested yet. */
98 class BTEA : public BTEA_Info, public BlockCipherDocumentation
99 {
100  class CRYPTOPP_NO_VTABLE Base : public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>, public BTEA_Info
101  {
102  public:
103  void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
104  {
105  CRYPTOPP_UNUSED(length), CRYPTOPP_UNUSED(params);
106  m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
107  GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
108  }
109 
110  unsigned int BlockSize() const {return m_blockSize;}
111 
112  protected:
114  unsigned int m_blockSize;
115  };
116 
117  class CRYPTOPP_NO_VTABLE Enc : public Base
118  {
119  public:
120  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
121  };
122 
123  class CRYPTOPP_NO_VTABLE Dec : public Base
124  {
125  public:
126  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
127  };
128 
129 public:
132 };
133 
134 NAMESPACE_END
135 
136 #endif
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:113
Utility functions for the Crypto++ library.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:385
static const int KEYLENGTH
The default key length used by the cipher provided as a constant.
Definition: seckey.h:118
Interface for one direction (encryption or decryption) of a block cipher.
Definition: cryptlib.h:1013
Classes and functions for secure memory allocations.
corrected Block TEA (as described in "xxtea").
Definition: tea.h:98
Inherited by block ciphers with fixed block size.
Definition: seckey.h:34
Inherited by ciphers 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:364
Classes and functions for implementing secret key algorithms.
_
Definition: tea.h:55
XTEA
Definition: tea.h:61
_
Definition: tea.h:16
TEA
Definition: tea.h:22
const char * BlockSize()
int, in bytes
Definition: argnames.h:26
Provides class member functions to access BlockCipher constants.
Definition: seckey.h:292
_
Definition: tea.h:91
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:261
Base class for identifying alogorithm.
Definition: simple.h:38