mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 07:04:17 +01:00
84 lines
2.8 KiB
Plaintext
84 lines
2.8 KiB
Plaintext
/* BEGIN_HEADER */
|
|
#include <polarssl/ctr_drbg.h>
|
|
|
|
int test_offset_idx;
|
|
int entropy_func( void *data, unsigned char *buf, size_t len )
|
|
{
|
|
unsigned char *p = (unsigned char *) data;
|
|
memcpy( buf, p + test_offset_idx, len );
|
|
test_offset_idx += 32;
|
|
return( 0 );
|
|
}
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:POLARSSL_CTR_DRBG_C
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE */
|
|
void ctr_drbg_validate_pr( char *add_init_string, char *entropy_string,
|
|
char *add1_string, char *add2_string,
|
|
char *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_idx = 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 */
|
|
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 )
|
|
{
|
|
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_idx = 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 */
|