From 0ed378aa02c22fdeba0113d7cd736777c0d4ebf6 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 22 Oct 2019 20:33:56 +0200 Subject: [PATCH] CTR_DRBG: explicitly set entropy_nonce_len=0 when desired No behavior change. Prepare for a future version that will set the entropy nonce length to a nonzero value by default. --- library/ctr_drbg.c | 2 ++ tests/suites/test_suite_ctr_drbg.function | 1 + 2 files changed, 3 insertions(+) diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c index 8a62f6d46..8c6ee59d5 100644 --- a/library/ctr_drbg.c +++ b/library/ctr_drbg.c @@ -732,6 +732,7 @@ int mbedtls_ctr_drbg_self_test( int verbose ) test_offset = 0; mbedtls_ctr_drbg_set_entropy_len( &ctx, 32 ); + mbedtls_ctr_drbg_set_nonce_len( &ctx, 0 ); CHK( mbedtls_ctr_drbg_seed( &ctx, ctr_drbg_self_test_entropy, (void *) entropy_source_pr, @@ -756,6 +757,7 @@ int mbedtls_ctr_drbg_self_test( int verbose ) test_offset = 0; mbedtls_ctr_drbg_set_entropy_len( &ctx, 32 ); + mbedtls_ctr_drbg_set_nonce_len( &ctx, 0 ); CHK( mbedtls_ctr_drbg_seed( &ctx, ctr_drbg_self_test_entropy, (void *) entropy_source_nopr, diff --git a/tests/suites/test_suite_ctr_drbg.function b/tests/suites/test_suite_ctr_drbg.function index 02f9eca5e..c79b6e2aa 100644 --- a/tests/suites/test_suite_ctr_drbg.function +++ b/tests/suites/test_suite_ctr_drbg.function @@ -45,6 +45,7 @@ static void ctr_drbg_validate_internal( int reseed_mode, data_t * nonce, /* CTR_DRBG_Instantiate(entropy[:entropy->len], nonce, perso, ) * where nonce||perso = nonce[nonce->len] */ mbedtls_ctr_drbg_set_entropy_len( &ctx, entropy_chunk_len ); + mbedtls_ctr_drbg_set_nonce_len( &ctx, 0 ); TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx, mbedtls_test_entropy_func, entropy->x,