Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

rc2.h

Go to the documentation of this file.
00001 #ifndef CRYPTOPP_RC2_H 00002 #define CRYPTOPP_RC2_H 00003 00004 /** \file 00005 */ 00006 00007 #include "seckey.h" 00008 #include "secblock.h" 00009 00010 NAMESPACE_BEGIN(CryptoPP) 00011 00012 struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128> 00013 { 00014 enum {DEFAULT_EFFECTIVE_KEYLENGTH = 1024, MAX_EFFECTIVE_KEYLENGTH = 1024}; 00015 static const char *StaticAlgorithmName() {return "RC2";} 00016 }; 00017 00018 /// <a href="http://www.weidai.com/scan-mirror/cs.html#RC2">RC2</a> 00019 class RC2 : public RC2_Info, public BlockCipherDocumentation 00020 { 00021 class Base : public BlockCipherBaseTemplate<RC2_Info> 00022 { 00023 public: 00024 void UncheckedSetKey(CipherDir direction, const byte *key, unsigned int length, unsigned int effectiveKeyLength); 00025 void SetKeyWithEffectiveKeyLength(const byte *key, unsigned int length, unsigned int effectiveKeyLength); 00026 00027 protected: 00028 template <class T> 00029 static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, unsigned int length, const NameValuePairs &param) 00030 { 00031 obj->ThrowIfInvalidKeyLength(length); 00032 int effectiveKeyLength = param.GetIntValueWithDefault("EffectiveKeyLength", DEFAULT_EFFECTIVE_KEYLENGTH); 00033 obj->SetKeyWithEffectiveKeyLength(key, length, effectiveKeyLength); 00034 } 00035 00036 FixedSizeSecBlock<word16, 64> K; // expanded key table 00037 }; 00038 00039 class Enc : public Base 00040 { 00041 public: 00042 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 00043 }; 00044 00045 class Dec : public Base 00046 { 00047 public: 00048 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; 00049 }; 00050 00051 public: 00052 class Encryption : public BlockCipherTemplate<ENCRYPTION, Enc> 00053 { 00054 public: 00055 Encryption() {} 00056 Encryption(const byte *key, unsigned int keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024) 00057 {SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);} 00058 }; 00059 00060 class Decryption : public BlockCipherTemplate<DECRYPTION, Dec> 00061 { 00062 public: 00063 Decryption() {} 00064 Decryption(const byte *key, unsigned int keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024) 00065 {SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);} 00066 }; 00067 }; 00068 00069 typedef RC2::Encryption RC2Encryption; 00070 typedef RC2::Decryption RC2Decryption; 00071 00072 NAMESPACE_END 00073 00074 #endif

Generated on Wed Jul 28 08:07:08 2004 for Crypto++ by doxygen 1.3.7