wlan_rsn/keywrap/
mod.rs

1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5mod aes;
6mod rc4;
7
8use crate::Error;
9
10use aes::NistAes;
11use rc4::Rc4;
12use wlan_common::ie::rsn::akm;
13
14/// An arbitrary algorithm used to encrypt the key data field of an EAPoL keyframe.
15/// Usage is specified in IEEE 802.11-2016 8.5.2 j
16pub trait Algorithm {
17    #[allow(clippy::result_large_err, reason = "mass allow for https://fxbug.dev/381896734")]
18    /// Uses the given KEK and IV as a key to wrap the given data for secure transmission.
19    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    /// Uses the given KEK and IV as a key to unwrap the given data after secure transmission.
22    fn unwrap_key(&self, kek: &[u8], iv: &[u8; 16], data: &[u8]) -> Result<Vec<u8>, Error>;
23}
24
25/// IEEE Std 802.11-2024, 12.7.2 b.1)
26/// IEEE Std 802.11-2024, 12.7.3 Table 12-11
27pub fn keywrap_algorithm(
28    key_descriptor_version: u16,
29    akm: &akm::Akm,
30) -> Option<Box<dyn Algorithm>> {
31    match key_descriptor_version {
32        1 => Some(Box::new(Rc4)),
33        2 => Some(Box::new(NistAes)),
34        0 if akm.suite_type == akm::SAE || akm.suite_type == akm::OWE => Some(Box::new(NistAes)),
35        _ => None,
36    }
37}