File indexing completed on 2025-01-18 09:54:56
0001
0002
0003
0004
0005
0006 #ifndef CRYPTOPP_DES_H
0007 #define CRYPTOPP_DES_H
0008
0009 #include "seckey.h"
0010 #include "secblock.h"
0011
0012 NAMESPACE_BEGIN(CryptoPP)
0013
0014
0015
0016 class CRYPTOPP_DLL RawDES
0017 {
0018 public:
0019 void RawSetKey(CipherDir direction, const byte *userKey);
0020 void RawProcessBlock(word32 &l, word32 &r) const;
0021
0022 protected:
0023 static const word32 Spbox[8][64];
0024
0025 FixedSizeSecBlock<word32, 32> k;
0026 };
0027
0028
0029
0030 struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
0031 {
0032
0033 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "DES";}
0034 };
0035
0036
0037
0038
0039
0040
0041
0042 class DES : public DES_Info, public BlockCipherDocumentation
0043 {
0044
0045 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
0046 {
0047 public:
0048 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
0049 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0050 };
0051
0052 public:
0053
0054 static bool CheckKeyParityBits(const byte *key);
0055
0056 static void CorrectKeyParityBits(byte *key);
0057
0058 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0059 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0060 };
0061
0062
0063
0064 struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
0065 {
0066 CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE2";}
0067 };
0068
0069
0070
0071
0072 class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
0073 {
0074
0075 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
0076 {
0077 public:
0078 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
0079 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0080
0081 protected:
0082 RawDES m_des1, m_des2;
0083 };
0084
0085 public:
0086 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0087 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0088 };
0089
0090
0091
0092 struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
0093 {
0094 CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE3";}
0095 };
0096
0097
0098
0099
0100 class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
0101 {
0102
0103 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
0104 {
0105 public:
0106 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
0107 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0108
0109 protected:
0110 RawDES m_des1, m_des2, m_des3;
0111 };
0112
0113 public:
0114 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0115 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0116 };
0117
0118
0119
0120 struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
0121 {
0122 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "DES-XEX3";}
0123 };
0124
0125
0126
0127
0128 class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
0129 {
0130
0131 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
0132 {
0133 public:
0134 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
0135 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
0136
0137 protected:
0138 FixedSizeSecBlock<byte, BLOCKSIZE> m_x1, m_x3;
0139
0140
0141 value_ptr<DES::Encryption> m_des;
0142 };
0143
0144 public:
0145 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
0146 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
0147 };
0148
0149 typedef DES::Encryption DESEncryption;
0150 typedef DES::Decryption DESDecryption;
0151
0152 typedef DES_EDE2::Encryption DES_EDE2_Encryption;
0153 typedef DES_EDE2::Decryption DES_EDE2_Decryption;
0154
0155 typedef DES_EDE3::Encryption DES_EDE3_Encryption;
0156 typedef DES_EDE3::Decryption DES_EDE3_Decryption;
0157
0158 typedef DES_XEX3::Encryption DES_XEX3_Encryption;
0159 typedef DES_XEX3::Decryption DES_XEX3_Decryption;
0160
0161 NAMESPACE_END
0162
0163 #endif