Manuel Pégourié-Gonnard | d1c7150 | 2013-01-26 19:09:07 +0100 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include <polarssl/ecdsa.h> |
| 3 | END_HEADER |
| 4 | |
| 5 | BEGIN_DEPENDENCIES |
| 6 | depends_on:POLARSSL_ECDSA_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C |
| 7 | END_DEPENDENCIES |
| 8 | |
| 9 | BEGIN_CASE |
Manuel Pégourié-Gonnard | 602a897 | 2013-01-27 08:10:28 +0100 | [diff] [blame] | 10 | ecdsa_random:id |
Manuel Pégourié-Gonnard | d1c7150 | 2013-01-26 19:09:07 +0100 | [diff] [blame] | 11 | { |
| 12 | ecp_group grp; |
| 13 | ecp_point Q; |
| 14 | mpi d, r, s; |
| 15 | rnd_pseudo_info rnd_info; |
| 16 | unsigned char buf[66]; |
| 17 | |
| 18 | ecp_group_init( &grp ); |
| 19 | ecp_point_init( &Q ); |
| 20 | mpi_init( &d ); mpi_init( &r ); mpi_init( &s ); |
| 21 | memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) ); |
Manuel Pégourié-Gonnard | 450a163 | 2013-01-27 09:08:18 +0100 | [diff] [blame^] | 22 | memset( buf, 0, sizeof( buf ) ); |
Manuel Pégourié-Gonnard | d1c7150 | 2013-01-26 19:09:07 +0100 | [diff] [blame] | 23 | |
| 24 | /* prepare material for signature */ |
| 25 | TEST_ASSERT( rnd_pseudo_rand( &rnd_info, buf, sizeof( buf ) ) == 0 ); |
| 26 | TEST_ASSERT( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_{id} ) == 0 ); |
| 27 | TEST_ASSERT( ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info ) |
| 28 | == 0 ); |
| 29 | |
| 30 | TEST_ASSERT( ecdsa_sign( &grp, &r, &s, &d, buf, sizeof( buf ), |
| 31 | &rnd_pseudo_rand, &rnd_info ) == 0 ); |
| 32 | TEST_ASSERT( ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 ); |
| 33 | |
| 34 | ecp_group_free( &grp ); |
| 35 | ecp_point_free( &Q ); |
| 36 | mpi_free( &d ); mpi_free( &r ); mpi_free( &s ); |
| 37 | } |
| 38 | END_CASE |
Manuel Pégourié-Gonnard | 602a897 | 2013-01-27 08:10:28 +0100 | [diff] [blame] | 39 | |
| 40 | BEGIN_CASE |
| 41 | ecdsa_test_vectors:id:d:xQ:yQ:k:hash:r:s |
| 42 | { |
| 43 | ecp_group grp; |
| 44 | ecp_point Q; |
| 45 | mpi d, r, s, r_check, s_check; |
| 46 | unsigned char buf[66]; |
| 47 | size_t len; |
| 48 | |
| 49 | ecp_group_init( &grp ); |
| 50 | ecp_point_init( &Q ); |
| 51 | mpi_init( &d ); mpi_init( &r ); mpi_init( &s ); |
| 52 | mpi_init( &r_check ); mpi_init( &s_check ); |
Manuel Pégourié-Gonnard | 450a163 | 2013-01-27 09:08:18 +0100 | [diff] [blame^] | 53 | memset( buf, 0, sizeof( buf ) ); |
Manuel Pégourié-Gonnard | 602a897 | 2013-01-27 08:10:28 +0100 | [diff] [blame] | 54 | |
| 55 | TEST_ASSERT( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_{id} ) == 0 ); |
| 56 | TEST_ASSERT( ecp_point_read_string( &Q, 16, "{xQ}", "{yQ}" ) == 0 ); |
| 57 | TEST_ASSERT( mpi_read_string( &d, 16, "{d}" ) == 0 ); |
| 58 | TEST_ASSERT( mpi_read_string( &r_check, 16, "{r}" ) == 0 ); |
| 59 | TEST_ASSERT( mpi_read_string( &s_check, 16, "{s}" ) == 0 ); |
| 60 | len = unhexify(buf, "{hash}"); |
| 61 | |
| 62 | TEST_ASSERT( ecdsa_sign( &grp, &r, &s, &d, buf, len, |
| 63 | ¬_rnd, "{k}" ) == 0 ); |
| 64 | |
| 65 | TEST_ASSERT( mpi_cmp_mpi( &r, &r_check ) == 0 ); |
| 66 | TEST_ASSERT( mpi_cmp_mpi( &s, &s_check ) == 0 ); |
| 67 | |
| 68 | TEST_ASSERT( ecdsa_verify( &grp, buf, len, &Q, &r_check, &s_check ) == 0 ); |
| 69 | |
| 70 | ecp_group_free( &grp ); |
| 71 | ecp_point_free( &Q ); |
| 72 | mpi_free( &d ); mpi_free( &r ); mpi_free( &s ); |
| 73 | mpi_free( &r_check ); mpi_free( &s_check ); |
| 74 | } |
| 75 | END_CASE |