blob: 739253d34c3f0231fe508c8d71658bf3e5fe7ebd [file] [log] [blame] [raw]
Paul Bakker1a7550a2013-09-15 13:01:22 +02001/* BEGIN_HEADER */
2#include <polarssl/pk.h>
3#include <polarssl/pem.h>
4#include <polarssl/oid.h>
5/* END_HEADER */
6
7/* BEGIN_DEPENDENCIES
Paul Bakker4606c732013-09-15 17:04:23 +02008 * depends_on:POLARSSL_PK_PARSE_C:POLARSSL_BIGNUM_C
Paul Bakker1a7550a2013-09-15 13:01:22 +02009 * END_DEPENDENCIES
10 */
11
Paul Bakker428b9ba2013-09-15 15:20:37 +020012/* BEGIN_CASE depends_on:POLARSSL_RSA_C:POLARSSL_FS_IO */
Paul Bakker1a7550a2013-09-15 13:01:22 +020013void pk_parse_keyfile_rsa( char *key_file, char *password, int result )
14{
15 pk_context ctx;
16 int res;
17 char *pwd = password;
18
19 pk_init( &ctx );
20
21 if( strcmp( pwd, "NULL" ) == 0 )
22 pwd = NULL;
23
24 res = pk_parse_keyfile( &ctx, key_file, pwd );
25
26 TEST_ASSERT( res == result );
27
28 if( res == 0 )
29 {
30 rsa_context *rsa;
31 TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_RSA ) );
32 rsa = pk_rsa( ctx );
33 TEST_ASSERT( rsa_check_privkey( rsa ) == 0 );
34 }
35
36 pk_free( &ctx );
37}
38/* END_CASE */
39
Paul Bakker428b9ba2013-09-15 15:20:37 +020040/* BEGIN_CASE depends_on:POLARSSL_RSA_C:POLARSSL_FS_IO */
Paul Bakker1a7550a2013-09-15 13:01:22 +020041void pk_parse_public_keyfile_rsa( char *key_file, int result )
42{
43 pk_context ctx;
44 int res;
45
46 pk_init( &ctx );
47
48 res = pk_parse_public_keyfile( &ctx, key_file );
49
50 TEST_ASSERT( res == result );
51
52 if( res == 0 )
53 {
54 rsa_context *rsa;
55 TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_RSA ) );
56 rsa = pk_rsa( ctx );
57 TEST_ASSERT( rsa_check_pubkey( rsa ) == 0 );
58 }
59
60 pk_free( &ctx );
61}
62/* END_CASE */
63
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +020064/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_ECP_C */
Paul Bakker1a7550a2013-09-15 13:01:22 +020065void pk_parse_public_keyfile_ec( char *key_file, int result )
66{
67 pk_context ctx;
68 int res;
69
70 pk_init( &ctx );
71
72 res = pk_parse_public_keyfile( &ctx, key_file );
73
74 TEST_ASSERT( res == result );
75
76 if( res == 0 )
77 {
78 ecp_keypair *eckey;
79 TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_ECKEY ) );
80 eckey = pk_ec( ctx );
81 TEST_ASSERT( ecp_check_pubkey( &eckey->grp, &eckey->Q ) == 0 );
82 }
83
84 pk_free( &ctx );
85}
86/* END_CASE */
87
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +020088/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_ECP_C */
Paul Bakker1a7550a2013-09-15 13:01:22 +020089void pk_parse_keyfile_ec( char *key_file, char *password, int result )
90{
91 pk_context ctx;
92 int res;
93
94 pk_init( &ctx );
95
96 res = pk_parse_keyfile( &ctx, key_file, password );
97
98 TEST_ASSERT( res == result );
99
100 if( res == 0 )
101 {
102 ecp_keypair *eckey;
103 TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_ECKEY ) );
104 eckey = pk_ec( ctx );
105 TEST_ASSERT( ecp_check_privkey( &eckey->grp, &eckey->d ) == 0 );
106 }
107
108 pk_free( &ctx );
109}
110/* END_CASE */
111
112/* BEGIN_CASE depends_on:POLARSSL_RSA_C */
113void pk_parse_key_rsa( char *key_data, char *result_str, int result )
114{
115 pk_context pk;
116 unsigned char buf[2000];
117 unsigned char output[2000];
118 int data_len;
119 ((void) result_str);
120
121 pk_init( &pk );
122
123 memset( buf, 0, 2000 );
124 memset( output, 0, 2000 );
125
126 data_len = unhexify( buf, key_data );
127
128 TEST_ASSERT( pk_parse_key( &pk, buf, data_len, NULL, 0 ) == ( result ) );
129 if( ( result ) == 0 )
130 {
131 TEST_ASSERT( 1 );
132 }
133
134 pk_free( &pk );
135}
136/* END_CASE */