@@ -381,10 +381,6 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
381
381
return ( ret );
382
382
}
383
383
384
- /*
385
- * Non-public function wrapped by mbedtls_ctr_drbg_seed(). Necessary to allow
386
- * NIST tests to succeed (which require known length fixed entropy)
387
- */
388
384
/* CTR_DRBG_Instantiate with derivation function (SP 800-90A §10.2.1.3.2)
389
385
* mbedtls_ctr_drbg_seed_entropy_len(ctx, f_entropy, p_entropy,
390
386
* custom, len, entropy_len)
@@ -397,13 +393,11 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
397
393
* and with outputs
398
394
* ctx = initial_working_state
399
395
*/
400
- int mbedtls_ctr_drbg_seed_entropy_len (
401
- mbedtls_ctr_drbg_context * ctx ,
402
- int (* f_entropy )(void * , unsigned char * , size_t ),
403
- void * p_entropy ,
404
- const unsigned char * custom ,
405
- size_t len ,
406
- size_t entropy_len )
396
+ int mbedtls_ctr_drbg_seed ( mbedtls_ctr_drbg_context * ctx ,
397
+ int (* f_entropy )(void * , unsigned char * , size_t ),
398
+ void * p_entropy ,
399
+ const unsigned char * custom ,
400
+ size_t len )
407
401
{
408
402
int ret ;
409
403
unsigned char key [MBEDTLS_CTR_DRBG_KEYSIZE ];
@@ -415,7 +409,8 @@ int mbedtls_ctr_drbg_seed_entropy_len(
415
409
ctx -> f_entropy = f_entropy ;
416
410
ctx -> p_entropy = p_entropy ;
417
411
418
- ctx -> entropy_len = entropy_len ;
412
+ if ( ctx -> entropy_len == 0 )
413
+ ctx -> entropy_len = MBEDTLS_CTR_DRBG_ENTROPY_LEN ;
419
414
ctx -> reseed_interval = MBEDTLS_CTR_DRBG_RESEED_INTERVAL ;
420
415
421
416
/*
@@ -434,17 +429,6 @@ int mbedtls_ctr_drbg_seed_entropy_len(
434
429
return ( 0 );
435
430
}
436
431
437
- int mbedtls_ctr_drbg_seed ( mbedtls_ctr_drbg_context * ctx ,
438
- int (* f_entropy )(void * , unsigned char * , size_t ),
439
- void * p_entropy ,
440
- const unsigned char * custom ,
441
- size_t len )
442
- {
443
- return ( mbedtls_ctr_drbg_seed_entropy_len ( ctx , f_entropy , p_entropy ,
444
- custom , len ,
445
- MBEDTLS_CTR_DRBG_ENTROPY_LEN ) );
446
- }
447
-
448
432
/* CTR_DRBG_Generate with derivation function (SP 800-90A §10.2.1.5.2)
449
433
* mbedtls_ctr_drbg_random_with_add(ctx, output, output_len, additional, add_len)
450
434
* implements
@@ -708,8 +692,11 @@ int mbedtls_ctr_drbg_self_test( int verbose )
708
692
mbedtls_printf ( " CTR_DRBG (PR = TRUE) : " );
709
693
710
694
test_offset = 0 ;
711
- CHK ( mbedtls_ctr_drbg_seed_entropy_len ( & ctx , ctr_drbg_self_test_entropy ,
712
- (void * ) entropy_source_pr , nonce_pers_pr , 16 , 32 ) );
695
+ mbedtls_ctr_drbg_set_entropy_len ( & ctx , 32 );
696
+ CHK ( mbedtls_ctr_drbg_seed ( & ctx ,
697
+ ctr_drbg_self_test_entropy ,
698
+ (void * ) entropy_source_pr ,
699
+ nonce_pers_pr , 16 ) );
713
700
mbedtls_ctr_drbg_set_prediction_resistance ( & ctx , MBEDTLS_CTR_DRBG_PR_ON );
714
701
CHK ( mbedtls_ctr_drbg_random ( & ctx , buf , MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
715
702
CHK ( mbedtls_ctr_drbg_random ( & ctx , buf , MBEDTLS_CTR_DRBG_BLOCKSIZE ) );
@@ -729,8 +716,11 @@ int mbedtls_ctr_drbg_self_test( int verbose )
729
716
mbedtls_ctr_drbg_init ( & ctx );
730
717
731
718
test_offset = 0 ;
732
- CHK ( mbedtls_ctr_drbg_seed_entropy_len ( & ctx , ctr_drbg_self_test_entropy ,
733
- (void * ) entropy_source_nopr , nonce_pers_nopr , 16 , 32 ) );
719
+ mbedtls_ctr_drbg_set_entropy_len ( & ctx , 32 );
720
+ CHK ( mbedtls_ctr_drbg_seed ( & ctx ,
721
+ ctr_drbg_self_test_entropy ,
722
+ (void * ) entropy_source_nopr ,
723
+ nonce_pers_nopr , 16 ) );
734
724
CHK ( mbedtls_ctr_drbg_random ( & ctx , buf , 16 ) );
735
725
CHK ( mbedtls_ctr_drbg_reseed ( & ctx , NULL , 0 ) );
736
726
CHK ( mbedtls_ctr_drbg_random ( & ctx , buf , 16 ) );
0 commit comments