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 struct DES_Info : public
FixedBlockSize<8>, public
FixedKeyLength<8>
00013 {
00014
static const char *StaticAlgorithmName() {
return "DES";}
00015 };
00016
00017
00018
00019
00020
00021
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
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
00041
static bool CheckKeyParityBits(
const byte *key);
00042
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
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
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
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