mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-14 01:26:49 +00:00
Add test for ECP export
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
parent
711d0f5e29
commit
4b30feb32e
@ -882,3 +882,11 @@ fix_negative:"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff":
|
||||
# The first call to fix_negative in the test case of issue #4296.
|
||||
ECP fix_negative: #4296.1
|
||||
fix_negative:"8A4DD4C8B42C5EAED15FE4F4579F4CE513EC90A94010BF000000000000000000":-1:256
|
||||
|
||||
ECP export key parameters #1 (OK)
|
||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
ecp_export:MBEDTLS_ECP_DP_SECP256R1:"37cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f76822596292":"4ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edff":"00f12a1320760270a83cbffd53f6031ef76a5d86c8a204f2c30ca9ebf51f0f0ea7":0:0
|
||||
|
||||
ECP export key parameters #2 (invalid group)
|
||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
ecp_export:MBEDTLS_ECP_DP_SECP256R1:"37cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f76822596292":"4ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edff":"00f12a1320760270a83cbffd53f6031ef76a5d86c8a204f2c30ca9ebf51f0f0ea7":MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE:1
|
@ -16,6 +16,44 @@
|
||||
mbedtls_ecp_point_free( x ); \
|
||||
mbedtls_ecp_point_init( x );
|
||||
|
||||
/* Auxiliary function to compare two mbedtls_ecp_group objects. */
|
||||
inline static int mbedtls_ecp_group_cmp( mbedtls_ecp_group *P,
|
||||
mbedtls_ecp_group *Q )
|
||||
{
|
||||
if( mbedtls_mpi_cmp_mpi( &P->P, &Q->P ) != 0 )
|
||||
return 1;
|
||||
if( mbedtls_mpi_cmp_mpi( &P->A, &Q->A ) != 0 )
|
||||
return 1;
|
||||
if( mbedtls_mpi_cmp_mpi( &P->B, &Q->B ) != 0 )
|
||||
return 1;
|
||||
if( mbedtls_mpi_cmp_mpi( &P->N, &Q->N ) != 0 )
|
||||
return 1;
|
||||
if( mbedtls_ecp_point_cmp( &P->G, &Q->G ) != 0 )
|
||||
return 1;
|
||||
if( P->id != Q->id )
|
||||
return 1;
|
||||
if( P->pbits != Q->pbits )
|
||||
return 1;
|
||||
if( P->nbits != Q->nbits )
|
||||
return 1;
|
||||
if( P->h != Q->h )
|
||||
return 1;
|
||||
if( P->modp != Q->modp )
|
||||
return 1;
|
||||
if( P->t_pre != Q->t_pre )
|
||||
return 1;
|
||||
if( P->t_post != Q->t_post )
|
||||
return 1;
|
||||
if( P->t_data != Q->t_data )
|
||||
return 1;
|
||||
if( P->T_size != Q->T_size )
|
||||
return 1;
|
||||
if( P->T != Q->T )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
@ -988,3 +1026,40 @@ void ecp_selftest( )
|
||||
TEST_ASSERT( mbedtls_ecp_self_test( 1 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecp_export( int id, char * Qx, char * Qy,char * d, int expected_ret, int invalid_grp )
|
||||
{
|
||||
mbedtls_ecp_keypair key;
|
||||
mbedtls_ecp_group export_grp;
|
||||
mbedtls_mpi export_d;
|
||||
mbedtls_ecp_point export_Q;
|
||||
|
||||
mbedtls_ecp_group_init( &export_grp );
|
||||
mbedtls_ecp_group_init( &key.grp );
|
||||
mbedtls_mpi_init( &export_d );
|
||||
mbedtls_ecp_point_init( &export_Q );
|
||||
|
||||
mbedtls_ecp_keypair_init( &key );
|
||||
if( invalid_grp == 0 )
|
||||
TEST_ASSERT( mbedtls_ecp_group_load( &key.grp, id ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecp_point_read_string( &key.Q, 16, Qx, Qy ) == 0 );
|
||||
TEST_ASSERT( mbedtls_test_read_mpi( &key.d, 16, d ) == 0 );
|
||||
|
||||
TEST_EQUAL( mbedtls_ecp_export( &key, &export_grp,
|
||||
&export_d, &export_Q ), expected_ret );
|
||||
|
||||
if( expected_ret == 0 )
|
||||
{
|
||||
TEST_EQUAL( mbedtls_ecp_point_cmp( &key.Q, &export_Q ), 0 );
|
||||
TEST_EQUAL( mbedtls_mpi_cmp_mpi( &key.d, &export_d ), 0 );
|
||||
TEST_EQUAL( mbedtls_ecp_group_cmp( &key.grp, &export_grp ), 0 );
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_ecp_keypair_free( &key );
|
||||
mbedtls_ecp_group_free( &export_grp );
|
||||
mbedtls_mpi_free( &export_d );
|
||||
mbedtls_ecp_point_free( &export_Q );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
x
Reference in New Issue
Block a user