@@ -449,6 +449,8 @@ static status_t csrng_send_app_cmd(uint32_t base_address,
449449 launder32 (cmd_type_used ) | kEntropyCsrngSendAppCmdTypeEdnRes ;
450450 break ;
451451 default :
452+ // COVERAGE (SW ERR) This is an internal function, the cmd_type given will
453+ // always be from these cases.
452454 return OTCRYPTO_BAD_ARGS ;
453455 }
454456 // Check if we landed in the correct case statement. Use ORs for this to
@@ -465,6 +467,7 @@ static status_t csrng_send_app_cmd(uint32_t base_address,
465467 } while (!ready && -- timeout );
466468
467469 if (timeout == 0 ) {
470+ // COVERAGE (HW ERR) The timeout should only happen with a HW error.
468471 return OTCRYPTO_RECOV_ERR ;
469472 }
470473 }
@@ -519,6 +522,7 @@ static status_t csrng_send_app_cmd(uint32_t base_address,
519522 } while (!ready && -- timeout );
520523
521524 if (timeout == 0 ) {
525+ // COVERAGE (HW ERR) The timeout should only happen with a HW error.
522526 return OTCRYPTO_RECOV_ERR ;
523527 }
524528 }
@@ -537,6 +541,7 @@ static status_t csrng_send_app_cmd(uint32_t base_address,
537541 -- timeout );
538542
539543 if (timeout == 0 ) {
544+ // COVERAGE (HW ERR) The timeout should only happen with a HW error.
540545 return OTCRYPTO_RECOV_ERR ;
541546 }
542547
@@ -552,12 +557,14 @@ static status_t csrng_send_app_cmd(uint32_t base_address,
552557 -- timeout );
553558
554559 if (timeout == 0 ) {
560+ // COVERAGE (HW ERR) The timeout should only happen with a HW error.
555561 return OTCRYPTO_RECOV_ERR ;
556562 }
557563
558- // Check the "status" bit, which will be 0 unless there was an error.
559564 reg = abs_mmio_read32 (kBaseCsrng + CSRNG_SW_CMD_STS_REG_OFFSET );
560565 if (bitfield_field32_read (reg , CSRNG_SW_CMD_STS_CMD_STS_FIELD )) {
566+ // COVERAGE (HW ERR) The status bit will be 0 unless there was a HW
567+ // error.
561568 return OTCRYPTO_RECOV_ERR ;
562569 }
563570 }
@@ -575,11 +582,13 @@ static status_t csrng_send_app_cmd(uint32_t base_address,
575582 -- timeout );
576583
577584 if (timeout == 0 ) {
585+ // COVERAGE (HW ERR) The timeout should only happen with a HW error.
578586 return OTCRYPTO_RECOV_ERR ;
579587 }
580588
581- // Check the "status" bit, which will be 0 unless there was an error.
582589 if (bitfield_field32_read (reg , CSRNG_SW_CMD_STS_CMD_STS_FIELD )) {
590+ // COVERAGE (HW ERR) The status bit will be 0 unless there was a HW
591+ // error.
583592 return OTCRYPTO_RECOV_ERR ;
584593 }
585594 }
@@ -655,10 +664,12 @@ static status_t edn_ready_block(uint32_t edn_address) {
655664 } while (!bitfield_bit32_read (reg , EDN_SW_CMD_STS_CMD_RDY_BIT ) && -- timeout );
656665
657666 if (timeout == 0 ) {
667+ // COVERAGE (HW ERR) The timeout should only happen with a HW error.
658668 return OTCRYPTO_RECOV_ERR ;
659669 }
660670
661671 if (bitfield_field32_read (reg , CSRNG_SW_CMD_STS_CMD_STS_FIELD )) {
672+ // COVERAGE (HW ERR) The status bit will be 0 unless there was a HW error.
662673 return OTCRYPTO_RECOV_ERR ;
663674 }
664675 return OTCRYPTO_OK ;
@@ -771,6 +782,7 @@ static status_t entropy_src_configure(const entropy_src_config_t *config) {
771782 if (config -> bypass_conditioner != kMultiBitBool4False ) {
772783 HARDENED_CHECK_NE (config -> bypass_conditioner , kMultiBitBool4False );
773784 // Bypassing the conditioner is not supported.
785+ // COVERAGE (SW ERR) The configs provided in the code do not support bypass.
774786 return OTCRYPTO_BAD_ARGS ;
775787 }
776788
@@ -870,6 +882,8 @@ static status_t entropy_src_configure(const entropy_src_config_t *config) {
870882 return OTCRYPTO_RECOV_ERR; \
871883 } \
872884 } while (false);
885+ // COVERAGE (HW ERR) This is only reached if the registers from the RNG were
886+ // faulted.
873887
874888/**
875889 * Check the entropy_src configuration.
@@ -888,13 +902,16 @@ static status_t entropy_src_check(const entropy_src_config_t *config) {
888902 config -> route_to_firmware != kMultiBitBool4False ) {
889903 // This check only supports FIPS-compatible configurations which do not
890904 // bypass the conditioner or route to firmware.
905+ // COVERAGE (SW ERR) This code does not support bypass.
891906 return OTCRYPTO_BAD_ARGS ;
892907 }
893908
894909 // Check that entropy_src is enabled.
895910 uint32_t reg =
896911 abs_mmio_read32 (kBaseEntropySrc + ENTROPY_SRC_MODULE_ENABLE_REG_OFFSET );
897912 if (reg != kMultiBitBool4True ) {
913+ // COVERAGE (HW ERR) This is only reached when the HW was not enabled before
914+ // the check.
898915 return OTCRYPTO_RECOV_ERR ;
899916 }
900917
@@ -912,6 +929,8 @@ static status_t entropy_src_check(const entropy_src_config_t *config) {
912929 bitfield_field32_read (reg , ENTROPY_SRC_CONF_RNG_BIT_ENABLE_FIELD );
913930 if (conf_fips_enable != kMultiBitBool4True ||
914931 conf_rng_bit_enable != kMultiBitBool4False ) {
932+ // COVERAGE (SW ERR) This is only reached when the RNG was not set in FIPS
933+ // mode, but we only support FIPS mode.
915934 return OTCRYPTO_RECOV_ERR ;
916935 }
917936 reg =
@@ -922,6 +941,8 @@ static status_t entropy_src_check(const entropy_src_config_t *config) {
922941 bitfield_field32_read (reg , ENTROPY_SRC_ENTROPY_CONTROL_ES_ROUTE_FIELD );
923942 if (control_es_type != kMultiBitBool4False ||
924943 control_es_route != kMultiBitBool4False ) {
944+ // COVERAGE (SW ERR) We only support configurations which set ES TYPE and
945+ // ROUTE to true.
925946 return OTCRYPTO_RECOV_ERR ;
926947 }
927948
@@ -931,6 +952,7 @@ static status_t entropy_src_check(const entropy_src_config_t *config) {
931952 if (bitfield_field32_read (
932953 reg , ENTROPY_SRC_HEALTH_TEST_WINDOWS_FIPS_WINDOW_FIELD ) !=
933954 config -> fips_test_window_size ) {
955+ // COVERAGE (SW ERR) We only support a single test window size.
934956 return OTCRYPTO_RECOV_ERR ;
935957 }
936958
@@ -943,6 +965,7 @@ static status_t entropy_src_check(const entropy_src_config_t *config) {
943965 ~(uint32_t )config -> alert_threshold );
944966 if (exp_reg != abs_mmio_read32 (kBaseEntropySrc +
945967 ENTROPY_SRC_ALERT_THRESHOLD_REG_OFFSET )) {
968+ // COVERAGE (SW ERR) We only support a single alert threshold.
946969 return OTCRYPTO_RECOV_ERR ;
947970 }
948971
@@ -1013,6 +1036,7 @@ status_t entropy_complex_init(hardened_bool_t fips) {
10131036 if (launder32 (config -> id ) != ((fips == kHardenedBoolFalse )
10141037 ? kEntropyComplexConfigIdContinuous
10151038 : kEntropyComplexConfigIdFipsContinuous )) {
1039+ // COVERAGE (SW ERR) We only support FIPS mode.
10161040 return OTCRYPTO_RECOV_ERR ;
10171041 }
10181042
@@ -1034,6 +1058,7 @@ status_t entropy_complex_check(hardened_bool_t fips) {
10341058 if (launder32 (config -> id ) != ((fips == kHardenedBoolFalse )
10351059 ? kEntropyComplexConfigIdContinuous
10361060 : kEntropyComplexConfigIdFipsContinuous )) {
1061+ // COVERAGE (SW ERR) We only support FIPS mode.
10371062 return OTCRYPTO_RECOV_ERR ;
10381063 }
10391064
@@ -1068,6 +1093,7 @@ status_t entropy_complex_health_test_config_check(hardened_bool_t fips) {
10681093 // Check recoverable alerts
10691094 if (abs_mmio_read32 (kBaseEntropySrc +
10701095 ENTROPY_SRC_RECOV_ALERT_STS_REG_OFFSET ) != 0 ) {
1096+ // COVERAGE (HW ERR) This is only reached when we detect a HW alert.
10711097 return OTCRYPTO_RECOV_ERR ;
10721098 }
10731099
@@ -1150,13 +1176,15 @@ status_t entropy_csrng_generate_data_get(uint32_t *buf, size_t len,
11501176 -- timeout );
11511177
11521178 if (timeout == 0 ) {
1179+ // COVERAGE (HW ERR) The timeout should only happen with a HW error.
11531180 return OTCRYPTO_RECOV_ERR ;
11541181 }
11551182
11561183 if (fips_check != kHardenedBoolFalse &&
11571184 !bitfield_bit32_read (reg , CSRNG_GENBITS_VLD_GENBITS_FIPS_BIT )) {
11581185 // Entropy isn't FIPS-compatible, so we should return an error when
11591186 // done. However, we still need to read the result to clear CSRNG's FIFO.
1187+ // COVERAGE (SW ERR) We only support FIPS mode.
11601188 res = OTCRYPTO_RECOV_ERR ;
11611189 }
11621190
0 commit comments