1
by weidai
Initial revision |
1 |
#ifndef CRYPTOPP_DES_H
|
2 |
#define CRYPTOPP_DES_H
|
|
3 |
||
4 |
/** \file
|
|
5 |
*/
|
|
6 |
||
7 |
#include "seckey.h" |
|
8 |
#include "secblock.h" |
|
9 |
||
10 |
NAMESPACE_BEGIN(CryptoPP) |
|
11 |
||
78
by weidai
merge in 5.0.4 changes (exclude DES and SHA-2 from DLL), |
12 |
class CRYPTOPP_DLL RawDES |
13 |
{
|
|
14 |
public: |
|
232
by weidai
port to GCC 4, reorganize implementations of SetKey |
15 |
void RawSetKey(CipherDir direction, const byte *userKey); |
78
by weidai
merge in 5.0.4 changes (exclude DES and SHA-2 from DLL), |
16 |
void RawProcessBlock(word32 &l, word32 &r) const; |
17 |
||
18 |
protected: |
|
19 |
static const word32 Spbox[8][64]; |
|
20 |
||
21 |
FixedSizeSecBlock<word32, 32> k; |
|
22 |
};
|
|
23 |
||
173
by weidai
fix documentation, fix PanamaMAC, fix algorithm names |
24 |
//! _
|
1
by weidai
Initial revision |
25 |
struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8> |
26 |
{
|
|
78
by weidai
merge in 5.0.4 changes (exclude DES and SHA-2 from DLL), |
27 |
// disable DES in DLL version by not exporting this function
|
28 |
static const char * StaticAlgorithmName() {return "DES";} |
|
1
by weidai
Initial revision |
29 |
};
|
30 |
||
31 |
/// <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
|
|
32 |
/*! The DES implementation in Crypto++ ignores the parity bits
|
|
33 |
(the least significant bits of each byte) in the key. However
|
|
34 |
you can use CheckKeyParityBits() and CorrectKeyParityBits() to
|
|
35 |
check or correct the parity bits if you wish. */
|
|
36 |
class DES : public DES_Info, public BlockCipherDocumentation |
|
37 |
{
|
|
78
by weidai
merge in 5.0.4 changes (exclude DES and SHA-2 from DLL), |
38 |
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES |
1
by weidai
Initial revision |
39 |
{
|
40 |
public: |
|
232
by weidai
port to GCC 4, reorganize implementations of SetKey |
41 |
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); |
1
by weidai
Initial revision |
42 |
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
43 |
};
|
|
44 |
||
45 |
public: |
|
46 |
//! check DES key parity bits
|
|
47 |
static bool CheckKeyParityBits(const byte *key); |
|
48 |
//! correct DES key parity bits
|
|
49 |
static void CorrectKeyParityBits(byte *key); |
|
50 |
||
75
by weidai
create DLL version, fix GetNextIV() bug in CTR and OFB modes |
51 |
typedef BlockCipherFinal<ENCRYPTION, Base> Encryption; |
52 |
typedef BlockCipherFinal<DECRYPTION, Base> Decryption; |
|
1
by weidai
Initial revision |
53 |
};
|
54 |
||
173
by weidai
fix documentation, fix PanamaMAC, fix algorithm names |
55 |
//! _
|
1
by weidai
Initial revision |
56 |
struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16> |
57 |
{
|
|
181
by weidai
changes done for FIPS-140 lab code drop |
58 |
CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE2";} |
1
by weidai
Initial revision |
59 |
};
|
60 |
||
61 |
/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
|
|
62 |
class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation |
|
63 |
{
|
|
75
by weidai
create DLL version, fix GetNextIV() bug in CTR and OFB modes |
64 |
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info> |
1
by weidai
Initial revision |
65 |
{
|
66 |
public: |
|
232
by weidai
port to GCC 4, reorganize implementations of SetKey |
67 |
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); |
1
by weidai
Initial revision |
68 |
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
69 |
||
70 |
protected: |
|
78
by weidai
merge in 5.0.4 changes (exclude DES and SHA-2 from DLL), |
71 |
RawDES m_des1, m_des2; |
1
by weidai
Initial revision |
72 |
};
|
73 |
||
74 |
public: |
|
75
by weidai
create DLL version, fix GetNextIV() bug in CTR and OFB modes |
75 |
typedef BlockCipherFinal<ENCRYPTION, Base> Encryption; |
76 |
typedef BlockCipherFinal<DECRYPTION, Base> Decryption; |
|
1
by weidai
Initial revision |
77 |
};
|
78 |
||
173
by weidai
fix documentation, fix PanamaMAC, fix algorithm names |
79 |
//! _
|
1
by weidai
Initial revision |
80 |
struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24> |
81 |
{
|
|
181
by weidai
changes done for FIPS-140 lab code drop |
82 |
CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE3";} |
1
by weidai
Initial revision |
83 |
};
|
84 |
||
85 |
/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
|
|
86 |
class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation |
|
87 |
{
|
|
75
by weidai
create DLL version, fix GetNextIV() bug in CTR and OFB modes |
88 |
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info> |
1
by weidai
Initial revision |
89 |
{
|
90 |
public: |
|
232
by weidai
port to GCC 4, reorganize implementations of SetKey |
91 |
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); |
1
by weidai
Initial revision |
92 |
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
93 |
||
94 |
protected: |
|
78
by weidai
merge in 5.0.4 changes (exclude DES and SHA-2 from DLL), |
95 |
RawDES m_des1, m_des2, m_des3; |
1
by weidai
Initial revision |
96 |
};
|
97 |
||
98 |
public: |
|
75
by weidai
create DLL version, fix GetNextIV() bug in CTR and OFB modes |
99 |
typedef BlockCipherFinal<ENCRYPTION, Base> Encryption; |
100 |
typedef BlockCipherFinal<DECRYPTION, Base> Decryption; |
|
1
by weidai
Initial revision |
101 |
};
|
102 |
||
173
by weidai
fix documentation, fix PanamaMAC, fix algorithm names |
103 |
//! _
|
1
by weidai
Initial revision |
104 |
struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24> |
105 |
{
|
|
106 |
static const char *StaticAlgorithmName() {return "DES-XEX3";} |
|
107 |
};
|
|
108 |
||
109 |
/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
|
|
110 |
class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation |
|
111 |
{
|
|
75
by weidai
create DLL version, fix GetNextIV() bug in CTR and OFB modes |
112 |
class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info> |
1
by weidai
Initial revision |
113 |
{
|
114 |
public: |
|
232
by weidai
port to GCC 4, reorganize implementations of SetKey |
115 |
void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms); |
1
by weidai
Initial revision |
116 |
void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const; |
117 |
||
118 |
protected: |
|
119 |
FixedSizeSecBlock<byte, BLOCKSIZE> m_x1, m_x3; |
|
229
by weidai
VC2005 workaround |
120 |
// VS2005 workaround: calling modules compiled with /clr gets unresolved external symbol DES::Base::ProcessAndXorBlock
|
121 |
// if we use DES::Encryption here directly without value_ptr.
|
|
122 |
value_ptr<DES::Encryption> m_des; |
|
1
by weidai
Initial revision |
123 |
};
|
124 |
||
125 |
public: |
|
75
by weidai
create DLL version, fix GetNextIV() bug in CTR and OFB modes |
126 |
typedef BlockCipherFinal<ENCRYPTION, Base> Encryption; |
127 |
typedef BlockCipherFinal<DECRYPTION, Base> Decryption; |
|
1
by weidai
Initial revision |
128 |
};
|
129 |
||
130 |
typedef DES::Encryption DESEncryption; |
|
131 |
typedef DES::Decryption DESDecryption; |
|
132 |
||
133 |
typedef DES_EDE2::Encryption DES_EDE2_Encryption; |
|
134 |
typedef DES_EDE2::Decryption DES_EDE2_Decryption; |
|
135 |
||
136 |
typedef DES_EDE3::Encryption DES_EDE3_Encryption; |
|
137 |
typedef DES_EDE3::Decryption DES_EDE3_Decryption; |
|
138 |
||
139 |
typedef DES_XEX3::Encryption DES_XEX3_Encryption; |
|
140 |
typedef DES_XEX3::Decryption DES_XEX3_Decryption; |
|
141 |
||
142 |
NAMESPACE_END
|
|
143 |
||
144 |
#endif
|