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 struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
00013 {
00014         static const char *StaticAlgorithmName() {return "DES";}
00015 };
00016 
00017 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
00018 /*! The DES implementation in Crypto++ ignores the parity bits
00019         (the least significant bits of each byte) in the key. However
00020         you can use CheckKeyParityBits() and CorrectKeyParityBits() to
00021         check or correct the parity bits if you wish. */
00022 class DES : public DES_Info, public BlockCipherDocumentation
00023 {
00024         class Base : public BlockCipherBaseTemplate<DES_Info>
00025         {
00026         public:
00027                 void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length = 8);
00028                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00029 
00030                 // exposed for faster Triple-DES
00031                 void RawProcessBlock(word32 &l, word32 &r) const;
00032 
00033         protected:
00034                 static const word32 Spbox[8][64];
00035 
00036                 FixedSizeSecBlock<word32, 32> k;
00037         };
00038 
00039 public:
00040         //! check DES key parity bits
00041         static bool CheckKeyParityBits(const byte *key);
00042         //! correct DES key parity bits
00043         static void CorrectKeyParityBits(byte *key);
00044 
00045         typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
00046         typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
00047 };
00048 
00049 struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
00050 {
00051         static const char *StaticAlgorithmName() {return "DES-EDE2";}
00052 };
00053 
00054 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
00055 class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
00056 {
00057         class Base : public BlockCipherBaseTemplate<DES_EDE2_Info>
00058         {
00059         public:
00060                 void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
00061                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00062 
00063         protected:
00064                 DES::Encryption m_des1, m_des2;
00065         };
00066 
00067 public:
00068         typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
00069         typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
00070 };
00071 
00072 struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
00073 {
00074         static const char *StaticAlgorithmName() {return "DES-EDE3";}
00075 };
00076 
00077 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
00078 class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
00079 {
00080         class Base : public BlockCipherBaseTemplate<DES_EDE3_Info>
00081         {
00082         public:
00083                 void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
00084                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00085 
00086         protected:
00087                 DES::Encryption m_des1, m_des2, m_des3;
00088         };
00089 
00090 public:
00091         typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
00092         typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
00093 };
00094 
00095 struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
00096 {
00097         static const char *StaticAlgorithmName() {return "DES-XEX3";}
00098 };
00099 
00100 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
00101 class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
00102 {
00103         class Base : public BlockCipherBaseTemplate<DES_XEX3_Info>
00104         {
00105         public:
00106                 void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
00107                 void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
00108 
00109         protected:
00110                 FixedSizeSecBlock<byte, BLOCKSIZE> m_x1, m_x3;
00111                 DES::Encryption m_des;
00112         };
00113 
00114 public:
00115         typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
00116         typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
00117 };
00118 
00119 typedef DES::Encryption DESEncryption;
00120 typedef DES::Decryption DESDecryption;
00121 
00122 typedef DES_EDE2::Encryption DES_EDE2_Encryption;
00123 typedef DES_EDE2::Decryption DES_EDE2_Decryption;
00124 
00125 typedef DES_EDE3::Encryption DES_EDE3_Encryption;
00126 typedef DES_EDE3::Decryption DES_EDE3_Decryption;
00127 
00128 typedef DES_XEX3::Encryption DES_XEX3_Encryption;
00129 typedef DES_XEX3::Decryption DES_XEX3_Decryption;
00130 
00131 NAMESPACE_END
00132 
00133 #endif

Generated on Sun Mar 14 20:44:25 2004 for Crypto++ by doxygen 1.3.6-20040222