Software APIs
firmware.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 <stdbool.h>
5 
6 #include "sw/device/lib/base/status.h"
7 #include "sw/device/lib/crypto/drivers/entropy.h"
8 #include "sw/device/lib/testing/test_framework/check.h"
10 #include "sw/device/lib/testing/test_framework/ujson_ottf.h"
11 #include "sw/device/lib/ujson/ujson.h"
12 
14 
15 // Include commands
16 #include "sw/device/tests/crypto/cryptotest/json/aes_commands.h"
17 #include "sw/device/tests/crypto/cryptotest/json/commands.h"
18 #include "sw/device/tests/crypto/cryptotest/json/drbg_commands.h"
19 #include "sw/device/tests/crypto/cryptotest/json/ecdh_commands.h"
20 #include "sw/device/tests/crypto/cryptotest/json/ecdsa_commands.h"
21 #include "sw/device/tests/crypto/cryptotest/json/hash_commands.h"
22 #include "sw/device/tests/crypto/cryptotest/json/hmac_commands.h"
23 #include "sw/device/tests/crypto/cryptotest/json/kmac_commands.h"
24 #include "sw/device/tests/crypto/cryptotest/json/sphincsplus_commands.h"
25 
26 // Include handlers
27 #include "aes.h"
28 #include "drbg.h"
29 #include "ecdh.h"
30 #include "ecdsa.h"
31 #include "hash.h"
32 #include "hmac.h"
33 #include "kmac.h"
34 #include "sphincsplus.h"
35 
36 OTTF_DEFINE_TEST_CONFIG(.console.type = kOttfConsoleSpiDevice,
37  .console.base_addr = TOP_EARLGREY_SPI_DEVICE_BASE_ADDR,
38  .console.test_may_clobber = false, );
39 
40 status_t process_cmd(ujson_t *uj) {
41  while (true) {
42  cryptotest_cmd_t cmd;
43  TRY(ujson_deserialize_cryptotest_cmd_t(uj, &cmd));
44  switch (cmd) {
45  case kCryptotestCommandAes:
46  RESP_ERR(uj, handle_aes(uj));
47  break;
48  case kCryptotestCommandDrbg:
49  RESP_ERR(uj, handle_drbg(uj));
50  break;
51  case kCryptotestCommandEcdsa:
52  RESP_ERR(uj, handle_ecdsa(uj));
53  break;
54  case kCryptotestCommandEcdh:
55  RESP_ERR(uj, handle_ecdh(uj));
56  break;
57  case kCryptotestCommandHash:
58  RESP_ERR(uj, handle_hash(uj));
59  break;
60  case kCryptotestCommandHmac:
61  RESP_ERR(uj, handle_hmac(uj));
62  break;
63  case kCryptotestCommandKmac:
64  RESP_ERR(uj, handle_kmac(uj));
65  break;
66  case kCryptotestCommandSphincsPlus:
67  RESP_ERR(uj, handle_sphincsplus(uj));
68  break;
69  default:
70  LOG_ERROR("Unrecognized command: %d", cmd);
71  RESP_ERR(uj, INVALID_ARGUMENT());
72  }
73  }
74 
75  return OK_STATUS(0);
76 }
77 
78 bool test_main(void) {
79  CHECK_STATUS_OK(entropy_complex_init());
80  ujson_t uj = ujson_ottf_console();
81  return status_ok(process_cmd(&uj));
82 }