blob: c0743268224f4749ba0654d8ca58a3afad707549 [file] [log] [blame]
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
Paul Bakkerbd51b262014-07-10 15:26:12 +020036exit:
Paul Bakker1a7550a2013-09-15 13:01:22 +020037 pk_free( &ctx );
38}
39/* END_CASE */
40
Paul Bakker428b9ba2013-09-15 15:20:37 +020041/* BEGIN_CASE depends_on:POLARSSL_RSA_C:POLARSSL_FS_IO */
Paul Bakker1a7550a2013-09-15 13:01:22 +020042void pk_parse_public_keyfile_rsa( char *key_file, int result )
43{
44 pk_context ctx;
45 int res;
46
47 pk_init( &ctx );
48
49 res = pk_parse_public_keyfile( &ctx, key_file );
50
51 TEST_ASSERT( res == result );
52
53 if( res == 0 )
54 {
55 rsa_context *rsa;
56 TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_RSA ) );
57 rsa = pk_rsa( ctx );
58 TEST_ASSERT( rsa_check_pubkey( rsa ) == 0 );
59 }
60
Paul Bakkerbd51b262014-07-10 15:26:12 +020061exit:
Paul Bakker1a7550a2013-09-15 13:01:22 +020062 pk_free( &ctx );
63}
64/* END_CASE */
65
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +020066/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_ECP_C */
Paul Bakker1a7550a2013-09-15 13:01:22 +020067void pk_parse_public_keyfile_ec( char *key_file, int result )
68{
69 pk_context ctx;
70 int res;
71
72 pk_init( &ctx );
73
74 res = pk_parse_public_keyfile( &ctx, key_file );
75
76 TEST_ASSERT( res == result );
77
78 if( res == 0 )
79 {
80 ecp_keypair *eckey;
81 TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_ECKEY ) );
82 eckey = pk_ec( ctx );
83 TEST_ASSERT( ecp_check_pubkey( &eckey->grp, &eckey->Q ) == 0 );
84 }
85
Paul Bakkerbd51b262014-07-10 15:26:12 +020086exit:
Paul Bakker1a7550a2013-09-15 13:01:22 +020087 pk_free( &ctx );
88}
89/* END_CASE */
90
Manuel Pégourié-Gonnard4fee79b2013-09-19 18:09:14 +020091/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_ECP_C */
Paul Bakker1a7550a2013-09-15 13:01:22 +020092void pk_parse_keyfile_ec( char *key_file, char *password, int result )
93{
94 pk_context ctx;
95 int res;
96
97 pk_init( &ctx );
98
99 res = pk_parse_keyfile( &ctx, key_file, password );
100
101 TEST_ASSERT( res == result );
102
103 if( res == 0 )
104 {
105 ecp_keypair *eckey;
106 TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_ECKEY ) );
107 eckey = pk_ec( ctx );
108 TEST_ASSERT( ecp_check_privkey( &eckey->grp, &eckey->d ) == 0 );
109 }
110
Paul Bakkerbd51b262014-07-10 15:26:12 +0200111exit:
Paul Bakker1a7550a2013-09-15 13:01:22 +0200112 pk_free( &ctx );
113}
114/* END_CASE */
115
116/* BEGIN_CASE depends_on:POLARSSL_RSA_C */
117void pk_parse_key_rsa( char *key_data, char *result_str, int result )
118{
119 pk_context pk;
120 unsigned char buf[2000];
121 unsigned char output[2000];
122 int data_len;
123 ((void) result_str);
124
125 pk_init( &pk );
126
127 memset( buf, 0, 2000 );
128 memset( output, 0, 2000 );
129
130 data_len = unhexify( buf, key_data );
131
132 TEST_ASSERT( pk_parse_key( &pk, buf, data_len, NULL, 0 ) == ( result ) );
133 if( ( result ) == 0 )
134 {
135 TEST_ASSERT( 1 );
136 }
137
Paul Bakkerbd51b262014-07-10 15:26:12 +0200138exit:
Paul Bakker1a7550a2013-09-15 13:01:22 +0200139 pk_free( &pk );
140}
141/* END_CASE */