Botan: src/ssl/tls_handshake_hash.cpp Source File

Botan 1.10.16

tls_handshake_hash.cpp
Go to the documentation of this file.
1 /*
2 * TLS Handshake Hash
3 * (C) 2004-2006 Jack Lloyd
4 *
5 * Released under the terms of the Botan license
6 */
7
8 #include <botan/internal/tls_handshake_hash.h>
9 #include <botan/md5.h>
10 #include <botan/sha160.h>
11 #include <memory>
12
13 namespace Botan {
14
15 /**
16 * Return a TLS Handshake Hash
17 */
18 SecureVector<byte> HandshakeHash::final()
19 {
20 MD5 md5;
21 SHA_160 sha1;
22
23 md5.update(data);
24 sha1.update(data);
25
26 SecureVector<byte> output;
27 output += md5.final();
28 output += sha1.final();
29 return output;
30 }
31
32 /**
33 * Return a SSLv3 Handshake Hash
34 */
35 SecureVector<byte> HandshakeHash::final_ssl3(const MemoryRegion<byte>& secret)
36 {
37 const byte PAD_INNER = 0x36, PAD_OUTER = 0x5C;
38
39 MD5 md5;
40 SHA_160 sha1;
41
42 md5.update(data);
43 sha1.update(data);
44
45 md5.update(secret);
46 sha1.update(secret);
47
48 for(size_t i = 0; i != 48; ++i)
49 md5.update(PAD_INNER);
50 for(size_t i = 0; i != 40; ++i)
51 sha1.update(PAD_INNER);
52
53 SecureVector<byte> inner_md5 = md5.final(), inner_sha1 = sha1.final();
54
55 md5.update(secret);
56 sha1.update(secret);
57 for(size_t i = 0; i != 48; ++i)
58 md5.update(PAD_OUTER);
59 for(size_t i = 0; i != 40; ++i)
60 sha1.update(PAD_OUTER);
61 md5.update(inner_md5);
62 sha1.update(inner_sha1);
63
64 SecureVector<byte> output;
65 output += md5.final();
66 output += sha1.final();
67 return output;
68 }
69
70 }
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::MD5
Definition: md5.h:18
Botan::SHA_160
Definition: sha160.h:18
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::HandshakeHash::final_ssl3
SecureVector< byte > final_ssl3(const MemoryRegion< byte > &)
Definition: tls_handshake_hash.cpp:35
Botan::Buffered_Computation::final
void final(byte out[])
Definition: buf_comp.h:80
Botan::SecureVector< byte >
Botan::HandshakeHash::final
SecureVector< byte > final()
Definition: tls_handshake_hash.cpp:18