mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
Merge branch 'fix/s31_nist_rng_error' into 'master'
RNG: initialize TRNG NIST path and complete RNG registers for ESP32-S31 Closes IDF-16088 See merge request espressif/esp-idf!51931
This commit is contained in:
@@ -464,10 +464,7 @@ TEST_GROUP_RUNNER(ecdsa)
|
||||
{
|
||||
/* SECP192R1 test cases */
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP192R1_signature_verification)
|
||||
#if !CONFIG_IDF_TARGET_ESP32S31
|
||||
// TODO: IDF-15703 re-enable TRNG-backed sign_and_verify on esp32s31 once the TRNG support update lands
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP192R1_sign_and_verify)
|
||||
#endif
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP192R1_corrupt_signature)
|
||||
#ifdef SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP192R1_det_sign_and_verify)
|
||||
@@ -478,10 +475,7 @@ TEST_GROUP_RUNNER(ecdsa)
|
||||
|
||||
/* SECP256R1 test cases */
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP256R1_signature_verification)
|
||||
#if !CONFIG_IDF_TARGET_ESP32S31
|
||||
// TODO: IDF-15703 re-enable TRNG-backed sign_and_verify on esp32s31 once the TRNG support update lands
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP256R1_sign_and_verify)
|
||||
#endif
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP256R1_corrupt_signature)
|
||||
#ifdef SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP256R1_det_sign_and_verify)
|
||||
@@ -493,10 +487,7 @@ TEST_GROUP_RUNNER(ecdsa)
|
||||
/* SECP384R1 test cases */
|
||||
#ifdef SOC_ECDSA_SUPPORT_CURVE_P384
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP384R1_signature_verification)
|
||||
#if !CONFIG_IDF_TARGET_ESP32S31
|
||||
// TODO: IDF-15703 re-enable TRNG-backed sign_and_verify on esp32s31 once the TRNG support update lands
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP384R1_sign_and_verify)
|
||||
#endif
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP384R1_corrupt_signature)
|
||||
#ifdef SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE
|
||||
RUN_TEST_CASE(ecdsa, ecdsa_SECP384R1_det_sign_and_verify)
|
||||
|
||||
@@ -69,6 +69,92 @@ static inline void rng_ll_enable_noise_crc(bool enable)
|
||||
LP_TRNG.conf.noise_crc_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Select the noise source for TRNG health tests
|
||||
*
|
||||
* @param source One-hot noise source selection
|
||||
*/
|
||||
static inline void rng_ll_set_noise_source(uint32_t source)
|
||||
{
|
||||
REG_SET_FIELD(TRNG_CONF_REG, TRNG_NOISE_SOURCE_SEL, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Select the sampling-enable signal for TRNG health tests
|
||||
*
|
||||
* @param position One-hot sampling-enable selection
|
||||
*/
|
||||
static inline void rng_ll_set_noise_position(uint32_t position)
|
||||
{
|
||||
REG_SET_FIELD(TRNG_CONF_REG, TRNG_NOISE_POS_SEL, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure repetition and adaptive proportion health-test thresholds
|
||||
*
|
||||
* @param repetition_cutoff Repetition count test cutoff
|
||||
* @param adaptive_cutoff Adaptive proportion test cutoff
|
||||
*/
|
||||
static inline void rng_ll_set_health_test_thresholds(uint32_t repetition_cutoff, uint32_t adaptive_cutoff)
|
||||
{
|
||||
REG_SET_FIELD(TRNG_CONF_REG, TRNG_REPETITION_VALUE_C, repetition_cutoff);
|
||||
REG_SET_FIELD(TRNG_CONF_REG, TRNG_ADPATIVE_VALUE_C, adaptive_cutoff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the number of samples processed by the startup health test
|
||||
*
|
||||
* @param sample_limit Number of startup test samples
|
||||
*/
|
||||
static inline void rng_ll_set_startup_test_limit(uint32_t sample_limit)
|
||||
{
|
||||
REG_SET_FIELD(TRNG_DEBUG_CONF_REG, TRNG_STARTUP_TEST_LIMIT, sample_limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable standard 256-bit TRNG output mode
|
||||
*
|
||||
* @param enable true to enable standard output mode, false otherwise
|
||||
*/
|
||||
static inline void rng_ll_enable_random_output_mode(bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
REG_SET_BIT(TRNG_CONF_REG, TRNG_RANDOM_OUTPUT_MODE);
|
||||
} else {
|
||||
REG_CLR_BIT(TRNG_CONF_REG, TRNG_RANDOM_OUTPUT_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or bypass TRNG health tests
|
||||
*
|
||||
* @param enable true to enable health tests, false to bypass them
|
||||
*/
|
||||
static inline void rng_ll_enable_health_test(bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
REG_CLR_BIT(TRNG_DEBUG_CONF_REG, TRNG_HEALTH_TEST_BYPASS);
|
||||
} else {
|
||||
REG_SET_BIT(TRNG_DEBUG_CONF_REG, TRNG_HEALTH_TEST_BYPASS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start the TRNG startup health test
|
||||
*/
|
||||
static inline void rng_ll_start_startup_test(void)
|
||||
{
|
||||
REG_SET_BIT(TRNG_DEBUG_CONF_REG, TRNG_STARTUP_TEST_START);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop TRNG health tests
|
||||
*/
|
||||
static inline void rng_ll_stop_health_test(void)
|
||||
{
|
||||
REG_SET_BIT(TRNG_DEBUG_CONF_REG, TRNG_HEALTH_TEST_END);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable RNG module
|
||||
*
|
||||
@@ -79,8 +165,16 @@ static inline void rng_ll_enable(void)
|
||||
rng_ll_enable_bus_clock(true);
|
||||
rng_ll_enable_clock(true);
|
||||
rng_ll_reset();
|
||||
rng_ll_enable_sample(true);
|
||||
|
||||
rng_ll_set_noise_source(BIT(4));
|
||||
rng_ll_set_noise_position(BIT(4));
|
||||
rng_ll_set_health_test_thresholds(0x1f, 0x12);
|
||||
rng_ll_set_startup_test_limit(1024);
|
||||
rng_ll_enable_health_test(true);
|
||||
rng_ll_enable_random_output_mode(true);
|
||||
rng_ll_enable_noise_crc(true);
|
||||
rng_ll_enable_sample(true);
|
||||
rng_ll_start_startup_test();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,6 +184,8 @@ static inline void rng_ll_enable(void)
|
||||
*/
|
||||
static inline void rng_ll_disable(void)
|
||||
{
|
||||
rng_ll_stop_health_test();
|
||||
rng_ll_enable_random_output_mode(false);
|
||||
rng_ll_enable_noise_crc(false);
|
||||
rng_ll_enable_sample(false);
|
||||
rng_ll_enable_clock(false);
|
||||
|
||||
Reference in New Issue
Block a user