Botan 2.19.3
Crypto and TLS for C&
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
10namespace Botan {
11
12/*
13* DESX Encryption
14*/
15void 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*/
33void 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*/
51void 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
59 {
60 m_des.clear();
61 zap(m_K1);
62 zap(m_K2);
63 }
64
65}
void encrypt(const uint8_t in[], uint8_t out[]) const
void decrypt(const uint8_t in[], uint8_t out[]) const
void clear() override
Definition desx.cpp:58
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition desx.cpp:15
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition desx.cpp:33
void clear() override
Definition des.cpp:305
void set_key(const SymmetricKey &key)
Definition sym_algo.h:147
void verify_key_set(bool cond) const
Definition sym_algo.h:171
void zap(std::vector< T, Alloc > &vec)
Definition secmem.h:124
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition mem_ops.h:262