Botan  2.10.0
Crypto and TLS for C++11
desx.cpp
Go to the documentation of this file.
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  {
17  verify_key_set(m_K1.empty() == false);
18 
19  for(size_t i = 0; i != blocks; ++i)
20  {
21  xor_buf(out, in, m_K1.data(), BLOCK_SIZE);
22  m_des.encrypt(out);
23  xor_buf(out, m_K2.data(), BLOCK_SIZE);
24 
25  in += BLOCK_SIZE;
26  out += BLOCK_SIZE;
27  }
28  }
29 
30 /*
31 * DESX Decryption
32 */
33 void DESX::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
34  {
35  verify_key_set(m_K1.empty() == false);
36 
37  for(size_t i = 0; i != blocks; ++i)
38  {
39  xor_buf(out, in, m_K2.data(), BLOCK_SIZE);
40  m_des.decrypt(out);
41  xor_buf(out, m_K1.data(), BLOCK_SIZE);
42 
43  in += BLOCK_SIZE;
44  out += BLOCK_SIZE;
45  }
46  }
47 
48 /*
49 * DESX Key Schedule
50 */
51 void DESX::key_schedule(const uint8_t key[], size_t)
52  {
53  m_K1.assign(key, key + 8);
54  m_des.set_key(key + 8, 8);
55  m_K2.assign(key + 16, key + 24);
56  }
57 
58 void DESX::clear()
59  {
60  m_des.clear();
61  zap(m_K1);
62  zap(m_K2);
63  }
64 
65 }
void zap(std::vector< T, Alloc > &vec)
Definition: secmem.h:170
void const uint8_t in[]
Definition: mgf1.h:26
const uint8_t uint8_t size_t blocks
Definition: ffi.h:686
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition: mem_ops.h:202
Definition: alg_id.cpp:13
uint8_t out[]
Definition: pbkdf2.h:19
const uint8_t * key
Definition: ffi.h:359