mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 20:48:19 +00:00
Add tests for th init_buf() variant of HMAC_DRBG
This commit is contained in:
parent
cf38367f45
commit
e6cdbbd40b
1 changed files with 17 additions and 0 deletions
|
@ -153,6 +153,7 @@ void hmac_drbg_no_reseed( int md_alg,
|
||||||
char *add1_hex, char *add2_hex,
|
char *add1_hex, char *add2_hex,
|
||||||
char *output_hex )
|
char *output_hex )
|
||||||
{
|
{
|
||||||
|
unsigned char data[1024];
|
||||||
unsigned char entropy[512];
|
unsigned char entropy[512];
|
||||||
unsigned char custom[512];
|
unsigned char custom[512];
|
||||||
unsigned char add1[512];
|
unsigned char add1[512];
|
||||||
|
@ -174,6 +175,21 @@ void hmac_drbg_no_reseed( int md_alg,
|
||||||
p_entropy.p = entropy;
|
p_entropy.p = entropy;
|
||||||
|
|
||||||
TEST_ASSERT( ( md_info = md_info_from_type( md_alg ) ) != NULL );
|
TEST_ASSERT( ( md_info = md_info_from_type( md_alg ) ) != NULL );
|
||||||
|
|
||||||
|
/* Test the simplified buffer-based variant */
|
||||||
|
memcpy( data, entropy, p_entropy.len );
|
||||||
|
memcpy( data + p_entropy.len, custom, custom_len );
|
||||||
|
TEST_ASSERT( hmac_drbg_init_buf( &ctx, md_info,
|
||||||
|
data, p_entropy.len + custom_len ) == 0 );
|
||||||
|
TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||||
|
add1, add1_len ) == 0 );
|
||||||
|
TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||||
|
add2, add2_len ) == 0 );
|
||||||
|
hmac_drbg_free( &ctx );
|
||||||
|
|
||||||
|
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||||
|
|
||||||
|
/* And now the normal entropy-based variant */
|
||||||
TEST_ASSERT( hmac_drbg_init( &ctx, md_info, entropy_func, &p_entropy,
|
TEST_ASSERT( hmac_drbg_init( &ctx, md_info, entropy_func, &p_entropy,
|
||||||
custom, custom_len ) == 0 );
|
custom, custom_len ) == 0 );
|
||||||
TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||||
|
@ -183,6 +199,7 @@ void hmac_drbg_no_reseed( int md_alg,
|
||||||
hmac_drbg_free( &ctx );
|
hmac_drbg_free( &ctx );
|
||||||
|
|
||||||
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue