tests: Add mbedtls_test_ prefix to rnd_* symbols
Add mbedtls_test_ prefix to rnd_buf_info and rnd_pseudo_info types, to rnd_std_rand(), rnd_zero_rand(), rnd_buffer_rand() and rnd_pseudo_rand() functions. Command to change *.function files: find . -name "*.function" -exec awk -i inplace \ '{sub(/rnd_(buf_info|pseudo_info|std_rand| \ zero_rand|buffer_rand|pseudo_rand)/, \ "mbedtls_test_&")}1' {} \; Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
2dbba99708
commit
351f0eee20
@ -39,7 +39,7 @@ typedef struct
|
||||
{
|
||||
unsigned char *buf;
|
||||
size_t length;
|
||||
} rnd_buf_info;
|
||||
} mbedtls_test_rnd_buf_info;
|
||||
|
||||
/**
|
||||
* Info structure for the pseudo random function
|
||||
@ -52,7 +52,7 @@ typedef struct
|
||||
{
|
||||
uint32_t key[16];
|
||||
uint32_t v0, v1;
|
||||
} rnd_pseudo_info;
|
||||
} mbedtls_test_rnd_pseudo_info;
|
||||
|
||||
/**
|
||||
* This function just returns data from rand().
|
||||
@ -63,14 +63,18 @@ typedef struct
|
||||
*
|
||||
* rng_state shall be NULL.
|
||||
*/
|
||||
int rnd_std_rand( void *rng_state, unsigned char *output, size_t len );
|
||||
int mbedtls_test_rnd_std_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
|
||||
/**
|
||||
* This function only returns zeros
|
||||
*
|
||||
* rng_state shall be NULL.
|
||||
*/
|
||||
int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len );
|
||||
int mbedtls_test_rnd_zero_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
|
||||
/**
|
||||
* This function returns random based on a buffer it receives.
|
||||
@ -83,7 +87,9 @@ int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len );
|
||||
*
|
||||
* After the buffer is empty it will return rand();
|
||||
*/
|
||||
int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len );
|
||||
int mbedtls_test_rnd_buffer_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
|
||||
/**
|
||||
* This function returns random based on a pseudo random function.
|
||||
@ -93,6 +99,8 @@ int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len );
|
||||
*
|
||||
* rng_state shall be a pointer to a rnd_pseudo_info structure.
|
||||
*/
|
||||
int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len );
|
||||
int mbedtls_test_rnd_pseudo_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len );
|
||||
|
||||
#endif /* TEST_RANDOM_H */
|
||||
|
@ -27,7 +27,9 @@
|
||||
#include <test/random.h>
|
||||
#include <string.h>
|
||||
|
||||
int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
|
||||
int mbedtls_test_rnd_std_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
{
|
||||
#if !defined(__OpenBSD__)
|
||||
size_t i;
|
||||
@ -47,7 +49,9 @@ int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
|
||||
int mbedtls_test_rnd_zero_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
{
|
||||
if( rng_state != NULL )
|
||||
rng_state = NULL;
|
||||
@ -57,13 +61,15 @@ int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
|
||||
int mbedtls_test_rnd_buffer_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
{
|
||||
rnd_buf_info *info = (rnd_buf_info *) rng_state;
|
||||
mbedtls_test_rnd_buf_info *info = (mbedtls_test_rnd_buf_info *) rng_state;
|
||||
size_t use_len;
|
||||
|
||||
if( rng_state == NULL )
|
||||
return( rnd_std_rand( NULL, output, len ) );
|
||||
return( mbedtls_test_rnd_std_rand( NULL, output, len ) );
|
||||
|
||||
use_len = len;
|
||||
if( len > info->length )
|
||||
@ -77,19 +83,23 @@ int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
|
||||
}
|
||||
|
||||
if( len - use_len > 0 )
|
||||
return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
|
||||
return( mbedtls_test_rnd_std_rand( NULL, output + use_len,
|
||||
len - use_len ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
|
||||
int mbedtls_test_rnd_pseudo_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
{
|
||||
rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
|
||||
mbedtls_test_rnd_pseudo_info *info =
|
||||
(mbedtls_test_rnd_pseudo_info *) rng_state;
|
||||
uint32_t i, *k, sum, delta=0x9E3779B9;
|
||||
unsigned char result[4], *out = output;
|
||||
|
||||
if( rng_state == NULL )
|
||||
return( rnd_std_rand( NULL, output, len ) );
|
||||
return( mbedtls_test_rnd_std_rand( NULL, output, len ) );
|
||||
|
||||
k = info->key;
|
||||
|
||||
|
@ -316,7 +316,7 @@ void ctr_drbg_seed_file( char * path, int ret )
|
||||
|
||||
mbedtls_ctr_drbg_init( &ctx );
|
||||
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx, rnd_std_rand, NULL, NULL, 0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx, mbedtls_test_rnd_std_rand, NULL, NULL, 0 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_write_seed_file( &ctx, path ) == ret );
|
||||
TEST_ASSERT( mbedtls_ctr_drbg_update_seed_file( &ctx, path ) == ret );
|
||||
|
||||
|
@ -36,17 +36,17 @@ void dhm_invalid_params( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_make_params( NULL, buflen,
|
||||
buf, &len,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_make_params( &ctx, buflen,
|
||||
NULL, &len,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_make_params( &ctx, buflen,
|
||||
buf, NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_make_params( &ctx, buflen,
|
||||
@ -69,12 +69,12 @@ void dhm_invalid_params( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_make_public( NULL, buflen,
|
||||
buf, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_make_public( &ctx, buflen,
|
||||
NULL, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_make_public( &ctx, buflen,
|
||||
@ -84,15 +84,15 @@ void dhm_invalid_params( )
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_calc_secret( NULL, buf, buflen,
|
||||
&len, rnd_std_rand,
|
||||
&len, mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_calc_secret( &ctx, NULL, buflen,
|
||||
&len, rnd_std_rand,
|
||||
&len, mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_DHM_BAD_INPUT_DATA,
|
||||
mbedtls_dhm_calc_secret( &ctx, buf, buflen,
|
||||
NULL, rnd_std_rand,
|
||||
NULL, mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
|
||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||
@ -130,7 +130,7 @@ void dhm_do_dhm( int radix_P, char *input_P,
|
||||
size_t sec_srv_len;
|
||||
size_t sec_cli_len;
|
||||
int x_size, i;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_dhm_init( &ctx_srv );
|
||||
mbedtls_dhm_init( &ctx_cli );
|
||||
@ -138,7 +138,7 @@ void dhm_do_dhm( int radix_P, char *input_P,
|
||||
memset( pub_cli, 0x00, 1000 );
|
||||
memset( sec_srv, 0x00, 1000 );
|
||||
memset( sec_cli, 0x00, 1000 );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
/*
|
||||
* Set params
|
||||
@ -151,7 +151,7 @@ void dhm_do_dhm( int radix_P, char *input_P,
|
||||
/*
|
||||
* First key exchange
|
||||
*/
|
||||
TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &rnd_pseudo_rand, &rnd_info ) == result );
|
||||
TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == result );
|
||||
if ( result != 0 )
|
||||
goto exit;
|
||||
|
||||
@ -159,10 +159,10 @@ void dhm_do_dhm( int radix_P, char *input_P,
|
||||
ske[ske_len++] = 0;
|
||||
TEST_ASSERT( mbedtls_dhm_read_params( &ctx_cli, &p, ske + ske_len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_read_public( &ctx_srv, pub_cli, pub_cli_len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ), &sec_srv_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ), &sec_srv_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ), &sec_cli_len, NULL, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( sec_srv_len == sec_cli_len );
|
||||
@ -173,7 +173,7 @@ void dhm_do_dhm( int radix_P, char *input_P,
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
sec_srv_len = 1000;
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ), &sec_srv_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ), &sec_srv_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
|
||||
TEST_ASSERT( sec_srv_len == sec_cli_len );
|
||||
TEST_ASSERT( sec_srv_len != 0 );
|
||||
@ -185,15 +185,15 @@ void dhm_do_dhm( int radix_P, char *input_P,
|
||||
*/
|
||||
p = ske;
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
ske[ske_len++] = 0;
|
||||
ske[ske_len++] = 0;
|
||||
TEST_ASSERT( mbedtls_dhm_read_params( &ctx_cli, &p, ske + ske_len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_read_public( &ctx_srv, pub_cli, pub_cli_len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ), &sec_srv_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_srv, sec_srv, sizeof( sec_srv ), &sec_srv_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_calc_secret( &ctx_cli, sec_cli, sizeof( sec_cli ), &sec_cli_len, NULL, NULL ) == 0 );
|
||||
|
||||
TEST_ASSERT( sec_srv_len == sec_cli_len );
|
||||
|
@ -19,7 +19,7 @@ exit:
|
||||
|
||||
static int load_private_key( int grp_id, data_t *private_key,
|
||||
mbedtls_ecp_keypair *ecp,
|
||||
rnd_pseudo_info *rnd_info )
|
||||
mbedtls_test_rnd_pseudo_info *rnd_info )
|
||||
{
|
||||
int ok = 0;
|
||||
TEST_ASSERT( mbedtls_ecp_read_key( grp_id, ecp,
|
||||
@ -29,7 +29,7 @@ static int load_private_key( int grp_id, data_t *private_key,
|
||||
/* Calculate the public key from the private key. */
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d,
|
||||
&ecp->grp.G,
|
||||
&rnd_pseudo_rand, rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, rnd_info ) == 0 );
|
||||
ok = 1;
|
||||
exit:
|
||||
return( ok );
|
||||
@ -72,29 +72,29 @@ void ecdh_invalid_param( )
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_gen_public( NULL, &m, &P,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_gen_public( &grp, NULL, &P,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_gen_public( &grp, &m, NULL,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_gen_public( &grp, &m, &P,
|
||||
NULL, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_compute_shared( NULL, &m, &P, &m,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_compute_shared( &grp, NULL, &P, &m,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_compute_shared( &grp, &m, NULL, &m,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_compute_shared( &grp, &m, &P, NULL,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_setup( NULL, valid_grp ) );
|
||||
@ -102,15 +102,15 @@ void ecdh_invalid_param( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_params( NULL, &olen,
|
||||
buf, buflen,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_params( &ctx, NULL,
|
||||
buf, buflen,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_params( &ctx, &olen,
|
||||
NULL, buflen,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_params( &ctx, &olen,
|
||||
buf, buflen,
|
||||
@ -143,17 +143,17 @@ void ecdh_invalid_param( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_public( NULL, &olen,
|
||||
buf, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_public( &ctx, NULL,
|
||||
buf, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_public( &ctx, &olen,
|
||||
NULL, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_make_public( &ctx, &olen,
|
||||
@ -168,15 +168,15 @@ void ecdh_invalid_param( )
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_calc_secret( NULL, &olen, buf, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_calc_secret( &ctx, NULL, buf, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdh_calc_secret( &ctx, &olen, NULL, buflen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
|
||||
exit:
|
||||
@ -190,22 +190,22 @@ void ecdh_primitive_random( int id )
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point qA, qB;
|
||||
mbedtls_mpi dA, dB, zA, zB;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &qA ); mbedtls_ecp_point_init( &qB );
|
||||
mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &dB );
|
||||
mbedtls_mpi_init( &zA ); mbedtls_mpi_init( &zB );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA, &rnd_pseudo_rand, &rnd_info )
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA, &mbedtls_test_rnd_pseudo_rand, &rnd_info )
|
||||
== 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB, &rnd_pseudo_rand, &rnd_info )
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB, &mbedtls_test_rnd_pseudo_rand, &rnd_info )
|
||||
== 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB,
|
||||
NULL, NULL ) == 0 );
|
||||
|
||||
@ -227,7 +227,7 @@ void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point qA, qB;
|
||||
mbedtls_mpi dA, dB, zA, zB, check;
|
||||
rnd_buf_info rnd_info_A, rnd_info_B;
|
||||
mbedtls_test_rnd_buf_info rnd_info_A, rnd_info_B;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &qA ); mbedtls_ecp_point_init( &qB );
|
||||
@ -269,7 +269,7 @@ void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
|
||||
}
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA,
|
||||
rnd_buffer_rand, &rnd_info_A ) == 0 );
|
||||
mbedtls_test_rnd_buffer_rand, &rnd_info_A ) == 0 );
|
||||
TEST_ASSERT( ! mbedtls_ecp_is_zero( &qA ) );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.X, &check ) == 0 );
|
||||
@ -277,7 +277,7 @@ void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.Y, &check ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB,
|
||||
rnd_buffer_rand, &rnd_info_B ) == 0 );
|
||||
mbedtls_test_rnd_buffer_rand, &rnd_info_B ) == 0 );
|
||||
TEST_ASSERT( ! mbedtls_ecp_is_zero( &qB ) );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.X, &check ) == 0 );
|
||||
@ -305,28 +305,28 @@ void ecdh_exchange( int id )
|
||||
unsigned char buf[1000];
|
||||
const unsigned char *vbuf;
|
||||
size_t len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
unsigned char res_buf[1000];
|
||||
size_t res_len;
|
||||
|
||||
mbedtls_ecdh_init( &srv );
|
||||
mbedtls_ecdh_init( &cli );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_setup( &srv, id ) == 0 );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
|
||||
TEST_ASSERT( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) );
|
||||
TEST_ASSERT( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &res_len, res_buf, 1000,
|
||||
NULL, NULL ) == 0 );
|
||||
TEST_ASSERT( len == res_len );
|
||||
@ -351,7 +351,7 @@ void ecdh_restart( int id, char *dA_str, char *dB_str, char *z_str,
|
||||
size_t z_len;
|
||||
unsigned char rnd_buf_A[MBEDTLS_ECP_MAX_BYTES];
|
||||
unsigned char rnd_buf_B[MBEDTLS_ECP_MAX_BYTES];
|
||||
rnd_buf_info rnd_info_A, rnd_info_B;
|
||||
mbedtls_test_rnd_buf_info rnd_info_A, rnd_info_B;
|
||||
int cnt_restart;
|
||||
mbedtls_ecp_group grp;
|
||||
|
||||
@ -393,7 +393,7 @@ void ecdh_restart( int id, char *dA_str, char *dB_str, char *z_str,
|
||||
cnt_restart = 0;
|
||||
do {
|
||||
ret = mbedtls_ecdh_make_params( &srv, &len, buf, sizeof( buf ),
|
||||
rnd_buffer_rand, &rnd_info_A );
|
||||
mbedtls_test_rnd_buffer_rand, &rnd_info_A );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
|
||||
|
||||
TEST_ASSERT( ret == 0 );
|
||||
@ -411,7 +411,7 @@ void ecdh_restart( int id, char *dA_str, char *dB_str, char *z_str,
|
||||
cnt_restart = 0;
|
||||
do {
|
||||
ret = mbedtls_ecdh_make_public( &cli, &len, buf, sizeof( buf ),
|
||||
rnd_buffer_rand, &rnd_info_B );
|
||||
mbedtls_test_rnd_buffer_rand, &rnd_info_B );
|
||||
} while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
|
||||
|
||||
TEST_ASSERT( ret == 0 );
|
||||
@ -470,26 +470,26 @@ void ecdh_exchange_legacy( int id )
|
||||
const unsigned char *vbuf;
|
||||
size_t len;
|
||||
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecdh_init( &srv );
|
||||
mbedtls_ecdh_init( &cli );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &srv.grp, id ) == 0 );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
|
||||
TEST_ASSERT( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
|
||||
|
||||
memset( buf, 0x00, sizeof( buf ) );
|
||||
TEST_ASSERT( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &len, buf, 1000, NULL,
|
||||
NULL ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &srv.z, &cli.z ) == 0 );
|
||||
@ -507,14 +507,14 @@ void ecdh_exchange_calc_secret( int grp_id,
|
||||
int ours_first,
|
||||
data_t *expected )
|
||||
{
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_ecp_keypair our_key;
|
||||
mbedtls_ecp_keypair their_key;
|
||||
mbedtls_ecdh_context ecdh;
|
||||
unsigned char shared_secret[MBEDTLS_ECP_MAX_BYTES];
|
||||
size_t shared_secret_length = 0;
|
||||
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
mbedtls_ecdh_init( &ecdh );
|
||||
mbedtls_ecp_keypair_init( &our_key );
|
||||
mbedtls_ecp_keypair_init( &their_key );
|
||||
@ -545,7 +545,7 @@ void ecdh_exchange_calc_secret( int grp_id,
|
||||
&ecdh,
|
||||
&shared_secret_length,
|
||||
shared_secret, sizeof( shared_secret ),
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( shared_secret_length == expected->len );
|
||||
TEST_ASSERT( memcmp( expected->x, shared_secret,
|
||||
shared_secret_length ) == 0 );
|
||||
@ -565,12 +565,12 @@ void ecdh_exchange_get_params_fail( int our_grp_id,
|
||||
int ours_first,
|
||||
int expected_ret )
|
||||
{
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_ecp_keypair our_key;
|
||||
mbedtls_ecp_keypair their_key;
|
||||
mbedtls_ecdh_context ecdh;
|
||||
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
mbedtls_ecdh_init( &ecdh );
|
||||
mbedtls_ecp_keypair_init( &our_key );
|
||||
mbedtls_ecp_keypair_init( &their_key );
|
||||
|
@ -31,23 +31,23 @@ void ecdsa_invalid_param( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign( NULL, &m, &m, &m,
|
||||
buf, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign( &grp, NULL, &m, &m,
|
||||
buf, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign( &grp, &m, NULL, &m,
|
||||
buf, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign( &grp, &m, &m, NULL,
|
||||
buf, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign( &grp, &m, &m, &m,
|
||||
NULL, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign( &grp, &m, &m, &m,
|
||||
buf, sizeof( buf ),
|
||||
@ -58,27 +58,27 @@ void ecdsa_invalid_param( )
|
||||
mbedtls_ecdsa_sign_det_ext( NULL, &m, &m, &m,
|
||||
buf, sizeof( buf ),
|
||||
valid_md,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign_det_ext( &grp, NULL, &m, &m,
|
||||
buf, sizeof( buf ),
|
||||
valid_md,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign_det_ext( &grp, &m, NULL, &m,
|
||||
buf, sizeof( buf ),
|
||||
valid_md,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign_det_ext( &grp, &m, &m, NULL,
|
||||
buf, sizeof( buf ),
|
||||
valid_md,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_sign_det_ext( &grp, &m, &m, &m,
|
||||
NULL, sizeof( buf ),
|
||||
valid_md,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
#endif /* MBEDTLS_ECDSA_DETERMINISTIC */
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
@ -107,28 +107,28 @@ void ecdsa_invalid_param( )
|
||||
valid_md,
|
||||
buf, sizeof( buf ),
|
||||
buf, &slen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_write_signature( &ctx,
|
||||
valid_md,
|
||||
NULL, sizeof( buf ),
|
||||
buf, &slen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_write_signature( &ctx,
|
||||
valid_md,
|
||||
buf, sizeof( buf ),
|
||||
NULL, &slen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_write_signature( &ctx,
|
||||
valid_md,
|
||||
buf, sizeof( buf ),
|
||||
buf, NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
@ -136,28 +136,28 @@ void ecdsa_invalid_param( )
|
||||
valid_md,
|
||||
buf, sizeof( buf ),
|
||||
buf, &slen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_write_signature_restartable( &ctx,
|
||||
valid_md,
|
||||
NULL, sizeof( buf ),
|
||||
buf, &slen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_write_signature_restartable( &ctx,
|
||||
valid_md,
|
||||
buf, sizeof( buf ),
|
||||
NULL, &slen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_write_signature_restartable( &ctx,
|
||||
valid_md,
|
||||
buf, sizeof( buf ),
|
||||
buf, NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
@ -191,7 +191,7 @@ void ecdsa_invalid_param( )
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_genkey( NULL, valid_group,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecdsa_genkey( &ctx, valid_group,
|
||||
NULL, NULL ) );
|
||||
@ -213,23 +213,23 @@ void ecdsa_prim_random( int id )
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point Q;
|
||||
mbedtls_mpi d, r, s;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
unsigned char buf[MBEDTLS_MD_MAX_SIZE];
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &Q );
|
||||
mbedtls_mpi_init( &d ); mbedtls_mpi_init( &r ); mbedtls_mpi_init( &s );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
/* prepare material for signature */
|
||||
TEST_ASSERT( rnd_pseudo_rand( &rnd_info, buf, sizeof( buf ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info, buf, sizeof( buf ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info )
|
||||
TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q, &mbedtls_test_rnd_pseudo_rand, &rnd_info )
|
||||
== 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, buf, sizeof( buf ),
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 );
|
||||
|
||||
exit:
|
||||
@ -248,7 +248,7 @@ void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str,
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point Q;
|
||||
mbedtls_mpi d, r, s, r_check, s_check;
|
||||
rnd_buf_info rnd_info;
|
||||
mbedtls_test_rnd_buf_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &Q );
|
||||
@ -276,7 +276,7 @@ void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str,
|
||||
}
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdsa_sign( &grp, &r, &s, &d, hash->x, hash->len,
|
||||
rnd_buffer_rand, &rnd_info ) == result );
|
||||
mbedtls_test_rnd_buffer_rand, &rnd_info ) == result );
|
||||
|
||||
if ( result == 0)
|
||||
{
|
||||
@ -332,7 +332,7 @@ void ecdsa_det_test_vectors( int id, char * d_str, int md_alg, char * msg,
|
||||
|
||||
TEST_ASSERT(
|
||||
mbedtls_ecdsa_sign_det_ext( &grp, &r, &s, &d, hash, hlen,
|
||||
md_alg, rnd_std_rand, NULL )
|
||||
md_alg, mbedtls_test_rnd_std_rand, NULL )
|
||||
== 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &r, &r_check ) == 0 );
|
||||
@ -349,26 +349,26 @@ exit:
|
||||
void ecdsa_write_read_random( int id )
|
||||
{
|
||||
mbedtls_ecdsa_context ctx;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
unsigned char hash[32];
|
||||
unsigned char sig[200];
|
||||
size_t sig_len, i;
|
||||
|
||||
mbedtls_ecdsa_init( &ctx );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
memset( hash, 0, sizeof( hash ) );
|
||||
memset( sig, 0x2a, sizeof( sig ) );
|
||||
|
||||
/* prepare material for signature */
|
||||
TEST_ASSERT( rnd_pseudo_rand( &rnd_info, hash, sizeof( hash ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_rnd_pseudo_rand( &rnd_info, hash, sizeof( hash ) ) == 0 );
|
||||
|
||||
/* generate signing key */
|
||||
TEST_ASSERT( mbedtls_ecdsa_genkey( &ctx, id, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdsa_genkey( &ctx, id, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
|
||||
/* generate and write signature, then read and verify it */
|
||||
TEST_ASSERT( mbedtls_ecdsa_write_signature( &ctx, MBEDTLS_MD_SHA256,
|
||||
hash, sizeof( hash ),
|
||||
sig, &sig_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
sig, &sig_len, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) == 0 );
|
||||
|
||||
|
@ -139,19 +139,19 @@ void ecjpake_invalid_param( )
|
||||
mbedtls_ecjpake_write_round_one( NULL,
|
||||
buf, len,
|
||||
&olen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_write_round_one( &ctx,
|
||||
NULL, len,
|
||||
&olen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_write_round_one( &ctx,
|
||||
buf, len,
|
||||
NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_write_round_one( &ctx,
|
||||
@ -164,19 +164,19 @@ void ecjpake_invalid_param( )
|
||||
mbedtls_ecjpake_write_round_two( NULL,
|
||||
buf, len,
|
||||
&olen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_write_round_two( &ctx,
|
||||
NULL, len,
|
||||
&olen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_write_round_two( &ctx,
|
||||
buf, len,
|
||||
NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_write_round_two( &ctx,
|
||||
@ -203,19 +203,19 @@ void ecjpake_invalid_param( )
|
||||
mbedtls_ecjpake_derive_secret( NULL,
|
||||
buf, len,
|
||||
&olen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_derive_secret( &ctx,
|
||||
NULL, len,
|
||||
&olen,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_derive_secret( &ctx,
|
||||
buf, len,
|
||||
NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecjpake_derive_secret( &ctx,
|
||||
|
@ -69,12 +69,12 @@ void ecp_invalid_param( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_privkey( NULL,
|
||||
&m,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_privkey( &grp,
|
||||
NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_privkey( &grp,
|
||||
@ -222,29 +222,29 @@ void ecp_invalid_param( )
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul( NULL, &P, &m, &P,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul( &grp, NULL, &m, &P,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul( &grp, &P, NULL, &P,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul( &grp, &P, &m, NULL,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul_restartable( NULL, &P, &m, &P,
|
||||
rnd_std_rand, NULL , NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL , NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul_restartable( &grp, NULL, &m, &P,
|
||||
rnd_std_rand, NULL , NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL , NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul_restartable( &grp, &P, NULL, &P,
|
||||
rnd_std_rand, NULL , NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL , NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_mul_restartable( &grp, &P, &m, NULL,
|
||||
rnd_std_rand, NULL , NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL , NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_muladd( NULL, &P, &m, &P,
|
||||
@ -302,22 +302,22 @@ void ecp_invalid_param( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair_base( NULL, &P,
|
||||
&m, &P,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair_base( &grp, NULL,
|
||||
&m, &P,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair_base( &grp, &P,
|
||||
NULL, &P,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair_base( &grp, &P,
|
||||
&m, NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair_base( &grp, &P,
|
||||
@ -328,17 +328,17 @@ void ecp_invalid_param( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair( NULL,
|
||||
&m, &P,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair( &grp,
|
||||
NULL, &P,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair( &grp,
|
||||
&m, NULL,
|
||||
rnd_std_rand,
|
||||
mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_keypair( &grp,
|
||||
@ -348,7 +348,7 @@ void ecp_invalid_param( )
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_key( valid_group, NULL,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
|
||||
mbedtls_ecp_gen_key( valid_group, &kp,
|
||||
NULL, NULL ) );
|
||||
@ -576,12 +576,12 @@ void ecp_test_vect( int id, char * dA_str, char * xA_str, char * yA_str,
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point R;
|
||||
mbedtls_mpi dA, xA, yA, dB, xB, yB, xZ, yZ;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &R );
|
||||
mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &xA ); mbedtls_mpi_init( &yA ); mbedtls_mpi_init( &dB );
|
||||
mbedtls_mpi_init( &xB ); mbedtls_mpi_init( &yB ); mbedtls_mpi_init( &xZ ); mbedtls_mpi_init( &yZ );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
@ -597,7 +597,7 @@ void ecp_test_vect( int id, char * dA_str, char * xA_str, char * yA_str,
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yZ, 16, yZ_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xA ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yA ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
|
||||
@ -611,7 +611,7 @@ void ecp_test_vect( int id, char * dA_str, char * xA_str, char * yA_str,
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yB ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &R,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xZ ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
|
||||
@ -630,13 +630,13 @@ void ecp_test_vec_x( int id, char * dA_hex, char * xA_hex, char * dB_hex,
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point R;
|
||||
mbedtls_mpi dA, xA, dB, xB, xS;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &R );
|
||||
mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &xA );
|
||||
mbedtls_mpi_init( &dB ); mbedtls_mpi_init( &xB );
|
||||
mbedtls_mpi_init( &xS );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
@ -649,12 +649,12 @@ void ecp_test_vec_x( int id, char * dA_hex, char * xA_hex, char * dB_hex,
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xS, 16, xS_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xA ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dB, &R,
|
||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &R ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &R.X, &xS ) == 0 );
|
||||
|
||||
@ -683,12 +683,12 @@ void ecp_test_mul( int id, data_t * n_hex,
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point P, nP, R;
|
||||
mbedtls_mpi n;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp ); mbedtls_ecp_point_init( &R );
|
||||
mbedtls_ecp_point_init( &P ); mbedtls_ecp_point_init( &nP );
|
||||
mbedtls_mpi_init( &n );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
@ -707,7 +707,7 @@ void ecp_test_mul( int id, data_t * n_hex,
|
||||
== 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &n, &P,
|
||||
&rnd_pseudo_rand, &rnd_info )
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info )
|
||||
== expected_ret );
|
||||
|
||||
if( expected_ret == 0 )
|
||||
@ -740,7 +740,7 @@ void ecp_test_mul_rng( int id, data_t * d_hex)
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_binary( &d, d_hex->x, d_hex->len ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &Q, &d, &grp.G, &rnd_zero_rand, NULL )
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &Q, &d, &grp.G, &mbedtls_test_rnd_zero_rand, NULL )
|
||||
== MBEDTLS_ERR_ECP_RANDOM_FAILED );
|
||||
|
||||
exit:
|
||||
@ -1052,16 +1052,16 @@ void mbedtls_ecp_gen_keypair( int id )
|
||||
mbedtls_ecp_group grp;
|
||||
mbedtls_ecp_point Q;
|
||||
mbedtls_mpi d;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
mbedtls_ecp_point_init( &Q );
|
||||
mbedtls_mpi_init( &d );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info )
|
||||
TEST_ASSERT( mbedtls_ecp_gen_keypair( &grp, &d, &Q, &mbedtls_test_rnd_pseudo_rand, &rnd_info )
|
||||
== 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &Q ) == 0 );
|
||||
@ -1078,12 +1078,12 @@ exit:
|
||||
void mbedtls_ecp_gen_key( int id )
|
||||
{
|
||||
mbedtls_ecp_keypair key;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_ecp_keypair_init( &key );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x00, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_gen_key( id, &key, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_gen_key( id, &key, &mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &key.grp, &key.Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_check_privkey( &key.grp, &key.d ) == 0 );
|
||||
|
@ -129,7 +129,7 @@ void hmac_drbg_seed_file( int md_alg, char * path, int ret )
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, rnd_std_rand, NULL,
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_seed( &ctx, md_info, mbedtls_test_rnd_std_rand, NULL,
|
||||
NULL, 0 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_hmac_drbg_write_seed_file( &ctx, path ) == ret );
|
||||
|
@ -240,7 +240,7 @@ void mpi_invalid_param( )
|
||||
mbedtls_mpi_exp_mod( &X, &X, &X, NULL, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_fill_random( NULL, 42, rnd_std_rand,
|
||||
mbedtls_mpi_fill_random( NULL, 42, mbedtls_test_rnd_std_rand,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
|
||||
mbedtls_mpi_fill_random( &X, 42, NULL, NULL ) );
|
||||
@ -1195,7 +1195,7 @@ void mbedtls_mpi_is_prime( int radix_X, char * input_X, int div_result )
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
res = mbedtls_mpi_is_prime_ext( &X, 40, rnd_std_rand, NULL );
|
||||
res = mbedtls_mpi_is_prime_ext( &X, 40, mbedtls_test_rnd_std_rand, NULL );
|
||||
TEST_ASSERT( res == div_result );
|
||||
|
||||
exit:
|
||||
@ -1244,7 +1244,7 @@ void mbedtls_mpi_gen_prime( int bits, int flags, int ref_ret )
|
||||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
my_ret = mbedtls_mpi_gen_prime( &X, bits, flags, rnd_std_rand, NULL );
|
||||
my_ret = mbedtls_mpi_gen_prime( &X, bits, flags, mbedtls_test_rnd_std_rand, NULL );
|
||||
TEST_ASSERT( my_ret == ref_ret );
|
||||
|
||||
if( ref_ret == 0 )
|
||||
@ -1254,13 +1254,13 @@ void mbedtls_mpi_gen_prime( int bits, int flags, int ref_ret )
|
||||
TEST_ASSERT( actual_bits >= (size_t) bits );
|
||||
TEST_ASSERT( actual_bits <= (size_t) bits + 1 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_is_prime_ext( &X, 40, rnd_std_rand, NULL )
|
||||
TEST_ASSERT( mbedtls_mpi_is_prime_ext( &X, 40, mbedtls_test_rnd_std_rand, NULL )
|
||||
== 0 );
|
||||
if( flags & MBEDTLS_MPI_GEN_PRIME_FLAG_DH )
|
||||
{
|
||||
/* X = ( X - 1 ) / 2 */
|
||||
TEST_ASSERT( mbedtls_mpi_shift_r( &X, 1 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_is_prime_ext( &X, 40, rnd_std_rand, NULL )
|
||||
TEST_ASSERT( mbedtls_mpi_is_prime_ext( &X, 40, mbedtls_test_rnd_std_rand, NULL )
|
||||
== 0 );
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ static int pk_genkey( mbedtls_pk_context *pk, int parameter )
|
||||
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
|
||||
if( mbedtls_pk_get_type( pk ) == MBEDTLS_PK_RSA )
|
||||
return mbedtls_rsa_gen_key( mbedtls_pk_rsa( *pk ),
|
||||
rnd_std_rand, NULL,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
parameter, 3 );
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
@ -63,7 +63,7 @@ static int pk_genkey( mbedtls_pk_context *pk, int parameter )
|
||||
return( ret );
|
||||
|
||||
return mbedtls_ecp_gen_keypair( &mbedtls_pk_ec( *pk )->grp, &mbedtls_pk_ec( *pk )->d,
|
||||
&mbedtls_pk_ec( *pk )->Q, rnd_std_rand, NULL );
|
||||
&mbedtls_pk_ec( *pk )->Q, mbedtls_test_rnd_std_rand, NULL );
|
||||
}
|
||||
#endif
|
||||
return( -1 );
|
||||
@ -75,7 +75,7 @@ int mbedtls_rsa_decrypt_func( void *ctx, int mode, size_t *olen,
|
||||
size_t output_max_len )
|
||||
{
|
||||
return( mbedtls_rsa_pkcs1_decrypt( (mbedtls_rsa_context *) ctx,
|
||||
rnd_std_rand, NULL, mode, olen,
|
||||
mbedtls_test_rnd_std_rand, NULL, mode, olen,
|
||||
input, output, output_max_len ) );
|
||||
}
|
||||
int mbedtls_rsa_sign_func( void *ctx,
|
||||
@ -85,7 +85,7 @@ int mbedtls_rsa_sign_func( void *ctx,
|
||||
{
|
||||
((void) f_rng);
|
||||
((void) p_rng);
|
||||
return( mbedtls_rsa_pkcs1_sign( (mbedtls_rsa_context *) ctx, rnd_std_rand, NULL, mode,
|
||||
return( mbedtls_rsa_pkcs1_sign( (mbedtls_rsa_context *) ctx, mbedtls_test_rnd_std_rand, NULL, mode,
|
||||
md_alg, hashlen, hash, sig ) );
|
||||
}
|
||||
size_t mbedtls_rsa_key_len_func( void *ctx )
|
||||
@ -235,7 +235,7 @@ void valid_parameters( )
|
||||
MBEDTLS_MD_NONE,
|
||||
NULL, 0,
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
NULL ) ==
|
||||
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
@ -243,7 +243,7 @@ void valid_parameters( )
|
||||
MBEDTLS_MD_NONE,
|
||||
NULL, 0,
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
NULL ) ==
|
||||
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
@ -251,7 +251,7 @@ void valid_parameters( )
|
||||
MBEDTLS_MD_NONE,
|
||||
NULL, 0,
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL ) ==
|
||||
mbedtls_test_rnd_std_rand, NULL ) ==
|
||||
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_verify_restartable( &pk,
|
||||
@ -277,13 +277,13 @@ void valid_parameters( )
|
||||
TEST_ASSERT( mbedtls_pk_encrypt( &pk,
|
||||
NULL, 0,
|
||||
NULL, &len, 0,
|
||||
rnd_std_rand, NULL ) ==
|
||||
mbedtls_test_rnd_std_rand, NULL ) ==
|
||||
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_decrypt( &pk,
|
||||
NULL, 0,
|
||||
NULL, &len, 0,
|
||||
rnd_std_rand, NULL ) ==
|
||||
mbedtls_test_rnd_std_rand, NULL ) ==
|
||||
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
#if defined(MBEDTLS_PK_PARSE_C)
|
||||
@ -435,28 +435,28 @@ void invalid_parameters( )
|
||||
MBEDTLS_MD_NONE,
|
||||
buf, sizeof( buf ),
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_sign_restartable( &pk,
|
||||
MBEDTLS_MD_NONE,
|
||||
NULL, sizeof( buf ),
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_sign_restartable( &pk,
|
||||
valid_md,
|
||||
NULL, 0,
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_sign_restartable( &pk,
|
||||
MBEDTLS_MD_NONE,
|
||||
buf, sizeof( buf ),
|
||||
NULL, &len,
|
||||
rnd_std_rand, NULL,
|
||||
mbedtls_test_rnd_std_rand, NULL,
|
||||
NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
@ -464,67 +464,67 @@ void invalid_parameters( )
|
||||
MBEDTLS_MD_NONE,
|
||||
buf, sizeof( buf ),
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_sign( &pk,
|
||||
MBEDTLS_MD_NONE,
|
||||
NULL, sizeof( buf ),
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_sign( &pk,
|
||||
valid_md,
|
||||
NULL, 0,
|
||||
buf, &len,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_sign( &pk,
|
||||
MBEDTLS_MD_NONE,
|
||||
buf, sizeof( buf ),
|
||||
NULL, &len,
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_decrypt( NULL,
|
||||
buf, sizeof( buf ),
|
||||
buf, &len, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_decrypt( &pk,
|
||||
NULL, sizeof( buf ),
|
||||
buf, &len, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_decrypt( &pk,
|
||||
buf, sizeof( buf ),
|
||||
NULL, &len, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_decrypt( &pk,
|
||||
buf, sizeof( buf ),
|
||||
buf, NULL, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_encrypt( NULL,
|
||||
buf, sizeof( buf ),
|
||||
buf, &len, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_encrypt( &pk,
|
||||
NULL, sizeof( buf ),
|
||||
buf, &len, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_encrypt( &pk,
|
||||
buf, sizeof( buf ),
|
||||
NULL, &len, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_encrypt( &pk,
|
||||
buf, sizeof( buf ),
|
||||
buf, NULL, sizeof( buf ),
|
||||
rnd_std_rand, NULL ) );
|
||||
mbedtls_test_rnd_std_rand, NULL ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_PK_BAD_INPUT_DATA,
|
||||
mbedtls_pk_check_pair( NULL, &pk ) );
|
||||
@ -945,7 +945,7 @@ void pk_sign_verify( int type, int parameter, int sign_ret, int verify_ret )
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_sign_restartable( &pk, MBEDTLS_MD_SHA256,
|
||||
hash, sizeof hash, sig, &sig_len,
|
||||
rnd_std_rand, NULL, rs_ctx ) == sign_ret );
|
||||
mbedtls_test_rnd_std_rand, NULL, rs_ctx ) == sign_ret );
|
||||
if( sign_ret == 0 )
|
||||
TEST_ASSERT( sig_len <= MBEDTLS_PK_SIGNATURE_MAX_SIZE );
|
||||
else
|
||||
@ -968,7 +968,7 @@ void pk_sign_verify( int type, int parameter, int sign_ret, int verify_ret )
|
||||
}
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256, hash, sizeof hash,
|
||||
sig, &sig_len, rnd_std_rand, NULL ) == sign_ret );
|
||||
sig, &sig_len, mbedtls_test_rnd_std_rand, NULL ) == sign_ret );
|
||||
if( sign_ret == 0 )
|
||||
TEST_ASSERT( sig_len <= MBEDTLS_PK_SIGNATURE_MAX_SIZE );
|
||||
else
|
||||
@ -1005,12 +1005,12 @@ void pk_rsa_encrypt_test_vec( data_t * message, int mod, int radix_N,
|
||||
data_t * result, int ret )
|
||||
{
|
||||
unsigned char output[300];
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
size_t olen;
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
memset( output, 0, sizeof( output ) );
|
||||
|
||||
|
||||
@ -1024,7 +1024,7 @@ void pk_rsa_encrypt_test_vec( data_t * message, int mod, int radix_N,
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_encrypt( &pk, message->x, message->len,
|
||||
output, &olen, sizeof( output ),
|
||||
rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
TEST_ASSERT( olen == result->len );
|
||||
TEST_ASSERT( memcmp( output, result->x, olen ) == 0 );
|
||||
|
||||
@ -1040,7 +1040,7 @@ void pk_rsa_decrypt_test_vec( data_t * cipher, int mod, int radix_P,
|
||||
char * input_E, data_t * clear, int ret )
|
||||
{
|
||||
unsigned char output[256];
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
mbedtls_rsa_context *rsa;
|
||||
mbedtls_pk_context pk;
|
||||
@ -1050,7 +1050,7 @@ void pk_rsa_decrypt_test_vec( data_t * cipher, int mod, int radix_P,
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
|
||||
/* init pk-rsa context */
|
||||
@ -1073,7 +1073,7 @@ void pk_rsa_decrypt_test_vec( data_t * cipher, int mod, int radix_P,
|
||||
olen = 0;
|
||||
TEST_ASSERT( mbedtls_pk_decrypt( &pk, cipher->x, cipher->len,
|
||||
output, &olen, sizeof( output ),
|
||||
rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
if( ret == 0 )
|
||||
{
|
||||
TEST_ASSERT( olen == clear->len );
|
||||
@ -1093,13 +1093,13 @@ void pk_ec_nocrypt( int type )
|
||||
mbedtls_pk_context pk;
|
||||
unsigned char output[100];
|
||||
unsigned char input[100];
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
size_t olen = 0;
|
||||
int ret = MBEDTLS_ERR_PK_TYPE_MISMATCH;
|
||||
|
||||
mbedtls_pk_init( &pk );
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
memset( output, 0, sizeof( output ) );
|
||||
memset( input, 0, sizeof( input ) );
|
||||
|
||||
@ -1107,11 +1107,11 @@ void pk_ec_nocrypt( int type )
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_encrypt( &pk, input, sizeof( input ),
|
||||
output, &olen, sizeof( output ),
|
||||
rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_decrypt( &pk, input, sizeof( input ),
|
||||
output, &olen, sizeof( output ),
|
||||
rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info ) == ret );
|
||||
|
||||
exit:
|
||||
mbedtls_pk_free( &pk );
|
||||
@ -1146,7 +1146,7 @@ void pk_rsa_overflow( )
|
||||
sig, sig_len ) == MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_NONE, hash, hash_len, sig, &sig_len,
|
||||
rnd_std_rand, NULL ) == MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
mbedtls_test_rnd_std_rand, NULL ) == MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
exit:
|
||||
mbedtls_pk_free( &pk );
|
||||
@ -1200,11 +1200,11 @@ void pk_rsa_alt( )
|
||||
/* Test signature */
|
||||
#if SIZE_MAX > UINT_MAX
|
||||
TEST_ASSERT( mbedtls_pk_sign( &alt, MBEDTLS_MD_NONE, hash, SIZE_MAX,
|
||||
sig, &sig_len, rnd_std_rand, NULL ) ==
|
||||
sig, &sig_len, mbedtls_test_rnd_std_rand, NULL ) ==
|
||||
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
#endif /* SIZE_MAX > UINT_MAX */
|
||||
TEST_ASSERT( mbedtls_pk_sign( &alt, MBEDTLS_MD_NONE, hash, sizeof hash,
|
||||
sig, &sig_len, rnd_std_rand, NULL ) == 0 );
|
||||
sig, &sig_len, mbedtls_test_rnd_std_rand, NULL ) == 0 );
|
||||
TEST_ASSERT( sig_len == RSA_KEY_LEN );
|
||||
TEST_ASSERT( mbedtls_pk_verify( &rsa, MBEDTLS_MD_NONE,
|
||||
hash, sizeof hash, sig, sig_len ) == 0 );
|
||||
@ -1212,17 +1212,17 @@ void pk_rsa_alt( )
|
||||
/* Test decrypt */
|
||||
TEST_ASSERT( mbedtls_pk_encrypt( &rsa, msg, sizeof msg,
|
||||
ciph, &ciph_len, sizeof ciph,
|
||||
rnd_std_rand, NULL ) == 0 );
|
||||
mbedtls_test_rnd_std_rand, NULL ) == 0 );
|
||||
TEST_ASSERT( mbedtls_pk_decrypt( &alt, ciph, ciph_len,
|
||||
test, &test_len, sizeof test,
|
||||
rnd_std_rand, NULL ) == 0 );
|
||||
mbedtls_test_rnd_std_rand, NULL ) == 0 );
|
||||
TEST_ASSERT( test_len == sizeof msg );
|
||||
TEST_ASSERT( memcmp( test, msg, test_len ) == 0 );
|
||||
|
||||
/* Test forbidden operations */
|
||||
TEST_ASSERT( mbedtls_pk_encrypt( &alt, msg, sizeof msg,
|
||||
ciph, &ciph_len, sizeof ciph,
|
||||
rnd_std_rand, NULL ) == ret );
|
||||
mbedtls_test_rnd_std_rand, NULL ) == ret );
|
||||
TEST_ASSERT( mbedtls_pk_verify( &alt, MBEDTLS_MD_NONE,
|
||||
hash, sizeof hash, sig, sig_len ) == ret );
|
||||
TEST_ASSERT( mbedtls_pk_debug( &alt, dbg_items ) == ret );
|
||||
@ -1267,7 +1267,7 @@ void pk_psa_sign( int grpid_arg,
|
||||
mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_gen_key( grpid,
|
||||
(mbedtls_ecp_keypair*) pk.pk_ctx,
|
||||
rnd_std_rand, NULL ) == 0 );
|
||||
mbedtls_test_rnd_std_rand, NULL ) == 0 );
|
||||
|
||||
/* Export underlying public key for re-importing in a legacy context. */
|
||||
ret = mbedtls_pk_write_pubkey_der( &pk, pkey_legacy,
|
||||
|
@ -16,7 +16,7 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
|
||||
{
|
||||
unsigned char output[128];
|
||||
mbedtls_rsa_context ctx;
|
||||
rnd_buf_info info;
|
||||
mbedtls_test_rnd_buf_info info;
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
info.buf = rnd_buf->x;
|
||||
@ -34,7 +34,7 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
|
||||
|
||||
if( message_str->len == 0 )
|
||||
message_str->x = NULL;
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, message_str->len, message_str->x, output ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &mbedtls_test_rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, message_str->len, message_str->x, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
@ -58,7 +58,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
|
||||
unsigned char output[128];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
((void) seed);
|
||||
|
||||
@ -67,7 +67,7 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
@ -81,11 +81,11 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
|
||||
|
||||
if( result_hex_str->len == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, NULL, 0 ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, NULL, 0 ) == result );
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, output, 1000 ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, output, 1000 ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
@ -110,7 +110,7 @@ void pkcs1_v15_decode( int mode,
|
||||
{
|
||||
size_t expected_plaintext_length = expected_plaintext_length_arg;
|
||||
size_t output_size = output_size_arg;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_mpi Nmpi, Empi, Pmpi, Qmpi;
|
||||
mbedtls_rsa_context ctx;
|
||||
static unsigned char N[128] = {
|
||||
@ -176,7 +176,7 @@ void pkcs1_v15_decode( int mode,
|
||||
unsigned char final[128];
|
||||
size_t output_length = 0x7EA0;
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
mbedtls_mpi_init( &Nmpi ); mbedtls_mpi_init( &Empi );
|
||||
mbedtls_mpi_init( &Pmpi ); mbedtls_mpi_init( &Qmpi );
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
@ -196,12 +196,12 @@ void pkcs1_v15_decode( int mode,
|
||||
if( mode == MBEDTLS_RSA_PRIVATE )
|
||||
TEST_ASSERT( mbedtls_rsa_public( &ctx, original, intermediate ) == 0 );
|
||||
else
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
original, intermediate ) == 0 );
|
||||
|
||||
memcpy( final, default_content, sizeof( final ) );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx,
|
||||
&rnd_pseudo_rand, &rnd_info,
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
mode,
|
||||
&output_length,
|
||||
intermediate,
|
||||
@ -260,7 +260,7 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
||||
unsigned char output[128];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
rnd_buf_info info;
|
||||
mbedtls_test_rnd_buf_info info;
|
||||
|
||||
info.buf = rnd_buf->x;
|
||||
info.length = rnd_buf->len;
|
||||
@ -286,7 +286,7 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PRIVATE, digest, 0, hash_result, output ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &mbedtls_test_rnd_buffer_rand, &info, MBEDTLS_RSA_PRIVATE, digest, 0, hash_result, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
|
@ -16,7 +16,7 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char * input_N,
|
||||
{
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
rnd_buf_info info;
|
||||
mbedtls_test_rnd_buf_info info;
|
||||
mbedtls_mpi N, E;
|
||||
|
||||
info.buf = rnd_buf->x;
|
||||
@ -34,7 +34,7 @@ void pkcs1_rsaes_oaep_encrypt( int mod, int radix_N, char * input_N,
|
||||
|
||||
if( message_str->len == 0 )
|
||||
message_str->x = NULL;
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, message_str->len, message_str->x, output ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &mbedtls_test_rnd_buffer_rand, &info, MBEDTLS_RSA_PUBLIC, message_str->len, message_str->x, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, result_hex_str->x,
|
||||
@ -58,7 +58,7 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char * input_P,
|
||||
unsigned char output[64];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
((void) seed);
|
||||
|
||||
@ -68,7 +68,7 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char * input_P,
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V21, hash );
|
||||
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
@ -82,13 +82,13 @@ void pkcs1_rsaes_oaep_decrypt( int mod, int radix_P, char * input_P,
|
||||
|
||||
if( result_hex_str->len == 0 )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PRIVATE, &output_len,
|
||||
message_str->x, NULL, 0 ) == result );
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PRIVATE, &output_len,
|
||||
message_str->x, output,
|
||||
sizeof( output ) ) == result );
|
||||
@ -117,7 +117,7 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
||||
unsigned char hash_result[MBEDTLS_MD_MAX_SIZE];
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
rnd_buf_info info;
|
||||
mbedtls_test_rnd_buf_info info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
|
||||
info.buf = rnd_buf->x;
|
||||
@ -144,7 +144,7 @@ void pkcs1_rsassa_pss_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_buffer_rand, &info, MBEDTLS_RSA_PRIVATE,
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &mbedtls_test_rnd_buffer_rand, &info, MBEDTLS_RSA_PRIVATE,
|
||||
digest, 0, hash_result, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ void rsa_invalid_param( )
|
||||
invalid_padding, 0 ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
|
||||
mbedtls_rsa_gen_key( NULL, rnd_std_rand,
|
||||
mbedtls_rsa_gen_key( NULL, mbedtls_test_rnd_std_rand,
|
||||
NULL, 0, 0 ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_RSA_BAD_INPUT_DATA,
|
||||
mbedtls_rsa_gen_key( &ctx, NULL,
|
||||
@ -476,7 +476,7 @@ void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
@ -484,7 +484,7 @@ void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
|
||||
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
@ -500,7 +500,7 @@ void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
TEST_ASSERT( mbedtls_md( mbedtls_md_info_from_type( digest ), message_str->x, message_str->len, hash_result ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PRIVATE, digest, 0,
|
||||
hash_result, output ) == result );
|
||||
if( result == 0 )
|
||||
@ -561,14 +561,14 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &E );
|
||||
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
@ -581,7 +581,7 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_NONE,
|
||||
hash_result->len, hash_result->x,
|
||||
output ) == 0 );
|
||||
@ -598,7 +598,7 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
||||
memset( output, 0x00, sizeof( output) );
|
||||
|
||||
res = mbedtls_rsa_rsaes_pkcs1_v15_encrypt( &ctx,
|
||||
&rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE,
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE,
|
||||
hash_result->len, hash_result->x, output );
|
||||
|
||||
#if !defined(MBEDTLS_RSA_ALT)
|
||||
@ -694,12 +694,12 @@ void mbedtls_rsa_pkcs1_encrypt( data_t * message_str, int padding_mode,
|
||||
{
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
mbedtls_mpi N, E;
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &E );
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
@ -712,7 +712,7 @@ void mbedtls_rsa_pkcs1_encrypt( data_t * message_str, int padding_mode,
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
MBEDTLS_RSA_PUBLIC, message_str->len,
|
||||
message_str->x, output ) == result );
|
||||
if( result == 0 )
|
||||
@ -751,7 +751,7 @@ void rsa_pkcs1_encrypt_bad_rng( data_t * message_str, int padding_mode,
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL,
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &mbedtls_test_rnd_zero_rand, NULL,
|
||||
MBEDTLS_RSA_PUBLIC, message_str->len,
|
||||
message_str->x, output ) == result );
|
||||
if( result == 0 )
|
||||
@ -778,7 +778,7 @@ void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, int padding_mode,
|
||||
unsigned char output[32];
|
||||
mbedtls_rsa_context ctx;
|
||||
size_t output_len;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
@ -787,7 +787,7 @@ void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, int padding_mode,
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
@ -802,7 +802,7 @@ void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, int padding_mode,
|
||||
|
||||
output_len = 0;
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, output, max_output ) == result );
|
||||
TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, mbedtls_test_rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &output_len, message_str->x, output, max_output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
|
||||
@ -882,7 +882,7 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
||||
unsigned char output[256];
|
||||
mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
|
||||
mbedtls_mpi N, P, Q, E;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
int i;
|
||||
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &P );
|
||||
@ -890,7 +890,7 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
|
||||
memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
@ -907,7 +907,7 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx, rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx, mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
message_str->x, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
@ -926,7 +926,7 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
||||
TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx2 ) == 0 );
|
||||
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx2, rnd_pseudo_rand, &rnd_info,
|
||||
TEST_ASSERT( mbedtls_rsa_private( &ctx2, mbedtls_test_rnd_pseudo_rand, &rnd_info,
|
||||
message_str->x, output ) == result );
|
||||
if( result == 0 )
|
||||
{
|
||||
|
@ -1174,8 +1174,8 @@ static int build_transforms( mbedtls_ssl_transform *t_in,
|
||||
unsigned char cid0[ SSL_CID_LEN_MIN ];
|
||||
unsigned char cid1[ SSL_CID_LEN_MIN ];
|
||||
|
||||
rnd_std_rand( NULL, cid0, sizeof( cid0 ) );
|
||||
rnd_std_rand( NULL, cid1, sizeof( cid1 ) );
|
||||
mbedtls_test_rnd_std_rand( NULL, cid0, sizeof( cid0 ) );
|
||||
mbedtls_test_rnd_std_rand( NULL, cid1, sizeof( cid1 ) );
|
||||
#else
|
||||
((void) cid0_len);
|
||||
((void) cid1_len);
|
||||
@ -3185,7 +3185,7 @@ void ssl_crypt_record( int cipher_type, int hash_id,
|
||||
|
||||
/* Encrypt record */
|
||||
ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec,
|
||||
rnd_std_rand, NULL );
|
||||
mbedtls_test_rnd_std_rand, NULL );
|
||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||
if( ret != 0 )
|
||||
{
|
||||
@ -3339,7 +3339,7 @@ void ssl_crypt_record_small( int cipher_type, int hash_id,
|
||||
rec_backup = rec;
|
||||
|
||||
/* Encrypt record */
|
||||
ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec, rnd_std_rand, NULL );
|
||||
ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec, mbedtls_test_rnd_std_rand, NULL );
|
||||
|
||||
if( ( mode == 1 || mode == 2 ) && seen_success )
|
||||
{
|
||||
|
@ -94,9 +94,9 @@ void x509_csr_check( char * key_file, char * cert_req_check_file, int md_type,
|
||||
int der_len = -1;
|
||||
FILE *f;
|
||||
const char *subject_name = "C=NL,O=PolarSSL,CN=PolarSSL Server 1";
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
memset( &rnd_info, 0x2a, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x2a, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
mbedtls_pk_init( &key );
|
||||
TEST_ASSERT( mbedtls_pk_parse_keyfile( &key, key_file, NULL ) == 0 );
|
||||
@ -111,7 +111,7 @@ void x509_csr_check( char * key_file, char * cert_req_check_file, int md_type,
|
||||
TEST_ASSERT( mbedtls_x509write_csr_set_ns_cert_type( &req, cert_type ) == 0 );
|
||||
|
||||
ret = mbedtls_x509write_csr_pem( &req, buf, sizeof( buf ),
|
||||
rnd_pseudo_rand, &rnd_info );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
pem_len = strlen( (char *) buf );
|
||||
@ -125,14 +125,14 @@ void x509_csr_check( char * key_file, char * cert_req_check_file, int md_type,
|
||||
TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
|
||||
|
||||
der_len = mbedtls_x509write_csr_der( &req, buf, sizeof( buf ),
|
||||
rnd_pseudo_rand, &rnd_info );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info );
|
||||
TEST_ASSERT( der_len >= 0 );
|
||||
|
||||
if( der_len == 0 )
|
||||
goto exit;
|
||||
|
||||
ret = mbedtls_x509write_csr_der( &req, buf, (size_t)( der_len - 1 ),
|
||||
rnd_pseudo_rand, &rnd_info );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info );
|
||||
TEST_ASSERT( ret == MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
||||
exit:
|
||||
@ -153,10 +153,10 @@ void x509_csr_check_opaque( char *key_file, int md_type, int key_usage,
|
||||
int ret;
|
||||
size_t pem_len = 0;
|
||||
const char *subject_name = "C=NL,O=PolarSSL,CN=PolarSSL Server 1";
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
psa_crypto_init();
|
||||
memset( &rnd_info, 0x2a, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x2a, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
|
||||
md_alg_psa = mbedtls_psa_translate_md( (mbedtls_md_type_t) md_type );
|
||||
TEST_ASSERT( md_alg_psa != MBEDTLS_MD_NONE );
|
||||
@ -175,7 +175,7 @@ void x509_csr_check_opaque( char *key_file, int md_type, int key_usage,
|
||||
TEST_ASSERT( mbedtls_x509write_csr_set_ns_cert_type( &req, cert_type ) == 0 );
|
||||
|
||||
ret = mbedtls_x509write_csr_pem( &req, buf, sizeof( buf ) - 1,
|
||||
rnd_pseudo_rand, &rnd_info );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
pem_len = strlen( (char *) buf );
|
||||
@ -208,9 +208,9 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
size_t olen = 0, pem_len = 0;
|
||||
int der_len = -1;
|
||||
FILE *f;
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_test_rnd_pseudo_info rnd_info;
|
||||
|
||||
memset( &rnd_info, 0x2a, sizeof( rnd_pseudo_info ) );
|
||||
memset( &rnd_info, 0x2a, sizeof( mbedtls_test_rnd_pseudo_info ) );
|
||||
mbedtls_mpi_init( &serial );
|
||||
|
||||
mbedtls_pk_init( &subject_key );
|
||||
@ -269,7 +269,7 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
}
|
||||
|
||||
ret = mbedtls_x509write_crt_pem( &crt, buf, sizeof( buf ),
|
||||
rnd_pseudo_rand, &rnd_info );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info );
|
||||
TEST_ASSERT( ret == 0 );
|
||||
|
||||
pem_len = strlen( (char *) buf );
|
||||
@ -284,14 +284,14 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
|
||||
|
||||
der_len = mbedtls_x509write_crt_der( &crt, buf, sizeof( buf ),
|
||||
rnd_pseudo_rand, &rnd_info );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info );
|
||||
TEST_ASSERT( der_len >= 0 );
|
||||
|
||||
if( der_len == 0 )
|
||||
goto exit;
|
||||
|
||||
ret = mbedtls_x509write_crt_der( &crt, buf, (size_t)( der_len - 1 ),
|
||||
rnd_pseudo_rand, &rnd_info );
|
||||
mbedtls_test_rnd_pseudo_rand, &rnd_info );
|
||||
TEST_ASSERT( ret == MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
||||
exit:
|
||||
|
Loading…
Reference in New Issue
Block a user