1mod aes;
6mod rc4;
7
8use crate::Error;
9
10use aes::NistAes;
11use rc4::Rc4;
12use wlan_common::ie::rsn::akm;
13
14pub trait Algorithm {
17 #[allow(clippy::result_large_err, reason = "mass allow for https://fxbug.dev/381896734")]
18 fn wrap_key(&self, kek: &[u8], iv: &[u8; 16], data: &[u8]) -> Result<Vec<u8>, Error>;
20 #[allow(clippy::result_large_err, reason = "mass allow for https://fxbug.dev/381896734")]
21 fn unwrap_key(&self, kek: &[u8], iv: &[u8; 16], data: &[u8]) -> Result<Vec<u8>, Error>;
23}
24
25pub fn keywrap_algorithm(
27 key_descriptor_version: u16,
28 akm: &akm::Akm,
29) -> Option<Box<dyn Algorithm>> {
30 match key_descriptor_version {
31 1 => Some(Box::new(Rc4)),
32 2 => Some(Box::new(NistAes)),
33 0 if akm.suite_type == akm::SAE => Some(Box::new(NistAes)),
34 _ => None,
35 }
36}