Crypto++  5.6.5
Free C++ class library of cryptographic schemes
rc2.h
Go to the documentation of this file.
1 // rc2.h - written and placed in the public domain by Wei Dai
2 
3 //! \file rc2.h
4 //! \brief Classes for the RC2 block cipher
5 
6 #ifndef CRYPTOPP_RC2_H
7 #define CRYPTOPP_RC2_H
8 
9 #include "seckey.h"
10 #include "secblock.h"
11 #include "algparam.h"
12 
13 NAMESPACE_BEGIN(CryptoPP)
14 
15 //! \class RC2_Info
16 //! \brief RC2 block cipher information
17 struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
18 {
19  CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024)
20  CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024)
21  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RC2";}
22 };
23 
24 //! \class RC2
25 //! \brief RC2 block cipher
26 //! \sa <a href="http://www.weidai.com/scan-mirror/cs.html#RC2">RC2</a> on the Crypto Lounge.
27 class RC2 : public RC2_Info, public BlockCipherDocumentation
28 {
29  //! \class Base
30  //! \brief Class specific methods used to operate the cipher.
31  //! \details Implementations and overrides in \p Base apply to both \p ENCRYPTION and \p DECRYPTION directions
32  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
33  {
34  public:
35  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
36  unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word16>();}
37 
38  protected:
39  FixedSizeSecBlock<word16, 64> K; // expanded key table
40  };
41 
42  //! \class Enc
43  //! \brief Class specific methods used to operate the cipher in the forward direction.
44  //! \details Implementations and overrides in \p Enc apply to \p ENCRYPTION.
45  class CRYPTOPP_NO_VTABLE Enc : public Base
46  {
47  public:
48  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
49  };
50 
51  //! \class Dec
52  //! \brief Class specific methods used to operate the cipher in the reverse direction.
53  //! \details Implementations and overrides in \p Dec apply to \p DECRYPTION.
54  class CRYPTOPP_NO_VTABLE Dec : public Base
55  {
56  public:
57  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
58  };
59 
60 public:
61 
62  //! \class Encryption
63  //! \brief Class specific methods used to operate the cipher in the forward direction.
64  //! \details Implementations and overrides in \p Encryption apply to \p ENCRYPTION.
65  class Encryption : public BlockCipherFinal<ENCRYPTION, Enc>
66  {
67  public:
68  Encryption() {}
69  Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
70  {SetKey(key, keyLen);}
71  Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
72  {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
73  };
74 
75  //! \class Decryption
76  //! \brief Class specific methods used to operate the cipher in the reverse direction.
77  //! \details Implementations and overrides in \p Decryption apply to \p DECRYPTION.
78  class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
79  {
80  public:
81  Decryption() {}
82  Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
83  {SetKey(key, keyLen);}
84  Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
85  {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
86  };
87 };
88 
91 
92 NAMESPACE_END
93 
94 #endif
95 
Classes for working with NameValuePairs.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:408
Classes and functions for secure memory allocations.
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:500
Classes and functions for implementing secret key algorithms.
static const int DEFAULT_KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:188
RC2 block cipher.
Definition: rc2.h:27
Provides class member functions to key a block cipher.
Definition: seckey.h:324
RC2 block cipher information.
Definition: rc2.h:17
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:169
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:311
Crypto++ library namespace.
Class specific methods used to operate the cipher in the reverse direction.
Definition: rc2.h:78
Class specific methods used to operate the cipher in the forward direction.
Definition: rc2.h:65
Interface for retrieving values given their names.
Definition: cryptlib.h:279