Botan  2.1.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  for(size_t i = 0; i != blocks; ++i)
18  {
19  xor_buf(out, in, m_K1.data(), BLOCK_SIZE);
20  m_des.encrypt(out);
21  xor_buf(out, m_K2.data(), BLOCK_SIZE);
22 
23  in += BLOCK_SIZE;
24  out += BLOCK_SIZE;
25  }
26  }
27 
28 /*
29 * DESX Decryption
30 */
31 void DESX::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
32  {
33  for(size_t i = 0; i != blocks; ++i)
34  {
35  xor_buf(out, in, m_K2.data(), BLOCK_SIZE);
36  m_des.decrypt(out);
37  xor_buf(out, m_K1.data(), BLOCK_SIZE);
38 
39  in += BLOCK_SIZE;
40  out += BLOCK_SIZE;
41  }
42  }
43 
44 /*
45 * DESX Key Schedule
46 */
47 void DESX::key_schedule(const uint8_t key[], size_t)
48  {
49  m_K1.assign(key, key + 8);
50  m_des.set_key(key + 8, 8);
51  m_K2.assign(key + 16, key + 24);
52  }
53 
55  {
56  m_des.clear();
57  zap(m_K1);
58  zap(m_K2);
59  }
60 
61 }
void xor_buf(T out[], const T in[], size_t length)
Definition: mem_ops.h:115
void encrypt(const uint8_t in[], uint8_t out[]) const
Definition: block_cipher.h:80
void decrypt(const uint8_t in[], uint8_t out[]) const
Definition: block_cipher.h:90
void zap(std::vector< T, Alloc > &vec)
Definition: secmem.h:221
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:66
Definition: alg_id.cpp:13
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition: desx.cpp:15
void clear() override
Definition: desx.cpp:54
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition: desx.cpp:31
void clear() override
Definition: des.cpp:206