Security Scol plugin
rc2.h
Go to the documentation of this file.
1// rc2.h - originally written and placed in the public domain by Wei Dai
2
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
14NAMESPACE_BEGIN(CryptoPP)
15
16
18struct 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
29{
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
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
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
58public:
59
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
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
87
88NAMESPACE_END
89
90#endif
Classes for working with NameValuePairs.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Definition algparam.h:508
Provides class member functions to key a block cipher.
Definition seckey.h:318
Provides a base implementation of Algorithm and SimpleKeyingInterface for block ciphers.
Definition seckey.h:306
Inherited by algorithms with fixed block size.
Definition seckey.h:41
Fixed size stack-based SecBlock.
Definition secblock.h:1246
Interface for retrieving values given their names.
Definition cryptlib.h:322
Class specific methods used to operate the cipher in the reverse direction.
Definition rc2.h:75
Class specific methods used to operate the cipher in the forward direction.
Definition rc2.h:63
RC2 block cipher.
Definition rc2.h:29
Inherited by keyed algorithms with variable key length.
Definition seckey.h:166
Classes and functions for secure memory allocations.
Classes and functions for implementing secret key algorithms.
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher.
Definition seckey.h:399
RC2 block cipher information.
Definition rc2.h:19