monotone

monotone Mtn Source Tree

Root/cryptopp/des.h

1#ifndef CRYPTOPP_DES_H
2#define CRYPTOPP_DES_H
3
4/** \file
5*/
6
7#include "seckey.h"
8#include "secblock.h"
9
10NAMESPACE_BEGIN(CryptoPP)
11
12struct DES_Info : public FixedBlockSize<8>, public FixedKeyLength<8>
13{
14static const char *StaticAlgorithmName() {return "DES";}
15};
16
17/// <a href="http://www.weidai.com/scan-mirror/cs.html#DES">DES</a>
18/*! The DES implementation in Crypto++ ignores the parity bits
19(the least significant bits of each byte) in the key. However
20you can use CheckKeyParityBits() and CorrectKeyParityBits() to
21check or correct the parity bits if you wish. */
22class DES : public DES_Info, public BlockCipherDocumentation
23{
24class Base : public BlockCipherBaseTemplate<DES_Info>
25{
26public:
27void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length = 8);
28void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
29
30// exposed for faster Triple-DES
31void RawProcessBlock(word32 &l, word32 &r) const;
32
33protected:
34static const word32 Spbox[8][64];
35
36FixedSizeSecBlock<word32, 32> k;
37};
38
39public:
40//! check DES key parity bits
41static bool CheckKeyParityBits(const byte *key);
42//! correct DES key parity bits
43static void CorrectKeyParityBits(byte *key);
44
45typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
46typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
47};
48
49struct DES_EDE2_Info : public FixedBlockSize<8>, public FixedKeyLength<16>
50{
51static const char *StaticAlgorithmName() {return "DES-EDE2";}
52};
53
54/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE2</a>
55class DES_EDE2 : public DES_EDE2_Info, public BlockCipherDocumentation
56{
57class Base : public BlockCipherBaseTemplate<DES_EDE2_Info>
58{
59public:
60void UncheckedSetKey(CipherDir direction, const byte *userKey, unsigned int length);
61void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
62
63protected:
64DES::Encryption m_des1, m_des2;
65};
66
67public:
68typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
69typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
70};
71
72struct DES_EDE3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
73{
74static const char *StaticAlgorithmName() {return "DES-EDE3";}
75};
76
77/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESede">DES-EDE3</a>
78class DES_EDE3 : public DES_EDE3_Info, public BlockCipherDocumentation
79{
80class Base : public BlockCipherBaseTemplate<DES_EDE3_Info>
81{
82public:
83void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
84void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
85
86protected:
87DES::Encryption m_des1, m_des2, m_des3;
88};
89
90public:
91typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
92typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
93};
94
95struct DES_XEX3_Info : public FixedBlockSize<8>, public FixedKeyLength<24>
96{
97static const char *StaticAlgorithmName() {return "DES-XEX3";}
98};
99
100/// <a href="http://www.weidai.com/scan-mirror/cs.html#DESX">DES-XEX3</a>, AKA DESX
101class DES_XEX3 : public DES_XEX3_Info, public BlockCipherDocumentation
102{
103class Base : public BlockCipherBaseTemplate<DES_XEX3_Info>
104{
105public:
106void UncheckedSetKey(CipherDir dir, const byte *key, unsigned int length);
107void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const;
108
109protected:
110FixedSizeSecBlock<byte, BLOCKSIZE> m_x1, m_x3;
111DES::Encryption m_des;
112};
113
114public:
115typedef BlockCipherTemplate<ENCRYPTION, Base> Encryption;
116typedef BlockCipherTemplate<DECRYPTION, Base> Decryption;
117};
118
119typedef DES::Encryption DESEncryption;
120typedef DES::Decryption DESDecryption;
121
122typedef DES_EDE2::Encryption DES_EDE2_Encryption;
123typedef DES_EDE2::Decryption DES_EDE2_Decryption;
124
125typedef DES_EDE3::Encryption DES_EDE3_Encryption;
126typedef DES_EDE3::Decryption DES_EDE3_Decryption;
127
128typedef DES_XEX3::Encryption DES_XEX3_Encryption;
129typedef DES_XEX3::Decryption DES_XEX3_Decryption;
130
131NAMESPACE_END
132
133#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status