wlan_rsn/integrity/
mod.rspub mod cmac_aes128;
pub mod hmac_md5;
pub mod hmac_sha1;
use crate::integrity::cmac_aes128::CmacAes128;
use crate::integrity::hmac_md5::HmacMd5;
use crate::integrity::hmac_sha1::HmacSha1;
use crate::Error;
use mundane::bytes;
use wlan_common::ie::rsn::akm;
pub trait Algorithm {
fn verify(&self, key: &[u8], data: &[u8], expected: &[u8]) -> bool {
self.compute(key, data)
.map(|mut output| {
output.resize(expected.len(), 0);
bytes::constant_time_eq(&output, expected)
})
.unwrap_or(false)
}
#[allow(clippy::result_large_err, reason = "mass allow for https://fxbug.dev/381896734")]
fn compute(&self, key: &[u8], data: &[u8]) -> Result<Vec<u8>, Error>;
}
pub fn integrity_algorithm(
key_descriptor_version: u16,
akm: &akm::Akm,
) -> Option<Box<dyn Algorithm>> {
match key_descriptor_version {
1 => Some(Box::new(HmacMd5::new())),
2 => Some(Box::new(HmacSha1::new())),
3 | 0 if akm.suite_type == akm::SAE => Some(Box::new(CmacAes128::new())),
_ => None,
}
}