Skip to content

Commit dbd3f7c

Browse files
mbedtls_ctr_drbg_reseed: Minor readability improvement
No semantic change.
1 parent c0ace35 commit dbd3f7c

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

library/ctr_drbg.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,41 +337,32 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
337337
size_t seedlen = 0;
338338
int ret;
339339

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 )
342343
return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
343344

344345
memset( seed, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT );
345346

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 ) )
351349
{
352350
return( MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED );
353351
}
354-
355352
seedlen += ctx->entropy_len;
356353

357-
/*
358-
* Add additional data
359-
*/
360-
if( additional && len )
354+
/* Add additional data if provided. */
355+
if( additional != NULL && len != 0 )
361356
{
362357
memcpy( seed + seedlen, additional, len );
363358
seedlen += len;
364359
}
365360

366-
/*
367-
* Reduce to 384 bits
368-
*/
361+
/* Reduce to 384 bits. */
369362
if( ( ret = block_cipher_df( seed, seed, seedlen ) ) != 0 )
370363
goto exit;
371364

372-
/*
373-
* Update state
374-
*/
365+
/* Update state. */
375366
if( ( ret = ctr_drbg_update_internal( ctx, seed ) ) != 0 )
376367
goto exit;
377368
ctx->reseed_counter = 1;

0 commit comments

Comments
 (0)