/src/botan/src/lib/block/des/desx.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * DES |
3 | | * (C) 1999-2007 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #include <botan/desx.h> |
9 | | |
10 | | namespace Botan { |
11 | | |
12 | | /* |
13 | | * DESX Encryption |
14 | | */ |
15 | | void DESX::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const |
16 | 0 | { |
17 | 0 | verify_key_set(m_K1.empty() == false); |
18 | 0 |
|
19 | 0 | for(size_t i = 0; i != blocks; ++i) |
20 | 0 | { |
21 | 0 | xor_buf(out, in, m_K1.data(), BLOCK_SIZE); |
22 | 0 | m_des.encrypt(out); |
23 | 0 | xor_buf(out, m_K2.data(), BLOCK_SIZE); |
24 | 0 |
|
25 | 0 | in += BLOCK_SIZE; |
26 | 0 | out += BLOCK_SIZE; |
27 | 0 | } |
28 | 0 | } |
29 | | |
30 | | /* |
31 | | * DESX Decryption |
32 | | */ |
33 | | void DESX::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const |
34 | 0 | { |
35 | 0 | verify_key_set(m_K1.empty() == false); |
36 | 0 |
|
37 | 0 | for(size_t i = 0; i != blocks; ++i) |
38 | 0 | { |
39 | 0 | xor_buf(out, in, m_K2.data(), BLOCK_SIZE); |
40 | 0 | m_des.decrypt(out); |
41 | 0 | xor_buf(out, m_K1.data(), BLOCK_SIZE); |
42 | 0 |
|
43 | 0 | in += BLOCK_SIZE; |
44 | 0 | out += BLOCK_SIZE; |
45 | 0 | } |
46 | 0 | } |
47 | | |
48 | | /* |
49 | | * DESX Key Schedule |
50 | | */ |
51 | | void DESX::key_schedule(const uint8_t key[], size_t) |
52 | 0 | { |
53 | 0 | m_K1.assign(key, key + 8); |
54 | 0 | m_des.set_key(key + 8, 8); |
55 | 0 | m_K2.assign(key + 16, key + 24); |
56 | 0 | } |
57 | | |
58 | | void DESX::clear() |
59 | 0 | { |
60 | 0 | m_des.clear(); |
61 | 0 | zap(m_K1); |
62 | 0 | zap(m_K2); |
63 | 0 | } |
64 | | |
65 | | } |