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