1use crate::crypto;
2use crate::crypto::hash;
3use crate::suites::{CipherSuiteCommon, SupportedCipherSuite};
4
5use alloc::vec::Vec;
6use core::fmt;
7
8pub(crate) mod key_schedule;
9
10pub struct Tls13CipherSuite {
12 pub common: CipherSuiteCommon,
14
15 pub hkdf_provider: &'static dyn crypto::tls13::Hkdf,
23
24 pub aead_alg: &'static dyn crypto::cipher::Tls13AeadAlgorithm,
30
31 pub quic: Option<&'static dyn crate::quic::Algorithm>,
37}
38
39impl Tls13CipherSuite {
40 pub fn can_resume_from(&self, prev: &'static Self) -> Option<&'static Self> {
42 (prev.common.hash_provider.algorithm() == self.common.hash_provider.algorithm())
43 .then(|| prev)
44 }
45}
46
47impl From<&'static Tls13CipherSuite> for SupportedCipherSuite {
48 fn from(s: &'static Tls13CipherSuite) -> Self {
49 Self::Tls13(s)
50 }
51}
52
53impl PartialEq for Tls13CipherSuite {
54 fn eq(&self, other: &Self) -> bool {
55 self.common.suite == other.common.suite
56 }
57}
58
59impl fmt::Debug for Tls13CipherSuite {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 f.debug_struct("Tls13CipherSuite")
62 .field("suite", &self.common.suite)
63 .finish()
64 }
65}
66
67pub(crate) fn construct_client_verify_message(handshake_hash: &hash::Output) -> Vec<u8> {
69 construct_verify_message(handshake_hash, b"TLS 1.3, client CertificateVerify\x00")
70}
71
72pub(crate) fn construct_server_verify_message(handshake_hash: &hash::Output) -> Vec<u8> {
74 construct_verify_message(handshake_hash, b"TLS 1.3, server CertificateVerify\x00")
75}
76
77fn construct_verify_message(
78 handshake_hash: &hash::Output,
79 context_string_with_0: &[u8],
80) -> Vec<u8> {
81 let mut msg = Vec::new();
82 msg.resize(64, 0x20u8);
83 msg.extend_from_slice(context_string_with_0);
84 msg.extend_from_slice(handshake_hash.as_ref());
85 msg
86}