00001
#ifndef CRYPTOPP_TEA_H
00002
#define CRYPTOPP_TEA_H
00003
00004
00005
00006
00007
#include "seckey.h"
00008
#include "secblock.h"
00009
00010 NAMESPACE_BEGIN(CryptoPP)
00011
00012
00013 struct
TEA_Info : public
FixedBlockSize<8>, public
FixedKeyLength<16>, public
VariableRounds<32>
00014 {
00015
static const char *StaticAlgorithmName() {
return "TEA";}
00016 };
00017
00018
00019 class TEA :
public TEA_Info,
public BlockCipherDocumentation
00020 {
00021
class CRYPTOPP_NO_VTABLE Base :
public BlockCipherImpl<TEA_Info>
00022 {
00023
public:
00024
void UncheckedSetKey(
CipherDir direction,
const byte *userKey,
unsigned int length,
unsigned int rounds);
00025
00026
protected:
00027 FixedSizeSecBlock<word32, 4> m_k;
00028 word32 m_limit;
00029 };
00030
00031
class CRYPTOPP_NO_VTABLE Enc :
public Base
00032 {
00033
public:
00034
void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const;
00035 };
00036
00037
class CRYPTOPP_NO_VTABLE Dec :
public Base
00038 {
00039
public:
00040
void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const;
00041 };
00042
00043
public:
00044 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
00045 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
00046 };
00047
00048
typedef TEA::Encryption TEAEncryption;
00049
typedef TEA::Decryption TEADecryption;
00050
00051
00052 struct XTEA_Info :
public FixedBlockSize<8>,
public FixedKeyLength<16>,
public VariableRounds<32>
00053 {
00054
static const char *StaticAlgorithmName() {
return "XTEA";}
00055 };
00056
00057
00058 class XTEA :
public XTEA_Info,
public BlockCipherDocumentation
00059 {
00060
class CRYPTOPP_NO_VTABLE Base :
public BlockCipherImpl<XTEA_Info>
00061 {
00062
public:
00063
void UncheckedSetKey(
CipherDir direction,
const byte *userKey,
unsigned int length,
unsigned int rounds);
00064
00065
protected:
00066 FixedSizeSecBlock<word32, 4> m_k;
00067 word32 m_limit;
00068 };
00069
00070
class CRYPTOPP_NO_VTABLE Enc :
public Base
00071 {
00072
public:
00073
void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const;
00074 };
00075
00076
class CRYPTOPP_NO_VTABLE Dec :
public Base
00077 {
00078
public:
00079
void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const;
00080 };
00081
00082
public:
00083 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
00084 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
00085 };
00086
00087
00088 struct BTEA_Info :
public FixedKeyLength<16>
00089 {
00090
static const char *StaticAlgorithmName() {
return "BTEA";}
00091 };
00092
00093
00094
00095 class BTEA :
public BTEA_Info,
public BlockCipherDocumentation
00096 {
00097
class CRYPTOPP_NO_VTABLE Base :
public AlgorithmImpl<SimpleKeyingInterfaceImpl<BlockCipher, BTEA_Info>, BTEA_Info>,
public BTEA_Info
00098 {
00099
public:
00100
template <
class T>
00101
static inline void CheckedSetKey(T *obj,
CipherDir dir,
const byte *key,
unsigned int length,
const NameValuePairs ¶m)
00102 {
00103 obj->ThrowIfInvalidKeyLength(length);
00104 obj->m_blockSize = param.
GetIntValueWithDefault(
"BlockSize", 60*4);
00105 GetUserKey(BIG_ENDIAN_ORDER, obj->m_k.begin(), 4, key, KEYLENGTH);
00106 }
00107
00108
unsigned int BlockSize()
const {
return m_blockSize;}
00109
00110
protected:
00111 FixedSizeSecBlock<word32, 4> m_k;
00112
unsigned int m_blockSize;
00113 };
00114
00115
class CRYPTOPP_NO_VTABLE Enc :
public Base
00116 {
00117
public:
00118
void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const;
00119 };
00120
00121
class CRYPTOPP_NO_VTABLE Dec :
public Base
00122 {
00123
public:
00124
void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const;
00125 };
00126
00127
public:
00128 typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
00129 typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
00130 };
00131
00132 NAMESPACE_END
00133
00134
#endif