Botan 2.19.3
Crypto and TLS for C&
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
10namespace Botan {
11
12/*
13* Update an ANSI X9.19 MAC Calculation
14*/
15void 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*/
43void 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*/
56void 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*/
72 {
73 m_des1->clear();
74 m_des2->clear();
75 zap(m_state);
76 m_position = 0;
77 }
78
79std::string ANSI_X919_MAC::name() const
80 {
81 return "X9.19-MAC";
82 }
83
88
89/*
90* ANSI X9.19 MAC Constructor
91*/
93 m_des1(BlockCipher::create("DES")),
94 m_des2(m_des1->clone()),
95 m_position(0)
96 {
97 }
98
99}
MessageAuthenticationCode * clone() const override
Definition x919_mac.cpp:84
std::string name() const override
Definition x919_mac.cpp:79
void clear() override
Definition x919_mac.cpp:71
void verify_key_set(bool cond) const
Definition sym_algo.h:171
void zeroise(std::vector< T, Alloc > &vec)
Definition secmem.h:114
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