Skip to content

Commit cbd91e0

Browse files
Fix entropy_threshold when MBEDTLS_TEST_NULL_ENTROPY is enabled
Don't use the default entropy sources so as not to depend on their characteristics.
1 parent ae67939 commit cbd91e0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/suites/test_suite_entropy.function

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,26 @@ exit:
251251
}
252252
/* END_CASE */
253253

254-
/* BEGIN_CASE depends_on:ENTROPY_HAVE_STRONG */
254+
/* BEGIN_CASE */
255255
void entropy_threshold( int threshold, int chunk_size, int result )
256256
{
257257
mbedtls_entropy_context ctx;
258-
entropy_dummy_context dummy = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
258+
entropy_dummy_context strong =
259+
{DUMMY_CONSTANT_LENGTH, MBEDTLS_ENTROPY_BLOCK_SIZE, 0};
260+
entropy_dummy_context weak = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
259261
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
260262
int ret;
261263

262264
mbedtls_entropy_init( &ctx );
265+
entropy_clear_sources( &ctx );
263266

267+
/* Set strong source that reaches its threshold immediately and
268+
* a weak source whose threshold is a test parameter. */
269+
TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
270+
&strong, 1,
271+
MBEDTLS_ENTROPY_SOURCE_STRONG ) == 0 );
264272
TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
265-
&dummy, threshold,
273+
&weak, threshold,
266274
MBEDTLS_ENTROPY_SOURCE_WEAK ) == 0 );
267275

268276
ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) );
@@ -275,7 +283,7 @@ void entropy_threshold( int threshold, int chunk_size, int result )
275283
* updates: before and after updating the NV seed. */
276284
result *= 2;
277285
#endif
278-
TEST_ASSERT( dummy.calls == (size_t) result );
286+
TEST_ASSERT( weak.calls == (size_t) result );
279287
}
280288
else
281289
{

0 commit comments

Comments
 (0)