Coverage Report

Created: 2024-11-21 07:03

/src/cryptopp/rc2.h
Line
Count
Source (jump to first uncovered line)
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
0
  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
0
    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
0
    Encryption() {}
66
    Encryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
67
0
      {SetKey(key, keyLen);}
68
    Encryption(const byte *key, size_t keyLen, int effectiveKeyLen)
69
0
      {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
0
    Decryption() {}
78
    Decryption(const byte *key, size_t keyLen=DEFAULT_KEYLENGTH)
79
0
      {SetKey(key, keyLen);}
80
    Decryption(const byte *key, size_t keyLen, int effectiveKeyLen)
81
0
      {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