blob: 9b3d05af84b6fe0ee988d05cb7f18ca2b20d4bbe [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Paul Bakker42a29bf2009-07-07 20:18:41 +00002#include <polarssl/rsa.h>
Paul Bakker821fb082009-07-12 13:26:42 +00003#include <polarssl/md2.h>
4#include <polarssl/md4.h>
5#include <polarssl/md5.h>
Paul Bakker42a29bf2009-07-07 20:18:41 +00006#include <polarssl/sha1.h>
Paul Bakkerd2681d82013-06-30 14:49:12 +02007#include <polarssl/sha256.h>
8#include <polarssl/sha512.h>
Paul Bakkerc0a1a312011-12-04 17:12:15 +00009#include <polarssl/entropy.h>
10#include <polarssl/ctr_drbg.h>
Paul Bakker33b43f12013-08-20 11:48:36 +020011/* END_HEADER */
Paul Bakker42a29bf2009-07-07 20:18:41 +000012
Paul Bakker33b43f12013-08-20 11:48:36 +020013/* BEGIN_DEPENDENCIES
14 * depends_on:POLARSSL_RSA_C:POLARSSL_BIGNUM_C:POLARSSL_GENPRIME
15 * END_DEPENDENCIES
16 */
Paul Bakker5690efc2011-05-26 13:16:06 +000017
Paul Bakker33b43f12013-08-20 11:48:36 +020018/* BEGIN_CASE */
19void rsa_pkcs1_sign( char *message_hex_string, int padding_mode, int digest,
20 int mod, int radix_P, char *input_P, int radix_Q,
21 char *input_Q, int radix_N, char *input_N, int radix_E,
22 char *input_E, char *result_hex_str, int result )
Paul Bakker42a29bf2009-07-07 20:18:41 +000023{
24 unsigned char message_str[1000];
25 unsigned char hash_result[1000];
26 unsigned char output[1000];
27 unsigned char output_str[1000];
28 rsa_context ctx;
29 mpi P1, Q1, H, G;
Paul Bakker69998dd2009-07-11 19:15:20 +000030 int msg_len;
Paul Bakker548957d2013-08-30 10:30:02 +020031 rnd_pseudo_info rnd_info;
Paul Bakker42a29bf2009-07-07 20:18:41 +000032
Paul Bakker6c591fa2011-05-05 11:49:20 +000033 mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
Paul Bakker33b43f12013-08-20 11:48:36 +020034 rsa_init( &ctx, padding_mode, 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +000035
36 memset( message_str, 0x00, 1000 );
37 memset( hash_result, 0x00, 1000 );
38 memset( output, 0x00, 1000 );
39 memset( output_str, 0x00, 1000 );
Paul Bakker548957d2013-08-30 10:30:02 +020040 memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
Paul Bakker42a29bf2009-07-07 20:18:41 +000041
Paul Bakker33b43f12013-08-20 11:48:36 +020042 ctx.len = mod / 8;
43 TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
44 TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
45 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
46 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +000047
48 TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
49 TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
50 TEST_ASSERT( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
51 TEST_ASSERT( mpi_gcd( &G, &ctx.E, &H ) == 0 );
52 TEST_ASSERT( mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
53 TEST_ASSERT( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
54 TEST_ASSERT( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
55 TEST_ASSERT( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
56
57 TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
58
Paul Bakker33b43f12013-08-20 11:48:36 +020059 msg_len = unhexify( message_str, message_hex_string );
Paul Bakker42a29bf2009-07-07 20:18:41 +000060
Paul Bakker33b43f12013-08-20 11:48:36 +020061 if( md_info_from_type( digest ) != NULL )
62 TEST_ASSERT( md( md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +000063
Paul Bakker548957d2013-08-30 10:30:02 +020064 TEST_ASSERT( rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PRIVATE, digest, 0, hash_result, output ) == result );
Paul Bakker33b43f12013-08-20 11:48:36 +020065 if( result == 0 )
Paul Bakker821fb082009-07-12 13:26:42 +000066 {
67 hexify( output_str, output, ctx.len );
Paul Bakker42a29bf2009-07-07 20:18:41 +000068
Paul Bakker33b43f12013-08-20 11:48:36 +020069 TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +000070 }
Paul Bakker6c591fa2011-05-05 11:49:20 +000071
Paul Bakkerbd51b262014-07-10 15:26:12 +020072exit:
Paul Bakker6c591fa2011-05-05 11:49:20 +000073 mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
Paul Bakker58ef6ec2013-01-03 11:33:48 +010074 rsa_free( &ctx );
Paul Bakker42a29bf2009-07-07 20:18:41 +000075}
Paul Bakker33b43f12013-08-20 11:48:36 +020076/* END_CASE */
Paul Bakker42a29bf2009-07-07 20:18:41 +000077
Paul Bakker33b43f12013-08-20 11:48:36 +020078/* BEGIN_CASE */
79void rsa_pkcs1_verify( char *message_hex_string, int padding_mode, int digest,
80 int mod, int radix_N, char *input_N, int radix_E,
81 char *input_E, char *result_hex_str, int result )
Paul Bakker42a29bf2009-07-07 20:18:41 +000082{
83 unsigned char message_str[1000];
84 unsigned char hash_result[1000];
85 unsigned char result_str[1000];
86 rsa_context ctx;
Paul Bakker69998dd2009-07-11 19:15:20 +000087 int msg_len;
Paul Bakker42a29bf2009-07-07 20:18:41 +000088
Paul Bakker33b43f12013-08-20 11:48:36 +020089 rsa_init( &ctx, padding_mode, 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +000090 memset( message_str, 0x00, 1000 );
91 memset( hash_result, 0x00, 1000 );
92 memset( result_str, 0x00, 1000 );
93
Paul Bakker33b43f12013-08-20 11:48:36 +020094 ctx.len = mod / 8;
95 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
96 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +000097
98 TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
99
Paul Bakker33b43f12013-08-20 11:48:36 +0200100 msg_len = unhexify( message_str, message_hex_string );
101 unhexify( result_str, result_hex_str );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000102
Paul Bakker33b43f12013-08-20 11:48:36 +0200103 if( md_info_from_type( digest ) != NULL )
104 TEST_ASSERT( md( md_info_from_type( digest ), message_str, msg_len, hash_result ) == 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000105
Paul Bakker548957d2013-08-30 10:30:02 +0200106 TEST_ASSERT( rsa_pkcs1_verify( &ctx, NULL, NULL, RSA_PUBLIC, digest, 0, hash_result, result_str ) == result );
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100107
Paul Bakkerbd51b262014-07-10 15:26:12 +0200108exit:
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100109 rsa_free( &ctx );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000110}
Paul Bakker33b43f12013-08-20 11:48:36 +0200111/* END_CASE */
Paul Bakker42a29bf2009-07-07 20:18:41 +0000112
Paul Bakker821fb082009-07-12 13:26:42 +0000113
Paul Bakker33b43f12013-08-20 11:48:36 +0200114/* BEGIN_CASE */
115void rsa_pkcs1_sign_raw( char *message_hex_string, char *hash_result_string,
116 int padding_mode, int mod, int radix_P, char *input_P,
117 int radix_Q, char *input_Q, int radix_N,
118 char *input_N, int radix_E, char *input_E,
119 char *result_hex_str )
Paul Bakker42a29bf2009-07-07 20:18:41 +0000120{
121 unsigned char message_str[1000];
122 unsigned char hash_result[1000];
123 unsigned char output[1000];
124 unsigned char output_str[1000];
125 rsa_context ctx;
Paul Bakker821fb082009-07-12 13:26:42 +0000126 mpi P1, Q1, H, G;
Paul Bakkereaf90d92011-07-13 14:21:52 +0000127 int hash_len;
Paul Bakker548957d2013-08-30 10:30:02 +0200128 rnd_pseudo_info rnd_info;
Paul Bakker42a29bf2009-07-07 20:18:41 +0000129
Paul Bakker6c591fa2011-05-05 11:49:20 +0000130 mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
Paul Bakker33b43f12013-08-20 11:48:36 +0200131 rsa_init( &ctx, padding_mode, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000132
Paul Bakker42a29bf2009-07-07 20:18:41 +0000133 memset( message_str, 0x00, 1000 );
134 memset( hash_result, 0x00, 1000 );
135 memset( output, 0x00, 1000 );
136 memset( output_str, 0x00, 1000 );
Paul Bakker548957d2013-08-30 10:30:02 +0200137 memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000138
Paul Bakker33b43f12013-08-20 11:48:36 +0200139 ctx.len = mod / 8;
140 TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
141 TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
142 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
143 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000144
145 TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
146 TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
147 TEST_ASSERT( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
148 TEST_ASSERT( mpi_gcd( &G, &ctx.E, &H ) == 0 );
149 TEST_ASSERT( mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
150 TEST_ASSERT( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
151 TEST_ASSERT( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
152 TEST_ASSERT( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
153
154 TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
155
Paul Bakker33b43f12013-08-20 11:48:36 +0200156 unhexify( message_str, message_hex_string );
157 hash_len = unhexify( hash_result, hash_result_string );
Paul Bakker821fb082009-07-12 13:26:42 +0000158
Paul Bakker548957d2013-08-30 10:30:02 +0200159 TEST_ASSERT( rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PRIVATE, POLARSSL_MD_NONE, hash_len, hash_result, output ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000160
161 hexify( output_str, output, ctx.len );
162
Paul Bakker33b43f12013-08-20 11:48:36 +0200163 TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
Paul Bakker6c591fa2011-05-05 11:49:20 +0000164
Manuel Pégourié-Gonnardfbf09152014-02-03 11:58:55 +0100165 /* For PKCS#1 v1.5, there is an alternative way to generate signatures */
166 if( padding_mode == RSA_PKCS_V15 )
167 {
168 memset( output, 0x00, 1000 );
169 memset( output_str, 0x00, 1000 );
170
171 TEST_ASSERT( rsa_rsaes_pkcs1_v15_encrypt( &ctx,
172 &rnd_pseudo_rand, &rnd_info, RSA_PRIVATE,
173 hash_len, hash_result, output ) == 0 );
174
175 hexify( output_str, output, ctx.len );
176
177 TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
178 }
179
Paul Bakkerbd51b262014-07-10 15:26:12 +0200180exit:
Paul Bakker6c591fa2011-05-05 11:49:20 +0000181 mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100182 rsa_free( &ctx );
Paul Bakker821fb082009-07-12 13:26:42 +0000183}
Paul Bakker33b43f12013-08-20 11:48:36 +0200184/* END_CASE */
Paul Bakker821fb082009-07-12 13:26:42 +0000185
Paul Bakker33b43f12013-08-20 11:48:36 +0200186/* BEGIN_CASE */
187void rsa_pkcs1_verify_raw( char *message_hex_string, char *hash_result_string,
188 int padding_mode, int mod, int radix_N,
189 char *input_N, int radix_E, char *input_E,
190 char *result_hex_str, int correct )
Paul Bakker821fb082009-07-12 13:26:42 +0000191{
192 unsigned char message_str[1000];
193 unsigned char hash_result[1000];
194 unsigned char result_str[1000];
Manuel Pégourié-Gonnardfbf09152014-02-03 11:58:55 +0100195 unsigned char output[1000];
Paul Bakker821fb082009-07-12 13:26:42 +0000196 rsa_context ctx;
Manuel Pégourié-Gonnardfbf09152014-02-03 11:58:55 +0100197 size_t hash_len, olen;
Paul Bakker821fb082009-07-12 13:26:42 +0000198
Paul Bakker33b43f12013-08-20 11:48:36 +0200199 rsa_init( &ctx, padding_mode, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000200 memset( message_str, 0x00, 1000 );
201 memset( hash_result, 0x00, 1000 );
202 memset( result_str, 0x00, 1000 );
Manuel Pégourié-Gonnardfbf09152014-02-03 11:58:55 +0100203 memset( output, 0x00, sizeof( output ) );
Paul Bakker821fb082009-07-12 13:26:42 +0000204
Paul Bakker33b43f12013-08-20 11:48:36 +0200205 ctx.len = mod / 8;
206 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
207 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000208
209 TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
210
Paul Bakker33b43f12013-08-20 11:48:36 +0200211 unhexify( message_str, message_hex_string );
212 hash_len = unhexify( hash_result, hash_result_string );
213 unhexify( result_str, result_hex_str );
Paul Bakker821fb082009-07-12 13:26:42 +0000214
Paul Bakker548957d2013-08-30 10:30:02 +0200215 TEST_ASSERT( rsa_pkcs1_verify( &ctx, NULL, NULL, RSA_PUBLIC, POLARSSL_MD_NONE, hash_len, hash_result, result_str ) == correct );
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100216
Manuel Pégourié-Gonnardfbf09152014-02-03 11:58:55 +0100217 /* For PKCS#1 v1.5, there is an alternative way to verify signatures */
218 if( padding_mode == RSA_PKCS_V15 )
219 {
220 int ok;
221
222 TEST_ASSERT( rsa_rsaes_pkcs1_v15_decrypt( &ctx,
223 NULL, NULL, RSA_PUBLIC,
224 &olen, result_str, output, sizeof( output ) ) == 0 );
225
226 ok = olen == hash_len && memcmp( output, hash_result, olen ) == 0;
227 if( correct == 0 )
228 TEST_ASSERT( ok == 1 );
229 else
230 TEST_ASSERT( ok == 0 );
231 }
232
Paul Bakkerbd51b262014-07-10 15:26:12 +0200233exit:
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100234 rsa_free( &ctx );
Paul Bakker821fb082009-07-12 13:26:42 +0000235}
Paul Bakker33b43f12013-08-20 11:48:36 +0200236/* END_CASE */
Paul Bakker821fb082009-07-12 13:26:42 +0000237
Paul Bakker33b43f12013-08-20 11:48:36 +0200238/* BEGIN_CASE */
239void rsa_pkcs1_encrypt( char *message_hex_string, int padding_mode, int mod,
240 int radix_N, char *input_N, int radix_E, char *input_E,
241 char *result_hex_str, int result )
Paul Bakker821fb082009-07-12 13:26:42 +0000242{
243 unsigned char message_str[1000];
244 unsigned char output[1000];
245 unsigned char output_str[1000];
246 rsa_context ctx;
Paul Bakkerf4a3f302011-04-24 15:53:29 +0000247 size_t msg_len;
Paul Bakker997bbd12011-03-13 15:45:42 +0000248 rnd_pseudo_info rnd_info;
249
250 memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
Paul Bakker821fb082009-07-12 13:26:42 +0000251
Paul Bakker33b43f12013-08-20 11:48:36 +0200252 rsa_init( &ctx, padding_mode, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000253 memset( message_str, 0x00, 1000 );
254 memset( output, 0x00, 1000 );
255 memset( output_str, 0x00, 1000 );
256
Paul Bakker33b43f12013-08-20 11:48:36 +0200257 ctx.len = mod / 8;
258 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
259 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000260
261 TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
262
Paul Bakker33b43f12013-08-20 11:48:36 +0200263 msg_len = unhexify( message_str, message_hex_string );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000264
Paul Bakker33b43f12013-08-20 11:48:36 +0200265 TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, RSA_PUBLIC, msg_len, message_str, output ) == result );
266 if( result == 0 )
Paul Bakker821fb082009-07-12 13:26:42 +0000267 {
268 hexify( output_str, output, ctx.len );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000269
Paul Bakker33b43f12013-08-20 11:48:36 +0200270 TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000271 }
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100272
Paul Bakkerbd51b262014-07-10 15:26:12 +0200273exit:
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100274 rsa_free( &ctx );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000275}
Paul Bakker33b43f12013-08-20 11:48:36 +0200276/* END_CASE */
Paul Bakker42a29bf2009-07-07 20:18:41 +0000277
Paul Bakker33b43f12013-08-20 11:48:36 +0200278/* BEGIN_CASE */
279void rsa_pkcs1_encrypt_bad_rng( char *message_hex_string, int padding_mode,
280 int mod, int radix_N, char *input_N,
281 int radix_E, char *input_E,
282 char *result_hex_str, int result )
Paul Bakkera6656852010-07-18 19:47:14 +0000283{
284 unsigned char message_str[1000];
285 unsigned char output[1000];
286 unsigned char output_str[1000];
287 rsa_context ctx;
Paul Bakkerf4a3f302011-04-24 15:53:29 +0000288 size_t msg_len;
Paul Bakkera6656852010-07-18 19:47:14 +0000289
Paul Bakker33b43f12013-08-20 11:48:36 +0200290 rsa_init( &ctx, padding_mode, 0 );
Paul Bakkera6656852010-07-18 19:47:14 +0000291 memset( message_str, 0x00, 1000 );
292 memset( output, 0x00, 1000 );
293 memset( output_str, 0x00, 1000 );
294
Paul Bakker33b43f12013-08-20 11:48:36 +0200295 ctx.len = mod / 8;
296 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
297 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakkera6656852010-07-18 19:47:14 +0000298
299 TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
300
Paul Bakker33b43f12013-08-20 11:48:36 +0200301 msg_len = unhexify( message_str, message_hex_string );
Paul Bakkera6656852010-07-18 19:47:14 +0000302
Paul Bakker33b43f12013-08-20 11:48:36 +0200303 TEST_ASSERT( rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL, RSA_PUBLIC, msg_len, message_str, output ) == result );
304 if( result == 0 )
Paul Bakkera6656852010-07-18 19:47:14 +0000305 {
306 hexify( output_str, output, ctx.len );
307
Paul Bakker33b43f12013-08-20 11:48:36 +0200308 TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
Paul Bakkera6656852010-07-18 19:47:14 +0000309 }
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100310
Paul Bakkerbd51b262014-07-10 15:26:12 +0200311exit:
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100312 rsa_free( &ctx );
Paul Bakkera6656852010-07-18 19:47:14 +0000313}
Paul Bakker33b43f12013-08-20 11:48:36 +0200314/* END_CASE */
Paul Bakkera6656852010-07-18 19:47:14 +0000315
Paul Bakker33b43f12013-08-20 11:48:36 +0200316/* BEGIN_CASE */
317void rsa_pkcs1_decrypt( char *message_hex_string, int padding_mode, int mod,
318 int radix_P, char *input_P, int radix_Q, char *input_Q,
319 int radix_N, char *input_N, int radix_E, char *input_E,
320 int max_output, char *result_hex_str, int result )
Paul Bakker42a29bf2009-07-07 20:18:41 +0000321{
322 unsigned char message_str[1000];
Paul Bakker42a29bf2009-07-07 20:18:41 +0000323 unsigned char output[1000];
324 unsigned char output_str[1000];
325 rsa_context ctx;
326 mpi P1, Q1, H, G;
Paul Bakkerf4a3f302011-04-24 15:53:29 +0000327 size_t output_len;
Paul Bakker548957d2013-08-30 10:30:02 +0200328 rnd_pseudo_info rnd_info;
Paul Bakker42a29bf2009-07-07 20:18:41 +0000329
Paul Bakker6c591fa2011-05-05 11:49:20 +0000330 mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
Paul Bakker33b43f12013-08-20 11:48:36 +0200331 rsa_init( &ctx, padding_mode, 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000332
333 memset( message_str, 0x00, 1000 );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000334 memset( output, 0x00, 1000 );
335 memset( output_str, 0x00, 1000 );
Paul Bakker548957d2013-08-30 10:30:02 +0200336 memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000337
Paul Bakker33b43f12013-08-20 11:48:36 +0200338 ctx.len = mod / 8;
339 TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
340 TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
341 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
342 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000343
344 TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
345 TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
346 TEST_ASSERT( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
347 TEST_ASSERT( mpi_gcd( &G, &ctx.E, &H ) == 0 );
348 TEST_ASSERT( mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
349 TEST_ASSERT( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
350 TEST_ASSERT( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
351 TEST_ASSERT( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
352
353 TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
354
Paul Bakker33b43f12013-08-20 11:48:36 +0200355 unhexify( message_str, message_hex_string );
Paul Bakker69998dd2009-07-11 19:15:20 +0000356 output_len = 0;
Paul Bakker42a29bf2009-07-07 20:18:41 +0000357
Paul Bakker548957d2013-08-30 10:30:02 +0200358 TEST_ASSERT( rsa_pkcs1_decrypt( &ctx, rnd_pseudo_rand, &rnd_info, RSA_PRIVATE, &output_len, message_str, output, max_output ) == result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200359 if( result == 0 )
Paul Bakker821fb082009-07-12 13:26:42 +0000360 {
361 hexify( output_str, output, ctx.len );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000362
Paul Bakker33b43f12013-08-20 11:48:36 +0200363 TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000364 }
Paul Bakker6c591fa2011-05-05 11:49:20 +0000365
Paul Bakkerbd51b262014-07-10 15:26:12 +0200366exit:
Paul Bakker6c591fa2011-05-05 11:49:20 +0000367 mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100368 rsa_free( &ctx );
Paul Bakker821fb082009-07-12 13:26:42 +0000369}
Paul Bakker33b43f12013-08-20 11:48:36 +0200370/* END_CASE */
Paul Bakker42a29bf2009-07-07 20:18:41 +0000371
Paul Bakker33b43f12013-08-20 11:48:36 +0200372/* BEGIN_CASE */
373void rsa_public( char *message_hex_string, int mod, int radix_N, char *input_N,
374 int radix_E, char *input_E, char *result_hex_str, int result )
Paul Bakker821fb082009-07-12 13:26:42 +0000375{
376 unsigned char message_str[1000];
377 unsigned char output[1000];
378 unsigned char output_str[1000];
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100379 rsa_context ctx, ctx2; /* Also test rsa_copy() while at it */
Paul Bakker821fb082009-07-12 13:26:42 +0000380
Paul Bakkerebcef6d2010-08-16 11:10:49 +0000381 rsa_init( &ctx, RSA_PKCS_V15, 0 );
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100382 rsa_init( &ctx2, RSA_PKCS_V15, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000383 memset( message_str, 0x00, 1000 );
384 memset( output, 0x00, 1000 );
385 memset( output_str, 0x00, 1000 );
386
Paul Bakker33b43f12013-08-20 11:48:36 +0200387 ctx.len = mod / 8;
388 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
389 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000390
391 TEST_ASSERT( rsa_check_pubkey( &ctx ) == 0 );
392
Paul Bakker33b43f12013-08-20 11:48:36 +0200393 unhexify( message_str, message_hex_string );
Paul Bakker821fb082009-07-12 13:26:42 +0000394
Paul Bakker33b43f12013-08-20 11:48:36 +0200395 TEST_ASSERT( rsa_public( &ctx, message_str, output ) == result );
396 if( result == 0 )
Paul Bakker821fb082009-07-12 13:26:42 +0000397 {
398 hexify( output_str, output, ctx.len );
399
Paul Bakker33b43f12013-08-20 11:48:36 +0200400 TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000401 }
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100402
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100403 /* And now with the copy */
404 TEST_ASSERT( rsa_copy( &ctx2, &ctx ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200405 /* clear the original to be sure */
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100406 rsa_free( &ctx );
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100407
408 TEST_ASSERT( rsa_check_pubkey( &ctx2 ) == 0 );
409
410 memset( output, 0x00, 1000 );
411 memset( output_str, 0x00, 1000 );
412 TEST_ASSERT( rsa_public( &ctx2, message_str, output ) == result );
413 if( result == 0 )
414 {
415 hexify( output_str, output, ctx2.len );
416
417 TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
418 }
419
Paul Bakkerbd51b262014-07-10 15:26:12 +0200420exit:
421 rsa_free( &ctx );
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100422 rsa_free( &ctx2 );
Paul Bakker821fb082009-07-12 13:26:42 +0000423}
Paul Bakker33b43f12013-08-20 11:48:36 +0200424/* END_CASE */
Paul Bakker821fb082009-07-12 13:26:42 +0000425
Paul Bakker33b43f12013-08-20 11:48:36 +0200426/* BEGIN_CASE */
427void rsa_private( char *message_hex_string, int mod, int radix_P, char *input_P,
428 int radix_Q, char *input_Q, int radix_N, char *input_N,
429 int radix_E, char *input_E, char *result_hex_str, int result )
Paul Bakker821fb082009-07-12 13:26:42 +0000430{
431 unsigned char message_str[1000];
432 unsigned char output[1000];
433 unsigned char output_str[1000];
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100434 rsa_context ctx, ctx2; /* Also test rsa_copy() while at it */
Paul Bakker821fb082009-07-12 13:26:42 +0000435 mpi P1, Q1, H, G;
Paul Bakker548957d2013-08-30 10:30:02 +0200436 rnd_pseudo_info rnd_info;
Manuel Pégourié-Gonnard735b8fc2013-09-13 12:57:23 +0200437 int i;
Paul Bakker821fb082009-07-12 13:26:42 +0000438
Paul Bakker6c591fa2011-05-05 11:49:20 +0000439 mpi_init( &P1 ); mpi_init( &Q1 ); mpi_init( &H ); mpi_init( &G );
Paul Bakkerebcef6d2010-08-16 11:10:49 +0000440 rsa_init( &ctx, RSA_PKCS_V15, 0 );
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100441 rsa_init( &ctx2, RSA_PKCS_V15, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000442
443 memset( message_str, 0x00, 1000 );
Paul Bakker548957d2013-08-30 10:30:02 +0200444 memset( &rnd_info, 0, sizeof( rnd_pseudo_info ) );
Paul Bakker821fb082009-07-12 13:26:42 +0000445
Paul Bakker33b43f12013-08-20 11:48:36 +0200446 ctx.len = mod / 8;
447 TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
448 TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
449 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
450 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000451
452 TEST_ASSERT( mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
453 TEST_ASSERT( mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
454 TEST_ASSERT( mpi_mul_mpi( &H, &P1, &Q1 ) == 0 );
455 TEST_ASSERT( mpi_gcd( &G, &ctx.E, &H ) == 0 );
456 TEST_ASSERT( mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
457 TEST_ASSERT( mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
458 TEST_ASSERT( mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
459 TEST_ASSERT( mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
460
461 TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
462
Paul Bakker33b43f12013-08-20 11:48:36 +0200463 unhexify( message_str, message_hex_string );
Paul Bakker821fb082009-07-12 13:26:42 +0000464
Manuel Pégourié-Gonnard735b8fc2013-09-13 12:57:23 +0200465 /* repeat three times to test updating of blinding values */
466 for( i = 0; i < 3; i++ )
Paul Bakker821fb082009-07-12 13:26:42 +0000467 {
Manuel Pégourié-Gonnard735b8fc2013-09-13 12:57:23 +0200468 memset( output, 0x00, 1000 );
469 memset( output_str, 0x00, 1000 );
470 TEST_ASSERT( rsa_private( &ctx, rnd_pseudo_rand, &rnd_info,
471 message_str, output ) == result );
472 if( result == 0 )
473 {
474 hexify( output_str, output, ctx.len );
Paul Bakker821fb082009-07-12 13:26:42 +0000475
Manuel Pégourié-Gonnard735b8fc2013-09-13 12:57:23 +0200476 TEST_ASSERT( strcasecmp( (char *) output_str,
477 result_hex_str ) == 0 );
478 }
Paul Bakker821fb082009-07-12 13:26:42 +0000479 }
Paul Bakker6c591fa2011-05-05 11:49:20 +0000480
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100481 /* And now one more time with the copy */
482 TEST_ASSERT( rsa_copy( &ctx2, &ctx ) == 0 );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200483 /* clear the original to be sure */
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100484 rsa_free( &ctx );
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100485
486 TEST_ASSERT( rsa_check_privkey( &ctx2 ) == 0 );
487
488 memset( output, 0x00, 1000 );
489 memset( output_str, 0x00, 1000 );
490 TEST_ASSERT( rsa_private( &ctx2, rnd_pseudo_rand, &rnd_info,
491 message_str, output ) == result );
492 if( result == 0 )
493 {
494 hexify( output_str, output, ctx2.len );
495
496 TEST_ASSERT( strcasecmp( (char *) output_str,
497 result_hex_str ) == 0 );
498 }
499
Paul Bakkerbd51b262014-07-10 15:26:12 +0200500exit:
Manuel Pégourié-Gonnardc4919bc2014-02-03 11:16:44 +0100501 mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
Paul Bakkerbd51b262014-07-10 15:26:12 +0200502 rsa_free( &ctx ); rsa_free( &ctx2 );
Paul Bakker42a29bf2009-07-07 20:18:41 +0000503}
Paul Bakker33b43f12013-08-20 11:48:36 +0200504/* END_CASE */
Paul Bakker42a29bf2009-07-07 20:18:41 +0000505
Paul Bakker33b43f12013-08-20 11:48:36 +0200506/* BEGIN_CASE */
507void rsa_check_privkey_null()
Paul Bakker37940d9f2009-07-10 22:38:58 +0000508{
509 rsa_context ctx;
510 memset( &ctx, 0x00, sizeof( rsa_context ) );
511
512 TEST_ASSERT( rsa_check_privkey( &ctx ) == POLARSSL_ERR_RSA_KEY_CHECK_FAILED );
513}
Paul Bakker33b43f12013-08-20 11:48:36 +0200514/* END_CASE */
Paul Bakker37940d9f2009-07-10 22:38:58 +0000515
Paul Bakker33b43f12013-08-20 11:48:36 +0200516/* BEGIN_CASE */
517void rsa_check_pubkey( int radix_N, char *input_N, int radix_E, char *input_E,
518 int result )
Paul Bakker821fb082009-07-12 13:26:42 +0000519{
520 rsa_context ctx;
521
Paul Bakkerebcef6d2010-08-16 11:10:49 +0000522 rsa_init( &ctx, RSA_PKCS_V15, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000523
Paul Bakker33b43f12013-08-20 11:48:36 +0200524 if( strlen( input_N ) )
Paul Bakker821fb082009-07-12 13:26:42 +0000525 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200526 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000527 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200528 if( strlen( input_E ) )
Paul Bakker821fb082009-07-12 13:26:42 +0000529 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200530 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000531 }
532
Paul Bakker33b43f12013-08-20 11:48:36 +0200533 TEST_ASSERT( rsa_check_pubkey( &ctx ) == result );
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100534
Paul Bakkerbd51b262014-07-10 15:26:12 +0200535exit:
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100536 rsa_free( &ctx );
Paul Bakker821fb082009-07-12 13:26:42 +0000537}
Paul Bakker33b43f12013-08-20 11:48:36 +0200538/* END_CASE */
Paul Bakker821fb082009-07-12 13:26:42 +0000539
Paul Bakker33b43f12013-08-20 11:48:36 +0200540/* BEGIN_CASE */
541void rsa_check_privkey( int mod, int radix_P, char *input_P, int radix_Q,
542 char *input_Q, int radix_N, char *input_N,
543 int radix_E, char *input_E, int radix_D, char *input_D,
544 int radix_DP, char *input_DP, int radix_DQ,
545 char *input_DQ, int radix_QP, char *input_QP,
546 int result )
Paul Bakker821fb082009-07-12 13:26:42 +0000547{
548 rsa_context ctx;
549
Paul Bakkerebcef6d2010-08-16 11:10:49 +0000550 rsa_init( &ctx, RSA_PKCS_V15, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000551
Paul Bakker33b43f12013-08-20 11:48:36 +0200552 ctx.len = mod / 8;
553 if( strlen( input_P ) )
Paul Bakker821fb082009-07-12 13:26:42 +0000554 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200555 TEST_ASSERT( mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000556 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200557 if( strlen( input_Q ) )
Paul Bakker821fb082009-07-12 13:26:42 +0000558 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200559 TEST_ASSERT( mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000560 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200561 if( strlen( input_N ) )
Paul Bakker821fb082009-07-12 13:26:42 +0000562 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200563 TEST_ASSERT( mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000564 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200565 if( strlen( input_E ) )
Paul Bakker821fb082009-07-12 13:26:42 +0000566 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200567 TEST_ASSERT( mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000568 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200569 if( strlen( input_D ) )
Paul Bakker821fb082009-07-12 13:26:42 +0000570 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200571 TEST_ASSERT( mpi_read_string( &ctx.D, radix_D, input_D ) == 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000572 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200573 if( strlen( input_DP ) )
Paul Bakker31417a72012-09-27 20:41:37 +0000574 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200575 TEST_ASSERT( mpi_read_string( &ctx.DP, radix_DP, input_DP ) == 0 );
Paul Bakker31417a72012-09-27 20:41:37 +0000576 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200577 if( strlen( input_DQ ) )
Paul Bakker31417a72012-09-27 20:41:37 +0000578 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200579 TEST_ASSERT( mpi_read_string( &ctx.DQ, radix_DQ, input_DQ ) == 0 );
Paul Bakker31417a72012-09-27 20:41:37 +0000580 }
Paul Bakker33b43f12013-08-20 11:48:36 +0200581 if( strlen( input_QP ) )
Paul Bakker31417a72012-09-27 20:41:37 +0000582 {
Paul Bakker33b43f12013-08-20 11:48:36 +0200583 TEST_ASSERT( mpi_read_string( &ctx.QP, radix_QP, input_QP ) == 0 );
Paul Bakker31417a72012-09-27 20:41:37 +0000584 }
Paul Bakker821fb082009-07-12 13:26:42 +0000585
Paul Bakker33b43f12013-08-20 11:48:36 +0200586 TEST_ASSERT( rsa_check_privkey( &ctx ) == result );
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100587
Paul Bakkerbd51b262014-07-10 15:26:12 +0200588exit:
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100589 rsa_free( &ctx );
Paul Bakker821fb082009-07-12 13:26:42 +0000590}
Paul Bakker33b43f12013-08-20 11:48:36 +0200591/* END_CASE */
Paul Bakker821fb082009-07-12 13:26:42 +0000592
Manuel Pégourié-Gonnarda0d758b2013-12-01 16:27:00 +0100593/* BEGIN_CASE depends_on:POLARSSL_CTR_DRBG_C:POLARSSL_ENTROPY_C */
Paul Bakker33b43f12013-08-20 11:48:36 +0200594void rsa_gen_key( int nrbits, int exponent, int result)
Paul Bakker821fb082009-07-12 13:26:42 +0000595{
596 rsa_context ctx;
Paul Bakkerc0a1a312011-12-04 17:12:15 +0000597 entropy_context entropy;
598 ctr_drbg_context ctr_drbg;
Paul Bakkeref3f8c72013-06-24 13:01:08 +0200599 const char *pers = "test_suite_rsa";
Paul Bakker821fb082009-07-12 13:26:42 +0000600
Paul Bakkerc0a1a312011-12-04 17:12:15 +0000601 entropy_init( &entropy );
602 TEST_ASSERT( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
Paul Bakkeref3f8c72013-06-24 13:01:08 +0200603 (const unsigned char *) pers, strlen( pers ) ) == 0 );
Paul Bakkerc0a1a312011-12-04 17:12:15 +0000604
Paul Bakkerebcef6d2010-08-16 11:10:49 +0000605 rsa_init( &ctx, 0, 0 );
Paul Bakker821fb082009-07-12 13:26:42 +0000606
Paul Bakker33b43f12013-08-20 11:48:36 +0200607 TEST_ASSERT( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, nrbits, exponent ) == result );
608 if( result == 0 )
Paul Bakker821fb082009-07-12 13:26:42 +0000609 {
610 TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
611 }
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100612
Paul Bakkerbd51b262014-07-10 15:26:12 +0200613exit:
Paul Bakker58ef6ec2013-01-03 11:33:48 +0100614 rsa_free( &ctx );
Paul Bakkera317a982014-06-18 16:44:11 +0200615 ctr_drbg_free( &ctr_drbg );
Paul Bakker1ffefac2013-09-28 15:23:03 +0200616 entropy_free( &entropy );
Paul Bakker821fb082009-07-12 13:26:42 +0000617}
Paul Bakker33b43f12013-08-20 11:48:36 +0200618/* END_CASE */
Paul Bakker821fb082009-07-12 13:26:42 +0000619
Manuel Pégourié-Gonnard20140162013-10-10 12:48:03 +0200620/* BEGIN_CASE depends_on:POLARSSL_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +0200621void rsa_selftest()
Paul Bakker42a29bf2009-07-07 20:18:41 +0000622{
623 TEST_ASSERT( rsa_self_test( 0 ) == 0 );
624}
Paul Bakker33b43f12013-08-20 11:48:36 +0200625/* END_CASE */