blob: 3cb1b9fd29bc2ca0fd08d68e6fab31a4b95fbb79 [file] [log] [blame]
Manuel Pégourié-Gonnardd1c71502013-01-26 19:09:07 +01001BEGIN_HEADER
2#include <polarssl/ecdsa.h>
3END_HEADER
4
5BEGIN_DEPENDENCIES
6depends_on:POLARSSL_ECDSA_C:POLARSSL_ECP_C:POLARSSL_BIGNUM_C
7END_DEPENDENCIES
8
9BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020010ecdsa_prim_random:#id
Manuel Pégourié-Gonnardd1c71502013-01-26 19:09:07 +010011{
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é-Gonnard450a1632013-01-27 09:08:18 +010022 memset( buf, 0, sizeof( buf ) );
Manuel Pégourié-Gonnardd1c71502013-01-26 19:09:07 +010023
24 /* prepare material for signature */
25 TEST_ASSERT( rnd_pseudo_rand( &rnd_info, buf, sizeof( buf ) ) == 0 );
Paul Bakkerdbd443d2013-08-16 13:38:47 +020026 TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
Manuel Pégourié-Gonnardd1c71502013-01-26 19:09:07 +010027 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}
38END_CASE
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010039
40BEGIN_CASE
Paul Bakkerdbd443d2013-08-16 13:38:47 +020041ecdsa_prim_test_vectors:#id:d_str:xQ_str:yQ_str:k_str:hash_str:r_str:s_str
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010042{
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é-Gonnard450a1632013-01-27 09:08:18 +010053 memset( buf, 0, sizeof( buf ) );
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010054
Paul Bakkerdbd443d2013-08-16 13:38:47 +020055 TEST_ASSERT( ecp_use_known_dp( &grp, {id} ) == 0 );
56 TEST_ASSERT( ecp_point_read_string( &Q, 16, {xQ_str}, {yQ_str} ) == 0 );
57 TEST_ASSERT( mpi_read_string( &d, 16, {d_str} ) == 0 );
58 TEST_ASSERT( mpi_read_string( &r_check, 16, {r_str} ) == 0 );
59 TEST_ASSERT( mpi_read_string( &s_check, 16, {s_str} ) == 0 );
60 len = unhexify(buf, {hash_str});
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010061
62 TEST_ASSERT( ecdsa_sign( &grp, &r, &s, &d, buf, len,
Paul Bakkerdbd443d2013-08-16 13:38:47 +020063 &not_rnd, {k_str} ) == 0 );
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010064
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}
75END_CASE