Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

x919_mac.cpp
Go to the documentation of this file.
1 /*
2 * ANSI X9.19 MAC
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/x919_mac.h>
9
10 namespace Botan {
11
12 /*
13 * Update an ANSI X9.19 MAC Calculation
14 */
15 void ANSI_X919_MAC::add_data(const uint8_t input[], size_t length)
16 {
17 verify_key_set(m_state.empty() == false);
18
19 size_t xored = std::min(8 - m_position, length);
20 xor_buf(&m_state[m_position], input, xored);
21 m_position += xored;
22
23 if(m_position < 8) return;
24
25 m_des1->encrypt(m_state);
26 input += xored;
27 length -= xored;
28 while(length >= 8)
29 {
30 xor_buf(m_state, input, 8);
31 m_des1->encrypt(m_state);
32 input += 8;
33 length -= 8;
34 }
35
36 xor_buf(m_state, input, length);
37 m_position = length;
38 }
39
40 /*
41 * Finalize an ANSI X9.19 MAC Calculation
42 */
43 void ANSI_X919_MAC::final_result(uint8_t mac[])
44 {
45 if(m_position)
46 m_des1->encrypt(m_state);
47 m_des2->decrypt(m_state.data(), mac);
48 m_des1->encrypt(mac);
49 zeroise(m_state);
50 m_position = 0;
51 }
52
53 /*
54 * ANSI X9.19 MAC Key Schedule
55 */
56 void ANSI_X919_MAC::key_schedule(const uint8_t key[], size_t length)
57 {
58 m_state.resize(8);
59
60 m_des1->set_key(key, 8);
61
62 if(length == 16)
63 key += 8;
64
65 m_des2->set_key(key, 8);
66 }
67
68 /*
69 * Clear memory of sensitive data
70 */
71 void ANSI_X919_MAC::clear()
72 {
73 m_des1->clear();
74 m_des2->clear();
75 zap(m_state);
76 m_position = 0;
77 }
78
79 std::string ANSI_X919_MAC::name() const
80 {
81 return "X9.19-MAC";
82 }
83
84 MessageAuthenticationCode* ANSI_X919_MAC::clone() const
85 {
86 return new ANSI_X919_MAC;
87 }
88
89 /*
90 * ANSI X9.19 MAC Constructor
91 */
92 ANSI_X919_MAC::ANSI_X919_MAC() :
93 m_des1(BlockCipher::create("DES")),
94 m_des2(m_des1->clone()),
95 m_position(0)
96 {
97 }
98
99 }
Botan::zap
void zap(std::vector< T, Alloc > &vec)
Definition: secmem.h:170
Botan::MessageAuthenticationCode
Definition: mac.h:21
Botan::ANSI_X919_MAC::clear
void clear() override
Definition: x919_mac.cpp:71
Botan::ANSI_X919_MAC::name
std::string name() const override
Definition: x919_mac.cpp:79
Botan::ANSI_X919_MAC::ANSI_X919_MAC
ANSI_X919_MAC()
Definition: x919_mac.cpp:92
Botan::xor_buf
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition: mem_ops.h:232
Botan::ANSI_X919_MAC::clone
MessageAuthenticationCode * clone() const override
Definition: x919_mac.cpp:84
Botan
Definition: alg_id.cpp:13
Botan::SymmetricAlgorithm::verify_key_set
void verify_key_set(bool cond) const
Definition: sym_algo.h:89
Botan::BlockCipher
Definition: block_cipher.h:21
Botan::zeroise
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:160