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
11NAMESPACE_BEGIN(CryptoPP)
12
13//! _
14struct 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>
22class 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
46public:
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
68typedef RC2::Encryption RC2Encryption;
69typedef RC2::Decryption RC2Decryption;
70
71NAMESPACE_END
72
73#endif
74