blob: 89f9979a6f002d43c06ec4a12094788591234ebf [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 ) );
22
23 /* prepare material for signature */
24 TEST_ASSERT( rnd_pseudo_rand( &rnd_info, buf, sizeof( buf ) ) == 0 );
25 TEST_ASSERT( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_{id} ) == 0 );
26 TEST_ASSERT( ecp_gen_keypair( &grp, &d, &Q, &rnd_pseudo_rand, &rnd_info )
27 == 0 );
28
29 TEST_ASSERT( ecdsa_sign( &grp, &r, &s, &d, buf, sizeof( buf ),
30 &rnd_pseudo_rand, &rnd_info ) == 0 );
31 TEST_ASSERT( ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 );
32
33 ecp_group_free( &grp );
34 ecp_point_free( &Q );
35 mpi_free( &d ); mpi_free( &r ); mpi_free( &s );
36}
37END_CASE
Manuel Pégourié-Gonnard602a8972013-01-27 08:10:28 +010038
39BEGIN_CASE
40ecdsa_test_vectors:id:d:xQ:yQ:k:hash:r:s
41{
42 ecp_group grp;
43 ecp_point Q;
44 mpi d, r, s, r_check, s_check;
45 unsigned char buf[66];
46 size_t len;
47
48 ecp_group_init( &grp );
49 ecp_point_init( &Q );
50 mpi_init( &d ); mpi_init( &r ); mpi_init( &s );
51 mpi_init( &r_check ); mpi_init( &s_check );
52
53 TEST_ASSERT( ecp_use_known_dp( &grp, POLARSSL_ECP_DP_{id} ) == 0 );
54 TEST_ASSERT( ecp_point_read_string( &Q, 16, "{xQ}", "{yQ}" ) == 0 );
55 TEST_ASSERT( mpi_read_string( &d, 16, "{d}" ) == 0 );
56 TEST_ASSERT( mpi_read_string( &r_check, 16, "{r}" ) == 0 );
57 TEST_ASSERT( mpi_read_string( &s_check, 16, "{s}" ) == 0 );
58 len = unhexify(buf, "{hash}");
59
60 TEST_ASSERT( ecdsa_sign( &grp, &r, &s, &d, buf, len,
61 &not_rnd, "{k}" ) == 0 );
62
63 TEST_ASSERT( mpi_cmp_mpi( &r, &r_check ) == 0 );
64 TEST_ASSERT( mpi_cmp_mpi( &s, &s_check ) == 0 );
65
66 TEST_ASSERT( ecdsa_verify( &grp, buf, len, &Q, &r_check, &s_check ) == 0 );
67
68 ecp_group_free( &grp );
69 ecp_point_free( &Q );
70 mpi_free( &d ); mpi_free( &r ); mpi_free( &s );
71 mpi_free( &r_check ); mpi_free( &s_check );
72}
73END_CASE