mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 11:04:24 +01:00
- Added internal ctr_drbg_init_entropy_len() to allow NIST determined entropy tests to work
This commit is contained in:
parent
bd4a9d0cda
commit
18d32911c0
@ -38,11 +38,17 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int ctr_drbg_init( ctr_drbg_context *ctx,
|
/*
|
||||||
|
* Non-public function wrapped by ctr_crbg_init(). Necessary to allow NIST
|
||||||
|
* tests to succeed (which require known length fixed entropy)
|
||||||
|
*/
|
||||||
|
int ctr_drbg_init_entropy_len(
|
||||||
|
ctr_drbg_context *ctx,
|
||||||
int (*f_entropy)(void *, unsigned char *, size_t),
|
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||||
void *p_entropy,
|
void *p_entropy,
|
||||||
const unsigned char *custom,
|
const unsigned char *custom,
|
||||||
size_t len )
|
size_t len,
|
||||||
|
size_t entropy_len )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned char key[CTR_DRBG_KEYSIZE];
|
unsigned char key[CTR_DRBG_KEYSIZE];
|
||||||
@ -53,7 +59,7 @@ int ctr_drbg_init( ctr_drbg_context *ctx,
|
|||||||
ctx->f_entropy = f_entropy;
|
ctx->f_entropy = f_entropy;
|
||||||
ctx->p_entropy = p_entropy;
|
ctx->p_entropy = p_entropy;
|
||||||
|
|
||||||
ctx->entropy_len = CTR_DRBG_ENTROPY_LEN;
|
ctx->entropy_len = entropy_len;
|
||||||
ctx->reseed_interval = CTR_DRBG_RESEED_INTERVAL;
|
ctx->reseed_interval = CTR_DRBG_RESEED_INTERVAL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -67,6 +73,16 @@ int ctr_drbg_init( ctr_drbg_context *ctx,
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ctr_drbg_init( ctr_drbg_context *ctx,
|
||||||
|
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||||
|
void *p_entropy,
|
||||||
|
const unsigned char *custom,
|
||||||
|
size_t len )
|
||||||
|
{
|
||||||
|
return( ctr_drbg_init_entropy_len( ctx, f_entropy, p_entropy, custom, len,
|
||||||
|
CTR_DRBG_ENTROPY_LEN ) );
|
||||||
|
}
|
||||||
|
|
||||||
void ctr_drbg_set_prediction_resistance( ctr_drbg_context *ctx, int resistance )
|
void ctr_drbg_set_prediction_resistance( ctr_drbg_context *ctx, int resistance )
|
||||||
{
|
{
|
||||||
ctx->prediction_resistance = resistance;
|
ctx->prediction_resistance = resistance;
|
||||||
|
@ -8,6 +8,14 @@ int entropy_func( void *p, unsigned char *buf, size_t len )
|
|||||||
test_offset += 32;
|
test_offset += 32;
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ctr_drbg_init_entropy_len(
|
||||||
|
ctr_drbg_context *ctx,
|
||||||
|
int (*f_entropy)(void *, unsigned char *, size_t),
|
||||||
|
void *p_entropy,
|
||||||
|
const unsigned char *custom,
|
||||||
|
size_t len,
|
||||||
|
size_t entropy_len );
|
||||||
END_HEADER
|
END_HEADER
|
||||||
|
|
||||||
BEGIN_DEPENDENCIES
|
BEGIN_DEPENDENCIES
|
||||||
@ -34,7 +42,7 @@ ctr_drbg_validate_pr:add_init_string:entropy_string:add1_string:add2_string:resu
|
|||||||
add2_len = unhexify( add2, {add2_string} );
|
add2_len = unhexify( add2, {add2_string} );
|
||||||
|
|
||||||
test_offset = 0;
|
test_offset = 0;
|
||||||
TEST_ASSERT( ctr_drbg_init( &ctx, entropy_func, entropy, add_init, add_init_len ) == 0 );
|
TEST_ASSERT( ctr_drbg_init_entropy_len( &ctx, entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
|
||||||
ctr_drbg_set_prediction_resistance( &ctx, CTR_DRBG_PR_ON );
|
ctr_drbg_set_prediction_resistance( &ctx, CTR_DRBG_PR_ON );
|
||||||
|
|
||||||
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
|
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
|
||||||
@ -66,7 +74,7 @@ ctr_drbg_validate_nopr:add_init_string:entropy_string:add1_string:add_reseed_str
|
|||||||
add2_len = unhexify( add2, {add2_string} );
|
add2_len = unhexify( add2, {add2_string} );
|
||||||
|
|
||||||
test_offset = 0;
|
test_offset = 0;
|
||||||
TEST_ASSERT( ctr_drbg_init( &ctx, entropy_func, entropy, add_init, add_init_len ) == 0 );
|
TEST_ASSERT( ctr_drbg_init_entropy_len( &ctx, entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
|
||||||
|
|
||||||
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
|
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
|
||||||
TEST_ASSERT( ctr_drbg_reseed( &ctx, add_reseed, add_reseed_len ) == 0 );
|
TEST_ASSERT( ctr_drbg_reseed( &ctx, add_reseed, add_reseed_len ) == 0 );
|
||||||
|
Loading…
Reference in New Issue
Block a user