nrf52840dk_test_kernel/test/
siphash24_test.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//! This tests a software SipHash24 implementation. To run this test,
6//! add this line to the boot sequence:
7//! ```
8//! test::siphash24_test::run_siphash24();
9//! ```
10
11use core::ptr::addr_of_mut;
12
13use capsules_core::test::capsule_test::{CapsuleTest, CapsuleTestClient};
14use capsules_extra::sip_hash::SipHasher24;
15use capsules_extra::test::siphash24::TestSipHash24;
16use kernel::static_init;
17
18pub unsafe fn run_siphash24(client: &'static dyn CapsuleTestClient) {
19    let t = static_init_test_siphash24(client);
20    t.run();
21}
22
23pub static mut HSTRING: [u8; 15] = *b"tickv-super-key";
24pub static mut HBUF: [u8; 64] = [0; 64];
25
26pub static mut HHASH: [u8; 8] = [0; 8];
27pub static mut CHASH: [u8; 8] = [0xd1, 0xdc, 0x3b, 0x92, 0xc2, 0x5a, 0x1b, 0x30];
28
29unsafe fn static_init_test_siphash24(
30    client: &'static dyn CapsuleTestClient,
31) -> &'static TestSipHash24 {
32    let sha = static_init!(SipHasher24<'static>, SipHasher24::new());
33    kernel::deferred_call::DeferredCallClient::register(sha);
34
35    // Copy to the 64 byte buffer because we always hash 64 bytes.
36    for i in 0..15 {
37        HBUF[i] = HSTRING[i];
38    }
39    let test = static_init!(
40        TestSipHash24,
41        TestSipHash24::new(
42            sha,
43            &mut *addr_of_mut!(HBUF),
44            &mut *addr_of_mut!(HHASH),
45            &mut *addr_of_mut!(CHASH)
46        )
47    );
48
49    test.set_client(client);
50
51    test
52}