Crypto++ 8.9
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
13NAMESPACE_BEGIN(CryptoPP)
14
15/// \brief TEA block cipher information
16struct 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>
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:
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
54public:
57};
58
61
62/// \brief XTEA block cipher information
63struct 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>
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:
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
101public:
104};
105
106/// \brief BTEA block cipher information
107struct 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>.
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:
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
154public:
157};
158
159NAMESPACE_END
160
161#endif
Base class information.
Definition simple.h:40
BTEA block cipher.
Definition tea.h:121
Provides class member functions to key a block cipher.
Definition seckey.h:318
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition seckey.h:306
Inherited by algorithms with fixed block size.
Definition seckey.h:41
Inherited by keyed algorithms with fixed key length.
Definition seckey.h:125
Fixed size stack-based SecBlock.
Definition secblock.h:1246
Interface for retrieving values given their names.
Definition cryptlib.h:327
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
Definition cryptlib.h:429
TEA block cipher.
Definition tea.h:28
Inherited by algorithms with variable number of rounds.
Definition seckey.h:65
XTEA block cipher.
Definition tea.h:75
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:72
@ BIG_ENDIAN_ORDER
byte order is big-endian
Definition cryptlib.h:152
Utility functions for the Crypto++ library.
void GetUserKey(ByteOrder order, T *out, size_t outlen, const byte *in, size_t inlen)
Copy bytes in a buffer to an array of elements in big-endian order.
Definition misc.h:2500
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Classes and functions for implementing secret key algorithms.
BTEA block cipher information.
Definition tea.h:108
static const char * StaticAlgorithmName()
The algorithm name.
Definition tea.h:113
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition seckey.h:399
TEA block cipher information.
Definition tea.h:17
static const char * StaticAlgorithmName()
The algorithm name.
Definition tea.h:22
XTEA block cipher information.
Definition tea.h:64
static const char * StaticAlgorithmName()
The algorithm name.
Definition tea.h:69