Debian Codegraph @

mlspp/src/crypto.cpp

raw symbols SCIP
1 #cxx . . $ `<file>/mlspp/src/crypto.cpp`/include <mls/core_types.h>cxx . . $ `<file>/mlspp/include/mls/core_types.h`/
2 #include <mls/crypto.h>cxx . . $ `<file>/mlspp/include/mls/crypto.h`/
3 #include <mls/messages.h>cxx . . $ `<file>/mlspp/include/mls/messages.h`/
4
5 #include <string>
6
7 using mlsppcxx . . $ mlspp/::hpkecxx . . $ mlspp/hpke/::AEADcxx . . $ AEAD#; // NOLINT(misc-unused-using-decls)
8 using mlsppcxx . . $ mlspp/::hpkecxx . . $ mlspp/hpke/::Digestcxx . . $ Digest#; // NOLINT(misc-unused-using-decls)
9 using mlsppcxx . . $ mlspp/::hpkecxx . . $ mlspp/hpke/::HPKEcxx . . $ HPKE#; // NOLINT(misc-unused-using-decls)
10 using mlsppcxx . . $ mlspp/::hpkecxx . . $ mlspp/hpke/::KDFcxx . . $ KDF#; // NOLINT(misc-unused-using-decls)
11 using mlsppcxx . . $ mlspp/::hpkecxx . . $ mlspp/hpke/::KEMcxx . . $ KEM#; // NOLINT(misc-unused-using-decls)
12 using mlsppcxx . . $ mlspp/::hpkecxx . . $ mlspp/hpke/::Signaturecxx . . $ Signature#; // NOLINT(misc-unused-using-decls)
13
14 namespace mlsppcxx . . $ mlspp/ {
15
16 SignatureSchemecxx . . $ mlspp/SignatureScheme#
17 tls_signature_schemecxx . . $ mlspp/tls_signature_scheme(902aafe9a6722bee).(Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID# id)
18 {
19 switch (id) {
20 case Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::P256_SHA256cxx . . $ mlspp/hpke/Signature#ID#P256_SHA256.:
21 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ecdsa_secp256r1_sha256cxx . . $ mlspp/SignatureScheme#ecdsa_secp256r1_sha256.;
22 case Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::P384_SHA384cxx . . $ mlspp/hpke/Signature#ID#P384_SHA384.:
23 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ecdsa_secp384r1_sha384cxx . . $ mlspp/SignatureScheme#ecdsa_secp384r1_sha384.;
24 case Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::P521_SHA512cxx . . $ mlspp/hpke/Signature#ID#P521_SHA512.:
25 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ecdsa_secp521r1_sha512cxx . . $ mlspp/SignatureScheme#ecdsa_secp521r1_sha512.;
26 case Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::Ed25519cxx . . $ mlspp/hpke/Signature#ID#Ed25519.:
27 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ed25519cxx . . $ mlspp/SignatureScheme#ed25519.;
28 #if !defined(WITH_BORINGSSL)
29 case Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::Ed448cxx . . $ mlspp/hpke/Signature#ID#Ed448.:
30 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ed448cxx . . $ mlspp/SignatureScheme#ed448.;
31 #endif
32 case Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::RSA_SHA256cxx . . $ mlspp/hpke/Signature#ID#RSA_SHA256.:
33 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::rsa_pkcs1_sha256cxx . . $ mlspp/SignatureScheme#rsa_pkcs1_sha256.;
34 default:
35 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Unsupported algorithm");
36 }
37 }
38
39 ///
40 /// CipherSuites and details
41 ///
42
43 CipherSuitecxx . . $ mlspp/CipherSuite#::CipherSuitecxx . . $ mlspp/CipherSuite#CipherSuite(49f6e7a06ebc5aa8).()
44 : idcxx . . $ mlspp/CipherSuite#id.(IDcxx . . $ mlspp/CipherSuite#ID#::unknowncxx . . $ mlspp/CipherSuite#ID#unknown.)
45 {
46 }
47
48 CipherSuitecxx . . $ mlspp/CipherSuite#::CipherSuitecxx . . $ mlspp/CipherSuite#CipherSuite(674032a9b97054f8).(IDcxx . . $ mlspp/CipherSuite#ID# id_in)
49 : idcxx . . $ mlspp/CipherSuite#id.(id_in)
50 {
51 }
52
53 SignatureSchemecxx . . $ mlspp/SignatureScheme#
54 CipherSuitecxx . . $ mlspp/CipherSuite#::signature_schemecxx . . $ mlspp/CipherSuite#signature_scheme(25c8e3499195dd1).() const
55 {
56 switch (idcxx . . $ mlspp/CipherSuite#id.) {
57 case IDcxx . . $ mlspp/CipherSuite#ID#::X25519_AES128GCM_SHA256_Ed25519cxx . . $ mlspp/CipherSuite#ID#X25519_AES128GCM_SHA256_Ed25519.:
58 case IDcxx . . $ mlspp/CipherSuite#ID#::X25519_CHACHA20POLY1305_SHA256_Ed25519cxx . . $ mlspp/CipherSuite#ID#X25519_CHACHA20POLY1305_SHA256_Ed25519.:
59 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ed25519cxx . . $ mlspp/SignatureScheme#ed25519.;
60 case IDcxx . . $ mlspp/CipherSuite#ID#::P256_AES128GCM_SHA256_P256cxx . . $ mlspp/CipherSuite#ID#P256_AES128GCM_SHA256_P256.:
61 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ecdsa_secp256r1_sha256cxx . . $ mlspp/SignatureScheme#ecdsa_secp256r1_sha256.;
62 case IDcxx . . $ mlspp/CipherSuite#ID#::X448_AES256GCM_SHA512_Ed448cxx . . $ mlspp/CipherSuite#ID#X448_AES256GCM_SHA512_Ed448.:
63 case IDcxx . . $ mlspp/CipherSuite#ID#::X448_CHACHA20POLY1305_SHA512_Ed448cxx . . $ mlspp/CipherSuite#ID#X448_CHACHA20POLY1305_SHA512_Ed448.:
64 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ed448cxx . . $ mlspp/SignatureScheme#ed448.;
65 case IDcxx . . $ mlspp/CipherSuite#ID#::P521_AES256GCM_SHA512_P521cxx . . $ mlspp/CipherSuite#ID#P521_AES256GCM_SHA512_P521.:
66 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ecdsa_secp521r1_sha512cxx . . $ mlspp/SignatureScheme#ecdsa_secp521r1_sha512.;
67 case IDcxx . . $ mlspp/CipherSuite#ID#::P384_AES256GCM_SHA384_P384cxx . . $ mlspp/CipherSuite#ID#P384_AES256GCM_SHA384_P384.:
68 return SignatureSchemecxx . . $ mlspp/SignatureScheme#::ecdsa_secp384r1_sha384cxx . . $ mlspp/SignatureScheme#ecdsa_secp384r1_sha384.;
69 default:
70 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Unsupported algorithm");
71 }
72 }
73
74 const CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#&
75 CipherSuitecxx . . $ mlspp/CipherSuite#::getcxx . . $ mlspp/CipherSuite#get(9d1ecf5d2a6cb924).() const
76 {
77 static const auto ciphers_X25519_AES128GCM_SHA256_Ed25519 =
78 CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#{
79 HPKEcxx . . $ mlspp/hpke/HPKE#HPKE(8898dfa600f2c6b2).(KEMcxx . . $ mlspp/hpke/KEM#::IDcxx . . $ mlspp/hpke/KEM#ID#::DHKEM_X25519_SHA256cxx . . $ mlspp/hpke/KEM#ID#DHKEM_X25519_SHA256.,
80 KDFcxx . . $ mlspp/hpke/KDF#::IDcxx . . $ mlspp/hpke/KDF#ID#::HKDF_SHA256cxx . . $ mlspp/hpke/KDF#ID#HKDF_SHA256.,
81 AEADcxx . . $ mlspp/hpke/AEAD#::IDcxx . . $ mlspp/hpke/AEAD#ID#::AES_128_GCMcxx . . $ mlspp/hpke/AEAD#ID#AES_128_GCM.),
82 Digestcxx . . $ mlspp/hpke/Digest#::getcxx . . $ mlspp/hpke/Digest#get(48440c38233383f7).<Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID#::SHA256cxx . . $ mlspp/hpke/Digest#ID#SHA256.>(),
83 Signaturecxx . . $ mlspp/hpke/Signature#::getcxx . . $ mlspp/hpke/Signature#get(9e8bfd5ad9358347).<Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::Ed25519cxx . . $ mlspp/hpke/Signature#ID#Ed25519.>(),
84 };
85
86 static const auto ciphers_P256_AES128GCM_SHA256_P256 = CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#{
87 HPKEcxx . . $ mlspp/hpke/HPKE#HPKE(8898dfa600f2c6b2).(
88 KEMcxx . . $ mlspp/hpke/KEM#::IDcxx . . $ mlspp/hpke/KEM#ID#::DHKEM_P256_SHA256cxx . . $ mlspp/hpke/KEM#ID#DHKEM_P256_SHA256., KDFcxx . . $ mlspp/hpke/KDF#::IDcxx . . $ mlspp/hpke/KDF#ID#::HKDF_SHA256cxx . . $ mlspp/hpke/KDF#ID#HKDF_SHA256., AEADcxx . . $ mlspp/hpke/AEAD#::IDcxx . . $ mlspp/hpke/AEAD#ID#::AES_128_GCMcxx . . $ mlspp/hpke/AEAD#ID#AES_128_GCM.),
89 Digestcxx . . $ mlspp/hpke/Digest#::getcxx . . $ mlspp/hpke/Digest#get(48440c38233383f7).<Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID#::SHA256cxx . . $ mlspp/hpke/Digest#ID#SHA256.>(),
90 Signaturecxx . . $ mlspp/hpke/Signature#::getcxx . . $ mlspp/hpke/Signature#get(9e8bfd5ad9358347).<Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::P256_SHA256cxx . . $ mlspp/hpke/Signature#ID#P256_SHA256.>(),
91 };
92
93 static const auto ciphers_X25519_CHACHA20POLY1305_SHA256_Ed25519 =
94 CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#{
95 HPKEcxx . . $ mlspp/hpke/HPKE#HPKE(8898dfa600f2c6b2).(KEMcxx . . $ mlspp/hpke/KEM#::IDcxx . . $ mlspp/hpke/KEM#ID#::DHKEM_X25519_SHA256cxx . . $ mlspp/hpke/KEM#ID#DHKEM_X25519_SHA256.,
96 KDFcxx . . $ mlspp/hpke/KDF#::IDcxx . . $ mlspp/hpke/KDF#ID#::HKDF_SHA256cxx . . $ mlspp/hpke/KDF#ID#HKDF_SHA256.,
97 AEADcxx . . $ mlspp/hpke/AEAD#::IDcxx . . $ mlspp/hpke/AEAD#ID#::CHACHA20_POLY1305cxx . . $ mlspp/hpke/AEAD#ID#CHACHA20_POLY1305.),
98 Digestcxx . . $ mlspp/hpke/Digest#::getcxx . . $ mlspp/hpke/Digest#get(48440c38233383f7).<Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID#::SHA256cxx . . $ mlspp/hpke/Digest#ID#SHA256.>(),
99 Signaturecxx . . $ mlspp/hpke/Signature#::getcxx . . $ mlspp/hpke/Signature#get(9e8bfd5ad9358347).<Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::Ed25519cxx . . $ mlspp/hpke/Signature#ID#Ed25519.>(),
100 };
101
102 static const auto ciphers_P521_AES256GCM_SHA512_P521 = CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#{
103 HPKEcxx . . $ mlspp/hpke/HPKE#HPKE(8898dfa600f2c6b2).(
104 KEMcxx . . $ mlspp/hpke/KEM#::IDcxx . . $ mlspp/hpke/KEM#ID#::DHKEM_P521_SHA512cxx . . $ mlspp/hpke/KEM#ID#DHKEM_P521_SHA512., KDFcxx . . $ mlspp/hpke/KDF#::IDcxx . . $ mlspp/hpke/KDF#ID#::HKDF_SHA512cxx . . $ mlspp/hpke/KDF#ID#HKDF_SHA512., AEADcxx . . $ mlspp/hpke/AEAD#::IDcxx . . $ mlspp/hpke/AEAD#ID#::AES_256_GCMcxx . . $ mlspp/hpke/AEAD#ID#AES_256_GCM.),
105 Digestcxx . . $ mlspp/hpke/Digest#::getcxx . . $ mlspp/hpke/Digest#get(48440c38233383f7).<Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID#::SHA512cxx . . $ mlspp/hpke/Digest#ID#SHA512.>(),
106 Signaturecxx . . $ mlspp/hpke/Signature#::getcxx . . $ mlspp/hpke/Signature#get(9e8bfd5ad9358347).<Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::P521_SHA512cxx . . $ mlspp/hpke/Signature#ID#P521_SHA512.>(),
107 };
108
109 static const auto ciphers_P384_AES256GCM_SHA384_P384 = CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#{
110 HPKEcxx . . $ mlspp/hpke/HPKE#HPKE(8898dfa600f2c6b2).(
111 KEMcxx . . $ mlspp/hpke/KEM#::IDcxx . . $ mlspp/hpke/KEM#ID#::DHKEM_P384_SHA384cxx . . $ mlspp/hpke/KEM#ID#DHKEM_P384_SHA384., KDFcxx . . $ mlspp/hpke/KDF#::IDcxx . . $ mlspp/hpke/KDF#ID#::HKDF_SHA384cxx . . $ mlspp/hpke/KDF#ID#HKDF_SHA384., AEADcxx . . $ mlspp/hpke/AEAD#::IDcxx . . $ mlspp/hpke/AEAD#ID#::AES_256_GCMcxx . . $ mlspp/hpke/AEAD#ID#AES_256_GCM.),
112 Digestcxx . . $ mlspp/hpke/Digest#::getcxx . . $ mlspp/hpke/Digest#get(48440c38233383f7).<Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID#::SHA384cxx . . $ mlspp/hpke/Digest#ID#SHA384.>(),
113 Signaturecxx . . $ mlspp/hpke/Signature#::getcxx . . $ mlspp/hpke/Signature#get(9e8bfd5ad9358347).<Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::P384_SHA384cxx . . $ mlspp/hpke/Signature#ID#P384_SHA384.>(),
114 };
115
116 #if !defined(WITH_BORINGSSL)
117 static const auto ciphers_X448_AES256GCM_SHA512_Ed448 = CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#{
118 HPKEcxx . . $ mlspp/hpke/HPKE#HPKE(8898dfa600f2c6b2).(
119 KEMcxx . . $ mlspp/hpke/KEM#::IDcxx . . $ mlspp/hpke/KEM#ID#::DHKEM_X448_SHA512cxx . . $ mlspp/hpke/KEM#ID#DHKEM_X448_SHA512., KDFcxx . . $ mlspp/hpke/KDF#::IDcxx . . $ mlspp/hpke/KDF#ID#::HKDF_SHA512cxx . . $ mlspp/hpke/KDF#ID#HKDF_SHA512., AEADcxx . . $ mlspp/hpke/AEAD#::IDcxx . . $ mlspp/hpke/AEAD#ID#::AES_256_GCMcxx . . $ mlspp/hpke/AEAD#ID#AES_256_GCM.),
120 Digestcxx . . $ mlspp/hpke/Digest#::getcxx . . $ mlspp/hpke/Digest#get(48440c38233383f7).<Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID#::SHA512cxx . . $ mlspp/hpke/Digest#ID#SHA512.>(),
121 Signaturecxx . . $ mlspp/hpke/Signature#::getcxx . . $ mlspp/hpke/Signature#get(9e8bfd5ad9358347).<Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::Ed448cxx . . $ mlspp/hpke/Signature#ID#Ed448.>(),
122 };
123
124 static const auto ciphers_X448_CHACHA20POLY1305_SHA512_Ed448 =
125 CipherSuitecxx . . $ mlspp/CipherSuite#::Cipherscxx . . $ mlspp/CipherSuite#Ciphers#{
126 HPKEcxx . . $ mlspp/hpke/HPKE#HPKE(8898dfa600f2c6b2).(KEMcxx . . $ mlspp/hpke/KEM#::IDcxx . . $ mlspp/hpke/KEM#ID#::DHKEM_X448_SHA512cxx . . $ mlspp/hpke/KEM#ID#DHKEM_X448_SHA512.,
127 KDFcxx . . $ mlspp/hpke/KDF#::IDcxx . . $ mlspp/hpke/KDF#ID#::HKDF_SHA512cxx . . $ mlspp/hpke/KDF#ID#HKDF_SHA512.,
128 AEADcxx . . $ mlspp/hpke/AEAD#::IDcxx . . $ mlspp/hpke/AEAD#ID#::CHACHA20_POLY1305cxx . . $ mlspp/hpke/AEAD#ID#CHACHA20_POLY1305.),
129 Digestcxx . . $ mlspp/hpke/Digest#::getcxx . . $ mlspp/hpke/Digest#get(48440c38233383f7).<Digestcxx . . $ mlspp/hpke/Digest#::IDcxx . . $ mlspp/hpke/Digest#ID#::SHA512cxx . . $ mlspp/hpke/Digest#ID#SHA512.>(),
130 Signaturecxx . . $ mlspp/hpke/Signature#::getcxx . . $ mlspp/hpke/Signature#get(9e8bfd5ad9358347).<Signaturecxx . . $ mlspp/hpke/Signature#::IDcxx . . $ mlspp/hpke/Signature#ID#::Ed448cxx . . $ mlspp/hpke/Signature#ID#Ed448.>(),
131 };
132 #endif
133
134 switch (idcxx . . $ mlspp/CipherSuite#id.) {
135 case IDcxx . . $ mlspp/CipherSuite#ID#::unknowncxx . . $ mlspp/CipherSuite#ID#unknown.:
136 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Uninitialized ciphersuite");
137
138 case IDcxx . . $ mlspp/CipherSuite#ID#::X25519_AES128GCM_SHA256_Ed25519cxx . . $ mlspp/CipherSuite#ID#X25519_AES128GCM_SHA256_Ed25519.:
139 return ciphers_X25519_AES128GCM_SHA256_Ed25519;
140
141 case IDcxx . . $ mlspp/CipherSuite#ID#::P256_AES128GCM_SHA256_P256cxx . . $ mlspp/CipherSuite#ID#P256_AES128GCM_SHA256_P256.:
142 return ciphers_P256_AES128GCM_SHA256_P256;
143
144 case IDcxx . . $ mlspp/CipherSuite#ID#::X25519_CHACHA20POLY1305_SHA256_Ed25519cxx . . $ mlspp/CipherSuite#ID#X25519_CHACHA20POLY1305_SHA256_Ed25519.:
145 return ciphers_X25519_CHACHA20POLY1305_SHA256_Ed25519;
146
147 case IDcxx . . $ mlspp/CipherSuite#ID#::P521_AES256GCM_SHA512_P521cxx . . $ mlspp/CipherSuite#ID#P521_AES256GCM_SHA512_P521.:
148 return ciphers_P521_AES256GCM_SHA512_P521;
149
150 case IDcxx . . $ mlspp/CipherSuite#ID#::P384_AES256GCM_SHA384_P384cxx . . $ mlspp/CipherSuite#ID#P384_AES256GCM_SHA384_P384.:
151 return ciphers_P384_AES256GCM_SHA384_P384;
152
153 #if !defined(WITH_BORINGSSL)
154 case IDcxx . . $ mlspp/CipherSuite#ID#::X448_AES256GCM_SHA512_Ed448cxx . . $ mlspp/CipherSuite#ID#X448_AES256GCM_SHA512_Ed448.:
155 return ciphers_X448_AES256GCM_SHA512_Ed448;
156
157 case IDcxx . . $ mlspp/CipherSuite#ID#::X448_CHACHA20POLY1305_SHA512_Ed448cxx . . $ mlspp/CipherSuite#ID#X448_CHACHA20POLY1305_SHA512_Ed448.:
158 return ciphers_X448_CHACHA20POLY1305_SHA512_Ed448;
159 #endif
160
161 default:
162 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("Unsupported ciphersuite");
163 }
164 }
165
166 struct HKDFLabelcxx . . $ mlspp/HKDFLabel#
167 {
168 uint16_tcxx . . $ uint16_t# lengthcxx . . $ mlspp/HKDFLabel#length.;
169 bytescxx . . $ mlspp/bytes_ns/bytes# labelcxx . . $ mlspp/HKDFLabel#label.;
170 bytescxx . . $ mlspp/bytes_ns/bytes# contextcxx . . $ mlspp/HKDFLabel#context.;
171
172 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(length, label, context)
173 };
174
175 bytescxx . . $ mlspp/bytes_ns/bytes#
176 CipherSuitecxx . . $ mlspp/CipherSuite#::expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(const bytescxx . . $ mlspp/bytes_ns/bytes#& secret,
177 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
178 const bytescxx . . $ mlspp/bytes_ns/bytes#& context,
179 size_t length) const
180 {
181 auto mls_label = from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).(stdcxx . . $ std/::stringcxx . . $ std/string#("MLS 1.0 ") +cxx . . $ std/operator+(db5dc2ea912c6495). label);
182 auto length16 = static_cast<uint16_tcxx . . $ uint16_t#>(length);
183 auto label_bytes = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(HKDFLabelcxx . . $ mlspp/HKDFLabel#{ length16, mls_label, context });
184 return getcxx . . $ mlspp/CipherSuite#get(9d1ecf5d2a6cb924).().hpkecxx . . $ mlspp/CipherSuite#Ciphers#hpke..kdfcxx . . $ mlspp/hpke/HPKE#kdf..expandcxx . . $ mlspp/hpke/KDF#expand(fc2505b904ce7e90).(secret, label_bytescxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., length);
185 }
186
187 bytescxx . . $ mlspp/bytes_ns/bytes#
188 CipherSuitecxx . . $ mlspp/CipherSuite#::derive_secretcxx . . $ mlspp/CipherSuite#derive_secret(5169660e3f01b6ab).(const bytescxx . . $ mlspp/bytes_ns/bytes#& secret, const stdcxx . . $ std/::stringcxx . . $ std/string#& label) const
189 {
190 return expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(secret, label, {cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, secret_sizecxx . . $ mlspp/CipherSuite#secret_size(fe4d2d262d4164a8).());
191 }
192
193 bytescxx . . $ mlspp/bytes_ns/bytes#
194 CipherSuitecxx . . $ mlspp/CipherSuite#::derive_tree_secretcxx . . $ mlspp/CipherSuite#derive_tree_secret(bad54adf3f284450).(const bytescxx . . $ mlspp/bytes_ns/bytes#& secret,
195 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
196 uint32_tcxx . . $ uint32_t# generation,
197 size_t length) const
198 {
199 return expand_with_labelcxx . . $ mlspp/CipherSuite#expand_with_label(5537b899fa4f16b5).(secret, label, tlscxx . . $ mlspp/bytes_ns/bytes#bytes(dd8c33c7e39dbe02).::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(generation), length);
200 }
201
202 #if WITH_BORINGSSL
203 const std::array<CipherSuite::ID, 5> all_supported_suites = {
204 CipherSuite::ID::X25519_AES128GCM_SHA256_Ed25519,
205 CipherSuite::ID::P256_AES128GCM_SHA256_P256,
206 CipherSuite::ID::X25519_CHACHA20POLY1305_SHA256_Ed25519,
207 CipherSuite::ID::P521_AES256GCM_SHA512_P521,
208 CipherSuite::ID::P384_AES256GCM_SHA384_P384,
209 };
210 #else
211 const stdcxx . . $ std/::arraycxx . . $ std/array#<CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#, 7> all_supported_suitescxx . . $ mlspp/all_supported_suites. = {
212 CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::X25519_AES128GCM_SHA256_Ed25519cxx . . $ mlspp/CipherSuite#ID#X25519_AES128GCM_SHA256_Ed25519.,
213 CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::P256_AES128GCM_SHA256_P256cxx . . $ mlspp/CipherSuite#ID#P256_AES128GCM_SHA256_P256.,
214 CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::X25519_CHACHA20POLY1305_SHA256_Ed25519cxx . . $ mlspp/CipherSuite#ID#X25519_CHACHA20POLY1305_SHA256_Ed25519.,
215 CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::P521_AES256GCM_SHA512_P521cxx . . $ mlspp/CipherSuite#ID#P521_AES256GCM_SHA512_P521.,
216 CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::P384_AES256GCM_SHA384_P384cxx . . $ mlspp/CipherSuite#ID#P384_AES256GCM_SHA384_P384.,
217 CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::X448_CHACHA20POLY1305_SHA512_Ed448cxx . . $ mlspp/CipherSuite#ID#X448_CHACHA20POLY1305_SHA512_Ed448.,
218 CipherSuitecxx . . $ mlspp/CipherSuite#::IDcxx . . $ mlspp/CipherSuite#ID#::X448_AES256GCM_SHA512_Ed448cxx . . $ mlspp/CipherSuite#ID#X448_AES256GCM_SHA512_Ed448.,
219 };
220 #endif
221
222 // MakeKeyPackageRef(value) = KDF.expand(
223 // KDF.extract("", value), "MLS 1.0 KeyPackage Reference", 16)
224 template<>
225 const bytescxx . . $ mlspp/bytes_ns/bytes#&
226 CipherSuitecxx . . $ mlspp/CipherSuite#::reference_labelcxx . . $ mlspp/CipherSuite#reference_label(f9dc8c7ea672a8f6).<KeyPackagecxx . . $ mlspp/KeyPackage#>()
227 {
228 static const auto label = from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).("MLS 1.0 KeyPackage Reference"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
229 return label;
230 }
231
232 // MakeProposalRef(value) = KDF.expand(
233 // KDF.extract("", value), "MLS 1.0 Proposal Reference", 16)
234 //
235 // Even though the label says "Proposal", we actually hash the entire enclosing
236 // AuthenticatedContent object.
237 template<>
238 const bytescxx . . $ mlspp/bytes_ns/bytes#&
239 CipherSuitecxx . . $ mlspp/CipherSuite#::reference_labelcxx . . $ mlspp/CipherSuite#reference_label(f9dc8c7ea672a8f6).<AuthenticatedContentcxx . . $ mlspp/AuthenticatedContent#>()
240 {
241 static const auto label = from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).("MLS 1.0 Proposal Reference"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
242 return label;
243 }
244
245 ///
246 /// HPKEPublicKey and HPKEPrivateKey
247 ///
248
249 // This function produces a non-literal type, so it can't be constexpr.
250 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
251 #define MLS_1_0_PLUScxx . . $ `mlspp/src/crypto.cpp:251:9`!(label) from_ascii("MLS 1.0 " label)
252
253 static bytescxx . . $ mlspp/bytes_ns/bytes#
254 mls_1_0_pluscxx . . $ mlspp/mls_1_0_plus(fc01d114001b7256).(const stdcxx . . $ std/::stringcxx . . $ std/string#& label)
255 {
256 auto plus = "MLS 1.0 "scxx . . $ std/literals/string_literals/`operator""s`(aa2a803d3c5b7a78). +cxx . . $ std/operator+(db5dc2ea912c6495). label;
257 return from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).(plus);
258 }
259
260 namespace encrypt_labelcxx . . $ mlspp/encrypt_label/ {
261 const stdcxx . . $ std/::stringcxx . . $ std/string# update_path_nodecxx . . $ mlspp/encrypt_label/update_path_node. = "UpdatePathNode"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
262 const stdcxx . . $ std/::stringcxx . . $ std/string# welcomecxx . . $ mlspp/encrypt_label/welcome. = "Welcome"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
263 } // namespace encrypt_label
264
265 struct EncryptContextcxx . . $ mlspp/EncryptContext#
266 {
267 const bytescxx . . $ mlspp/bytes_ns/bytes#& labelcxx . . $ mlspp/EncryptContext#label.;
268 const bytescxx . . $ mlspp/bytes_ns/bytes#& contentcxx . . $ mlspp/EncryptContext#content.;
269 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(label, content)
270 };
271
272 HPKECiphertextcxx . . $ mlspp/HPKECiphertext#
273 HPKEPublicKeycxx . . $ mlspp/HPKEPublicKey#::encryptcxx . . $ mlspp/HPKEPublicKey#encrypt(4062c3a081c08efa).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
274 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
275 const bytescxx . . $ mlspp/bytes_ns/bytes#& context,
276 const bytescxx . . $ mlspp/bytes_ns/bytes#& pt) const
277 {
278 auto label_plus = mls_1_0_pluscxx . . $ mlspp/mls_1_0_plus(fc01d114001b7256).(label);
279 auto encrypt_context = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(EncryptContextcxx . . $ mlspp/EncryptContext#{ label_plus, context });
280 auto pkR = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..deserializecxx . . $ mlspp/hpke/KEM#deserialize(3971047ebd94cce).(datacxx . . $ mlspp/HPKEPublicKey#data.);
281 auto [enc, ctx] = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().setup_base_scxx . . $ mlspp/hpke/HPKE#setup_base_s(8d59ca38ce5a36e0).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pkR, encrypt_contextcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
282 auto ct = ctx.sealcxx . . $ mlspp/hpke/SenderContext#seal(5591ef0fb4aab668).({cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, pt);
283 return HPKECiphertextcxx . . $ mlspp/HPKECiphertext#{ enc, ct };
284 }
285
286 stdcxx . . $ std/::tuplecxx . . $ std/tuple#<bytescxx . . $ mlspp/bytes_ns/bytes#, bytescxx . . $ mlspp/bytes_ns/bytes#>
287 HPKEPublicKeycxx . . $ mlspp/HPKEPublicKey#::do_exportcxx . . $ mlspp/HPKEPublicKey#do_export(10426ae6d3f47ac5).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
288 const bytescxx . . $ mlspp/bytes_ns/bytes#& info,
289 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
290 size_t size) const
291 {
292 auto label_data = from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).(label);
293 auto pkR = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..deserializecxx . . $ mlspp/hpke/KEM#deserialize(3971047ebd94cce).(datacxx . . $ mlspp/HPKEPublicKey#data.);
294 auto [enc, ctx] = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().setup_base_scxx . . $ mlspp/hpke/HPKE#setup_base_s(8d59ca38ce5a36e0).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pkR, info);
295 auto exported = ctx.do_exportcxx . . $ mlspp/hpke/Context#do_export(25e8a9b4283f7384).(label_data, size);
296 return stdcxx . . $ std/::make_tuplecxx . . $ std/make_tuple(3964edbfd7e8599f).(enc, exported);
297 }
298
299 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#
300 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::generatecxx . . $ mlspp/HPKEPrivateKey#generate(4a2a6d1c0a9e0cd3).(CipherSuitecxx . . $ mlspp/CipherSuite# suite)
301 {
302 auto priv = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..generate_key_paircxx . . $ mlspp/hpke/KEM#generate_key_pair(cb2cb9028da54d79).();
303 auto priv_data = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..serialize_privatecxx . . $ mlspp/hpke/KEM#serialize_private(659c63e46d9645fb).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).priv);
304 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/KEM#PrivateKey#public_key(db950997dbdd512b).();
305 auto pub_data = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..serializecxx . . $ mlspp/hpke/KEM#serialize(f76243b94cf1479f).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
306 return {cxx . . $ mlspp/HPKEPrivateKey#HPKEPrivateKey(6452a1c837d26c07). priv_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)., pub_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). };
307 }
308
309 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#
310 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::parsecxx . . $ mlspp/HPKEPrivateKey#parse(d8fbf663c4028288).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, const bytescxx . . $ mlspp/bytes_ns/bytes#& data)
311 {
312 auto priv = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..deserialize_privatecxx . . $ mlspp/hpke/KEM#deserialize_private(b1a67661546df615).(data);
313 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/KEM#PrivateKey#public_key(db950997dbdd512b).();
314 auto pub_data = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..serializecxx . . $ mlspp/hpke/KEM#serialize(f76243b94cf1479f).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
315 return {cxx . . $ mlspp/HPKEPrivateKey#HPKEPrivateKey(6452a1c837d26c07). datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)., pub_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). };
316 }
317
318 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#
319 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::derivecxx . . $ mlspp/HPKEPrivateKey#derive(d8fbf663c4028288).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, const bytescxx . . $ mlspp/bytes_ns/bytes#& secret)
320 {
321 auto priv = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..derive_key_paircxx . . $ mlspp/hpke/KEM#derive_key_pair(b1a67661546df615).(secret);
322 auto priv_data = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..serialize_privatecxx . . $ mlspp/hpke/KEM#serialize_private(659c63e46d9645fb).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).priv);
323 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/KEM#PrivateKey#public_key(db950997dbdd512b).();
324 auto pub_data = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..serializecxx . . $ mlspp/hpke/KEM#serialize(f76243b94cf1479f).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
325 return {cxx . . $ mlspp/HPKEPrivateKey#HPKEPrivateKey(6452a1c837d26c07). priv_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)., pub_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). };
326 }
327
328 bytescxx . . $ mlspp/bytes_ns/bytes#
329 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::decryptcxx . . $ mlspp/HPKEPrivateKey#decrypt(e80468221b998043).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
330 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
331 const bytescxx . . $ mlspp/bytes_ns/bytes#& context,
332 const HPKECiphertextcxx . . $ mlspp/HPKECiphertext#& ct) const
333 {
334 auto label_plus = mls_1_0_pluscxx . . $ mlspp/mls_1_0_plus(fc01d114001b7256).(label);
335 auto encrypt_context = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(EncryptContextcxx . . $ mlspp/EncryptContext#{ label_plus, context });
336 auto skR = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..deserialize_privatecxx . . $ mlspp/hpke/KEM#deserialize_private(b1a67661546df615).(datacxx . . $ mlspp/HPKEPrivateKey#data.);
337 auto ctx = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().setup_base_rcxx . . $ mlspp/hpke/HPKE#setup_base_r(684b9f3e9f783afe).(ct.kem_outputcxx . . $ mlspp/HPKECiphertext#kem_output., *cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).skR, encrypt_contextcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4).);
338 auto pt = ctx.opencxx . . $ mlspp/hpke/ReceiverContext#open(4e9304a318c66e3a).({cxx . . $ mlspp/bytes_ns/bytes#bytes(ced63f7c635d850d).}, ct.ciphertextcxx . . $ mlspp/HPKECiphertext#ciphertext.);
339 if (!pt) {
340 throw InvalidParameterErrorcxx . . $ mlspp/InvalidParameterError#("HPKE decryption failure");
341 }
342
343 return optcxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e).::getcxx . . $ mlspp/tls/opt/get(f3e04ae79584f296).(pt);
344 }
345
346 bytescxx . . $ mlspp/bytes_ns/bytes#
347 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::do_exportcxx . . $ mlspp/HPKEPrivateKey#do_export(7d96ce105d93ef47).(CipherSuitecxx . . $ mlspp/CipherSuite# suite,
348 const bytescxx . . $ mlspp/bytes_ns/bytes#& info,
349 const bytescxx . . $ mlspp/bytes_ns/bytes#& kem_output,
350 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
351 size_t size) const
352 {
353 auto label_data = from_asciicxx . . $ mlspp/bytes_ns/from_ascii(fc01d114001b7256).(label);
354 auto skR = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..deserialize_privatecxx . . $ mlspp/hpke/KEM#deserialize_private(b1a67661546df615).(datacxx . . $ mlspp/HPKEPrivateKey#data.);
355 auto ctx = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().setup_base_rcxx . . $ mlspp/hpke/HPKE#setup_base_r(684b9f3e9f783afe).(kem_output, *cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).skR, info);
356 return ctx.do_exportcxx . . $ mlspp/hpke/Context#do_export(25e8a9b4283f7384).(label_data, size);
357 }
358
359 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#HPKEPrivateKey(6452a1c837d26c07).(bytescxx . . $ mlspp/bytes_ns/bytes# priv_data, bytescxx . . $ mlspp/bytes_ns/bytes# pub_data)
360 : datacxx . . $ mlspp/HPKEPrivateKey#data.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(priv_data))
361 , public_keycxx . . $ mlspp/HPKEPrivateKey#public_key.{ stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(pub_data) }
362 {
363 }
364
365 void
366 HPKEPrivateKeycxx . . $ mlspp/HPKEPrivateKey#::set_public_keycxx . . $ mlspp/HPKEPrivateKey#set_public_key(1ae84ca71f879861).(CipherSuitecxx . . $ mlspp/CipherSuite# suite)
367 {
368 const auto priv = suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..deserialize_privatecxx . . $ mlspp/hpke/KEM#deserialize_private(b1a67661546df615).(datacxx . . $ mlspp/HPKEPrivateKey#data.);
369 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/KEM#PrivateKey#public_key(db950997dbdd512b).();
370 public_keycxx . . $ mlspp/HPKEPrivateKey#public_key..datacxx . . $ mlspp/HPKEPublicKey#data. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). suite.hpkecxx . . $ mlspp/CipherSuite#hpke(4248c68506dc683b).().kemcxx . . $ mlspp/hpke/HPKE#kem..serializecxx . . $ mlspp/hpke/KEM#serialize(f76243b94cf1479f).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
371 }
372
373 ///
374 /// SignaturePublicKey and SignaturePrivateKey
375 ///
376 namespace sign_labelcxx . . $ mlspp/sign_label/ {
377 const stdcxx . . $ std/::stringcxx . . $ std/string# mls_contentcxx . . $ mlspp/sign_label/mls_content. = "FramedContentTBS"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
378 const stdcxx . . $ std/::stringcxx . . $ std/string# leaf_nodecxx . . $ mlspp/sign_label/leaf_node. = "LeafNodeTBS"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
379 const stdcxx . . $ std/::stringcxx . . $ std/string# key_packagecxx . . $ mlspp/sign_label/key_package. = "KeyPackageTBS"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
380 const stdcxx . . $ std/::stringcxx . . $ std/string# group_infocxx . . $ mlspp/sign_label/group_info. = "GroupInfoTBS"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
381 const stdcxx . . $ std/::stringcxx . . $ std/string# multi_credentialcxx . . $ mlspp/sign_label/multi_credential. = "MultiCredential"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
382 } // namespace sign_label
383
384 struct SignContentcxx . . $ mlspp/SignContent#
385 {
386 const bytescxx . . $ mlspp/bytes_ns/bytes#& labelcxx . . $ mlspp/SignContent#label.;
387 const bytescxx . . $ mlspp/bytes_ns/bytes#& contentcxx . . $ mlspp/SignContent#content.;
388 TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(label, content)
389 };
390
391 bool
392 SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#::verifycxx . . $ mlspp/SignaturePublicKey#verify(e28f084f4f4fb6fe).(const CipherSuitecxx . . $ mlspp/CipherSuite#& suite,
393 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
394 const bytescxx . . $ mlspp/bytes_ns/bytes#& message,
395 const bytescxx . . $ mlspp/bytes_ns/bytes#& signature) const
396 {
397 auto label_plus = mls_1_0_pluscxx . . $ mlspp/mls_1_0_plus(fc01d114001b7256).(label);
398 const auto content = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(SignContentcxx . . $ mlspp/SignContent#{ label_plus, message });
399 auto pub = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().deserializecxx . . $ mlspp/hpke/Signature#deserialize(321ec828a61140d).(datacxx . . $ mlspp/SignaturePublicKey#data.);
400 return suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().verifycxx . . $ mlspp/hpke/Signature#verify(c2ebb5c61451baa6).(contentcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., signature, *cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
401 }
402
403 SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#
404 SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#::from_jwkcxx . . $ mlspp/SignaturePublicKey#from_jwk(332579c13420cdc2).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, const stdcxx . . $ std/::stringcxx . . $ std/string#& json_str)
405 {
406 auto pub = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().import_jwkcxx . . $ mlspp/hpke/Signature#import_jwk(a53063c3da59064e).(json_str);
407 auto pub_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serializecxx . . $ mlspp/hpke/Signature#serialize(85b79100656811f8).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
408 return SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#{ pub_data };
409 }
410
411 stdcxx . . $ std/::stringcxx . . $ std/string#
412 SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#::to_jwkcxx . . $ mlspp/SignaturePublicKey#to_jwk(e01dc7b933c172c2).(CipherSuitecxx . . $ mlspp/CipherSuite# suite) const
413 {
414 auto pub = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().deserializecxx . . $ mlspp/hpke/Signature#deserialize(321ec828a61140d).(datacxx . . $ mlspp/SignaturePublicKey#data.);
415 return suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().export_jwkcxx . . $ mlspp/hpke/Signature#export_jwk(f9fdd4f558be28e4).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
416 }
417
418 PublicJWKcxx . . $ mlspp/PublicJWK#
419 PublicJWKcxx . . $ mlspp/PublicJWK#::parsecxx . . $ mlspp/PublicJWK#parse(53a0670584dd2f31).(const stdcxx . . $ std/::stringcxx . . $ std/string#& jwk_json)
420 {
421 const auto parsed = Signaturecxx . . $ mlspp/hpke/Signature#::parse_jwkcxx . . $ mlspp/hpke/Signature#parse_jwk(13862ca891fb571b).(jwk_json);
422 const auto scheme = tls_signature_schemecxx . . $ mlspp/tls_signature_scheme(902aafe9a6722bee).(parsed.sigcxx . . $ mlspp/hpke/Signature#PublicJWK#sig..idcxx . . $ mlspp/hpke/Signature#id.);
423 const auto pub_data = parsed.sigcxx . . $ mlspp/hpke/Signature#PublicJWK#sig..serializecxx . . $ mlspp/hpke/Signature#serialize(85b79100656811f8).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).parsed.keycxx . . $ mlspp/hpke/Signature#PublicJWK#key.);
424 return { scheme, parsed.key_idcxx . . $ mlspp/hpke/Signature#PublicJWK#key_id., { pub_data } };
425 }
426
427 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#
428 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::generatecxx . . $ mlspp/SignaturePrivateKey#generate(9eace4066238b439).(CipherSuitecxx . . $ mlspp/CipherSuite# suite)
429 {
430 auto priv = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().generate_key_paircxx . . $ mlspp/hpke/Signature#generate_key_pair(8d27edcb683c805).();
431 auto priv_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serialize_privatecxx . . $ mlspp/hpke/Signature#serialize_private(46640a7490dcfaec).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).priv);
432 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/Signature#PrivateKey#public_key(cad5d51d56ce4928).();
433 auto pub_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serializecxx . . $ mlspp/hpke/Signature#serialize(85b79100656811f8).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
434 return {cxx . . $ mlspp/SignaturePrivateKey#SignaturePrivateKey(6452a1c837d26c07). priv_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)., pub_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). };
435 }
436
437 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#
438 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::parsecxx . . $ mlspp/SignaturePrivateKey#parse(2f8f1effe03d5e1a).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, const bytescxx . . $ mlspp/bytes_ns/bytes#& data)
439 {
440 auto priv = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().deserialize_privatecxx . . $ mlspp/hpke/Signature#deserialize_private(5746faca826a5ccd).(data);
441 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/Signature#PrivateKey#public_key(cad5d51d56ce4928).();
442 auto pub_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serializecxx . . $ mlspp/hpke/Signature#serialize(85b79100656811f8).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
443 return {cxx . . $ mlspp/SignaturePrivateKey#SignaturePrivateKey(6452a1c837d26c07). datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)., pub_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). };
444 }
445
446 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#
447 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::derivecxx . . $ mlspp/SignaturePrivateKey#derive(2f8f1effe03d5e1a).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, const bytescxx . . $ mlspp/bytes_ns/bytes#& secret)
448 {
449 auto priv = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().derive_key_paircxx . . $ mlspp/hpke/Signature#derive_key_pair(5746faca826a5ccd).(secret);
450 auto priv_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serialize_privatecxx . . $ mlspp/hpke/Signature#serialize_private(46640a7490dcfaec).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).priv);
451 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/Signature#PrivateKey#public_key(cad5d51d56ce4928).();
452 auto pub_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serializecxx . . $ mlspp/hpke/Signature#serialize(85b79100656811f8).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
453 return {cxx . . $ mlspp/SignaturePrivateKey#SignaturePrivateKey(6452a1c837d26c07). priv_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)., pub_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). };
454 }
455
456 bytescxx . . $ mlspp/bytes_ns/bytes#
457 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::signcxx . . $ mlspp/SignaturePrivateKey#sign(9a20592b3b42a8ed).(const CipherSuitecxx . . $ mlspp/CipherSuite#& suite,
458 const stdcxx . . $ std/::stringcxx . . $ std/string#& label,
459 const bytescxx . . $ mlspp/bytes_ns/bytes#& message) const
460 {
461 auto label_plus = mls_1_0_pluscxx . . $ mlspp/mls_1_0_plus(fc01d114001b7256).(label);
462 const auto content = tlscxx . . $ mlspp/tls/::marshalcxx . . $ mlspp/tls/marshal(7df0b13a9cabe487).(SignContentcxx . . $ mlspp/SignContent#{ label_plus, message });
463 const auto priv = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().deserialize_privatecxx . . $ mlspp/hpke/Signature#deserialize_private(5746faca826a5ccd).(datacxx . . $ mlspp/SignaturePrivateKey#data.);
464 return suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().signcxx . . $ mlspp/hpke/Signature#sign(4ebbf3240e588aaf).(contentcxx . . $ mlspp/bytes_ns/bytes#bytes(981a1a29c6e5fab4)., *cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).priv);
465 }
466
467 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#SignaturePrivateKey(6452a1c837d26c07).(bytescxx . . $ mlspp/bytes_ns/bytes# priv_data, bytescxx . . $ mlspp/bytes_ns/bytes# pub_data)
468 : datacxx . . $ mlspp/SignaturePrivateKey#data.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(priv_data))
469 , public_keycxx . . $ mlspp/SignaturePrivateKey#public_key.{ stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(pub_data) }
470 {
471 }
472
473 void
474 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::set_public_keycxx . . $ mlspp/SignaturePrivateKey#set_public_key(1ae84ca71f879861).(CipherSuitecxx . . $ mlspp/CipherSuite# suite)
475 {
476 const auto priv = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().deserialize_privatecxx . . $ mlspp/hpke/Signature#deserialize_private(5746faca826a5ccd).(datacxx . . $ mlspp/SignaturePrivateKey#data.);
477 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/Signature#PrivateKey#public_key(cad5d51d56ce4928).();
478 public_keycxx . . $ mlspp/SignaturePrivateKey#public_key..datacxx . . $ mlspp/SignaturePublicKey#data. =cxx . . $ mlspp/bytes_ns/bytes#`operator=`(463b53a2545785ed). suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serializecxx . . $ mlspp/hpke/Signature#serialize(85b79100656811f8).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
479 }
480
481 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#
482 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::from_jwkcxx . . $ mlspp/SignaturePrivateKey#from_jwk(bf859b0d4268fccb).(CipherSuitecxx . . $ mlspp/CipherSuite# suite, const stdcxx . . $ std/::stringcxx . . $ std/string#& json_str)
483 {
484 auto priv = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().import_jwk_privatecxx . . $ mlspp/hpke/Signature#import_jwk_private(8828a0bfc3408e3c).(json_str);
485 auto priv_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serialize_privatecxx . . $ mlspp/hpke/Signature#serialize_private(46640a7490dcfaec).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).priv);
486 auto pub = priv->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).public_keycxx . . $ mlspp/hpke/Signature#PrivateKey#public_key(cad5d51d56ce4928).();
487 auto pub_data = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().serializecxx . . $ mlspp/hpke/Signature#serialize(85b79100656811f8).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).pub);
488 return {cxx . . $ mlspp/SignaturePrivateKey#SignaturePrivateKey(6452a1c837d26c07). priv_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e)., pub_datacxx . . $ mlspp/bytes_ns/bytes#bytes(68ca607eebb5be3e). };
489 }
490
491 stdcxx . . $ std/::stringcxx . . $ std/string#
492 SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#::to_jwkcxx . . $ mlspp/SignaturePrivateKey#to_jwk(e01dc7b933c172c2).(CipherSuitecxx . . $ mlspp/CipherSuite# suite) const
493 {
494 const auto priv = suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().deserialize_privatecxx . . $ mlspp/hpke/Signature#deserialize_private(5746faca826a5ccd).(datacxx . . $ mlspp/SignaturePrivateKey#data.);
495 return suite.sigcxx . . $ mlspp/CipherSuite#sig(aab2196748eae221).().export_jwk_privatecxx . . $ mlspp/hpke/Signature#export_jwk_private(9eb010d7f7e5c82e).(*cxx . . $ std/unique_ptr#`operator*`(26c95836c1e8ca05).priv);
496 }
497
498 } // namespace mlspp