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 //! _
    00013 struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
    00014 {
    00015         enum {DEFAULT_EFFECTIVE_KEYLENGTH = 1024, MAX_EFFECTIVE_KEYLENGTH = 1024};
    00016         static const char *StaticAlgorithmName() {return "RC2";}
    00017 };
    00018
    00019 /// <a href="http://www.weidai.com/scan-mirror/cs.html#RC2">RC2</a>
    00020 class RC2 : public RC2_Info, public BlockCipherDocumentation
    00021 {
    00022         class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
    00023         {
    00024         public:
    00025                 void UncheckedSetKey(CipherDir direction, const byte *key, unsigned int length, unsigned int effectiveKeyLength);
    00026                 void SetKeyWithEffectiveKeyLength(const byte *key, unsigned int length, unsigned int effectiveKeyLength);
    00027
    00028         protected:
    00029                 template <class T>
    00030                 static inline void CheckedSetKey(T *obj, CipherDir dir, const byte *key, unsigned int length, const NameValuePairs &param)
    00031                 {
    00032                         obj->ThrowIfInvalidKeyLength(length);
    00033                         int effectiveKeyLength = param.GetIntValueWithDefault("EffectiveKeyLength", DEFAULT_EFFECTIVE_KEYLENGTH);
    00034                         obj->SetKeyWithEffectiveKeyLength(key, length, effectiveKeyLength);
    00035                 }
    00036
    00037                 FixedSizeSecBlock<word16, 64> K;  // expanded key table
    00038         };
    00039
    00040         class CRYPTOPP_NO_VTABLE Enc : public Base
    00041         {
    00042         public:
    00043                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
    00044         };
    00045
    00046         class CRYPTOPP_NO_VTABLE Dec : public Base
    00047         {
    00048         public:
    00049                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
    00050         };
    00051
    00052 public:
    00053         class Encryption : public BlockCipherFinal<ENCRYPTION, Enc>
    00054         {
    00055         public:
    00056                 Encryption() {}
    00057                 Encryption(const byte *key, unsigned int keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024)
    00058                         {SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);}
    00059         };
    00060
    00061         class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
    00062         {
    00063         public:
    00064                 Decryption() {}
    00065                 Decryption(const byte *key, unsigned int keyLen=DEFAULT_KEYLENGTH, unsigned int effectiveLen=1024)
    00066                         {SetKeyWithEffectiveKeyLength(key, keyLen, effectiveLen);}
    00067         };
    00068 };
    00069
    00070 typedef RC2::Encryption RC2Encryption;
    00071 typedef RC2::Decryption RC2Decryption;
    00072
    00073 NAMESPACE_END
    00074
    00075 #endif