nrf52dk/tests/
aes.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 2022.
4
5use capsules_extra::test::aes::TestAes128Ctr;
6use kernel::hil::symmetric_encryption::{AES128, AES128_BLOCK_SIZE, AES128_KEY_SIZE};
7use kernel::static_init;
8use nrf52832::aes::AesECB;
9
10/// To run the tests add the following `main.rs::main` somewhere after that the AES
11/// peripheral has been initialized:
12///
13/// ```rustc
14///     aes::run(base_peripherals.ecb);
15/// ```
16///
17pub unsafe fn run(aesecb: &'static AesECB) {
18    let t = static_init_test(aesecb);
19    aesecb.set_client(t);
20    t.run();
21}
22
23unsafe fn static_init_test(
24    aesecb: &'static AesECB,
25) -> &'static TestAes128Ctr<'static, AesECB<'static>> {
26    let source = static_init!([u8; 4 * AES128_BLOCK_SIZE], [0; 4 * AES128_BLOCK_SIZE]);
27    let data = static_init!([u8; 6 * AES128_BLOCK_SIZE], [0; 6 * AES128_BLOCK_SIZE]);
28    let key = static_init!([u8; AES128_KEY_SIZE], [0; AES128_KEY_SIZE]);
29    let iv = static_init!([u8; AES128_BLOCK_SIZE], [0; AES128_BLOCK_SIZE]);
30
31    static_init!(
32        TestAes128Ctr<'static, AesECB>,
33        TestAes128Ctr::new(aesecb, key, iv, source, data, true)
34    )
35}