Skip to content

Commit

Permalink
Merge pull request tock#3503 from tock/remove-non-virtualizers
Browse files Browse the repository at this point in the history
capsules: remove virtual_[digest|flash|sha].rs which do not virtualize
  • Loading branch information
ppannuto authored Jul 17, 2023
2 parents e665031 + 57d6496 commit 70b2b28
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 1,633 deletions.
112 changes: 0 additions & 112 deletions boards/components/src/digest.rs

This file was deleted.

81 changes: 14 additions & 67 deletions boards/components/src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,51 @@
//! Usage
//! -----
//! ```rust
//! let mux_hmac = components::hmac::HmacMuxComponent::new(&earlgrey::hmac::HMAC).finalize(
//! components::hmac_mux_component_static!(lowrisc::hmac::Hmac, 32),
//! );
//!
//! let hmac = components::hmac::HmacComponent::new(
//! board_kernel,
//! &mux_hmac,
//! chip.hmac,
//! )
//! .finalize(components::hmac_component_static!(
//! lowrisc::hmac::Hmac,
//! 32
//! ));
//! ```

use capsules_core::virtualizers::virtual_hmac::MuxHmac;
use capsules_core::virtualizers::virtual_hmac::VirtualMuxHmac;
use capsules_extra::hmac::HmacDriver;
use core::mem::MaybeUninit;
use kernel::capabilities;
use kernel::component::Component;
use kernel::create_capability;
use kernel::hil::digest;

#[macro_export]
macro_rules! hmac_mux_component_static {
($A:ty, $L:expr $(,)?) => {{
kernel::static_buf!(capsules_core::virtualizers::virtual_hmac::MuxHmac<'static, $A, $L>)
};};
}

#[macro_export]
macro_rules! hmac_component_static {
($A:ty, $L:expr $(,)?) => {{
let virtual_mux = kernel::static_buf!(
capsules_core::virtualizers::virtual_hmac::VirtualMuxHmac<'static, $A, $L>
);
let hmac = kernel::static_buf!(
capsules_extra::hmac::HmacDriver<
'static,
capsules_core::virtualizers::virtual_hmac::VirtualMuxHmac<'static, $A, $L>,
$L,
>
);
let hmac = kernel::static_buf!(capsules_extra::hmac::HmacDriver<'static, $A, $L>);

let key_buffer = kernel::static_buf!([u8; 32]);
let data_buffer = kernel::static_buf!([u8; 64]);
let dest_buffer = kernel::static_buf!([u8; $L]);

(virtual_mux, hmac, key_buffer, data_buffer, dest_buffer)
(hmac, data_buffer, dest_buffer)
};};
}

pub struct HmacMuxComponent<A: 'static + digest::Digest<'static, L>, const L: usize> {
hmac: &'static A,
}

impl<A: 'static + digest::Digest<'static, L>, const L: usize> HmacMuxComponent<A, L> {
pub fn new(hmac: &'static A) -> HmacMuxComponent<A, L> {
HmacMuxComponent { hmac }
}
}

impl<
A: 'static
+ digest::Digest<'static, L>
+ digest::HmacSha256
+ digest::HmacSha384
+ digest::HmacSha512,
const L: usize,
> Component for HmacMuxComponent<A, L>
{
type StaticInput = &'static mut MaybeUninit<MuxHmac<'static, A, L>>;
type Output = &'static MuxHmac<'static, A, L>;

fn finalize(self, s: Self::StaticInput) -> Self::Output {
s.write(MuxHmac::new(self.hmac))
}
}

pub struct HmacComponent<A: 'static + digest::Digest<'static, L>, const L: usize> {
board_kernel: &'static kernel::Kernel,
driver_num: usize,
mux_hmac: &'static MuxHmac<'static, A, L>,
hmac: &'static A,
}

impl<A: 'static + digest::Digest<'static, L>, const L: usize> HmacComponent<A, L> {
pub fn new(
board_kernel: &'static kernel::Kernel,
driver_num: usize,
mux_hmac: &'static MuxHmac<'static, A, L>,
hmac: &'static A,
) -> HmacComponent<A, L> {
HmacComponent {
board_kernel,
driver_num,
mux_hmac,
hmac,
}
}
}
Expand All @@ -116,30 +66,27 @@ impl<
> Component for HmacComponent<A, L>
{
type StaticInput = (
&'static mut MaybeUninit<VirtualMuxHmac<'static, A, L>>,
&'static mut MaybeUninit<HmacDriver<'static, VirtualMuxHmac<'static, A, L>, L>>,
&'static mut MaybeUninit<[u8; 32]>,
&'static mut MaybeUninit<HmacDriver<'static, A, L>>,
&'static mut MaybeUninit<[u8; 64]>,
&'static mut MaybeUninit<[u8; L]>,
);
type Output = &'static HmacDriver<'static, VirtualMuxHmac<'static, A, L>, L>;
type Output = &'static HmacDriver<'static, A, L>;

fn finalize(self, s: Self::StaticInput) -> Self::Output {
let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);

let key_buffer = s.2.write([0; 32]);
let data_buffer = s.3.write([0; 64]);
let dest_buffer = s.4.write([0; L]);

let virtual_hmac_user = s.0.write(VirtualMuxHmac::new(self.mux_hmac, key_buffer));
let data_buffer = s.1.write([0; 64]);
let dest_buffer = s.2.write([0; L]);

let hmac = s.1.write(capsules_extra::hmac::HmacDriver::new(
virtual_hmac_user,
let hmac = s.0.write(capsules_extra::hmac::HmacDriver::new(
self.hmac,
data_buffer,
dest_buffer,
self.board_kernel.create_grant(self.driver_num, &grant_cap),
));

self.hmac.set_client(hmac);

hmac
}
}
1 change: 0 additions & 1 deletion boards/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub mod ctap;
pub mod dac;
pub mod debug_queue;
pub mod debug_writer;
pub mod digest;
pub mod flash;
pub mod fm25cl;
pub mod ft6x06;
Expand Down
Loading

0 comments on commit 70b2b28

Please sign in to comment.