mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 19:55:37 +00:00
79 lines
2.6 KiB
Plaintext
79 lines
2.6 KiB
Plaintext
BEGIN_HEADER
|
|
#include <polarssl/ctr_drbg.h>
|
|
|
|
int test_offset;
|
|
int entropy_func( void *data, unsigned char *buf, size_t len )
|
|
{
|
|
unsigned char *p = (unsigned char *) data;
|
|
memcpy( buf, p + test_offset, len );
|
|
test_offset += 32;
|
|
return( 0 );
|
|
}
|
|
END_HEADER
|
|
|
|
BEGIN_DEPENDENCIES
|
|
depends_on:POLARSSL_CTR_DRBG_C
|
|
END_DEPENDENCIES
|
|
|
|
BEGIN_CASE
|
|
ctr_drbg_validate_pr:add_init_string:entropy_string:add1_string:add2_string:result_str
|
|
{
|
|
unsigned char entropy[512];
|
|
unsigned char add_init[512];
|
|
unsigned char add1[512];
|
|
unsigned char add2[512];
|
|
ctr_drbg_context ctx;
|
|
unsigned char buf[512];
|
|
unsigned char output_str[512];
|
|
int add_init_len, add1_len, add2_len;
|
|
|
|
memset( output_str, 0, 512 );
|
|
|
|
unhexify( entropy, {entropy_string} );
|
|
add_init_len = unhexify( add_init, {add_init_string} );
|
|
add1_len = unhexify( add1, {add1_string} );
|
|
add2_len = unhexify( add2, {add2_string} );
|
|
|
|
test_offset = 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 );
|
|
|
|
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add1, add1_len ) == 0 );
|
|
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 );
|
|
hexify( output_str, buf, 16 );
|
|
TEST_ASSERT( strcmp( (char *) output_str, {result_str} ) == 0 );
|
|
}
|
|
END_CASE
|
|
|
|
BEGIN_CASE
|
|
ctr_drbg_validate_nopr:add_init_string:entropy_string:add1_string:add_reseed_string:add2_string:result_str
|
|
{
|
|
unsigned char entropy[512];
|
|
unsigned char add_init[512];
|
|
unsigned char add1[512];
|
|
unsigned char add_reseed[512];
|
|
unsigned char add2[512];
|
|
ctr_drbg_context ctx;
|
|
unsigned char buf[512];
|
|
unsigned char output_str[512];
|
|
int add_init_len, add1_len, add_reseed_len, add2_len;
|
|
|
|
memset( output_str, 0, 512 );
|
|
|
|
unhexify( entropy, {entropy_string} );
|
|
add_init_len = unhexify( add_init, {add_init_string} );
|
|
add1_len = unhexify( add1, {add1_string} );
|
|
add_reseed_len = unhexify( add_reseed, {add_reseed_string} );
|
|
add2_len = unhexify( add2, {add2_string} );
|
|
|
|
test_offset = 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_reseed( &ctx, add_reseed, add_reseed_len ) == 0 );
|
|
TEST_ASSERT( ctr_drbg_random_with_add( &ctx, buf, 16, add2, add2_len ) == 0 );
|
|
hexify( output_str, buf, 16 );
|
|
TEST_ASSERT( strcmp( (char *) output_str, {result_str} ) == 0 );
|
|
}
|
|
END_CASE
|