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
00025 struct DES_Info :
public FixedBlockSize<8>,
public FixedKeyLength<8>
00026 {
00027
00028
static const char * StaticAlgorithmName() {
return "DES";}
00029 };
00030
00031
00032
00033
00034
00035
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
00046
static bool CheckKeyParityBits(
const byte *key);
00047
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
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
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
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