Software APIs
aes_smoketest.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 
5 #include "hw/ip/aes/model/aes_modes.h"
10 #include "sw/device/lib/testing/aes_testutils.h"
11 #include "sw/device/lib/testing/test_framework/check.h"
13 
14 #define TIMEOUT (1000 * 1000)
15 
16 OTTF_DEFINE_TEST_CONFIG();
17 
18 status_t execute_test(dif_aes_t *aes) {
19  // Setup ECB encryption transaction.
20  dif_aes_transaction_t transaction = {
21  .operation = kDifAesOperationEncrypt,
22  .mode = kDifAesModeEcb,
23  .key_len = kDifAesKey256,
24  .key_provider = kDifAesKeySoftwareProvided,
25  .mask_reseeding = kDifAesReseedPerBlock,
26  .manual_operation = kDifAesManualOperationAuto,
27  .reseed_on_key_change = false,
28  .ctrl_aux_lock = false,
29  };
30 
31  CHECK_STATUS_OK(aes_testutils_setup_encryption(transaction, aes));
32 
33  AES_TESTUTILS_WAIT_FOR_STATUS(aes, kDifAesStatusOutputValid, true, TIMEOUT);
34 
35  return aes_testutils_decrypt_ciphertext(transaction, aes);
36 }
37 
38 bool test_main(void) {
39  dif_aes_t aes;
40 
41  // Initialise AES.
42  CHECK_DIF_OK(dif_aes_init_from_dt(kDtAes, &aes));
43  CHECK_DIF_OK(dif_aes_reset(&aes));
44 
45  return status_ok(execute_test(&aes));
46 }