mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-07 06:59:19 +01:00
Combine hex parameters in a struct
This commit is contained in:
parent
5cfc06832e
commit
d30ca130e8
36 changed files with 756 additions and 1014 deletions
|
|
@ -161,12 +161,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hmac_drbg_no_reseed( int md_alg, uint8_t * entropy,
|
||||
uint32_t entropy_len, uint8_t * custom,
|
||||
uint32_t custom_len, uint8_t * add1,
|
||||
uint32_t add1_len, uint8_t * add2,
|
||||
uint32_t add2_len, uint8_t * output,
|
||||
uint32_t out_len )
|
||||
void hmac_drbg_no_reseed( int md_alg, HexParam_t * entropy,
|
||||
HexParam_t * custom, HexParam_t * add1,
|
||||
HexParam_t * add2, HexParam_t * output )
|
||||
{
|
||||
unsigned char data[1024];
|
||||
unsigned char my_output[512];
|
||||
|
|
@ -176,35 +173,35 @@ void hmac_drbg_no_reseed( int md_alg, uint8_t * entropy,
|
|||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
|
||||
p_entropy.p = entropy;
|
||||
p_entropy.len = entropy_len;
|
||||
p_entropy.p = entropy->x;
|
||||
p_entropy.len = entropy->len;
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
/* Test the simplified buffer-based variant */
|
||||
memcpy( data, entropy, p_entropy.len );
|
||||
memcpy( data + p_entropy.len, custom, custom_len );
|
||||
memcpy( data, entropy->x, p_entropy.len );
|
||||
memcpy( data + p_entropy.len, custom->x, custom->len );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_seed_buf( &ctx, md_info,
|
||||
data, p_entropy.len + custom_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add1, add1_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add2, add2_len ) == 0 );
|
||||
data, p_entropy.len + custom->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add1->x, add1->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add2->x, add2->len ) == 0 );
|
||||
|
||||
/* clear for second run */
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
||||
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||
TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
|
||||
|
||||
/* And now the normal entropy-based variant */
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
|
||||
custom, custom_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add1, add1_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add2, add2_len ) == 0 );
|
||||
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||
custom->x, custom->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add1->x, add1->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add2->x, add2->len ) == 0 );
|
||||
TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
|
@ -212,11 +209,9 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hmac_drbg_nopr( int md_alg, uint8_t * entropy, uint32_t entropy_len,
|
||||
uint8_t * custom, uint32_t custom_len, uint8_t * add1,
|
||||
uint32_t add1_len, uint8_t * add2, uint32_t add2_len,
|
||||
uint8_t * add3, uint32_t add3_len, uint8_t * output,
|
||||
uint32_t out_len )
|
||||
void hmac_drbg_nopr( int md_alg, HexParam_t * entropy, HexParam_t * custom,
|
||||
HexParam_t * add1, HexParam_t * add2, HexParam_t * add3,
|
||||
HexParam_t * output )
|
||||
{
|
||||
unsigned char my_output[512];
|
||||
entropy_ctx p_entropy;
|
||||
|
|
@ -225,21 +220,21 @@ void hmac_drbg_nopr( int md_alg, uint8_t * entropy, uint32_t entropy_len,
|
|||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
|
||||
p_entropy.p = entropy;
|
||||
p_entropy.len = entropy_len;
|
||||
p_entropy.p = entropy->x;
|
||||
p_entropy.len = entropy->len;
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
|
||||
custom, custom_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_reseed( &ctx, add1, add1_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add2, add2_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add3, add3_len ) == 0 );
|
||||
custom->x, custom->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_reseed( &ctx, add1->x, add1->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add2->x, add2->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add3->x, add3->len ) == 0 );
|
||||
|
||||
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||
TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
|
@ -247,10 +242,8 @@ exit:
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void hmac_drbg_pr( int md_alg, uint8_t * entropy, uint32_t entropy_len,
|
||||
uint8_t * custom, uint32_t custom_len, uint8_t * add1,
|
||||
uint32_t add1_len, uint8_t * add2, uint32_t add2_len,
|
||||
uint8_t * output, uint32_t out_len )
|
||||
void hmac_drbg_pr( int md_alg, HexParam_t * entropy, HexParam_t * custom,
|
||||
HexParam_t * add1, HexParam_t * add2, HexParam_t * output )
|
||||
{
|
||||
unsigned char my_output[512];
|
||||
entropy_ctx p_entropy;
|
||||
|
|
@ -259,21 +252,21 @@ void hmac_drbg_pr( int md_alg, uint8_t * entropy, uint32_t entropy_len,
|
|||
|
||||
mbedtls_hmac_drbg_init( &ctx );
|
||||
|
||||
p_entropy.p = entropy;
|
||||
p_entropy.len = entropy_len;
|
||||
p_entropy.p = entropy->x;
|
||||
p_entropy.len = entropy->len;
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_entropy_func, &p_entropy,
|
||||
custom, custom_len ) == 0 );
|
||||
custom->x, custom->len ) == 0 );
|
||||
mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add1, add1_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, out_len,
|
||||
add2, add2_len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add1->x, add1->len ) == 0 );
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_random_with_add( &ctx, my_output, output->len,
|
||||
add2->x, add2->len ) == 0 );
|
||||
|
||||
TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
|
||||
TEST_ASSERT( memcmp( my_output, output->x, output->len ) == 0 );
|
||||
|
||||
exit:
|
||||
mbedtls_hmac_drbg_free( &ctx );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue