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.
45mod aes;
6mod rc4;
78use crate::Error;
910use aes::NistAes;
11use rc4::Rc4;
12use wlan_common::ie::rsn::akm;
1314/// 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.
19fn 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.
22fn unwrap_key(&self, kek: &[u8], iv: &[u8; 16], data: &[u8]) -> Result<Vec<u8>, Error>;
23}
2425/// 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>> {
30match key_descriptor_version {
311 => Some(Box::new(Rc4)),
322 => Some(Box::new(NistAes)),
330 if akm.suite_type == akm::SAE => Some(Box::new(NistAes)),
34_ => None,
35 }
36}