-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdes.h
67 lines (60 loc) · 1.66 KB
/
des.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Rename this file DES.H
// DES Encryption and Decryption
// from efgh.com/software
const int DES_KEY_SIZE = 56;
const int DES_DATA_SIZE = 64;
const int DES_SBUFFER_SIZE = 48;
const int DES_ROUNDS = 16;
#ifdef TRIPLEDES
class triple_des;
#endif
class des
{
private:
const char *xmix(const char *, unsigned char [DES_DATA_SIZE],
const unsigned char [DES_KEY_SIZE]);
void encrypt_decrypt(unsigned char [DES_DATA_SIZE], int /* boolean */);
unsigned char compressed_shifted_key[DES_ROUNDS][DES_SBUFFER_SIZE];
public:
void initialize(const unsigned char[DES_KEY_SIZE]);
void password(const char *);
void encrypt(unsigned char data[DES_DATA_SIZE])
{
encrypt_decrypt(data, 1 /* true */);
}
void decrypt(unsigned char data[DES_DATA_SIZE])
{
encrypt_decrypt(data, 0 /* false */);
}
#ifdef TRIPLEDES
friend triple_des;
#endif // TRIPLEDES
};
#ifdef TRIPLEDES
class triple_des
{
private:
des part[3];
void encrypt_decrypt(unsigned char [DES_DATA_SIZE], int /* boolean */);
public:
void initialize(const unsigned char key[3*DES_KEY_SIZE])
{
part[0].initialize(key);
part[1].initialize(key + DES_KEY_SIZE);
part[2].initialize(key + 2*DES_KEY_SIZE);
}
void password(const char *);
void encrypt(unsigned char data[DES_DATA_SIZE])
{
part[0].encrypt(data);
part[1].decrypt(data);
part[2].encrypt(data);
}
void decrypt(unsigned char data[DES_DATA_SIZE])
{
part[2].decrypt(data);
part[1].encrypt(data);
part[0].decrypt(data);
}
};
#endif