blob: d5b21d468c239b2fba3126b042f47307a2c80cd1 [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
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010010ecdsa_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 );
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}
38END_CASE
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010039
40BEGIN_CASE
41ecdsa_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é-Gonnard450a1632013-01-27 09:08:18 +010053 memset( buf, 0, sizeof( buf ) );
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010054
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 &not_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}
75END_CASE