diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fda5bd36b..863d7a5a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -46,6 +46,7 @@ add_test_suite(debug) add_test_suite(des) add_test_suite(dhm) add_test_suite(ecp) +add_test_suite(ecdh) add_test_suite(error) add_test_suite(gcm gcm.encrypt) add_test_suite(gcm gcm.decrypt) diff --git a/tests/suites/test_suite_ecdh.data b/tests/suites/test_suite_ecdh.data new file mode 100644 index 000000000..5b98b6285 --- /dev/null +++ b/tests/suites/test_suite_ecdh.data @@ -0,0 +1,15 @@ +ECDH primitive agreement #1 +ecdh_primitive_agreement:SECP192R1 + +ECDH primitive agreement #2 +ecdh_primitive_agreement:SECP224R1 + +ECDH primitive agreement #3 +ecdh_primitive_agreement:SECP256R1 + +ECDH primitive agreement #4 +ecdh_primitive_agreement:SECP384R1 + +ECDH primitive agreement #5 +ecdh_primitive_agreement:SECP521R1 + diff --git a/tests/suites/test_suite_ecdh.function b/tests/suites/test_suite_ecdh.function new file mode 100644 index 000000000..76e6977a9 --- /dev/null +++ b/tests/suites/test_suite_ecdh.function @@ -0,0 +1,39 @@ +BEGIN_HEADER +#include +END_HEADER + +BEGIN_DEPENDENCIES +depends_on:POLARSSL_ECDH_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C +END_DEPENDENCIES + +BEGIN_CASE +ecdh_primitive_agreement:id +{ + ecp_group grp; + ecp_point qA, qB; + mpi dA, dB, zA, zB; + rnd_pseudo_info rnd_info; + + ecp_group_init( &grp ); + ecp_point_init( &qA ); ecp_point_init( &qB ); + mpi_init( &dA ); mpi_init( &dB ); + mpi_init( &zA ); mpi_init( &zB ); + memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) ); + + TEST_ASSERT( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_{id} ) == 0 ); + + TEST_ASSERT( ecdh_gen_public( &grp, &dA, &qA, &rnd_pseudo_rand, &rnd_info ) + == 0 ); + TEST_ASSERT( ecdh_gen_public( &grp, &dB, &qB, &rnd_pseudo_rand, &rnd_info ) + == 0 ); + TEST_ASSERT( ecdh_compute_shared( &grp, &zA, &qB, &dA ) == 0 ); + TEST_ASSERT( ecdh_compute_shared( &grp, &zB, &qA, &dB ) == 0 ); + + TEST_ASSERT( mpi_cmp_mpi( &zA, &zB ) == 0 ); + + ecp_group_free( &grp ); + ecp_point_free( &qA ); ecp_point_free( &qB ); + mpi_free( &dA ); mpi_free( &dB ); + mpi_free( &zA ); mpi_free( &zB ); +} +END_CASE