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
|
/*
* DES
* (C) 1999-2007 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/desx.h>
namespace Botan {
/*
* DESX Encryption
*/
void DESX::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
xor_buf(out, in, m_K1.data(), BLOCK_SIZE);
m_des.encrypt(out);
xor_buf(out, m_K2.data(), BLOCK_SIZE);
in += BLOCK_SIZE;
out += BLOCK_SIZE;
}
}
/*
* DESX Decryption
*/
void DESX::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
xor_buf(out, in, m_K2.data(), BLOCK_SIZE);
m_des.decrypt(out);
xor_buf(out, m_K1.data(), BLOCK_SIZE);
in += BLOCK_SIZE;
out += BLOCK_SIZE;
}
}
/*
* DESX Key Schedule
*/
void DESX::key_schedule(const uint8_t key[], size_t)
{
m_K1.assign(key, key + 8);
m_des.set_key(key + 8, 8);
m_K2.assign(key + 16, key + 24);
}
void DESX::clear()
{
m_des.clear();
zap(m_K1);
zap(m_K2);
}
}
|