2011-11-27 15:46:59 +01:00
|
|
|
BEGIN_HEADER
|
|
|
|
#include <polarssl/ctr_drbg.h>
|
|
|
|
|
|
|
|
int test_offset;
|
2011-12-10 22:55:01 +01:00
|
|
|
int entropy_func( void *data, unsigned char *buf, size_t len )
|
2011-11-27 15:46:59 +01:00
|
|
|
{
|
2011-12-10 22:55:01 +01:00
|
|
|
unsigned char *p = (unsigned char *) data;
|
2011-11-27 15:46:59 +01:00
|
|
|
memcpy( buf, p + test_offset, len );
|
|
|
|
test_offset += 32;
|
|
|
|
return( 0 );
|
|
|
|
}
|
2011-12-10 22:42:49 +01:00
|
|
|
|
|
|
|
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 );
|
2011-11-27 15:46:59 +01:00
|
|
|
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;
|
2011-12-10 22:42:49 +01:00
|
|
|
TEST_ASSERT( ctr_drbg_init_entropy_len( &ctx, entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
|
2011-11-27 15:46:59 +01:00
|
|
|
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;
|
2011-12-10 22:42:49 +01:00
|
|
|
TEST_ASSERT( ctr_drbg_init_entropy_len( &ctx, entropy_func, entropy, add_init, add_init_len, 32 ) == 0 );
|
2011-11-27 15:46:59 +01:00
|
|
|
|
|
|
|
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
|