Skip to content

Commit f81d880

Browse files
nasahlpavogelpi
authored andcommitted
[crypto] Check if jittery clock is enabled
When using the CryptoLib, the jittery clock security function should be enabled. This commit adds a function that checks if the JITTER_ENABLE is set to kMultiBitBool4True. Signed-off-by: Pascal Nasahl <[email protected]>
1 parent 92c25e7 commit f81d880

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

sw/device/silicon_creator/lib/drivers/BUILD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ cc_test(
137137
],
138138
)
139139

140+
cc_library(
141+
name = "clkmgr",
142+
srcs = ["clkmgr.c"],
143+
hdrs = [
144+
"clkmgr.h",
145+
],
146+
deps = [
147+
"//hw/top:dt_clkmgr",
148+
"//sw/device/lib/base:abs_mmio",
149+
"//sw/device/lib/base:hardened",
150+
"//sw/device/lib/base:macros",
151+
"//sw/device/lib/base:multibits",
152+
],
153+
)
154+
140155
dual_cc_library(
141156
name = "flash_ctrl",
142157
srcs = dual_inputs(
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 "sw/device/silicon_creator/lib/drivers/clkmgr.h"
6+
7+
#include "hw/top/dt/dt_clkmgr.h"
8+
#include "sw/device/lib/base/abs_mmio.h"
9+
#include "sw/device/lib/base/multibits.h"
10+
11+
#include "hw/top/clkmgr_regs.h"
12+
13+
// Module ID for status codes.
14+
#define MODULE_ID MAKE_MODULE_ID('c', 'l', 'k')
15+
16+
hardened_bool_t clkmgr_check_jittery_clk_en(void) {
17+
uintptr_t clkmgr_base_addr = dt_clkmgr_primary_reg_block(kDtClkmgrAon);
18+
uint32_t jittery_clk_en =
19+
abs_mmio_read32(clkmgr_base_addr + CLKMGR_JITTER_ENABLE_REG_OFFSET);
20+
21+
// Check that the jittery clock is set to kMultiBitBool4True
22+
if (launder32(jittery_clk_en) != kMultiBitBool4True) {
23+
return kHardenedBoolFalse;
24+
}
25+
HARDENED_CHECK_EQ(jittery_clk_en, kMultiBitBool4True);
26+
27+
return kHardenedBoolTrue;
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_CLKMGR_H_
6+
#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_CLKMGR_H_
7+
8+
#include <stdbool.h>
9+
#include <stddef.h>
10+
#include <stdint.h>
11+
12+
#include "sw/device/lib/base/hardened.h"
13+
#include "sw/device/lib/base/macros.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/**
20+
* Checks if the JITTER_ENABLE register of the CLKMGR is set to on.
21+
*
22+
* @return Whether the jittery clock is enabled.
23+
*/
24+
OT_WARN_UNUSED_RESULT
25+
hardened_bool_t clkmgr_check_jittery_clk_en(void);
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif
30+
31+
#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_DRIVERS_CLKMGR_H_

0 commit comments

Comments
 (0)