@@ -337,41 +337,32 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
337
337
size_t seedlen = 0 ;
338
338
int ret ;
339
339
340
- if ( ctx -> entropy_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ||
341
- len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx -> entropy_len )
340
+ if ( ctx -> entropy_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT )
341
+ return ( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
342
+ if ( len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx -> entropy_len )
342
343
return ( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
343
344
344
345
memset ( seed , 0 , MBEDTLS_CTR_DRBG_MAX_SEED_INPUT );
345
346
346
- /*
347
- * Gather entropy_len bytes of entropy to seed state
348
- */
349
- if ( 0 != ctx -> f_entropy ( ctx -> p_entropy , seed ,
350
- ctx -> entropy_len ) )
347
+ /* Gather entropy_len bytes of entropy to seed state. */
348
+ if ( 0 != ctx -> f_entropy ( ctx -> p_entropy , seed , ctx -> entropy_len ) )
351
349
{
352
350
return ( MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED );
353
351
}
354
-
355
352
seedlen += ctx -> entropy_len ;
356
353
357
- /*
358
- * Add additional data
359
- */
360
- if ( additional && len )
354
+ /* Add additional data if provided. */
355
+ if ( additional != NULL && len != 0 )
361
356
{
362
357
memcpy ( seed + seedlen , additional , len );
363
358
seedlen += len ;
364
359
}
365
360
366
- /*
367
- * Reduce to 384 bits
368
- */
361
+ /* Reduce to 384 bits. */
369
362
if ( ( ret = block_cipher_df ( seed , seed , seedlen ) ) != 0 )
370
363
goto exit ;
371
364
372
- /*
373
- * Update state
374
- */
365
+ /* Update state. */
375
366
if ( ( ret = ctr_drbg_update_internal ( ctx , seed ) ) != 0 )
376
367
goto exit ;
377
368
ctx -> reseed_counter = 1 ;
0 commit comments