Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:08

0001 // rc2.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file rc2.h

0004 /// \brief Classes for the RC2 block cipher

0005 /// \since Crypto++ 3.0

0006 
0007 #ifndef CRYPTOPP_RC2_H
0008 #define CRYPTOPP_RC2_H
0009 
0010 #include "seckey.h"
0011 #include "secblock.h"
0012 #include "algparam.h"
0013 
0014 NAMESPACE_BEGIN(CryptoPP)
0015 
0016 /// \brief RC2 block cipher information

0017 /// \since Crypto++ 3.0

0018 struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
0019 {
0020     CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024);
0021     CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024);
0022     CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RC2";}
0023 };
0024 
0025 /// \brief RC2 block cipher

0026 /// \sa <a href="http://www.cryptopp.com/wiki/RC2">RC2</a> on the Crypto Lounge.

0027 /// \since Crypto++ 3.0

0028 class RC2 : public RC2_Info, public BlockCipherDocumentation
0029 {
0030     /// \brief Class specific methods used to operate the cipher.

0031     /// \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions

0032     class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
0033     {
0034     public:
0035         void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
0036         unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word16>();}
0037 
0038     protected:
0039         FixedSizeSecBlock<word16, 64> K;  // expanded key table

0040     };
0041 
0042     /// \brief Class specific methods used to operate the cipher in the forward direction.

0043     /// \details Implementations and overrides in \p Enc apply to \p ENCRYPTION.

0044     class CRYPTOPP_NO_VTABLE Enc : public Base
0045     {
0046     public:
0047         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0048     };
0049 
0050     /// \brief Class specific methods used to operate the cipher in the reverse direction.

0051     /// \details Implementations and overrides in \p Dec apply to \p DECRYPTION.

0052     class CRYPTOPP_NO_VTABLE Dec : public Base
0053     {
0054     public:
0055         void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0056     };
0057 
0058 public:
0059 
0060     /// \brief Class specific methods used to operate the cipher in the forward direction.

0061     /// \details Implementations and overrides in \p Encryption apply to \p ENCRYPTION.

0062     class Encryption : public BlockCipherFinal<ENCRYPTION, Enc>
0063     {
0064     public:
0065         Encryption() {}
0066         Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
0067             {SetKey(key, keyLen);}
0068         Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
0069             {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
0070     };
0071 
0072     /// \brief Class specific methods used to operate the cipher in the reverse direction.

0073     /// \details Implementations and overrides in \p Decryption apply to \p DECRYPTION.

0074     class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
0075     {
0076     public:
0077         Decryption() {}
0078         Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
0079             {SetKey(key, keyLen);}
0080         Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
0081             {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
0082     };
0083 };
0084 
0085 typedef RC2::Encryption RC2Encryption;
0086 typedef RC2::Decryption RC2Decryption;
0087 
0088 NAMESPACE_END
0089 
0090 #endif