components/
siphash.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2023.
4
5//! Components for SipHash hasher.
6
7use core::mem::MaybeUninit;
8use kernel::component::Component;
9use kernel::deferred_call::DeferredCallClient;
10
11// Setup static space for the objects.
12#[macro_export]
13macro_rules! siphasher24_component_static {
14    ($(,)?) => {{
15        kernel::static_buf!(capsules_extra::sip_hash::SipHasher24)
16    };};
17}
18
19pub type Siphasher24ComponentType = capsules_extra::sip_hash::SipHasher24<'static>;
20
21pub struct Siphasher24Component {}
22
23impl Siphasher24Component {
24    pub fn new() -> Siphasher24Component {
25        Siphasher24Component {}
26    }
27}
28
29impl Component for Siphasher24Component {
30    type StaticInput = &'static mut MaybeUninit<capsules_extra::sip_hash::SipHasher24<'static>>;
31    type Output = &'static capsules_extra::sip_hash::SipHasher24<'static>;
32
33    fn finalize(self, s: Self::StaticInput) -> Self::Output {
34        let sip_hash = s.write(capsules_extra::sip_hash::SipHasher24::new());
35        sip_hash.register();
36        sip_hash
37    }
38}