Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

des.h

Go to the documentation of this file.
00001 #ifndef CRYPTOPP_DES_H
00002 #define CRYPTOPP_DES_H
00003 
00004 /** \file
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 //! _
00025 struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
00026 {
00027         // disable DES in DLL version by not exporting this function
00028         static const char * StaticAlgorithmName() {return "DES";}
00029 };
00030 
00031 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
00032 /*! The DES implementation in Crypto++ ignores the parity bits
00033         (the least significant bits of each byte) in the key. However
00034         you can use CheckKeyParityBits() and CorrectKeyParityBits() to
00035         check or correct the parity bits if you wish. */
00036 class DES : public DES_Info, public BlockCipherDocumentation
00037 {
00038         class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_Info>, public RawDES
00039         {
00040         public:
00041                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00042         };
00043 
00044 public:
00045         //! check DES key parity bits
00046         static bool CheckKeyParityBits(const byte *key);
00047         //! correct DES key parity bits
00048         static void CorrectKeyParityBits(byte *key);
00049 
00050         typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00051         typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00052 };
00053 
00054 //! _
00055 struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
00056 {
00057         CRYPTOPP_DLL static const char * StaticAlgorithmName() {return "DES-EDE2";}
00058 };
00059 
00060 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
00061 class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
00062 {
00063         class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE2_Info>
00064         {
00065         public:
00066                 void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
00067                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00068 
00069         protected:
00070                 RawDES m_des1, m_des2;
00071         };
00072 
00073 public:
00074         typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00075         typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00076 };
00077 
00078 //! _
00079 struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
00080 {
00081         CRYPTOPP_DLL static const char * StaticAlgorithmName() {return "DES-EDE3";}
00082 };
00083 
00084 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
00085 class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
00086 {
00087         class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_EDE3_Info>
00088         {
00089         public:
00090                 void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
00091                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00092 
00093         protected:
00094                 RawDES m_des1, m_des2, m_des3;
00095         };
00096 
00097 public:
00098         typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00099         typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00100 };
00101 
00102 //! _
00103 struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
00104 {
00105         static const char *StaticAlgorithmName() {return "DES-XEX3";}
00106 };
00107 
00108 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
00109 class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
00110 {
00111         class CRYPTOPP_NO_VTABLE Base : public BlockCipherImpl<DES_XEX3_Info>
00112         {
00113         public:
00114                 void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
00115                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00116 
00117         protected:
00118                 FixedSizeSecBlock<byte, BLOCKSIZE> m_x1, m_x3;
00119                 DES::Encryption m_des;
00120         };
00121 
00122 public:
00123         typedef BlockCipherFinal<ENCRYPTION, Base> Encryption;
00124         typedef BlockCipherFinal<DECRYPTION, Base> Decryption;
00125 };
00126 
00127 typedef DES::Encryption DESEncryption;
00128 typedef DES::Decryption DESDecryption;
00129 
00130 typedef DES_EDE2::Encryption DES_EDE2_Encryption;
00131 typedef DES_EDE2::Decryption DES_EDE2_Decryption;
00132 
00133 typedef DES_EDE3::Encryption DES_EDE3_Encryption;
00134 typedef DES_EDE3::Decryption DES_EDE3_Decryption;
00135 
00136 typedef DES_XEX3::Encryption DES_XEX3_Encryption;
00137 typedef DES_XEX3::Decryption DES_XEX3_Decryption;
00138 
00139 NAMESPACE_END
00140 
00141 #endif

Generated on Wed Nov 17 21:26:06 2004 for Crypto++ by  doxygen 1.3.9.1