Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound 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 struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
    00025 {
    00026         // disable DES in DLL version by not exporting this function
    00027         static const char * StaticAlgorithmName() {return "DES";}
    00028 };
    00029
    00030 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
    00031 /*! The DES implementation in Crypto++ ignores the parity bits
    00032         (the least significant bits of each byte) in the key. However
    00033         you can use CheckKeyParityBits() and CorrectKeyParityBits() to
    00034         check or correct the parity bits if you wish. */
    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         //! check DES key parity bits
    00045         static bool CheckKeyParityBits(const byte *key);
    00046         //! correct DES key parity bits
    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 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
    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 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
    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 /// <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
    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