Skip to content

Commit 0912e5f

Browse files
committed
[crypto/entropy] Set FIPS thresholds
Set the entropy source driver to align with certified NIST SP 800-90B requirements. Specific changes include: - NIST 800-90B Health Test Thresholds: Increased the `fips_test_window_size` to 2048 bits to comply with FIPS standards for binary noise sources. - Bypass Register Configuration: Updated the `SET_FIPS_THRESH` and `VERIFY_FIPS_THRESH` macros to write and verify both the `FIPS_THRESH` and `BYPASS_THRESH` fields simultaneously. Note: CSRNG `FIPS_FORCE_ENABLE` and EDN continuous polling rates remain at their defaults to ensure the FIFO does not run empty with, for exmaple, the OTBN during the initial TRNG FIPS warm-up phase. Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
1 parent 5c5a1ad commit 0912e5f

15 files changed

+69
-69
lines changed

sw/device/lib/crypto/drivers/entropy.c

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum {
3636
kEntropyCsrngBitsBufferNumWords = 4,
3737

3838
// Fast timeout for checking if hardware is ready to accept a command word
39-
kEntropyPollReadyTimeout = 100,
39+
kEntropyPollReadyTimeout = 1000000,
4040
// Longer timeout for waiting for a command to finish executing
4141
kEntropyPollCmdDoneTimeout = 1000000,
4242
// Timeout for waiting for GenBits to become valid
@@ -237,16 +237,15 @@ static const entropy_complex_config_t
237237
.route_to_firmware = kMultiBitBool4False,
238238
.bypass_conditioner = kMultiBitBool4False,
239239
.single_bit_mode = kMultiBitBool4False,
240-
.fips_test_window_size = 0x200,
241-
.alert_threshold = 2,
242-
// TODO(#19392): Figure out appropriate thresholds.
243-
.repcnt_threshold = 0xffff,
244-
.repcnts_threshold = 0xffff,
245-
.adaptp_hi_threshold = 0xffff,
246-
.adaptp_lo_threshold = 0x0,
247-
.bucket_threshold = 0xffff,
248-
.markov_hi_threshold = 0xffff,
249-
.markov_lo_threshold = 0x0,
240+
.fips_test_window_size = 2048,
241+
.alert_threshold = 4,
242+
.repcnt_threshold = 81,
243+
.repcnts_threshold = 21,
244+
.adaptp_hi_threshold = 1591,
245+
.adaptp_lo_threshold = 2048 - 1591, // 457
246+
.bucket_threshold = 201,
247+
.markov_hi_threshold = 824,
248+
.markov_lo_threshold = 1024 - 824, // 200
250249
.extht_hi_threshold = 0xffff,
251250
.extht_lo_threshold = 0x0,
252251
},
@@ -464,9 +463,7 @@ static status_t csrng_send_app_cmd(uint32_t base_address,
464463
// The non-Generate commands complete earlier, so poll the "command
465464
// request done" interrupt bit. Once it is set, the "status" bit is
466465
// updated.
467-
uint32_t timeout = (cmd.id == kEntropyDrbgOpInstantiate)
468-
? kEntropyPollCmdDoneTimeout
469-
: kEntropyPollReadyTimeout;
466+
uint32_t timeout = kEntropyPollCmdDoneTimeout;
470467
do {
471468
reg = abs_mmio_read32(kBaseCsrng + CSRNG_INTR_STATE_REG_OFFSET);
472469
} while (
@@ -668,19 +665,19 @@ static void entropy_complex_stop_all(void) {
668665
/**
669666
* Set the value of an entropy_src threshold register.
670667
*
671-
* Only sets the FIPS threshold value, not the bypass threshold field; for the
672-
* bypass threshold we use the reset value, which is ignored if looser than the
673-
* thresholds already set.
668+
* Sets both the FIPS and BYPASS threshold fields to the same value.
674669
*
675670
* @param name Name of register (e.g. REPCNT, BUCKET).
676-
* @param value Value to set for the FIPS_THRESH field.
671+
* @param value Value to set for the FIPS_THRESH and BYPASS_THRESH fields.
677672
*/
678-
#define SET_FIPS_THRESH(name, value) \
679-
abs_mmio_write32( \
680-
kBaseEntropySrc + ENTROPY_SRC_##name##_THRESHOLDS_REG_OFFSET, \
681-
bitfield_field32_write( \
682-
ENTROPY_SRC_##name##_THRESHOLDS_REG_RESVAL, \
683-
ENTROPY_SRC_##name##_THRESHOLDS_FIPS_THRESH_FIELD, value));
673+
#define SET_FIPS_THRESH(name, value) \
674+
abs_mmio_write32( \
675+
kBaseEntropySrc + ENTROPY_SRC_##name##_THRESHOLDS_REG_OFFSET, \
676+
bitfield_field32_write( \
677+
bitfield_field32_write( \
678+
ENTROPY_SRC_##name##_THRESHOLDS_REG_RESVAL, \
679+
ENTROPY_SRC_##name##_THRESHOLDS_FIPS_THRESH_FIELD, value), \
680+
ENTROPY_SRC_##name##_THRESHOLDS_BYPASS_THRESH_FIELD, value));
684681

685682
/**
686683
* Configures the entropy_src with based on `config` options.
@@ -727,6 +724,10 @@ static status_t entropy_src_configure(const entropy_src_config_t *config) {
727724
bitfield_field32_write(ENTROPY_SRC_HEALTH_TEST_WINDOWS_REG_RESVAL,
728725
ENTROPY_SRC_HEALTH_TEST_WINDOWS_FIPS_WINDOW_FIELD,
729726
config->fips_test_window_size);
727+
health_test_windows = bitfield_field32_write(
728+
health_test_windows, ENTROPY_SRC_HEALTH_TEST_WINDOWS_BYPASS_WINDOW_FIELD,
729+
0x60);
730+
730731
abs_mmio_write32(kBaseEntropySrc + ENTROPY_SRC_HEALTH_TEST_WINDOWS_REG_OFFSET,
731732
health_test_windows);
732733

@@ -777,18 +778,20 @@ static status_t entropy_src_configure(const entropy_src_config_t *config) {
777778
/**
778779
* Verify the value of an entropy_src threshold register.
779780
*
780-
* Only checks the FIPS threshold value, not the bypass threshold field.
781+
* Checks both the FIPS and BYPASS threshold values.
781782
*
782783
* @param name Name of register (e.g. REPCNT, BUCKET).
783-
* @param exp Expected value of the FIPS_THRESH field.
784+
* @param exp Expected value of the FIPS_THRESH and BYPASS_THRESH fields.
784785
*/
785786
#define VERIFY_FIPS_THRESH(name, exp) \
786787
do { \
787788
uint32_t reg = abs_mmio_read32( \
788789
kBaseEntropySrc + ENTROPY_SRC_##name##_THRESHOLDS_REG_OFFSET); \
789-
uint32_t act = bitfield_field32_read( \
790+
uint32_t act_fips = bitfield_field32_read( \
790791
reg, ENTROPY_SRC_##name##_THRESHOLDS_FIPS_THRESH_FIELD); \
791-
if (act != exp) { \
792+
uint32_t act_bypass = bitfield_field32_read( \
793+
reg, ENTROPY_SRC_##name##_THRESHOLDS_BYPASS_THRESH_FIELD); \
794+
if (act_fips != exp || act_bypass != exp) { \
792795
return OTCRYPTO_RECOV_ERR; \
793796
} \
794797
} while (false);
@@ -847,12 +850,16 @@ static status_t entropy_src_check(const entropy_src_config_t *config) {
847850
return OTCRYPTO_RECOV_ERR;
848851
}
849852

850-
// Check health test window register.
853+
// Check health test window register for fips and bypass.
851854
reg = abs_mmio_read32(kBaseEntropySrc +
852855
ENTROPY_SRC_HEALTH_TEST_WINDOWS_REG_OFFSET);
853-
if (bitfield_field32_read(
854-
reg, ENTROPY_SRC_HEALTH_TEST_WINDOWS_FIPS_WINDOW_FIELD) !=
855-
config->fips_test_window_size) {
856+
uint32_t act_fips_window = bitfield_field32_read(
857+
reg, ENTROPY_SRC_HEALTH_TEST_WINDOWS_FIPS_WINDOW_FIELD);
858+
uint32_t act_bypass_window = bitfield_field32_read(
859+
reg, ENTROPY_SRC_HEALTH_TEST_WINDOWS_BYPASS_WINDOW_FIELD);
860+
861+
if (act_fips_window != config->fips_test_window_size ||
862+
act_bypass_window != 0x60) {
856863
return OTCRYPTO_RECOV_ERR;
857864
}
858865

sw/device/tests/crypto/BUILD

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ opentitan_test(
219219
deps = [
220220
"//sw/device/lib/crypto/drivers:otbn",
221221
"//sw/device/lib/crypto/impl:ecc_p256",
222+
"//sw/device/lib/crypto/impl:entropy_src",
222223
"//sw/device/lib/crypto/include:datatypes",
223224
"//sw/device/lib/runtime:log",
224-
"//sw/device/lib/testing:entropy_testutils",
225225
"//sw/device/lib/testing/test_framework:ottf_main",
226226
],
227227
)
@@ -235,11 +235,11 @@ opentitan_test(
235235
),
236236
deps = [
237237
"//sw/device/lib/crypto/impl:ecc_p256",
238+
"//sw/device/lib/crypto/impl:entropy_src",
238239
"//sw/device/lib/crypto/impl:keyblob",
239240
"//sw/device/lib/crypto/impl:sha2",
240241
"//sw/device/lib/crypto/impl/ecc:p256",
241242
"//sw/device/lib/runtime:log",
242-
"//sw/device/lib/testing:entropy_testutils",
243243
"//sw/device/lib/testing/test_framework:ottf_main",
244244
],
245245
)
@@ -254,9 +254,9 @@ opentitan_test(
254254
deps = [
255255
"//sw/device/lib/crypto/drivers:otbn",
256256
"//sw/device/lib/crypto/impl:ecc_p384",
257+
"//sw/device/lib/crypto/impl:entropy_src",
257258
"//sw/device/lib/crypto/include:datatypes",
258259
"//sw/device/lib/runtime:log",
259-
"//sw/device/lib/testing:entropy_testutils",
260260
"//sw/device/lib/testing/test_framework:ottf_main",
261261
],
262262
)
@@ -270,11 +270,11 @@ opentitan_test(
270270
),
271271
deps = [
272272
"//sw/device/lib/crypto/impl:ecc_p384",
273+
"//sw/device/lib/crypto/impl:entropy_src",
273274
"//sw/device/lib/crypto/impl:keyblob",
274275
"//sw/device/lib/crypto/impl:sha2",
275276
"//sw/device/lib/crypto/impl/ecc:p384",
276277
"//sw/device/lib/runtime:log",
277-
"//sw/device/lib/testing:entropy_testutils",
278278
"//sw/device/lib/testing/test_framework:ottf_main",
279279
],
280280
)
@@ -289,8 +289,8 @@ opentitan_test(
289289
deps = [
290290
"//sw/device/lib/crypto/drivers:otbn",
291291
"//sw/device/lib/crypto/impl:ecc_p256",
292+
"//sw/device/lib/crypto/impl:entropy_src",
292293
"//sw/device/lib/runtime:log",
293-
"//sw/device/lib/testing:entropy_testutils",
294294
"//sw/device/lib/testing/test_framework:ottf_main",
295295
],
296296
)
@@ -308,8 +308,8 @@ opentitan_test(
308308
deps = [
309309
"//sw/device/lib/crypto/drivers:otbn",
310310
"//sw/device/lib/crypto/impl:ecc_p384",
311+
"//sw/device/lib/crypto/impl:entropy_src",
311312
"//sw/device/lib/runtime:log",
312-
"//sw/device/lib/testing:entropy_testutils",
313313
"//sw/device/lib/testing/test_framework:ottf_main",
314314
],
315315
)
@@ -330,7 +330,6 @@ opentitan_test(
330330
"//sw/device/lib/crypto/impl:entropy_src",
331331
"//sw/device/lib/crypto/impl:key_transport",
332332
"//sw/device/lib/runtime:log",
333-
"//sw/device/lib/testing:entropy_testutils",
334333
"//sw/device/lib/testing:keymgr_testutils",
335334
"//sw/device/lib/testing/test_framework:ottf_main",
336335
],
@@ -352,7 +351,6 @@ opentitan_test(
352351
"//sw/device/lib/crypto/impl:entropy_src",
353352
"//sw/device/lib/crypto/impl:key_transport",
354353
"//sw/device/lib/runtime:log",
355-
"//sw/device/lib/testing:entropy_testutils",
356354
"//sw/device/lib/testing:keymgr_testutils",
357355
"//sw/device/lib/testing/test_framework:ottf_main",
358356
],
@@ -368,11 +366,11 @@ opentitan_test(
368366
deps = [
369367
"//sw/device/lib/crypto/drivers:otbn",
370368
"//sw/device/lib/crypto/impl:ecc_p256",
369+
"//sw/device/lib/crypto/impl:entropy_src",
371370
"//sw/device/lib/crypto/impl:keyblob",
372371
"//sw/device/lib/crypto/impl:sha2",
373372
"//sw/device/lib/crypto/include:datatypes",
374373
"//sw/device/lib/runtime:log",
375-
"//sw/device/lib/testing:entropy_testutils",
376374
"//sw/device/lib/testing/test_framework:ottf_main",
377375
],
378376
)
@@ -390,11 +388,11 @@ opentitan_test(
390388
deps = [
391389
"//sw/device/lib/crypto/drivers:otbn",
392390
"//sw/device/lib/crypto/impl:ecc_p384",
391+
"//sw/device/lib/crypto/impl:entropy_src",
393392
"//sw/device/lib/crypto/impl:keyblob",
394393
"//sw/device/lib/crypto/impl:sha2",
395394
"//sw/device/lib/crypto/include:datatypes",
396395
"//sw/device/lib/runtime:log",
397-
"//sw/device/lib/testing:entropy_testutils",
398396
"//sw/device/lib/testing/test_framework:ottf_main",
399397
],
400398
)
@@ -760,7 +758,6 @@ opentitan_test(
760758
"//sw/device/lib/crypto/impl:sha2",
761759
"//sw/device/lib/crypto/impl/rsa:rsa_datatypes",
762760
"//sw/device/lib/runtime:log",
763-
"//sw/device/lib/testing:entropy_testutils",
764761
"//sw/device/lib/testing:profile",
765762
"//sw/device/lib/testing/test_framework:ottf_main",
766763
],
@@ -810,7 +807,6 @@ opentitan_test(
810807
"//sw/device/lib/crypto/impl:sha2",
811808
"//sw/device/lib/crypto/impl/rsa:rsa_datatypes",
812809
"//sw/device/lib/runtime:log",
813-
"//sw/device/lib/testing:entropy_testutils",
814810
"//sw/device/lib/testing:profile",
815811
"//sw/device/lib/testing/test_framework:ottf_main",
816812
],
@@ -858,7 +854,6 @@ opentitan_test(
858854
"//sw/device/lib/crypto/impl:sha2",
859855
"//sw/device/lib/crypto/impl/rsa:rsa_datatypes",
860856
"//sw/device/lib/runtime:log",
861-
"//sw/device/lib/testing:entropy_testutils",
862857
"//sw/device/lib/testing:profile",
863858
"//sw/device/lib/testing/test_framework:ottf_main",
864859
],

sw/device/tests/crypto/ecc_p256_key_import_export_functest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "sw/device/lib/crypto/impl/keyblob.h"
77
#include "sw/device/lib/crypto/include/datatypes.h"
88
#include "sw/device/lib/crypto/include/ecc_p256.h"
9+
#include "sw/device/lib/crypto/include/entropy_src.h"
910
#include "sw/device/lib/crypto/include/sha2.h"
1011
#include "sw/device/lib/runtime/log.h"
11-
#include "sw/device/lib/testing/entropy_testutils.h"
1212
#include "sw/device/lib/testing/test_framework/check.h"
1313
#include "sw/device/lib/testing/test_framework/ottf_main.h"
1414

@@ -230,7 +230,7 @@ static status_t ecdh_key_mode_test(void) {
230230
OTTF_DEFINE_TEST_CONFIG();
231231

232232
bool test_main(void) {
233-
CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
233+
CHECK_STATUS_OK(otcrypto_entropy_init());
234234

235235
CHECK_STATUS_OK(ecdh_key_mode_test());
236236

sw/device/tests/crypto/ecc_p256_point_on_curve_check_functest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "sw/device/lib/crypto/drivers/otbn.h"
66
#include "sw/device/lib/crypto/impl/ecc/p256.h"
77
#include "sw/device/lib/crypto/include/ecc_p256.h"
8+
#include "sw/device/lib/crypto/include/entropy_src.h"
89
#include "sw/device/lib/runtime/log.h"
9-
#include "sw/device/lib/testing/entropy_testutils.h"
1010
#include "sw/device/lib/testing/test_framework/check.h"
1111
#include "sw/device/lib/testing/test_framework/ottf_main.h"
1212

@@ -74,7 +74,7 @@ status_t point_valid_test(void) {
7474
OTTF_DEFINE_TEST_CONFIG();
7575

7676
bool test_main(void) {
77-
CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
77+
CHECK_STATUS_OK(otcrypto_entropy_init());
7878

7979
status_t err = point_valid_test();
8080
if (!status_ok(err)) {

sw/device/tests/crypto/ecc_p384_key_import_export_functest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "sw/device/lib/crypto/impl/keyblob.h"
77
#include "sw/device/lib/crypto/include/datatypes.h"
88
#include "sw/device/lib/crypto/include/ecc_p384.h"
9+
#include "sw/device/lib/crypto/include/entropy_src.h"
910
#include "sw/device/lib/crypto/include/sha2.h"
1011
#include "sw/device/lib/runtime/log.h"
11-
#include "sw/device/lib/testing/entropy_testutils.h"
1212
#include "sw/device/lib/testing/test_framework/check.h"
1313
#include "sw/device/lib/testing/test_framework/ottf_main.h"
1414

@@ -230,7 +230,7 @@ static status_t ecdh_key_mode_test(void) {
230230
OTTF_DEFINE_TEST_CONFIG();
231231

232232
bool test_main(void) {
233-
CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
233+
CHECK_STATUS_OK(otcrypto_entropy_init());
234234

235235
CHECK_STATUS_OK(ecdh_key_mode_test());
236236

sw/device/tests/crypto/ecc_p384_point_on_curve_check_functest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "sw/device/lib/crypto/drivers/otbn.h"
66
#include "sw/device/lib/crypto/impl/ecc/p384.h"
77
#include "sw/device/lib/crypto/include/ecc_p384.h"
8+
#include "sw/device/lib/crypto/include/entropy_src.h"
89
#include "sw/device/lib/runtime/log.h"
9-
#include "sw/device/lib/testing/entropy_testutils.h"
1010
#include "sw/device/lib/testing/test_framework/check.h"
1111
#include "sw/device/lib/testing/test_framework/ottf_main.h"
1212

@@ -82,7 +82,7 @@ status_t point_valid_test(void) {
8282
OTTF_DEFINE_TEST_CONFIG();
8383

8484
bool test_main(void) {
85-
CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
85+
CHECK_STATUS_OK(otcrypto_entropy_init());
8686

8787
status_t err = point_valid_test();
8888
if (!status_ok(err)) {

sw/device/tests/crypto/ecdh_p256_functest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "sw/device/lib/crypto/impl/integrity.h"
77
#include "sw/device/lib/crypto/impl/keyblob.h"
88
#include "sw/device/lib/crypto/include/ecc_p256.h"
9+
#include "sw/device/lib/crypto/include/entropy_src.h"
910
#include "sw/device/lib/runtime/log.h"
10-
#include "sw/device/lib/testing/entropy_testutils.h"
1111
#include "sw/device/lib/testing/test_framework/check.h"
1212
#include "sw/device/lib/testing/test_framework/ottf_main.h"
1313

@@ -256,7 +256,7 @@ static status_t run_ecdh_negative_tests(void) {
256256
OTTF_DEFINE_TEST_CONFIG();
257257

258258
bool test_main(void) {
259-
CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
259+
CHECK_STATUS_OK(otcrypto_entropy_init());
260260

261261
status_t err = key_exchange_test();
262262
if (!status_ok(err)) {

sw/device/tests/crypto/ecdh_p256_sideload_functest.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "sw/device/lib/crypto/include/entropy_src.h"
1010
#include "sw/device/lib/crypto/include/key_transport.h"
1111
#include "sw/device/lib/runtime/log.h"
12-
#include "sw/device/lib/testing/entropy_testutils.h"
1312
#include "sw/device/lib/testing/keymgr_testutils.h"
1413
#include "sw/device/lib/testing/test_framework/check.h"
1514
#include "sw/device/lib/testing/test_framework/ottf_main.h"

sw/device/tests/crypto/ecdh_p384_functest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "sw/device/lib/crypto/impl/integrity.h"
77
#include "sw/device/lib/crypto/impl/keyblob.h"
88
#include "sw/device/lib/crypto/include/ecc_p384.h"
9+
#include "sw/device/lib/crypto/include/entropy_src.h"
910
#include "sw/device/lib/runtime/log.h"
10-
#include "sw/device/lib/testing/entropy_testutils.h"
1111
#include "sw/device/lib/testing/test_framework/check.h"
1212
#include "sw/device/lib/testing/test_framework/ottf_main.h"
1313

@@ -250,7 +250,7 @@ static status_t run_ecdh_negative_tests(void) {
250250
OTTF_DEFINE_TEST_CONFIG();
251251

252252
bool test_main(void) {
253-
CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
253+
CHECK_STATUS_OK(otcrypto_entropy_init());
254254

255255
status_t err = key_exchange_test();
256256
if (!status_ok(err)) {

sw/device/tests/crypto/ecdh_p384_sideload_functest.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "sw/device/lib/crypto/include/entropy_src.h"
1010
#include "sw/device/lib/crypto/include/key_transport.h"
1111
#include "sw/device/lib/runtime/log.h"
12-
#include "sw/device/lib/testing/entropy_testutils.h"
1312
#include "sw/device/lib/testing/keymgr_testutils.h"
1413
#include "sw/device/lib/testing/test_framework/check.h"
1514
#include "sw/device/lib/testing/test_framework/ottf_main.h"

0 commit comments

Comments
 (0)