blob: 82a26cfaf308df626768ddb6c3f39d625b87664e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* SSL3-MAC
* (C) 1999-2004 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#include <botan/ssl3_mac.h>
namespace Botan {
/*
* Update a SSL3-MAC Calculation
*/
void SSL3_MAC::add_data(const byte input[], size_t length)
{
m_hash->update(input, length);
}
/*
* Finalize a SSL3-MAC Calculation
*/
void SSL3_MAC::final_result(byte mac[])
{
m_hash->final(mac);
m_hash->update(m_okey);
m_hash->update(mac, output_length());
m_hash->final(mac);
m_hash->update(m_ikey);
}
/*
* SSL3-MAC Key Schedule
*/
void SSL3_MAC::key_schedule(const byte key[], size_t length)
{
m_hash->clear();
// Quirk to deal with specification bug
const size_t inner_hash_length =
(m_hash->name() == "SHA-160") ? 60 : m_hash->hash_block_size();
m_ikey.resize(inner_hash_length);
m_okey.resize(inner_hash_length);
std::fill(m_ikey.begin(), m_ikey.end(), 0x36);
std::fill(m_okey.begin(), m_okey.end(), 0x5C);
copy_mem(&m_ikey[0], key, length);
copy_mem(&m_okey[0], key, length);
m_hash->update(m_ikey);
}
/*
* Clear memory of sensitive data
*/
void SSL3_MAC::clear()
{
m_hash->clear();
zap(m_ikey);
zap(m_okey);
}
/*
* Return the name of this type
*/
std::string SSL3_MAC::name() const
{
return "SSL3-MAC(" + m_hash->name() + ")";
}
/*
* Return a clone of this object
*/
MessageAuthenticationCode* SSL3_MAC::clone() const
{
return new SSL3_MAC(m_hash->clone());
}
/*
* SSL3-MAC Constructor
*/
SSL3_MAC::SSL3_MAC(HashFunction* hash) : m_hash(hash)
{
if(m_hash->hash_block_size() == 0)
throw Invalid_Argument("SSL3-MAC cannot be used with " + m_hash->name());
}
}
|