Coverage Report

Created: 2020-02-14 15:38

/src/botan/src/lib/mac/x919_mac/x919_mac.cpp
Line
Count
Source (jump to first uncovered line)
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
0
   {
17
0
   verify_key_set(m_state.empty() == false);
18
0
19
0
   size_t xored = std::min(8 - m_position, length);
20
0
   xor_buf(&m_state[m_position], input, xored);
21
0
   m_position += xored;
22
0
23
0
   if(m_position < 8) return;
24
0
25
0
   m_des1->encrypt(m_state);
26
0
   input += xored;
27
0
   length -= xored;
28
0
   while(length >= 8)
29
0
      {
30
0
      xor_buf(m_state, input, 8);
31
0
      m_des1->encrypt(m_state);
32
0
      input += 8;
33
0
      length -= 8;
34
0
      }
35
0
36
0
   xor_buf(m_state, input, length);
37
0
   m_position = length;
38
0
   }
39
40
/*
41
* Finalize an ANSI X9.19 MAC Calculation
42
*/
43
void ANSI_X919_MAC::final_result(uint8_t mac[])
44
0
   {
45
0
   if(m_position)
46
0
      m_des1->encrypt(m_state);
47
0
   m_des2->decrypt(m_state.data(), mac);
48
0
   m_des1->encrypt(mac);
49
0
   zeroise(m_state);
50
0
   m_position = 0;
51
0
   }
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
0
   {
58
0
   m_state.resize(8);
59
0
60
0
   m_des1->set_key(key, 8);
61
0
62
0
   if(length == 16)
63
0
      key += 8;
64
0
65
0
   m_des2->set_key(key, 8);
66
0
   }
67
68
/*
69
* Clear memory of sensitive data
70
*/
71
void ANSI_X919_MAC::clear()
72
0
   {
73
0
   m_des1->clear();
74
0
   m_des2->clear();
75
0
   zap(m_state);
76
0
   m_position = 0;
77
0
   }
78
79
std::string ANSI_X919_MAC::name() const
80
0
   {
81
0
   return "X9.19-MAC";
82
0
   }
83
84
MessageAuthenticationCode* ANSI_X919_MAC::clone() const
85
0
   {
86
0
   return new ANSI_X919_MAC;
87
0
   }
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
0
   {
97
0
   }
98
99
}