Software APIs
entropy_test.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 #include "sw/device/lib/crypto/drivers/entropy.h"
5 
7 #include "sw/device/lib/base/status.h"
8 #include "sw/device/lib/crypto/drivers/entropy_kat.h"
11 #include "sw/device/lib/testing/test_framework/check.h"
13 #include "sw/device/tests/otbn_randomness_impl.h"
14 
16 
17 #define MODULE_ID MAKE_MODULE_ID('e', 'n', 't')
18 
19 OTTF_DEFINE_TEST_CONFIG();
20 
21 static status_t entropy_complex_init_test(void) {
22  TRY(entropy_complex_init());
23 
24  // Check the configuration.
25  TRY(entropy_complex_check());
26 
27  // The following test requests entropy from both EDN0 and EDN1.
28  dif_otbn_t otbn;
29  TRY_CHECK(dif_otbn_init(mmio_region_from_addr(TOP_EARLGREY_OTBN_BASE_ADDR),
30  &otbn) == kDifOk);
31  otbn_randomness_test_start(&otbn, /*iters=*/0);
32  TRY_CHECK(otbn_randomness_test_end(&otbn, /*skip_otbn_don_check=*/false));
33  return OK_STATUS();
34 }
35 
36 bool test_main(void) {
37  status_t result = OK_STATUS();
38 
39  EXECUTE_TEST(result, entropy_complex_init_test);
40  EXECUTE_TEST(result, entropy_csrng_kat);
41  return status_ok(result);
42 }