clia_rustls_mod/tls13/
mod.rs1use alloc::vec::Vec;
2use core::fmt;
3
4use crate::crypto;
5use crate::crypto::hash;
6use crate::suites::{CipherSuiteCommon, SupportedCipherSuite};
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 pub fn fips(&self) -> bool {
50 let Self {
51 common,
52 hkdf_provider,
53 aead_alg,
54 quic,
55 } = self;
56 common.fips()
57 && hkdf_provider.fips()
58 && aead_alg.fips()
59 && quic.map(|q| q.fips()).unwrap_or(true)
60 }
61
62 pub fn quic_suite(&'static self) -> Option<crate::quic::Suite> {
64 self.quic
65 .map(|quic| crate::quic::Suite { quic, suite: self })
66 }
67}
68
69impl From<&'static Tls13CipherSuite> for SupportedCipherSuite {
70 fn from(s: &'static Tls13CipherSuite) -> Self {
71 Self::Tls13(s)
72 }
73}
74
75impl PartialEq for Tls13CipherSuite {
76 fn eq(&self, other: &Self) -> bool {
77 self.common.suite == other.common.suite
78 }
79}
80
81impl fmt::Debug for Tls13CipherSuite {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 f.debug_struct("Tls13CipherSuite")
84 .field("suite", &self.common.suite)
85 .finish()
86 }
87}
88
89pub(crate) fn construct_client_verify_message(handshake_hash: &hash::Output) -> Vec<u8> {
91 construct_verify_message(handshake_hash, b"TLS 1.3, client CertificateVerify\x00")
92}
93
94pub(crate) fn construct_server_verify_message(handshake_hash: &hash::Output) -> Vec<u8> {
96 construct_verify_message(handshake_hash, b"TLS 1.3, server CertificateVerify\x00")
97}
98
99fn construct_verify_message(
100 handshake_hash: &hash::Output,
101 context_string_with_0: &[u8],
102) -> Vec<u8> {
103 let mut msg = Vec::new();
104 msg.resize(64, 0x20u8);
105 msg.extend_from_slice(context_string_with_0);
106 msg.extend_from_slice(handshake_hash.as_ref());
107 msg
108}