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-2016, 12.7.2 b.1)
26pub 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}