Files
VoelinClient/third_party/dimpl/src/crypto/aws_lc_rs/hmac.rs
T
Claude d1c4424789 Vendor dimpl 0.7.4 unmodified and patch it in from third_party
str0m's DTLS stack (dimpl) hard-codes the SRTP profile a DTLS server picks
(AES-256-GCM first), with no way to configure it. Official TeamSpeak 6
clients use AES_CM_128_HMAC_SHA1_80, so we need to patch dimpl. This commit
only vendors the crate as published and routes crates.io's dimpl to it;
the change follows separately so it can be reviewed and dropped on its own.

third_party is excluded from the workspace so dimpl's dev-dependencies and
tests stay out of our builds, and own-crates.sh skips it like crates/proto.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-26 23:27:21 +00:00

41 lines
1.1 KiB
Rust

//! HMAC implementation using aws-lc-rs.
use aws_lc_rs::hmac;
use super::super::HmacProvider;
use crate::CryptoError;
use crate::types::HashAlgorithm;
/// Get HMAC algorithm from hash algorithm.
fn hmac_algorithm(hash: HashAlgorithm) -> Result<hmac::Algorithm, CryptoError> {
match hash {
HashAlgorithm::SHA256 => Ok(hmac::HMAC_SHA256),
HashAlgorithm::SHA384 => Ok(hmac::HMAC_SHA384),
_ => Err(CryptoError::UnsupportedHmacHash(hash)),
}
}
/// HMAC provider implementation.
#[derive(Debug)]
pub(crate) struct AwsLcHmacProvider;
impl HmacProvider for AwsLcHmacProvider {
fn hmac(
&self,
hash: HashAlgorithm,
key: &[u8],
data: &[u8],
out: &mut [u8],
) -> Result<usize, CryptoError> {
let algorithm = hmac_algorithm(hash)?;
let hmac_key = hmac::Key::new(algorithm, key);
let tag = hmac::sign(&hmac_key, data);
let len = tag.as_ref().len();
out[..len].copy_from_slice(tag.as_ref());
Ok(len)
}
}
/// Static instance of the HMAC provider.
pub(crate) static HMAC_PROVIDER: AwsLcHmacProvider = AwsLcHmacProvider;