Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 }
Botan::BlockCipher::encrypt
void encrypt(const uint8_t in[], uint8_t out[]) const
Definition: block_cipher.h:82
Botan::BlockCipher::decrypt
void decrypt(const uint8_t in[], uint8_t out[]) const
Definition: block_cipher.h:92
Botan::zap
void zap(std::vector< T, Alloc > &vec)
Definition: secmem.h:170
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:65
Botan::xor_buf
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition: mem_ops.h:232
Botan::Block_Cipher_Fixed_Params< 8, 24 >::BLOCK_SIZE
Definition: block_cipher.h:224
Botan
Definition: alg_id.cpp:13
Botan::DESX::encrypt_n
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition: desx.cpp:15
Botan::SymmetricAlgorithm::verify_key_set
void verify_key_set(bool cond) const
Definition: sym_algo.h:89
Botan::DESX::clear
void clear() override
Definition: desx.cpp:58
Botan::DESX::decrypt_n
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition: desx.cpp:33
Botan::DES::clear
void clear() override
Definition: des.cpp:305