slightly improved API safety

This commit is contained in:
Monica Moniot
2024-03-21 12:44:21 -04:00
parent 32183bee0a
commit e4f6772f5d
2 changed files with 10 additions and 1 deletions
+9
View File
@@ -120,6 +120,15 @@ pub trait HighThroughputAesGcmPool: Send + Sync {
/// Be sure to perform your own benchmark.
#[must_use]
fn finish_dec<'a>(&'a self, dec: Self::DecContext<'a>, tag: &[u8; AES_GCM_TAG_SIZE]) -> bool;
/// Cancel encryption with `enc` without creating an authentication tag.
/// This is near identical in behavior to `finish_enc`, and is implemented by `finish_enc`
/// by default.
/// It is somewhat more secure to replace this default implementation with a version that does
/// not produce a valid authentication tag on an invalid payload.
fn cancel_enc<'a>(&'a self, enc: Self::EncContext<'a>) {
self.finish_enc(enc);
}
}
/// A trait for implementing AES-GCM-256 to handle the more varied, but much lower throughput
+1 -1
View File
@@ -1692,7 +1692,7 @@ pub(crate) fn send_payload<C: CryptoLayer>(
if !send.send_frag(&mut mtu_sized_buffer[..HEADER_SIZE + fragment_len]) {
// We need to give the cipher back to the pool instead of dropping it,
// so it can do memory cleanup.
cipher_pool.finish_enc(cipher);
cipher_pool.cancel_enc(cipher);
return Ok(false);
}
i = j;