00001
00002
00003
00004
00005
00006 #ifndef CRYPTOPP_DES_H
00007 #define CRYPTOPP_DES_H
00008
00009 #include "seckey.h"
00010 #include "secblock.h"
00011
00012 NAMESPACE_BEGIN(CryptoPP)
00013
00014 class CRYPTOPP_DLL RawDES
00015 {
00016 public:
00017 void RawSetKey(CipherDir direction, const byte *userKey);
00018 void RawProcessBlock(word32 &l, word32 &r) const;
00019
00020 protected:
00021 static const word32 Spbox[8][64];
00022
00023 FixedSizeSecBlock<word32, 32> k;
00024 };
00025
00026
00027 struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
00028 {
00029
00030 static const char * StaticAlgorithmName() {return "DES";}
00031 };
00032
00033
00034
00035
00036
00037
00038 class DES : public DES_Info, public BlockCipherDocumentation
00039 {
00040 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
00041 {
00042 public:
00043 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
00044 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00045 };
00046
00047 public:
00048
00049 static bool CheckKeyParityBits(const byte *key);
00050
00051 static void CorrectKeyParityBits(byte *key);
00052
00053 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00054 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00055 };
00056
00057
00058 struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
00059 {
00060 CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE2";}
00061 };
00062
00063
00064 class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
00065 {
00066 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
00067 {
00068 public:
00069 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
00070 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00071
00072 protected:
00073 RawDES m_des1, m_des2;
00074 };
00075
00076 public:
00077 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00078 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00079 };
00080
00081
00082 struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
00083 {
00084 CRYPTOPP_DLL static const char * CRYPTOPP_API StaticAlgorithmName() {return "DES-EDE3";}
00085 };
00086
00087
00088 class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
00089 {
00090 class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
00091 {
00092 public:
00093 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
00094 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00095
00096 protected:
00097 RawDES m_des1, m_des2, m_des3;
00098 };
00099
00100 public:
00101 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00102 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00103 };
00104
00105
00106 struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
00107 {
00108 static const char *StaticAlgorithmName() {return "DES-XEX3";}
00109 };
00110
00111
00112 class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
00113 {
00114 class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
00115 {
00116 public:
00117 void UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms);
00118 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00119
00120 protected:
00121 FixedSizeSecBlock<byte, BLOCKSIZE> m_x1, m_x3;
00122
00123
00124 value_ptr<DES::Encryption> m_des;
00125 };
00126
00127 public:
00128 typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00129 typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00130 };
00131
00132 typedef DES::Encryption DESEncryption;
00133 typedef DES::Decryption DESDecryption;
00134
00135 typedef DES_EDE2::Encryption DES_EDE2_Encryption;
00136 typedef DES_EDE2::Decryption DES_EDE2_Decryption;
00137
00138 typedef DES_EDE3::Encryption DES_EDE3_Encryption;
00139 typedef DES_EDE3::Decryption DES_EDE3_Decryption;
00140
00141 typedef DES_XEX3::Encryption DES_XEX3_Encryption;
00142 typedef DES_XEX3::Decryption DES_XEX3_Decryption;
00143
00144 NAMESPACE_END
00145
00146 #endif