Add re-seeding option to test

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
Paul Elliott 2023-11-21 17:07:40 +00:00
parent 20b2efa293
commit bda25dd29c
2 changed files with 23 additions and 14 deletions

View file

@ -1097,10 +1097,10 @@ CTR_DRBG Special Behaviours
ctr_drbg_special_behaviours:
CTR_DRBG Threads: no reseed
ctr_drbg_threads:"1fafa98bc83d95e10f2d5ed339a553e1":10000
ctr_drbg_threads:"1fafa98bc83d95e10f2d5ed339a553e1":0
CTR_DRBG Threads: reseed
ctr_drbg_threads:"0d2dda60286dc738ddcc2dd3520bb988":25
ctr_drbg_threads:"B10A961F2EA39927B4C48AEDDD299026":1
CTR_DRBG self test
ctr_drbg_selftest:

View file

@ -343,29 +343,37 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_THREADING_PTHREAD */
void ctr_drbg_threads(data_t *expected_result, int reseed_interval)
void ctr_drbg_threads(data_t *expected_result, int reseed)
{
#define THREAD_CNT 5
pthread_t threads[THREAD_CNT];
unsigned char out[16];
unsigned char *entropy = NULL;
const size_t n_random_calls = THREAD_CNT * thread_random_reps + 1;
memset(out, 0, sizeof(out));
unsigned char entropy[1024];
memset(entropy, 0, sizeof(entropy));
test_offset_idx = 0;
test_max_idx = sizeof(entropy);
mbedtls_ctr_drbg_context ctx;
mbedtls_ctr_drbg_init(&ctx);
mbedtls_ctr_drbg_set_reseed_interval(&ctx, reseed_interval);
test_offset_idx = 0;
/* There are too many calls in this test to conveniently provide enough
* entropy for this to be on. Test cases can trigger reseeding by setting
* \p reseed_interval appropriately. */
mbedtls_ctr_drbg_set_prediction_resistance(&ctx, MBEDTLS_CTR_DRBG_PR_OFF);
if (reseed == 0) {
mbedtls_ctr_drbg_set_prediction_resistance(&ctx, MBEDTLS_CTR_DRBG_PR_OFF);
mbedtls_ctr_drbg_set_reseed_interval(&ctx, n_random_calls + 1);
TEST_CALLOC(entropy, MBEDTLS_CTR_DRBG_ENTROPY_LEN);
test_max_idx = MBEDTLS_CTR_DRBG_ENTROPY_LEN;
} else {
const size_t entropy_size = (n_random_calls + 1) * MBEDTLS_CTR_DRBG_ENTROPY_LEN;
mbedtls_ctr_drbg_set_prediction_resistance(&ctx, MBEDTLS_CTR_DRBG_PR_ON);
TEST_CALLOC(entropy, entropy_size);
test_max_idx = entropy_size;
}
TEST_EQUAL(
mbedtls_ctr_drbg_seed(&ctx, mbedtls_test_entropy_func, entropy, NULL, 0),
@ -389,6 +397,7 @@ void ctr_drbg_threads(data_t *expected_result, int reseed_interval)
exit:
mbedtls_ctr_drbg_free(&ctx);
mbedtls_free(entropy);
}
#undef THREAD_CNT
/* END_CASE */