Crypto++ 8.6 Free C++ class library of cryptographic schemes

rc2.h
Go to the documentation of this file.
1 // rc2.h - originally written and placed in the public domain by Wei Dai
2
3 /// \file rc2.h
4 /// \brief Classes for the RC2 block cipher
5 /// \since Crypto++ 3.0
6
7 #ifndef CRYPTOPP_RC2_H
8 #define CRYPTOPP_RC2_H
9
10 #include "seckey.h"
11 #include "secblock.h"
12 #include "algparam.h"
13
14 NAMESPACE_BEGIN(CryptoPP)
15
16 /// \brief RC2 block cipher information
17 /// \since Crypto++ 3.0
18 struct RC2_Info : public FixedBlockSize<8>, public VariableKeyLength<16, 1, 128>
19 {
20 CRYPTOPP_CONSTANT(DEFAULT_EFFECTIVE_KEYLENGTH = 1024);
21 CRYPTOPP_CONSTANT(MAX_EFFECTIVE_KEYLENGTH = 1024);
22 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "RC2";}
23 };
24
25 /// \brief RC2 block cipher
26 /// \sa <a href="http://www.cryptopp.com/wiki/RC2">RC2</a> on the Crypto Lounge.
27 /// \since Crypto++ 3.0
28 class RC2 : public RC2_Info, public BlockCipherDocumentation
29 {
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 /// \brief Class specific methods used to operate the cipher in the forward direction.
43 /// \details Implementations and overrides in \p Enc apply to \p ENCRYPTION.
44 class CRYPTOPP_NO_VTABLE Enc : public Base
45 {
46 public:
47 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
48 };
49
50 /// \brief Class specific methods used to operate the cipher in the reverse direction.
51 /// \details Implementations and overrides in \p Dec apply to \p DECRYPTION.
52 class CRYPTOPP_NO_VTABLE Dec : public Base
53 {
54 public:
55 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
56 };
57
58 public:
59
60 /// \brief Class specific methods used to operate the cipher in the forward direction.
61 /// \details Implementations and overrides in \p Encryption apply to \p ENCRYPTION.
62 class Encryption : public BlockCipherFinal<ENCRYPTION, Enc>
63 {
64 public:
65 Encryption() {}
66 Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
67 {SetKey(key, keyLen);}
68 Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
69 {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
70 };
71
72 /// \brief Class specific methods used to operate the cipher in the reverse direction.
73 /// \details Implementations and overrides in \p Decryption apply to \p DECRYPTION.
74 class Decryption : public BlockCipherFinal<DECRYPTION, Dec>
75 {
76 public:
77 Decryption() {}
78 Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
79 {SetKey(key, keyLen);}
80 Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
81 {SetKey(key, keyLen, MakeParameters("EffectiveKeyLength", effectiveKeyLen));}
82 };
83 };
84
85 typedef RC2::Encryption RC2Encryption;
86 typedef RC2::Decryption RC2Decryption;
87
88 NAMESPACE_END
89
90 #endif
RC2
RC2 block cipher.
Definition: rc2.h:28
MakeParameters
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition: algparam.h:508
secblock.h
Classes and functions for secure memory allocations.
RC2::Decryption
Class specific methods used to operate the cipher in the reverse direction.
Definition: rc2.h:74
RC2::Encryption
Class specific methods used to operate the cipher in the forward direction.
Definition: rc2.h:62
FixedBlockSize
Inherited by algorithms with fixed block size.
Definition: seckey.h:40
BlockCipherImpl
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition: seckey.h:305
RC2_Info
RC2 block cipher information.
Definition: rc2.h:18
BlockCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition: seckey.h:398
seckey.h
Classes and functions for implementing secret key algorithms.
BlockCipherFinal
Provides class member functions to key a block cipher.
Definition: seckey.h:317
FixedSizeSecBlock< word16, 64 >
CryptoPP
Crypto++ library namespace.
VariableKeyLength< 16, 1, 128 >::DEFAULT_KEYLENGTH
static const int DEFAULT_KEYLENGTH
The default key length used by the algorithm provided as a constant.
Definition: seckey.h:184
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
algparam.h
Classes for working with NameValuePairs.
VariableKeyLength
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:165