Botan 2.1.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 size_t xored = std::min(8 - m_position, length);
18 xor_buf(&m_state[m_position], input, xored);
19 m_position += xored;
20
21 if(m_position < 8) return;
22
23 m_des1->encrypt(m_state);
24 input += xored;
25 length -= xored;
26 while(length >= 8)
27 {
28 xor_buf(m_state, input, 8);
29 m_des1->encrypt(m_state);
30 input += 8;
31 length -= 8;
32 }
33
34 xor_buf(m_state, input, length);
35 m_position = length;
36 }
37
38 /*
39 * Finalize an ANSI X9.19 MAC Calculation
40 */
41 void ANSI_X919_MAC::final_result(uint8_t mac[])
42 {
43 if(m_position)
44 m_des1->encrypt(m_state);
45 m_des2->decrypt(m_state.data(), mac);
46 m_des1->encrypt(mac);
47 zeroise(m_state);
48 m_position = 0;
49 }
50
51 /*
52 * ANSI X9.19 MAC Key Schedule
53 */
54 void ANSI_X919_MAC::key_schedule(const uint8_t key[], size_t length)
55 {
56 m_des1->set_key(key, 8);
57
58 if(length == 16)
59 key += 8;
60
61 m_des2->set_key(key, 8);
62 }
63
64 /*
65 * Clear memory of sensitive data
66 */
67 void ANSI_X919_MAC::clear()
68 {
69 m_des1->clear();
70 m_des2->clear();
71 zeroise(m_state);
72 m_position = 0;
73 }
74
75 std::string ANSI_X919_MAC::name() const
76 {
77 return "X9.19-MAC";
78 }
79
80 MessageAuthenticationCode* ANSI_X919_MAC::clone() const
81 {
82 return new ANSI_X919_MAC;
83 }
84
85 /*
86 * ANSI X9.19 MAC Constructor
87 */
88 ANSI_X919_MAC::ANSI_X919_MAC() :
89 m_des1(BlockCipher::create("DES")),
90 m_des2(BlockCipher::create("DES")),
91 m_state(8), m_position(0)
92 {
93 }
94
95 }
Botan::xor_buf
void xor_buf(T out[], const T in[], size_t length)
Definition: mem_ops.h:115
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::ANSI_X919_MAC::clear
void clear() override
Definition: x919_mac.cpp:67
Botan::ANSI_X919_MAC::name
std::string name() const override
Definition: x919_mac.cpp:75
Botan::ANSI_X919_MAC::ANSI_X919_MAC
ANSI_X919_MAC()
Definition: x919_mac.cpp:88
Botan::ANSI_X919_MAC::clone
MessageAuthenticationCode * clone() const override
Definition: x919_mac.cpp:80
Botan
Definition: alg_id.cpp:13
Botan::CT::min
T min(T a, T b)
Definition: ct_utils.h:180
Botan::BlockCipher
Definition: block_cipher.h:19
Botan::zeroise
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:211