wlan_rsn/integrity/
mod.rs1pub mod cmac_aes128;
6pub mod hmac_md5;
7pub mod hmac_sha1;
8pub mod hmac_sha256;
9
10use crate::Error;
11use crate::integrity::cmac_aes128::CmacAes128;
12use crate::integrity::hmac_md5::HmacMd5;
13use crate::integrity::hmac_sha1::HmacSha1;
14use crate::integrity::hmac_sha256::HmacSha256;
15use mundane::bytes;
16use wlan_common::ie::rsn::akm;
17
18pub trait Algorithm {
19 fn verify(&self, key: &[u8], data: &[u8], expected: &[u8]) -> bool {
22 self.compute(key, data)
23 .map(|mut output| {
24 output.resize(expected.len(), 0);
25 bytes::constant_time_eq(&output, expected)
26 })
27 .unwrap_or(false)
28 }
29
30 #[allow(clippy::result_large_err, reason = "mass allow for https://fxbug.dev/381896734")]
31 fn compute(&self, key: &[u8], data: &[u8]) -> Result<Vec<u8>, Error>;
32}
33
34pub fn integrity_algorithm(
36 key_descriptor_version: u16,
37 akm: &akm::Akm,
38) -> Option<Box<dyn Algorithm>> {
39 match key_descriptor_version {
40 1 => Some(Box::new(HmacMd5::new())),
41 2 => Some(Box::new(HmacSha1::new())),
42 3 | 0 if akm.suite_type == akm::SAE => Some(Box::new(CmacAes128::new())),
44 0 if akm.suite_type == akm::OWE => Some(Box::new(HmacSha256::new())),
49 _ => None,
50 }
51}