Skip to content

Commit b17904e

Browse files
committed
crypto: use the FIPS-compliant AEAD from BoringCrypto
The main difference is that the _tls13() AEAD follows the FIPS requirements, the main one being that AEAD counters are strictly monotonically incresing for each seal operation.
1 parent e434e42 commit b17904e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

quiche/src/crypto/boringssl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ struct EVP_AEAD_CTX {
1818
impl Algorithm {
1919
fn get_evp_aead(self) -> *const EVP_AEAD {
2020
match self {
21-
Algorithm::AES128_GCM => unsafe { EVP_aead_aes_128_gcm() },
22-
Algorithm::AES256_GCM => unsafe { EVP_aead_aes_256_gcm() },
21+
Algorithm::AES128_GCM => unsafe { EVP_aead_aes_128_gcm_tls13() },
22+
Algorithm::AES256_GCM => unsafe { EVP_aead_aes_256_gcm_tls13() },
2323
Algorithm::ChaCha20_Poly1305 => unsafe {
2424
EVP_aead_chacha20_poly1305()
2525
},
@@ -227,9 +227,9 @@ pub(crate) fn hkdf_expand(
227227
}
228228

229229
extern {
230-
fn EVP_aead_aes_128_gcm() -> *const EVP_AEAD;
230+
fn EVP_aead_aes_128_gcm_tls13() -> *const EVP_AEAD;
231231

232-
fn EVP_aead_aes_256_gcm() -> *const EVP_AEAD;
232+
fn EVP_aead_aes_256_gcm_tls13() -> *const EVP_AEAD;
233233

234234
fn EVP_aead_chacha20_poly1305() -> *const EVP_AEAD;
235235

quiche/src/crypto/mod.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,25 @@ impl Seal {
238238
}
239239

240240
pub fn from_secret(aead: Algorithm, secret: &[u8]) -> Result<Seal> {
241-
Ok(Seal {
241+
let seal = Seal {
242242
alg: aead,
243243

244244
secret: secret.to_vec(),
245245

246246
header: HeaderProtectionKey::from_secret(aead, secret)?,
247247

248248
packet: PacketKey::from_secret(aead, secret, Self::ENCRYPT)?,
249-
})
249+
};
250+
251+
// Dummy seal operation to prime the AEAD context with the nonce mask.
252+
//
253+
// This is needed because BoringCrypto requires the first counter (i.e.
254+
// packet number) to be zero, which would not be the case for packet
255+
// number spaces after Initial as the same packet number sequence is
256+
// shared.
257+
let _ = seal.seal_with_u64_counter(0, b"", &mut [0_u8; 16], 0, None);
258+
259+
Ok(seal)
250260
}
251261

252262
pub fn new_mask(&self, sample: &[u8]) -> Result<[u8; 5]> {

0 commit comments

Comments
 (0)