Crypto++
rc2.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_RC2_H
2 #define CRYPTOPP_RC2_H
3 
4 /** \file
5 */
6 
7 #include "seckey.h"
8 #include "secblock.h"
9 #include "algparam.h"
10 
11 NAMESPACE_BEGIN(CryptoPP)
12 
13 //! _
14 struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
15 {
16  CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024)
17  CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024)
18  static const char *StaticAlgorithmName() {return "RC2";}
19 };
20 
21 /// <a href="http://www.weidai.com/scan-mirror/cs.html#RC2">RC2</a>
22 class RC2 : public RC2_Info, public BlockCipherDocumentation
23 {
24  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<RC2_Info>
25  {
26  public:
27  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
28  unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word16>();}
29 
30  protected:
31  FixedSizeSecBlock<word16, 64> K; // expanded key table
32  };
33 
34  class CRYPTOPP_NO_VTABLE Enc : public Base
35  {
36  public:
37  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
38  };
39 
40  class CRYPTOPP_NO_VTABLE Dec : public Base
41  {
42  public:
43  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
44  };
45 
46 public:
47  class Encryption : public BlockCipherFinal<ENCRYPTION, Enc>
48  {
49  public:
50  Encryption() {}
51  Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
52  {SetKey(key, keyLen);}
53  Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
54  {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
55  };
56 
57  class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
58  {
59  public:
60  Decryption() {}
61  Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
62  {SetKey(key, keyLen);}
63  Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
64  {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
65  };
66 };
67 
70 
71 NAMESPACE_END
72 
73 #endif
These objects usually should not be used directly. See CipherModeDocumentation instead.
Definition: seckey.h:188
to be inherited by block ciphers with fixed block size
Definition: seckey.h:21
RC2
Definition: rc2.h:22
_
Definition: rc2.h:14
support query of variable key length, template parameters are default, min, max, multiple (default mu...
Definition: seckey.h:80
interface for retrieving values given their names
Definition: cryptlib.h:224