Crypto++  5.6.3
Free C++ class library of cryptographic schemes
des.h
Go to the documentation of this file.
1 // des.h - written and placed in the public domain by Wei Dai
2 
3 //! \file des.h
4 //! \brief Classes for DES, 2-key Triple-DES, 3-key Triple-DES and DESX
5 
6 #ifndef CRYPTOPP_DES_H
7 #define CRYPTOPP_DES_H
8 
9 #include "seckey.h"
10 #include "secblock.h"
11 
12 NAMESPACE_BEGIN(CryptoPP)
13 
14 class CRYPTOPP_DLL RawDES
15 {
16 public:
17  void RawSetKey(CipherDir direction, const byte *userKey);
18  void RawProcessBlock(word32 &l, word32 &r) const;
19 
20 protected:
21  static const word32 Spbox[8][64];
22 
24 };
25 
26 //! _
27 struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
28 {
29  // disable DES in DLL version by not exporting this function
30  static const char * StaticAlgorithmName() {return "DES";}
31 };
32 
33 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
34 /*! The DES implementation in Crypto++ ignores the parity bits
35  (the least significant bits of each byte) in the key. However
36  you can use CheckKeyParityBits() and CorrectKeyParityBits() to
37  check or correct the parity bits if you wish. */
38 class DES : public DES_Info, public BlockCipherDocumentation
39 {
40  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
41  {
42  public:
43  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
44  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
45  };
46 
47 public:
48  //! check DES key parity bits
49  static bool CheckKeyParityBits(const byte *key);
50  //! correct DES key parity bits
51  static void CorrectKeyParityBits(byte *key);
52 
55 };
56 
57 //! _
58 struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
59 {
60  CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE2";}
61 };
62 
63 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
65 {
66  class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
67  {
68  public:
69  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
70  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
71 
72  protected:
73  RawDES m_des1, m_des2;
74  };
75 
76 public:
79 };
80 
81 //! _
82 struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
83 {
84  CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE3";}
85 };
86 
87 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
89 {
90  class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
91  {
92  public:
93  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
94  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
95 
96  protected:
97  RawDES m_des1, m_des2, m_des3;
98  };
99 
100 public:
103 };
104 
105 //! _
106 struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
107 {
108  static const char *StaticAlgorithmName() {return "DES-XEX3";}
109 };
110 
111 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
113 {
114  class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
115  {
116  public:
117  void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs &params);
118  void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
119 
120  protected:
122  // VS2005 workaround: calling modules compiled with /clr gets unresolved external symbol DES::Base::ProcessAndXorBlock
123  // if we use DES::Encryption here directly without value_ptr.
125  };
126 
127 public:
130 };
131 
134 
137 
140 
143 
144 NAMESPACE_END
145 
146 #endif
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:113
Provides Encryption and Decryption typedefs used by derived classes to implement a block cipher...
Definition: seckey.h:385
CipherDir
Specifies a direction for a cipher to operate.
Definition: cryptlib.h:102
Definition: des.h:14
DES
Definition: des.h:38
Classes and functions for secure memory allocations.
Inherited by block ciphers with fixed block size.
Definition: seckey.h:34
DES-XEX3, AKA DESX
Definition: des.h:112
DES-EDE3
Definition: des.h:88
Classes and functions for implementing secret key algorithms.
_
Definition: des.h:58
Provides class member functions to key a block cipher.
Definition: seckey.h:305
_
Definition: des.h:82
DES-EDE2
Definition: des.h:64
_
Definition: des.h:27
Value pointer.
Definition: smartptr.h:79
Provides class member functions to access BlockCipher constants.
Definition: seckey.h:292
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:261