Botan 3.4.0
Crypto and TLS for C&
tls_cipher_state.cpp
Go to the documentation of this file.
1/*
2* TLS cipher state 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/**
10 * Cipher_State state machine adapted from RFC 8446 7.1.
11 *
12 * 0
13 * |
14 * v
15 * PSK -> HKDF-Extract = Early Secret
16 * |
17 * +-----> Derive-Secret(., "ext binder" | "res binder", "")
18 * | = binder_key
19 * STATE PSK BINDER
20 * This state is reached by constructing the Cipher_State using init_with_psk().
21 * The state can then be further advanced using advance_with_client_hello() once
22 * the initial Client Hello is fully generated.
23 * |
24 * +-----> Derive-Secret(., "c e traffic", ClientHello)
25 * | = client_early_traffic_secret
26 * |
27 * +-----> Derive-Secret(., "e exp master", ClientHello)
28 * | = early_exporter_master_secret
29 * v
30 * Derive-Secret(., "derived", "")
31 * |
32 * *
33 * STATE EARLY TRAFFIC
34 * This state is reached by calling advance_with_client_hello().
35 * In this state the early data traffic secrets are available. TODO: implement early data.
36 * The state can then be further advanced using advance_with_server_hello().
37 * *
38 * |
39 * v
40 * (EC)DHE -> HKDF-Extract = Handshake Secret
41 * |
42 * +-----> Derive-Secret(., "c hs traffic",
43 * | ClientHello...ServerHello)
44 * | = client_handshake_traffic_secret
45 * |
46 * +-----> Derive-Secret(., "s hs traffic",
47 * | ClientHello...ServerHello)
48 * | = server_handshake_traffic_secret
49 * v
50 * Derive-Secret(., "derived", "")
51 * |
52 * *
53 * STATE HANDSHAKE TRAFFIC
54 * This state is reached by constructing Cipher_State using init_with_server_hello() or
55 * advance_with_server_hello(). In this state the handshake traffic secrets are available.
56 * The state can then be further advanced using advance_with_server_finished().
57 * *
58 * |
59 * v
60 * 0 -> HKDF-Extract = Master Secret
61 * |
62 * +-----> Derive-Secret(., "c ap traffic",
63 * | ClientHello...server Finished)
64 * | = client_application_traffic_secret_0
65 * |
66 * +-----> Derive-Secret(., "s ap traffic",
67 * | ClientHello...server Finished)
68 * | = server_application_traffic_secret_0
69 * |
70 * +-----> Derive-Secret(., "exp master",
71 * | ClientHello...server Finished)
72 * | = exporter_master_secret
73 * *
74 * STATE SERVER APPLICATION TRAFFIC
75 * This state is reached by calling advance_with_server_finished(). It allows the server
76 * to send application traffic and the client to receive it. The opposite direction is not
77 * yet possible in this state. The state can then be further advanced using
78 * advance_with_client_finished().
79 * *
80 * |
81 * +-----> Derive-Secret(., "res master",
82 * ClientHello...client Finished)
83 * = resumption_master_secret
84 * STATE COMPLETED
85 * Once this state is reached the handshake is finished, both client and server can exchange
86 * application data and no further cipher state advances are possible.
87 */
88
89#include <limits>
90#include <utility>
91
92#include <botan/internal/tls_cipher_state.h>
93
94#include <botan/aead.h>
95#include <botan/assert.h>
96#include <botan/hash.h>
97#include <botan/secmem.h>
98#include <botan/tls_ciphersuite.h>
99#include <botan/tls_magic.h>
100
101#include <botan/internal/hkdf.h>
102#include <botan/internal/hmac.h>
103#include <botan/internal/loadstor.h>
104
105namespace Botan::TLS {
106
107namespace {
108// RFC 8446 5.3
109// Each AEAD algorithm will specify a range of possible lengths for the
110// per-record nonce, from N_MIN bytes to N_MAX bytes of input [RFC5116].
111// The length of the TLS per-record nonce (iv_length) is set to the
112// larger of 8 bytes and N_MIN for the AEAD algorithm (see [RFC5116],
113// Section 4).
114//
115// N_MIN is 12 for AES_GCM and AES_CCM as per RFC 5116 and also 12 for ChaCha20 per RFC 8439.
116constexpr size_t NONCE_LENGTH = 12;
117} // namespace
118
119std::unique_ptr<Cipher_State> Cipher_State::init_with_server_hello(const Connection_Side side,
120 secure_vector<uint8_t>&& shared_secret,
121 const Ciphersuite& cipher,
122 const Transcript_Hash& transcript_hash) {
123 auto cs = std::unique_ptr<Cipher_State>(new Cipher_State(side, cipher.prf_algo()));
124 cs->advance_without_psk();
125 cs->advance_with_server_hello(cipher, std::move(shared_secret), transcript_hash);
126 return cs;
127}
128
129std::unique_ptr<Cipher_State> Cipher_State::init_with_psk(const Connection_Side side,
130 const Cipher_State::PSK_Type type,
132 std::string_view prf_algo) {
133 auto cs = std::unique_ptr<Cipher_State>(new Cipher_State(side, prf_algo));
134 cs->advance_with_psk(type, std::move(psk));
135 return cs;
136}
137
139 BOTAN_ASSERT_NOMSG(m_state == State::PskBinder);
140
141 zap(m_binder_key);
142
143 // TODO: Currently 0-RTT is not yet implemented, hence we don't derive the
144 // early traffic secret for now.
145 //
146 // const auto client_early_traffic_secret = derive_secret(m_early_secret, "c e traffic", transcript_hash);
147 // derive_write_traffic_key(client_early_traffic_secret);
148
149 m_exporter_master_secret = derive_secret(m_early_secret, "e exp master", transcript_hash);
150
151 m_salt = derive_secret(m_early_secret, "derived", empty_hash());
152 zap(m_early_secret);
153
154 m_state = State::EarlyTraffic;
155}
156
158 BOTAN_ASSERT_NOMSG(m_state == State::HandshakeTraffic);
159
160 const auto master_secret = hkdf_extract(secure_vector<uint8_t>(m_hash->output_length(), 0x00));
161
162 auto client_application_traffic_secret = derive_secret(master_secret, "c ap traffic", transcript_hash);
163 auto server_application_traffic_secret = derive_secret(master_secret, "s ap traffic", transcript_hash);
164
165 // Note: the secrets for processing client's application data
166 // are not derived before the client's Finished message
167 // was seen and the handshake can be considered finished.
168 if(m_connection_side == Connection_Side::Server) {
169 derive_write_traffic_key(server_application_traffic_secret);
170 m_read_application_traffic_secret = std::move(client_application_traffic_secret);
171 m_write_application_traffic_secret = std::move(server_application_traffic_secret);
172 } else {
173 derive_read_traffic_key(server_application_traffic_secret);
174 m_read_application_traffic_secret = std::move(server_application_traffic_secret);
175 m_write_application_traffic_secret = std::move(client_application_traffic_secret);
176 }
177
178 m_exporter_master_secret = derive_secret(master_secret, "exp master", transcript_hash);
179
180 m_state = State::ServerApplicationTraffic;
181}
182
184 BOTAN_ASSERT_NOMSG(m_state == State::ServerApplicationTraffic);
185
186 zap(m_finished_key);
187 zap(m_peer_finished_key);
188
189 // With the client's Finished message, the handshake is complete and
190 // we can process client application data.
191 if(m_connection_side == Connection_Side::Server) {
192 derive_read_traffic_key(m_read_application_traffic_secret);
193 } else {
194 derive_write_traffic_key(m_write_application_traffic_secret);
195 }
196
197 const auto master_secret = hkdf_extract(secure_vector<uint8_t>(m_hash->output_length(), 0x00));
198
199 m_resumption_master_secret = derive_secret(master_secret, "res master", transcript_hash);
200
201 // This was the final state change; the salt is no longer needed.
202 zap(m_salt);
203
204 m_state = State::Completed;
205}
206
207namespace {
208
209std::vector<uint8_t> current_nonce(const uint64_t seq_no, const secure_vector<uint8_t>& iv) {
210 // RFC 8446 5.3
211 // The per-record nonce for the AEAD construction is formed as follows:
212 //
213 // 1. The 64-bit record sequence number is encoded in network byte
214 // order and padded to the left with zeros to iv_length.
215 //
216 // 2. The padded sequence number is XORed with either the static
217 // client_write_iv or server_write_iv (depending on the role).
218 std::vector<uint8_t> nonce(NONCE_LENGTH);
219 store_be(seq_no, nonce.data() + (NONCE_LENGTH - sizeof(seq_no)));
220 xor_buf(nonce, iv.data(), iv.size());
221 return nonce;
222}
223
224} // namespace
225
226uint64_t Cipher_State::encrypt_record_fragment(const std::vector<uint8_t>& header, secure_vector<uint8_t>& fragment) {
227 BOTAN_ASSERT_NONNULL(m_encrypt);
228
229 m_encrypt->set_key(m_write_key);
230 m_encrypt->set_associated_data(header);
231 m_encrypt->start(current_nonce(m_write_seq_no, m_write_iv));
232 m_encrypt->finish(fragment);
233
234 return m_write_seq_no++;
235}
236
237uint64_t Cipher_State::decrypt_record_fragment(const std::vector<uint8_t>& header,
238 secure_vector<uint8_t>& encrypted_fragment) {
239 BOTAN_ASSERT_NONNULL(m_decrypt);
240 BOTAN_ARG_CHECK(encrypted_fragment.size() >= m_decrypt->minimum_final_size(), "fragment too short to decrypt");
241
242 m_decrypt->set_key(m_read_key);
243 m_decrypt->set_associated_data(header);
244 m_decrypt->start(current_nonce(m_read_seq_no, m_read_iv));
245
246 m_decrypt->finish(encrypted_fragment);
247
248 return m_read_seq_no++;
249}
250
251size_t Cipher_State::encrypt_output_length(const size_t input_length) const {
252 BOTAN_ASSERT_NONNULL(m_encrypt);
253 return m_encrypt->output_length(input_length);
254}
255
256size_t Cipher_State::decrypt_output_length(const size_t input_length) const {
257 BOTAN_ASSERT_NONNULL(m_decrypt);
258 return m_decrypt->output_length(input_length);
259}
260
262 BOTAN_ASSERT_NONNULL(m_decrypt);
263 return m_decrypt->minimum_final_size();
264}
265
267 // Client side:
268 // After successfully receiving a Server Hello we expect servers to send
269 // alerts as protected records only, just like they start protecting their
270 // handshake data at this point.
271 if(m_connection_side == Connection_Side::Client && m_state == State::EarlyTraffic) {
272 return true;
273 }
274
275 // Server side:
276 // Servers must expect clients to send unprotected alerts during the hand-
277 // shake. In particular, in the response to the server's first protected
278 // flight. We don't expect the client to send alerts protected under the
279 // early traffic secret.
280 //
281 // TODO: when implementing PSK and/or early data for the server, we might
282 // need to reconsider this decision.
283 if(m_connection_side == Connection_Side::Server &&
284 (m_state == State::HandshakeTraffic || m_state == State::ServerApplicationTraffic)) {
285 return true;
286 }
287
288 return false;
289}
290
292 // TODO: when implementing early traffic (0-RTT) this will likely need
293 // to allow `State::EarlyTraffic`.
294
295 if(m_connection_side == Connection_Side::Client && m_state != State::Completed) {
296 return false;
297 }
298
299 if(m_connection_side == Connection_Side::Server && m_state != State::ServerApplicationTraffic &&
300 m_state != State::Completed) {
301 return false;
302 }
303
304 return !m_write_key.empty() && !m_write_iv.empty();
305}
306
308 // TODO: when implementing early traffic (0-RTT) this will likely need
309 // to allow `State::EarlyTraffic`.
310
311 if(m_connection_side == Connection_Side::Client && m_state != State::ServerApplicationTraffic &&
312 m_state != State::Completed) {
313 return false;
314 }
315
316 if(m_connection_side == Connection_Side::Server && m_state != State::Completed) {
317 return false;
318 }
319
320 return !m_read_key.empty() && !m_read_iv.empty();
321}
322
323std::string Cipher_State::hash_algorithm() const {
324 BOTAN_ASSERT_NONNULL(m_hash);
325 return m_hash->name();
326}
327
329 if(!cipher.usable_in_version(Protocol_Version::TLS_V13)) {
330 return false;
331 }
332
333 if(hash_algorithm() != cipher.prf_algo()) {
334 return false;
335 }
336
337 BOTAN_ASSERT_NOMSG((m_encrypt == nullptr) == (m_decrypt == nullptr));
338 // TODO: Find a better way to check that the instantiated cipher algorithm
339 // is compatible with the one required by the cipher suite.
340 // AEAD_Mode::create() sets defaults the tag length to 16 which is then
341 // reported via AEAD_Mode::name() and hinders the trivial string comparison.
342 if(m_encrypt && m_encrypt->name() != cipher.cipher_algo() && m_encrypt->name() != cipher.cipher_algo() + "(16)") {
343 return false;
344 }
345
346 return true;
347}
348
349std::vector<uint8_t> Cipher_State::psk_binder_mac(
350 const Transcript_Hash& transcript_hash_with_truncated_client_hello) const {
351 BOTAN_ASSERT_NOMSG(m_state == State::PskBinder);
352
353 auto hmac = HMAC(m_hash->new_object());
354 hmac.set_key(m_binder_key);
355 hmac.update(transcript_hash_with_truncated_client_hello);
356 return hmac.final_stdvec();
357}
358
359std::vector<uint8_t> Cipher_State::finished_mac(const Transcript_Hash& transcript_hash) const {
360 BOTAN_ASSERT_NOMSG(m_connection_side != Connection_Side::Server || m_state == State::HandshakeTraffic);
361 BOTAN_ASSERT_NOMSG(m_connection_side != Connection_Side::Client || m_state == State::ServerApplicationTraffic);
362 BOTAN_ASSERT_NOMSG(!m_finished_key.empty());
363
364 auto hmac = HMAC(m_hash->new_object());
365 hmac.set_key(m_finished_key);
366 hmac.update(transcript_hash);
367 return hmac.final_stdvec();
368}
369
371 const std::vector<uint8_t>& peer_mac) const {
372 BOTAN_ASSERT_NOMSG(m_connection_side != Connection_Side::Server || m_state == State::ServerApplicationTraffic);
373 BOTAN_ASSERT_NOMSG(m_connection_side != Connection_Side::Client || m_state == State::HandshakeTraffic);
374 BOTAN_ASSERT_NOMSG(!m_peer_finished_key.empty());
375
376 auto hmac = HMAC(m_hash->new_object());
377 hmac.set_key(m_peer_finished_key);
378 hmac.update(transcript_hash);
379 return hmac.verify_mac(peer_mac);
380}
381
383 BOTAN_ASSERT_NOMSG(m_state == State::Completed);
384
385 return derive_secret(m_resumption_master_secret, "resumption", nonce.get());
386}
387
389 BOTAN_STATE_CHECK(m_state == State::Completed);
390 if(m_ticket_nonce == std::numeric_limits<decltype(m_ticket_nonce)>::max()) {
391 throw Botan::Invalid_State("ticket nonce pool exhausted");
392 }
393
394 Ticket_Nonce retval(std::vector<uint8_t>(sizeof(m_ticket_nonce)));
395 store_be(m_ticket_nonce++, retval.data());
396
397 return retval;
398}
399
400secure_vector<uint8_t> Cipher_State::export_key(std::string_view label, std::string_view context, size_t length) const {
402
403 m_hash->update(context);
404 const auto context_hash = m_hash->final_stdvec();
405 return hkdf_expand_label(
406 derive_secret(m_exporter_master_secret, label, empty_hash()), "exporter", context_hash, length);
407}
408
409namespace {
410
411std::unique_ptr<MessageAuthenticationCode> create_hmac(std::string_view hash) {
412 return std::make_unique<HMAC>(HashFunction::create_or_throw(hash));
413}
414
415} // namespace
416
417Cipher_State::Cipher_State(Connection_Side whoami, std::string_view hash_function) :
418 m_state(State::Uninitialized),
419 m_connection_side(whoami),
420 m_extract(std::make_unique<HKDF_Extract>(create_hmac(hash_function))),
421 m_expand(std::make_unique<HKDF_Expand>(create_hmac(hash_function))),
422 m_hash(HashFunction::create_or_throw(hash_function)),
423 m_salt(m_hash->output_length(), 0x00),
424 m_write_seq_no(0),
425 m_read_seq_no(0),
426 m_ticket_nonce(0) {}
427
429
430void Cipher_State::advance_without_psk() {
431 BOTAN_ASSERT_NOMSG(m_state == State::Uninitialized);
432
433 // We are not using `m_early_secret` here because the secret won't be needed
434 // in any further state advancement methods.
435 const auto early_secret = hkdf_extract(secure_vector<uint8_t>(m_hash->output_length(), 0x00));
436 m_salt = derive_secret(early_secret, "derived", empty_hash());
437
438 // Without PSK we skip the `PskBinder` state and go right to `EarlyTraffic`.
439 m_state = State::EarlyTraffic;
440}
441
442void Cipher_State::advance_with_psk(PSK_Type type, secure_vector<uint8_t>&& psk) {
443 BOTAN_ASSERT_NOMSG(m_state == State::Uninitialized);
444
445 m_early_secret = hkdf_extract(std::move(psk));
446
447 const char* binder_label = (type == PSK_Type::Resumption) ? "res binder" : "ext binder";
448
449 // RFC 8446 4.2.11.2
450 // The PskBinderEntry is computed in the same way as the Finished message
451 // [...] but with the BaseKey being the binder_key derived via the key
452 // schedule from the corresponding PSK which is being offered.
453 //
454 // Hence we are doing the binder key derivation and expansion in one go.
455 const auto binder_key = derive_secret(m_early_secret, binder_label, empty_hash());
456 m_binder_key = hkdf_expand_label(binder_key, "finished", {}, m_hash->output_length());
457
458 m_state = State::PskBinder;
459}
460
462 secure_vector<uint8_t>&& shared_secret,
463 const Transcript_Hash& transcript_hash) {
464 BOTAN_ASSERT_NOMSG(m_state == State::EarlyTraffic);
465 BOTAN_ASSERT_NOMSG(!m_encrypt);
466 BOTAN_ASSERT_NOMSG(!m_decrypt);
468
471
472 const auto handshake_secret = hkdf_extract(std::move(shared_secret));
473
474 const auto client_handshake_traffic_secret = derive_secret(handshake_secret, "c hs traffic", transcript_hash);
475 const auto server_handshake_traffic_secret = derive_secret(handshake_secret, "s hs traffic", transcript_hash);
476
477 if(m_connection_side == Connection_Side::Server) {
478 derive_read_traffic_key(client_handshake_traffic_secret, true);
479 derive_write_traffic_key(server_handshake_traffic_secret, true);
480 } else {
481 derive_read_traffic_key(server_handshake_traffic_secret, true);
482 derive_write_traffic_key(client_handshake_traffic_secret, true);
483 }
484
485 m_salt = derive_secret(handshake_secret, "derived", empty_hash());
486
487 m_state = State::HandshakeTraffic;
488}
489
490void Cipher_State::derive_write_traffic_key(const secure_vector<uint8_t>& traffic_secret,
491 const bool handshake_traffic_secret) {
492 BOTAN_ASSERT_NONNULL(m_encrypt);
493
494 m_write_key = hkdf_expand_label(traffic_secret, "key", {}, m_encrypt->minimum_keylength());
495 m_write_iv = hkdf_expand_label(traffic_secret, "iv", {}, NONCE_LENGTH);
496 m_write_seq_no = 0;
497
498 if(handshake_traffic_secret) {
499 // Key derivation for the MAC in the "Finished" handshake message as described in RFC 8446 4.4.4
500 // (will be cleared in advance_with_server_finished())
501 m_finished_key = hkdf_expand_label(traffic_secret, "finished", {}, m_hash->output_length());
502 }
503}
504
505void Cipher_State::derive_read_traffic_key(const secure_vector<uint8_t>& traffic_secret,
506 const bool handshake_traffic_secret) {
507 BOTAN_ASSERT_NONNULL(m_encrypt);
508
509 m_read_key = hkdf_expand_label(traffic_secret, "key", {}, m_encrypt->minimum_keylength());
510 m_read_iv = hkdf_expand_label(traffic_secret, "iv", {}, NONCE_LENGTH);
511 m_read_seq_no = 0;
512
513 if(handshake_traffic_secret) {
514 // Key derivation for the MAC in the "Finished" handshake message as described in RFC 8446 4.4.4
515 // (will be cleared in advance_with_client_finished())
516 m_peer_finished_key = hkdf_expand_label(traffic_secret, "finished", {}, m_hash->output_length());
517 }
518}
519
520secure_vector<uint8_t> Cipher_State::hkdf_extract(secure_vector<uint8_t>&& ikm) const {
521 return m_extract->derive_key(m_hash->output_length(), ikm, m_salt, std::vector<uint8_t>());
522}
523
524secure_vector<uint8_t> Cipher_State::hkdf_expand_label(const secure_vector<uint8_t>& secret,
525 std::string_view label,
526 const std::vector<uint8_t>& context,
527 const size_t length) const {
528 // assemble (serialized) HkdfLabel
529 secure_vector<uint8_t> hkdf_label;
530 hkdf_label.reserve(2 /* length */ + (label.size() + 6 /* 'tls13 ' */ + 1 /* length field*/) +
531 (context.size() + 1 /* length field*/));
532
533 // length
534 BOTAN_ARG_CHECK(length <= std::numeric_limits<uint16_t>::max(), "invalid length");
535 const auto len = static_cast<uint16_t>(length);
536 hkdf_label.push_back(get_byte<0>(len));
537 hkdf_label.push_back(get_byte<1>(len));
538
539 // label
540 const std::string prefix = "tls13 ";
541 BOTAN_ARG_CHECK(prefix.size() + label.size() <= 255, "label too large");
542 hkdf_label.push_back(static_cast<uint8_t>(prefix.size() + label.size()));
543 hkdf_label.insert(hkdf_label.end(), prefix.cbegin(), prefix.cend());
544 hkdf_label.insert(hkdf_label.end(), label.cbegin(), label.cend());
545
546 // context
547 BOTAN_ARG_CHECK(context.size() <= 255, "context too large");
548 hkdf_label.push_back(static_cast<uint8_t>(context.size()));
549 hkdf_label.insert(hkdf_label.end(), context.cbegin(), context.cend());
550
551 // HKDF-Expand
552 return m_expand->derive_key(
553 length, secret, hkdf_label, std::vector<uint8_t>() /* just pleasing botan's interface */);
554}
555
556secure_vector<uint8_t> Cipher_State::derive_secret(const secure_vector<uint8_t>& secret,
557 std::string_view label,
558 const Transcript_Hash& messages_hash) const {
559 return hkdf_expand_label(secret, label, messages_hash, m_hash->output_length());
560}
561
562std::vector<uint8_t> Cipher_State::empty_hash() const {
563 m_hash->update("");
564 return m_hash->final_stdvec();
565}
566
568 BOTAN_ASSERT_NOMSG(m_state == State::ServerApplicationTraffic || m_state == State::Completed);
569
570 m_read_application_traffic_secret =
571 hkdf_expand_label(m_read_application_traffic_secret, "traffic upd", {}, m_hash->output_length());
572
573 derive_read_traffic_key(m_read_application_traffic_secret);
574}
575
577 BOTAN_ASSERT_NOMSG(m_state == State::ServerApplicationTraffic || m_state == State::Completed);
578 m_write_application_traffic_secret =
579 hkdf_expand_label(m_write_application_traffic_secret, "traffic upd", {}, m_hash->output_length());
580
581 derive_write_traffic_key(m_write_application_traffic_secret);
582}
583
585 zap(m_read_key);
586 zap(m_read_iv);
587 zap(m_read_application_traffic_secret);
588}
589
591 zap(m_write_key);
592 zap(m_write_iv);
593 zap(m_write_application_traffic_secret);
594}
595
596} // namespace Botan::TLS
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:41
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:86
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
static std::unique_ptr< AEAD_Mode > create_or_throw(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
Definition aead.cpp:43
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
bool can_decrypt_application_traffic() const
uint64_t decrypt_record_fragment(const std::vector< uint8_t > &header, secure_vector< uint8_t > &encrypted_fragment)
void advance_with_client_hello(const Transcript_Hash &transcript_hash)
size_t minimum_decryption_input_length() const
void advance_with_server_finished(const Transcript_Hash &transcript_hash)
bool must_expect_unprotected_alert_traffic() const
void advance_with_client_finished(const Transcript_Hash &transcript_hash)
bool verify_peer_finished_mac(const Transcript_Hash &transcript_hash, const std::vector< uint8_t > &peer_mac) const
std::string hash_algorithm() const
static std::unique_ptr< Cipher_State > init_with_psk(Connection_Side side, PSK_Type type, secure_vector< uint8_t > &&psk, std::string_view prf_algo)
uint64_t encrypt_record_fragment(const std::vector< uint8_t > &header, secure_vector< uint8_t > &fragment)
static std::unique_ptr< Cipher_State > init_with_server_hello(Connection_Side side, secure_vector< uint8_t > &&shared_secret, const Ciphersuite &cipher, const Transcript_Hash &transcript_hash)
secure_vector< uint8_t > psk(const Ticket_Nonce &nonce) const
void advance_with_server_hello(const Ciphersuite &cipher, secure_vector< uint8_t > &&shared_secret, const Transcript_Hash &transcript_hash)
bool is_compatible_with(const Ciphersuite &cipher) const
secure_vector< uint8_t > export_key(std::string_view label, std::string_view context, size_t length) const
bool can_encrypt_application_traffic() const
size_t encrypt_output_length(size_t input_length) const
std::vector< uint8_t > psk_binder_mac(const Transcript_Hash &transcript_hash_with_truncated_client_hello) const
size_t decrypt_output_length(size_t input_length) const
std::vector< uint8_t > finished_mac(const Transcript_Hash &transcript_hash) const
bool usable_in_version(Protocol_Version version) const
std::string prf_algo() const
std::string cipher_algo() const
std::vector< uint8_t > Transcript_Hash
Definition tls_magic.h:81
void zap(std::vector< T, Alloc > &vec)
Definition secmem.h:117
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
Definition mem_ops.h:343
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:711