2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_HEADER */
|
2011-11-27 15:46:59 +01:00
|
|
|
#include <polarssl/ctr_drbg.h>
|
|
|
|
|
2013-11-26 17:45:20 +01:00
|
|
|
int test_offset_idx;
|
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;
|
2013-11-26 17:45:20 +01:00
|
|
|
memcpy( buf, p + test_offset_idx, len );
|
|
|
|
test_offset_idx += 32;
|
2011-11-27 15:46:59 +01:00
|
|
|
return( 0 );
|
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_HEADER */
|
2011-11-27 15:46:59 +01:00
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:POLARSSL_CTR_DRBG_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
2011-11-27 15:46:59 +01:00
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_CASE */
|
|
|
|
void ctr_drbg_validate_pr( char *add_init_string, char *entropy_string,
|
|
|
|
char *add1_string, char *add2_string,
|
|
|
|
char *result_str )
|
2011-11-27 15:46:59 +01:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
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 );
|
2011-11-27 15:46:59 +01:00
|
|
|
|
2013-11-26 17:45:20 +01:00
|
|
|
test_offset_idx = 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 );
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
|
2011-11-27 15:46:59 +01:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2011-11-27 15:46:59 +01:00
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_CASE */
|
|
|
|
void ctr_drbg_validate_nopr( char *add_init_string, char *entropy_string,
|
|
|
|
char *add1_string, char *add_reseed_string,
|
|
|
|
char *add2_string, char *result_str )
|
2011-11-27 15:46:59 +01:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
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 );
|
2011-11-27 15:46:59 +01:00
|
|
|
|
2013-11-26 17:45:20 +01:00
|
|
|
test_offset_idx = 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 );
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
|
2011-11-27 15:46:59 +01:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2014-01-31 12:04:06 +01:00
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SELF_TEST */
|
|
|
|
void ctr_drbg_selftest( )
|
|
|
|
{
|
|
|
|
TEST_ASSERT( ctr_drbg_self_test( 0 ) == 0 );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|