Botan 3.11.0
Crypto and TLS for C&
tls_transcript_hash_13.h
Go to the documentation of this file.
1/*
2* TLS transcript hash implementation for TLS 1.3
3* (C) 2022 Jack Lloyd
4* 2022 Hannes Rantzsch, René Meusel - neXenio GmbH
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_TLS_TRANSCRIPT_HASH_13_H_
10#define BOTAN_TLS_TRANSCRIPT_HASH_13_H_
11
12#include <botan/tls_magic.h>
13#include <memory>
14#include <span>
15#include <string_view>
16#include <vector>
17
18namespace Botan {
19
20class HashFunction;
21
22} // namespace Botan
23
24namespace Botan::TLS {
25
26/**
27 * Wraps the behaviour of the TLS 1.3 transcript hash as described in
28 * RFC 8446 4.4.1. Particularly, it hides the complexity that the
29 * utilized hash algorithm might become evident only after receiving
30 * a server hello message.
31 */
33 public:
35 explicit Transcript_Hash_State(std::string_view algo_spec);
37
38 /**
39 * Recreates a Transcript_Hash_State after receiving a Hello Retry Request.
40 * Note that the `prev_transcript_hash_state` must not have an hash algorithm
41 * set, yet. Furthermore it must contain exactly TWO unprocessed messages:
42 * * Client Hello 1, and
43 * * Hello Retry Request
44 * The result of this function is an ordinary transcript hash that can replace
45 * the previously used object in client and server implementations.
46 */
48 std::string_view algo_spec, const Transcript_Hash_State& prev_transcript_hash_state);
49
51
54
55 void update(std::span<const uint8_t> serialized_message_s);
56
57 /**
58 * returns the latest transcript hash
59 * (given an algorithm was already specified and some data was provided to `update`)
60 */
61 const Transcript_Hash& current() const;
62
63 /**
64 * returns the second-latest transcript hash
65 * throws if no 'current' was ever replaced by a call to `update`
66 */
67 const Transcript_Hash& previous() const;
68
69 /**
70 * returns a truncated transcript hash (see RFC 8446 4.2.11.2)
71 *
72 * This is useful for implementing PSK binders in the PSK extension of
73 * client hello. It is a transcript over a partially marshalled client
74 * hello message. This hash is available only if the last processed
75 * message was a client hello with a PSK extension.
76 *
77 * throws if no 'truncated' hash is available
78 */
79 const Transcript_Hash& truncated() const;
80
81 void set_algorithm(std::string_view algo_spec);
82
84
85 private:
86 // called by clone
88
89 private:
90 std::unique_ptr<HashFunction> m_hash;
91
92 // This buffer is filled with the data that is passed into
93 // `update()` before `set_algorithm()` was called.
94 std::vector<std::vector<uint8_t>> m_unprocessed_transcript;
95
96 Transcript_Hash m_current;
97 Transcript_Hash m_previous;
98 Transcript_Hash m_truncated;
99};
100
101} // namespace Botan::TLS
102
103#endif // BOTAN_TLS_TRANSCRIPT_HASH_13_H_
#define BOTAN_TEST_API
Definition api.h:41
void update(std::span< const uint8_t > serialized_message_s)
const Transcript_Hash & current() const
Transcript_Hash_State & operator=(Transcript_Hash_State &&other) noexcept
static Transcript_Hash_State recreate_after_hello_retry_request(std::string_view algo_spec, const Transcript_Hash_State &prev_transcript_hash_state)
void set_algorithm(std::string_view algo_spec)
const Transcript_Hash & previous() const
Transcript_Hash_State(Transcript_Hash_State &&other) noexcept
const Transcript_Hash & truncated() const
Transcript_Hash_State & operator=(const Transcript_Hash_State &)=delete
std::vector< uint8_t > Transcript_Hash
Definition tls_magic.h:93