@@ -251,18 +251,26 @@ exit:
251
251
}
252
252
/* END_CASE */
253
253
254
- /* BEGIN_CASE depends_on:ENTROPY_HAVE_STRONG */
254
+ /* BEGIN_CASE */
255
255
void entropy_threshold( int threshold, int chunk_size, int result )
256
256
{
257
257
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};
259
261
unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
260
262
int ret;
261
263
262
264
mbedtls_entropy_init( &ctx );
265
+ entropy_clear_sources( &ctx );
263
266
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 );
264
272
TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
265
- &dummy , threshold,
273
+ &weak , threshold,
266
274
MBEDTLS_ENTROPY_SOURCE_WEAK ) == 0 );
267
275
268
276
ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) );
@@ -275,7 +283,7 @@ void entropy_threshold( int threshold, int chunk_size, int result )
275
283
* updates: before and after updating the NV seed. */
276
284
result *= 2;
277
285
#endif
278
- TEST_ASSERT( dummy .calls == (size_t) result );
286
+ TEST_ASSERT( weak .calls == (size_t) result );
279
287
}
280
288
else
281
289
{
0 commit comments