Botan: src/mac/ssl3mac/ssl3_mac.cpp Source File

Botan 1.10.16

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