mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 03:05:43 +01:00
Use mbedtls_test_read_mpi in test suites
Replace calls to mbedtls_mpi_read_string() with a wrapper mbedtls_test_read_mpi() when reading test data except for the purpose of testing mbedtls_mpi_read_string() itself. The wrapper lets the test data control precisely how many limbs the constructed MPI has. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
db4797198a
commit
a0f4e10e61
@ -417,7 +417,7 @@ void get_integer( const data_t *input,
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
ret = mbedtls_mpi_read_string( &expected_mpi, 16, expected_hex );
|
||||
ret = mbedtls_test_read_mpi( &expected_mpi, 16, expected_hex );
|
||||
TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
if( ret == MBEDTLS_ERR_MPI_BAD_INPUT_DATA )
|
||||
{
|
||||
|
@ -179,9 +179,7 @@ void mbedtls_debug_print_mpi( int radix, char * value, char * file, int line,
|
||||
|
||||
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
||||
|
||||
/* If value is empty, keep val->n == 0. */
|
||||
if( value[0] != 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &val, radix, value ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &val, radix, value ) == 0 );
|
||||
|
||||
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
||||
|
||||
|
@ -206,8 +206,8 @@ void dhm_do_dhm( int radix_P, char *input_P, int x_size,
|
||||
/*
|
||||
* Set params
|
||||
*/
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx_srv.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx_srv.G, radix_G, input_G ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx_srv.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx_srv.G, radix_G, input_G ) == 0 );
|
||||
pub_cli_len = mbedtls_mpi_size( &ctx_srv.P );
|
||||
|
||||
/*
|
||||
@ -307,7 +307,7 @@ void dhm_make_public( int P_bytes, int radix_G, char *input_G, int result )
|
||||
TEST_ASSERT( mbedtls_mpi_shift_l( &P, ( P_bytes * 8 ) - 1 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_set_bit( &P, 0, 1 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &G, radix_G, input_G ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &G, radix_G, input_G ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_set_group( &ctx, &P, &G ) == 0 );
|
||||
TEST_ASSERT( mbedtls_dhm_make_public( &ctx, (int) mbedtls_mpi_size( &P ),
|
||||
@ -331,8 +331,8 @@ void dhm_file( char * filename, char * p, char * g, int len )
|
||||
mbedtls_dhm_init( &ctx );
|
||||
mbedtls_mpi_init( &P ); mbedtls_mpi_init( &G );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, 16, p ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &G, 16, g ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, 16, p ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &G, 16, g ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_dhm_parse_dhmfile( &ctx, filename ) == 0 );
|
||||
|
||||
|
@ -278,21 +278,21 @@ void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
|
||||
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_test_read_mpi( &check, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.X, &check ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.Y, &check ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB,
|
||||
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_test_read_mpi( &check, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.X, &check ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.Y, &check ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, z_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &check, 16, z_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA, NULL, NULL ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zA, &check ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB, NULL, NULL ) == 0 );
|
||||
|
@ -289,9 +289,9 @@ void ecdsa_prim_test_vectors( int id, char * d_str, char * xQ_str,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_string( &Q, 16, xQ_str, yQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &s_check, 16, s_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &s_check, 16, s_str ) == 0 );
|
||||
rnd_info.fallback_f_rng = mbedtls_test_rnd_std_rand;
|
||||
rnd_info.fallback_p_rng = NULL;
|
||||
rnd_info.buf = rnd_buf->x;
|
||||
@ -354,9 +354,9 @@ void ecdsa_det_test_vectors( int id, char * d_str, int md_alg, char * msg,
|
||||
memset( hash, 0, sizeof( hash ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &s_check, 16, s_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &r_check, 16, r_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &s_check, 16, s_str ) == 0 );
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
@ -585,7 +585,7 @@ void ecdsa_write_restart( int id, char *d_str, int md_alg,
|
||||
memset( sig, 0, sizeof( sig ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &ctx.grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.d, 16, d_str ) == 0 );
|
||||
|
||||
md_info = mbedtls_md_info_from_type( md_alg );
|
||||
TEST_ASSERT( md_info != NULL );
|
||||
|
@ -401,9 +401,9 @@ void ecp_check_pub( int grp_id, char * x_hex, char * y_hex, char * z_hex,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, grp_id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.X, 16, x_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Y, 16, y_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Z, 16, z_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.X, 16, x_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Y, 16, y_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Z, 16, z_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &P ) == ret );
|
||||
|
||||
@ -452,13 +452,13 @@ void ecp_test_vect_restart( int id,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yA, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yA, 16, yA_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yZ, 16, yZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yZ, 16, yZ_str ) == 0 );
|
||||
|
||||
mbedtls_ecp_set_max_ops( (unsigned) max_ops );
|
||||
|
||||
@ -536,13 +536,13 @@ void ecp_muladd_restart( int id, char *xR_str, char *yR_str,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &u1, 16, u1_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &u2, 16, u2_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xR, 16, xR_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yR, 16, yR_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &u1, 16, u1_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &u2, 16, u2_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xR, 16, xR_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yR, 16, yR_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q.X, 16, xQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q.Y, 16, yQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q.X, 16, xQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q.Y, 16, yQ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_lset( &Q.Z, 1 ) == 0 );
|
||||
|
||||
mbedtls_ecp_set_max_ops( (unsigned) max_ops );
|
||||
@ -599,14 +599,14 @@ void ecp_test_vect( int id, char * dA_str, char * xA_str, char * yA_str,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yA, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xB, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yB, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &yZ, 16, yZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dA, 16, dA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xA, 16, xA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yA, 16, yA_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dB, 16, dB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xB, 16, xB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yB, 16, yB_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xZ, 16, xZ_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &yZ, 16, yZ_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
@ -654,11 +654,11 @@ void ecp_test_vec_x( int id, char * dA_hex, char * xA_hex, char * dB_hex,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pubkey( &grp, &grp.G ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dA, 16, dA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &dB, 16, dB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xA, 16, xA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xB, 16, xB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &xS, 16, xS_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dA, 16, dA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &dB, 16, dB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xA, 16, xA_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xB, 16, xB_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &xS, 16, xS_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_mul( &grp, &R, &dA, &grp.G,
|
||||
&mbedtls_test_rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
@ -817,7 +817,7 @@ void ecp_fast_mod( int id, char * N_str )
|
||||
mbedtls_mpi_init( &N ); mbedtls_mpi_init( &R );
|
||||
mbedtls_ecp_group_init( &grp );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, 16, N_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, 16, N_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( grp.modp != NULL );
|
||||
|
||||
@ -856,9 +856,9 @@ void ecp_write_binary( int id, char * x, char * y, char * z, int format,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P.Z, 16, z ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P.Z, 16, z ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_point_write_binary( &grp, &P, format,
|
||||
&olen, buf, blen ) == ret );
|
||||
@ -887,9 +887,9 @@ void ecp_read_binary( int id, data_t * buf, char * x, char * y, char * z,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Z, 16, z ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_binary( &grp, &P, buf->x, buf->len ) == ret );
|
||||
|
||||
@ -931,9 +931,9 @@ void mbedtls_ecp_tls_read_point( int id, data_t * buf, char * x, char * y,
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Z, 16, z ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Z, 16, z ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_tls_read_point( &grp, &P, &vbuf, buf->len ) == ret );
|
||||
|
||||
@ -1068,7 +1068,7 @@ void mbedtls_ecp_check_privkey( int id, char * key_hex, int ret )
|
||||
mbedtls_mpi_init( &d );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &d, 16, key_hex ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &d, 16, key_hex ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_privkey( &grp, &d ) == ret );
|
||||
|
||||
@ -1095,7 +1095,7 @@ void mbedtls_ecp_check_pub_priv( int id_pub, char * Qx_pub, char * Qy_pub,
|
||||
if( id != MBEDTLS_ECP_DP_NONE )
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &prv.grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_string( &prv.Q, 16, Qx, Qy ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.d, 16, d ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.d, 16, d ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ecp_check_pub_priv( &pub, &prv ) == ret );
|
||||
|
||||
|
@ -429,7 +429,7 @@ void mbedtls_mpi_write_binary( int radix_X, char * input_X,
|
||||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
buflen = mbedtls_mpi_size( &X );
|
||||
if( buflen > (size_t) output_size )
|
||||
@ -461,7 +461,7 @@ void mbedtls_mpi_write_binary_le( int radix_X, char * input_X,
|
||||
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
buflen = mbedtls_mpi_size( &X );
|
||||
if( buflen > (size_t) output_size )
|
||||
@ -525,7 +525,7 @@ void mbedtls_mpi_write_file( int radix_X, char * input_X, int output_radix,
|
||||
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
file_out = fopen( output_file, "w" );
|
||||
TEST_ASSERT( file_out != NULL );
|
||||
@ -551,7 +551,7 @@ void mbedtls_mpi_get_bit( int radix_X, char * input_X, int pos, int val )
|
||||
{
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_get_bit( &X, pos ) == val );
|
||||
|
||||
exit:
|
||||
@ -566,8 +566,8 @@ void mbedtls_mpi_set_bit( int radix_X, char * input_X, int pos, int val,
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, output_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, output_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_set_bit( &X, pos, val ) == result );
|
||||
|
||||
if( result == 0 )
|
||||
@ -586,7 +586,7 @@ void mbedtls_mpi_lsb( int radix_X, char * input_X, int nr_bits )
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_lsb( &X ) == (size_t) nr_bits );
|
||||
|
||||
exit:
|
||||
@ -600,7 +600,7 @@ void mbedtls_mpi_bitlen( int radix_X, char * input_X, int nr_bits )
|
||||
mbedtls_mpi X;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_bitlen( &X ) == (size_t) nr_bits );
|
||||
|
||||
exit:
|
||||
@ -615,9 +615,9 @@ void mbedtls_mpi_gcd( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi A, X, Y, Z;
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_gcd( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
@ -647,8 +647,8 @@ void mbedtls_mpi_cmp_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == input_A );
|
||||
|
||||
exit:
|
||||
@ -666,8 +666,8 @@ void mbedtls_mpi_lt_mpi_ct( int size_X, char * input_X,
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, input_Y ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_grow( &X, size_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_grow( &Y, size_Y ) == 0 );
|
||||
@ -688,8 +688,8 @@ void mbedtls_mpi_cmp_abs( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi X, Y;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_abs( &X, &Y ) == input_A );
|
||||
|
||||
exit:
|
||||
@ -774,9 +774,9 @@ void mbedtls_mpi_safe_cond_assign( int x_sign, char * x_str, int y_sign,
|
||||
mbedtls_mpi X, Y, XX;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &XX );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, x_str ) == 0 );
|
||||
X.s = x_sign;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, y_str ) == 0 );
|
||||
Y.s = y_sign;
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &XX, &X ) == 0 );
|
||||
|
||||
@ -800,9 +800,9 @@ void mbedtls_mpi_safe_cond_swap( int x_sign, char * x_str, int y_sign,
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
|
||||
mbedtls_mpi_init( &XX ); mbedtls_mpi_init( &YY );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, 16, x_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, 16, x_str ) == 0 );
|
||||
X.s = x_sign;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, 16, y_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, 16, y_str ) == 0 );
|
||||
Y.s = y_sign;
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_copy( &XX, &X ) == 0 );
|
||||
@ -888,16 +888,16 @@ void mbedtls_mpi_add_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
/* result == first operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &X, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &Y, &X, &Y ) == 0 );
|
||||
@ -915,17 +915,17 @@ void mbedtls_mpi_add_mpi_inplace( int radix_X, char * input_X, int radix_A,
|
||||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_sub_abs( &X, &X, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_int( &X, 0 ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &X, &X, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_mpi( &X, &X, &X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
@ -942,16 +942,16 @@ void mbedtls_mpi_add_abs( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
/* result == first operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &X, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_add_abs( &Y, &X, &Y ) == 0 );
|
||||
@ -969,8 +969,8 @@ void mbedtls_mpi_add_int( int radix_X, char * input_X, int input_Y,
|
||||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_add_int( &Z, &X, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
@ -986,16 +986,16 @@ void mbedtls_mpi_sub_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_sub_mpi( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
/* result == first operand */
|
||||
TEST_ASSERT( mbedtls_mpi_sub_mpi( &X, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_sub_mpi( &Y, &X, &Y ) == 0 );
|
||||
@ -1015,9 +1015,9 @@ void mbedtls_mpi_sub_abs( int radix_X, char * input_X, int radix_Y,
|
||||
int res;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
|
||||
res = mbedtls_mpi_sub_abs( &Z, &X, &Y );
|
||||
TEST_ASSERT( res == sub_result );
|
||||
@ -1028,7 +1028,7 @@ void mbedtls_mpi_sub_abs( int radix_X, char * input_X, int radix_Y,
|
||||
TEST_ASSERT( mbedtls_mpi_sub_abs( &X, &X, &Y ) == sub_result );
|
||||
if( sub_result == 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
/* result == second operand */
|
||||
TEST_ASSERT( mbedtls_mpi_sub_abs( &Y, &X, &Y ) == sub_result );
|
||||
@ -1047,8 +1047,8 @@ void mbedtls_mpi_sub_int( int radix_X, char * input_X, int input_Y,
|
||||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_sub_int( &Z, &X, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
@ -1064,9 +1064,9 @@ void mbedtls_mpi_mul_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi X, Y, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_mul_mpi( &Z, &X, &Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
|
||||
@ -1083,8 +1083,8 @@ void mbedtls_mpi_mul_int( int radix_X, char * input_X, int input_Y,
|
||||
mbedtls_mpi X, Z, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_mul_int( &Z, &X, input_Y ) == 0 );
|
||||
if( strcmp( result_comparison, "==" ) == 0 )
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &Z, &A ) == 0 );
|
||||
@ -1108,10 +1108,10 @@ void mbedtls_mpi_div_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &R );
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &B );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &B, radix_B, input_B ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &B, radix_B, input_B ) == 0 );
|
||||
res = mbedtls_mpi_div_mpi( &Q, &R, &X, &Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
@ -1136,9 +1136,9 @@ void mbedtls_mpi_div_int( int radix_X, char * input_X, int input_Y,
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &R ); mbedtls_mpi_init( &A );
|
||||
mbedtls_mpi_init( &B );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &B, radix_B, input_B ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &B, radix_B, input_B ) == 0 );
|
||||
res = mbedtls_mpi_div_int( &Q, &R, &X, input_Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
@ -1162,9 +1162,9 @@ void mbedtls_mpi_mod_mpi( int radix_X, char * input_X, int radix_Y,
|
||||
int res;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
res = mbedtls_mpi_mod_mpi( &X, &X, &Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
@ -1186,7 +1186,7 @@ void mbedtls_mpi_mod_int( int radix_X, char * input_X, int input_Y,
|
||||
mbedtls_mpi_uint r;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
res = mbedtls_mpi_mod_int( &r, &X, input_Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
@ -1210,13 +1210,13 @@ void mbedtls_mpi_exp_mod( int radix_A, char * input_A, int radix_E,
|
||||
mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N );
|
||||
mbedtls_mpi_init( &RR ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
|
||||
if( strlen( input_RR ) )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &RR, radix_RR, input_RR ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &RR, radix_RR, input_RR ) == 0 );
|
||||
|
||||
res = mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR );
|
||||
TEST_ASSERT( res == div_result );
|
||||
@ -1255,7 +1255,7 @@ void mbedtls_mpi_exp_mod_size( int A_bytes, int E_bytes, int N_bytes,
|
||||
TEST_ASSERT( mbedtls_mpi_set_bit( &N, 0, 1 ) == 0 );
|
||||
|
||||
if( strlen( input_RR ) )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &RR, radix_RR, input_RR ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &RR, radix_RR, input_RR ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_exp_mod( &Z, &A, &E, &N, &RR ) == exp_result );
|
||||
|
||||
@ -1274,9 +1274,9 @@ void mbedtls_mpi_inv_mod( int radix_X, char * input_X, int radix_Y,
|
||||
int res;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Y, radix_Y, input_Y ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
res = mbedtls_mpi_inv_mod( &Z, &X, &Y );
|
||||
TEST_ASSERT( res == div_result );
|
||||
if( res == 0 )
|
||||
@ -1296,7 +1296,7 @@ void mbedtls_mpi_is_prime( int radix_X, char * input_X, int div_result )
|
||||
int res;
|
||||
mbedtls_mpi_init( &X );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
res = mbedtls_mpi_is_prime_ext( &X, 40, mbedtls_test_rnd_std_rand, NULL );
|
||||
TEST_ASSERT( res == div_result );
|
||||
|
||||
@ -1382,8 +1382,8 @@ void mbedtls_mpi_shift_l( int radix_X, char * input_X, int shift_X,
|
||||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_shift_l( &X, shift_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
@ -1399,8 +1399,8 @@ void mbedtls_mpi_shift_r( int radix_X, char * input_X, int shift_X,
|
||||
mbedtls_mpi X, A;
|
||||
mbedtls_mpi_init( &X ); mbedtls_mpi_init( &A );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &X, radix_X, input_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &A, radix_A, input_A ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_shift_r( &X, shift_X ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &A ) == 0 );
|
||||
|
||||
|
@ -670,8 +670,8 @@ void pk_rsa_verify_test_vec( data_t * message_str, int digest, int mod,
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
rsa->len = mod / 8;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, radix_E, input_E ) == 0 );
|
||||
|
||||
|
||||
if( mbedtls_md_info_from_type( digest ) != NULL )
|
||||
@ -713,8 +713,8 @@ void pk_rsa_verify_ext_test_vec( data_t * message_str, int digest,
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
rsa->len = mod / 8;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, radix_E, input_E ) == 0 );
|
||||
|
||||
|
||||
if( digest != MBEDTLS_MD_NONE )
|
||||
@ -801,7 +801,7 @@ void pk_sign_verify_restart( int pk_type, int grp_id, char *d_str,
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &prv, mbedtls_pk_info_from_type( pk_type ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &mbedtls_pk_ec( prv )->grp, grp_id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &mbedtls_pk_ec( prv )->d, 16, d_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &mbedtls_pk_ec( prv )->d, 16, d_str ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_setup( &pub, mbedtls_pk_info_from_type( pk_type ) ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &mbedtls_pk_ec( pub )->grp, grp_id ) == 0 );
|
||||
@ -985,8 +985,8 @@ void pk_rsa_encrypt_test_vec( data_t * message, int mod, int radix_N,
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
rsa->len = mod / 8;
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &rsa->E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &rsa->E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_pk_encrypt( &pk, message->x, message->len,
|
||||
output, &olen, sizeof( output ),
|
||||
@ -1024,12 +1024,12 @@ void pk_rsa_decrypt_test_vec( data_t * cipher, int mod, int radix_P,
|
||||
rsa = mbedtls_pk_rsa( pk );
|
||||
|
||||
/* load public key */
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
/* load private key */
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( rsa, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( rsa ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_complete( rsa ) == 0 );
|
||||
|
@ -28,8 +28,8 @@ void pkcs1_rsaes_v15_encrypt( int mod, int radix_N, char * input_N,
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
@ -76,10 +76,10 @@ void pkcs1_rsaes_v15_decrypt( int mod, int radix_P, char * input_P,
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
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 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
@ -289,10 +289,10 @@ void pkcs1_rsassa_v15_sign( int mod, int radix_P, char * input_P, int radix_Q,
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
@ -335,8 +335,8 @@ void pkcs1_rsassa_v15_verify( int mod, int radix_N, char * input_N,
|
||||
mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, hash );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( ( mod + 7 ) / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
|
@ -532,10 +532,10 @@ void mbedtls_rsa_pkcs1_sign( data_t * message_str, int padding_mode,
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
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 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -578,8 +578,8 @@ void mbedtls_rsa_pkcs1_verify( data_t * message_str, int padding_mode,
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( hash_result, 0x00, sizeof( hash_result ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
|
||||
@ -616,10 +616,10 @@ void rsa_pkcs1_sign_raw( data_t * hash_result,
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
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 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -687,8 +687,8 @@ void rsa_pkcs1_verify_raw( data_t * hash_result,
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -751,8 +751,8 @@ void mbedtls_rsa_pkcs1_encrypt( data_t * message_str, int padding_mode,
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -792,8 +792,8 @@ void rsa_pkcs1_encrypt_bad_rng( data_t * message_str, int padding_mode,
|
||||
mbedtls_rsa_init( &ctx, padding_mode, 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -840,10 +840,10 @@ void mbedtls_rsa_pkcs1_decrypt( data_t * message_str, int padding_mode,
|
||||
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 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -886,8 +886,8 @@ void mbedtls_rsa_public( data_t * message_str, int mod, int radix_N,
|
||||
mbedtls_rsa_init( &ctx2, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -945,10 +945,10 @@ void mbedtls_rsa_private( data_t * message_str, int mod, int radix_P,
|
||||
|
||||
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 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, &P, &Q, NULL, &E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_rsa_get_len( &ctx ) == (size_t) ( mod / 8 ) );
|
||||
@ -1021,11 +1021,11 @@ void mbedtls_rsa_check_pubkey( int radix_N, char * input_N, int radix_E,
|
||||
|
||||
if( strlen( input_N ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
}
|
||||
if( strlen( input_E ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
}
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx, &N, NULL, NULL, NULL, &E ) == 0 );
|
||||
@ -1053,36 +1053,36 @@ void mbedtls_rsa_check_privkey( int mod, int radix_P, char * input_P,
|
||||
ctx.len = mod / 8;
|
||||
if( strlen( input_P ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.P, radix_P, input_P ) == 0 );
|
||||
}
|
||||
if( strlen( input_Q ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.Q, radix_Q, input_Q ) == 0 );
|
||||
}
|
||||
if( strlen( input_N ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.N, radix_N, input_N ) == 0 );
|
||||
}
|
||||
if( strlen( input_E ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.E, radix_E, input_E ) == 0 );
|
||||
}
|
||||
if( strlen( input_D ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.D, radix_D, input_D ) == 0 );
|
||||
}
|
||||
#if !defined(MBEDTLS_RSA_NO_CRT)
|
||||
if( strlen( input_DP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.DP, radix_DP, input_DP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.DP, radix_DP, input_DP ) == 0 );
|
||||
}
|
||||
if( strlen( input_DQ ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
}
|
||||
if( strlen( input_QP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &ctx.QP, radix_QP, input_QP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &ctx.QP, radix_QP, input_QP ) == 0 );
|
||||
}
|
||||
#else
|
||||
((void) radix_DP); ((void) input_DP);
|
||||
@ -1117,45 +1117,45 @@ void rsa_check_pubpriv( int mod, int radix_Npub, char * input_Npub,
|
||||
|
||||
if( strlen( input_Npub ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &pub.N, radix_Npub, input_Npub ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &pub.N, radix_Npub, input_Npub ) == 0 );
|
||||
}
|
||||
if( strlen( input_Epub ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &pub.E, radix_Epub, input_Epub ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &pub.E, radix_Epub, input_Epub ) == 0 );
|
||||
}
|
||||
|
||||
if( strlen( input_P ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.P, radix_P, input_P ) == 0 );
|
||||
}
|
||||
if( strlen( input_Q ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.Q, radix_Q, input_Q ) == 0 );
|
||||
}
|
||||
if( strlen( input_N ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.N, radix_N, input_N ) == 0 );
|
||||
}
|
||||
if( strlen( input_E ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.E, radix_E, input_E ) == 0 );
|
||||
}
|
||||
if( strlen( input_D ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.D, radix_D, input_D ) == 0 );
|
||||
}
|
||||
#if !defined(MBEDTLS_RSA_NO_CRT)
|
||||
if( strlen( input_DP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.DP, radix_DP, input_DP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.DP, radix_DP, input_DP ) == 0 );
|
||||
}
|
||||
if( strlen( input_DQ ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.DQ, radix_DQ, input_DQ ) == 0 );
|
||||
}
|
||||
if( strlen( input_QP ) )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &prv.QP, radix_QP, input_QP ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &prv.QP, radix_QP, input_QP ) == 0 );
|
||||
}
|
||||
#else
|
||||
((void) radix_DP); ((void) input_DP);
|
||||
@ -1216,11 +1216,11 @@ void mbedtls_rsa_deduce_primes( int radix_N, char *input_N,
|
||||
mbedtls_mpi_init( &Pp ); mbedtls_mpi_init( &Qp );
|
||||
mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Qp, radix_P, output_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Pp, radix_Q, output_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Qp, radix_P, output_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Pp, radix_Q, output_Q ) == 0 );
|
||||
|
||||
if( corrupt )
|
||||
TEST_ASSERT( mbedtls_mpi_add_int( &D, &D, 2 ) == 0 );
|
||||
@ -1257,10 +1257,10 @@ void mbedtls_rsa_deduce_private_exponent( int radix_P, char *input_P,
|
||||
mbedtls_mpi_init( &E );
|
||||
mbedtls_mpi_init( &R ); mbedtls_mpi_init( &Rp );
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Dp, radix_D, output_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Dp, radix_D, output_D ) == 0 );
|
||||
|
||||
if( corrupt )
|
||||
{
|
||||
@ -1343,19 +1343,19 @@ void mbedtls_rsa_import( int radix_N, char *input_N,
|
||||
(const unsigned char *) pers, strlen( pers ) ) == 0 );
|
||||
|
||||
if( have_N )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
|
||||
if( have_P )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
|
||||
if( have_Q )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
||||
if( have_D )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
|
||||
if( have_E )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
if( !successive )
|
||||
{
|
||||
@ -1487,19 +1487,19 @@ void mbedtls_rsa_export( int radix_N, char *input_N,
|
||||
/* Setup RSA context */
|
||||
|
||||
if( have_N )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
|
||||
if( have_P )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
|
||||
if( have_Q )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
||||
if( have_D )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
|
||||
if( have_E )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_import( &ctx,
|
||||
strlen( input_N ) ? &N : NULL,
|
||||
@ -1607,19 +1607,19 @@ void mbedtls_rsa_validate_params( int radix_N, char *input_N,
|
||||
strlen( pers ) ) == 0 );
|
||||
|
||||
if( have_N )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &N, radix_N, input_N ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &N, radix_N, input_N ) == 0 );
|
||||
|
||||
if( have_P )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &P, radix_P, input_P ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &P, radix_P, input_P ) == 0 );
|
||||
|
||||
if( have_Q )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &Q, radix_Q, input_Q ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &Q, radix_Q, input_Q ) == 0 );
|
||||
|
||||
if( have_D )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &D, radix_D, input_D ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &D, radix_D, input_D ) == 0 );
|
||||
|
||||
if( have_E )
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &E, radix_E, input_E ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &E, radix_E, input_E ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_rsa_validate_params( have_N ? &N : NULL,
|
||||
have_P ? &P : NULL,
|
||||
|
@ -246,7 +246,7 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
|
||||
(void) rsa_alt;
|
||||
#endif
|
||||
|
||||
TEST_ASSERT( mbedtls_mpi_read_string( &serial, 10, serial_str ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &serial, 10, serial_str ) == 0 );
|
||||
|
||||
if( ver != -1 )
|
||||
mbedtls_x509write_crt_set_version( &crt, ver );
|
||||
|
Loading…
Reference in New Issue
Block a user