From d1c7150bf51c8450381fd1b53d0a41191cf6c700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Sat, 26 Jan 2013 19:09:07 +0100 Subject: [PATCH] Basic tests for ECDSA. --- tests/CMakeLists.txt | 1 + tests/suites/test_suite_ecdsa.data | 15 +++++++++++ tests/suites/test_suite_ecdsa.function | 37 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 tests/suites/test_suite_ecdsa.data create mode 100644 tests/suites/test_suite_ecdsa.function diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 863d7a5a9..63224b261 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,6 +47,7 @@ add_test_suite(des) add_test_suite(dhm) add_test_suite(ecp) add_test_suite(ecdh) +add_test_suite(ecdsa) add_test_suite(error) add_test_suite(gcm gcm.encrypt) add_test_suite(gcm gcm.decrypt) diff --git a/tests/suites/test_suite_ecdsa.data b/tests/suites/test_suite_ecdsa.data new file mode 100644 index 000000000..b13d8889b --- /dev/null +++ b/tests/suites/test_suite_ecdsa.data @@ -0,0 +1,15 @@ +ECDSA sign-verify #1 +ecdsa_sign_verify:SECP192R1 + +ECDSA sign-verify #2 +ecdsa_sign_verify:SECP224R1 + +ECDSA sign-verify #3 +ecdsa_sign_verify:SECP256R1 + +ECDSA sign-verify #4 +ecdsa_sign_verify:SECP384R1 + +ECDSA sign-verify #5 +ecdsa_sign_verify:SECP521R1 + diff --git a/tests/suites/test_suite_ecdsa.function b/tests/suites/test_suite_ecdsa.function new file mode 100644 index 000000000..e90938c63 --- /dev/null +++ b/tests/suites/test_suite_ecdsa.function @@ -0,0 +1,37 @@ +BEGIN_HEADER +#include +END_HEADER + +BEGIN_DEPENDENCIES +depends_on:POLARSSL_ECDSA_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C +END_DEPENDENCIES + +BEGIN_CASE +ecdsa_sign_verify:id +{ + ecp_group grp; + ecp_point Q; + mpi d, r, s; + rnd_pseudo_info rnd_info; + unsigned char buf[66]; + + ecp_group_init( &grp ); + ecp_point_init( &Q ); + mpi_init( &d ); mpi_init( &r ); mpi_init( &s ); + memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) ); + + /* prepare material for signature */ + TEST_ASSERT( rnd_pseudo_rand( &rnd_info, buf, sizeof( buf ) ) == 0 ); + TEST_ASSERT( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_{id} ) == 0 ); + TEST_ASSERT( ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info ) + == 0 ); + + TEST_ASSERT( ecdsa_sign( &grp, &r, &s, &d, buf, sizeof( buf ), + &rnd_pseudo_rand, &rnd_info ) == 0 ); + TEST_ASSERT( ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 ); + + ecp_group_free( &grp ); + ecp_point_free( &Q ); + mpi_free( &d ); mpi_free( &r ); mpi_free( &s ); +} +END_CASE