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