Skip to content

Commit 19adc6b

Browse files
siemen11nasahlpa
authored andcommitted
[crypto/alert] Connect alert management to cryptolib
The cryptolib resets the alert manager's CSRs upon init and reads the registers upon execution of any API. In case an alert was raised, the cryptolib now returns a fatal error. Important is that init is only called at startup where the init function can be provided the priviledge of setting registers. The cryptolib requires read access to the alert manager range of addresses during function but no write access. This protects the cryptolib to provide a bad status in case even a recoverable alert is raised. Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
1 parent 87b102f commit 19adc6b

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

sw/device/lib/crypto/impl/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ cc_library(
279279
"//hw/top_earlgrey/ip_autogen/clkmgr:clkmgr_c_regs",
280280
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
281281
"//sw/device/lib/base:hardened_memory",
282+
"//sw/device/lib/crypto/drivers:alert",
282283
"//sw/device/lib/crypto/drivers:rv_core_ibex",
283284
],
284285
)

sw/device/lib/crypto/impl/config.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "sw/device/lib/crypto/include/config.h"
66

77
#include "sw/device/lib/base/hardened.h"
8+
#include "sw/device/lib/crypto/drivers/alert.h"
89
#include "sw/device/lib/crypto/drivers/rv_core_ibex.h"
910

1011
#include "clkmgr_regs.h"
@@ -40,9 +41,16 @@ otcrypto_status_t otcrypto_security_config_check(
4041
otcrypto_status_t otcrypto_init(otcrypto_key_security_level_t security_level) {
4142
(void)security_level;
4243

44+
HARDENED_TRY(init_alert_registers());
45+
4346
return OTCRYPTO_OK;
4447
}
4548

4649
otcrypto_status_t otcrypto_eval_exit(otcrypto_status_t status) {
50+
if (read_alert_registers()) {
51+
return OTCRYPTO_FATAL_ERR;
52+
}
53+
HARDENED_CHECK_EQ(launder32(read_alert_registers()), 0);
54+
4755
return status;
4856
}

0 commit comments

Comments
 (0)