tea.h

Go to the documentation of this file.
00001 #ifndef CRYPTOPP_TEA_H
00002 #define CRYPTOPP_TEA_H
00003 
00004 /** \file
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 /// <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">TEA</a>
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(const byte *userKey, unsigned int length, const NameValuePairs &params);
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 /// <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">XTEA</a>
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(const byte *userKey, unsigned int length, const NameValuePairs &params);
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 //! <a href="http://www.weidai.com/scan-mirror/cs.html#TEA">corrected Block TEA</a> (as described in "xxtea").
00094 /*! This class hasn't been tested yet. */
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                 void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
00101                 {
00102                         m_blockSize = params.GetIntValueWithDefault("BlockSize", 60*4);
00103                         GetUserKey(BIG_ENDIAN_ORDER, m_k.begin(), 4, key, KEYLENGTH);
00104                 }
00105 
00106                 unsigned int BlockSize() const {return m_blockSize;}
00107 
00108         protected:
00109                 FixedSizeSecBlock<word32, 4> m_k;
00110                 unsigned int m_blockSize;
00111         };
00112 
00113         class CRYPTOPP_NO_VTABLE Enc : public Base
00114         {
00115         public:
00116                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00117         };
00118 
00119         class CRYPTOPP_NO_VTABLE Dec : public Base
00120         {
00121         public:
00122                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00123         };
00124 
00125 public:
00126         typedef BlockCipherFinal<ENCRYPTION, Enc> Encryption;
00127         typedef BlockCipherFinal<DECRYPTION, Dec> Decryption;
00128 };
00129 
00130 NAMESPACE_END
00131 
00132 #endif

Generated on Sat Dec 23 02:07:10 2006 for Crypto++ by  doxygen 1.5.1-p1