blob: c9830c2590518259361cade62e433dbacf01dacb [file] [log] [blame]
Paul Bakkerbdb912d2012-02-13 23:11:30 +00001/*
Paul Bakkerf3df61a2013-08-26 17:22:23 +02002 * Key writing application
Paul Bakkerbdb912d2012-02-13 23:11:30 +00003 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerbdb912d2012-02-13 23:11:30 +00005 *
Manuel Pégourié-Gonnard860b5162015-01-28 17:12:07 +00006 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkerbdb912d2012-02-13 23:11:30 +00007 *
Paul Bakkerbdb912d2012-02-13 23:11:30 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020023#if !defined(POLARSSL_CONFIG_FILE)
Manuel Pégourié-Gonnardabd6e022013-09-20 13:30:43 +020024#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020025#else
26#include POLARSSL_CONFIG_FILE
27#endif
Paul Bakkerbdb912d2012-02-13 23:11:30 +000028
Rich Evansf90016a2015-01-19 14:26:37 +000029#if defined(POLARSSL_PLATFORM_C)
30#include "polarssl/platform.h"
31#else
32#define polarssl_printf printf
Rich Evansf90016a2015-01-19 14:26:37 +000033#endif
34
Paul Bakkerbdb912d2012-02-13 23:11:30 +000035#include <string.h>
36#include <stdlib.h>
37#include <stdio.h>
38
Paul Bakker2e24ca72013-09-18 15:21:27 +020039#include "polarssl/error.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020040#include "polarssl/pk.h"
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +020041#include "polarssl/error.h"
Paul Bakkerbdb912d2012-02-13 23:11:30 +000042
Paul Bakker7c6b2c32013-09-16 13:49:26 +020043#if !defined(POLARSSL_PK_WRITE_C) || !defined(POLARSSL_FS_IO)
Paul Bakkered27a042013-04-18 22:46:23 +020044int main( int argc, char *argv[] )
45{
46 ((void) argc);
47 ((void) argv);
48
Rich Evansf90016a2015-01-19 14:26:37 +000049 polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
Paul Bakkered27a042013-04-18 22:46:23 +020050 return( 0 );
51}
52#else
53
Paul Bakkerbdb912d2012-02-13 23:11:30 +000054#define MODE_NONE 0
55#define MODE_PRIVATE 1
56#define MODE_PUBLIC 2
57
58#define OUTPUT_MODE_NONE 0
59#define OUTPUT_MODE_PRIVATE 1
60#define OUTPUT_MODE_PUBLIC 2
61
Paul Bakkerf3df61a2013-08-26 17:22:23 +020062#define OUTPUT_FORMAT_PEM 0
63#define OUTPUT_FORMAT_DER 1
64
Paul Bakkerbdb912d2012-02-13 23:11:30 +000065#define DFL_MODE MODE_NONE
66#define DFL_FILENAME "keyfile.key"
67#define DFL_DEBUG_LEVEL 0
Paul Bakkerf3df61a2013-08-26 17:22:23 +020068#define DFL_OUTPUT_MODE OUTPUT_MODE_NONE
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +020069#if defined(POLARSSL_PEM_WRITE_C)
Paul Bakkerbdb912d2012-02-13 23:11:30 +000070#define DFL_OUTPUT_FILENAME "keyfile.pem"
Paul Bakkerf3df61a2013-08-26 17:22:23 +020071#define DFL_OUTPUT_FORMAT OUTPUT_FORMAT_PEM
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +020072#else
73#define DFL_OUTPUT_FILENAME "keyfile.der"
74#define DFL_OUTPUT_FORMAT OUTPUT_FORMAT_DER
75#endif
Paul Bakkerbdb912d2012-02-13 23:11:30 +000076
77/*
78 * global options
79 */
80struct options
81{
82 int mode; /* the mode to run the application in */
Paul Bakkeref3f8c72013-06-24 13:01:08 +020083 const char *filename; /* filename of the key file */
Paul Bakkerbdb912d2012-02-13 23:11:30 +000084 int output_mode; /* the output mode to use */
Paul Bakkeref3f8c72013-06-24 13:01:08 +020085 const char *output_file; /* where to store the constructed key file */
Paul Bakkerf3df61a2013-08-26 17:22:23 +020086 int output_format; /* the output format to use */
Paul Bakkerbdb912d2012-02-13 23:11:30 +000087} opt;
88
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +020089static int write_public_key( pk_context *key, const char *output_file )
Paul Bakkerbdb912d2012-02-13 23:11:30 +000090{
Paul Bakkerf3df61a2013-08-26 17:22:23 +020091 int ret;
Paul Bakkerbdb912d2012-02-13 23:11:30 +000092 FILE *f;
Paul Bakker1d569582012-10-03 20:35:44 +000093 unsigned char output_buf[16000];
Paul Bakkerf3df61a2013-08-26 17:22:23 +020094 unsigned char *c = output_buf;
95 size_t len = 0;
Paul Bakkerbdb912d2012-02-13 23:11:30 +000096
Paul Bakker1d569582012-10-03 20:35:44 +000097 memset(output_buf, 0, 16000);
Paul Bakkerbdb912d2012-02-13 23:11:30 +000098
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +020099#if defined(POLARSSL_PEM_WRITE_C)
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200100 if( opt.output_format == OUTPUT_FORMAT_PEM )
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000101 {
Paul Bakkerc7bb02b2013-09-15 14:54:56 +0200102 if( ( ret = pk_write_pubkey_pem( key, output_buf, 16000 ) ) != 0 )
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200103 return( ret );
104
105 len = strlen( (char *) output_buf );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000106 }
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200107 else
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +0200108#endif
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200109 {
Paul Bakkerc7bb02b2013-09-15 14:54:56 +0200110 if( ( ret = pk_write_pubkey_der( key, output_buf, 16000 ) ) < 0 )
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200111 return( ret );
112
113 len = ret;
114 c = output_buf + sizeof(output_buf) - len - 1;
115 }
116
117 if( ( f = fopen( output_file, "w" ) ) == NULL )
118 return( -1 );
119
120 if( fwrite( c, 1, len, f ) != len )
Paul Bakker0c226102014-04-17 16:02:36 +0200121 {
122 fclose( f );
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200123 return( -1 );
Paul Bakker0c226102014-04-17 16:02:36 +0200124 }
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200125
Paul Bakker0c226102014-04-17 16:02:36 +0200126 fclose( f );
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200127
128 return( 0 );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000129}
130
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200131static int write_private_key( pk_context *key, const char *output_file )
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000132{
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200133 int ret;
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000134 FILE *f;
Paul Bakker1d569582012-10-03 20:35:44 +0000135 unsigned char output_buf[16000];
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200136 unsigned char *c = output_buf;
137 size_t len = 0;
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000138
Paul Bakker1d569582012-10-03 20:35:44 +0000139 memset(output_buf, 0, 16000);
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +0200140
141#if defined(POLARSSL_PEM_WRITE_C)
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200142 if( opt.output_format == OUTPUT_FORMAT_PEM )
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000143 {
Paul Bakkerc7bb02b2013-09-15 14:54:56 +0200144 if( ( ret = pk_write_key_pem( key, output_buf, 16000 ) ) != 0 )
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200145 return( ret );
146
147 len = strlen( (char *) output_buf );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000148 }
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200149 else
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +0200150#endif
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200151 {
Paul Bakkerc7bb02b2013-09-15 14:54:56 +0200152 if( ( ret = pk_write_key_der( key, output_buf, 16000 ) ) < 0 )
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200153 return( ret );
154
155 len = ret;
156 c = output_buf + sizeof(output_buf) - len - 1;
157 }
158
159 if( ( f = fopen( output_file, "w" ) ) == NULL )
160 return( -1 );
161
162 if( fwrite( c, 1, len, f ) != len )
Paul Bakker0c226102014-04-17 16:02:36 +0200163 {
164 fclose( f );
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200165 return( -1 );
Paul Bakker0c226102014-04-17 16:02:36 +0200166 }
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200167
Paul Bakker0c226102014-04-17 16:02:36 +0200168 fclose( f );
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200169
170 return( 0 );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000171}
172
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +0200173#if defined(POLARSSL_PEM_WRITE_C)
174#define USAGE_OUT \
175 " output_file=%%s default: keyfile.pem\n" \
176 " output_format=pem|der default: pem\n"
177#else
178#define USAGE_OUT \
179 " output_file=%%s default: keyfile.der\n" \
180 " output_format=der default: der\n"
181#endif
182
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000183#define USAGE \
184 "\n usage: key_app param=<>...\n" \
185 "\n acceptable parameters:\n" \
186 " mode=private|public default: none\n" \
187 " filename=%%s default: keyfile.key\n" \
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000188 " output_mode=private|public default: none\n" \
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +0200189 USAGE_OUT \
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000190 "\n"
191
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000192int main( int argc, char *argv[] )
193{
194 int ret = 0;
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200195 pk_context key;
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000196 char buf[1024];
Paul Bakker1d569582012-10-03 20:35:44 +0000197 int i;
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000198 char *p, *q;
199
200 /*
201 * Set to sane values
202 */
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200203 pk_init( &key );
204 memset( buf, 0, sizeof( buf ) );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000205
206 if( argc == 0 )
207 {
208 usage:
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200209 ret = 1;
Rich Evansf90016a2015-01-19 14:26:37 +0000210 polarssl_printf( USAGE );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000211 goto exit;
212 }
213
214 opt.mode = DFL_MODE;
215 opt.filename = DFL_FILENAME;
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000216 opt.output_mode = DFL_OUTPUT_MODE;
217 opt.output_file = DFL_OUTPUT_FILENAME;
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200218 opt.output_format = DFL_OUTPUT_FORMAT;
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000219
220 for( i = 1; i < argc; i++ )
221 {
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000222 p = argv[i];
223 if( ( q = strchr( p, '=' ) ) == NULL )
224 goto usage;
225 *q++ = '\0';
226
227 if( strcmp( p, "mode" ) == 0 )
228 {
229 if( strcmp( q, "private" ) == 0 )
230 opt.mode = MODE_PRIVATE;
231 else if( strcmp( q, "public" ) == 0 )
232 opt.mode = MODE_PUBLIC;
233 else
234 goto usage;
235 }
236 else if( strcmp( p, "output_mode" ) == 0 )
237 {
238 if( strcmp( q, "private" ) == 0 )
239 opt.output_mode = OUTPUT_MODE_PRIVATE;
240 else if( strcmp( q, "public" ) == 0 )
241 opt.output_mode = OUTPUT_MODE_PUBLIC;
242 else
243 goto usage;
244 }
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200245 else if( strcmp( p, "output_format" ) == 0 )
246 {
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +0200247#if defined(POLARSSL_PEM_WRITE_C)
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200248 if( strcmp( q, "pem" ) == 0 )
249 opt.output_format = OUTPUT_FORMAT_PEM;
Manuel Pégourié-Gonnardf9378d82014-06-24 13:11:25 +0200250 else
251#endif
252 if( strcmp( q, "der" ) == 0 )
Paul Bakkerf3df61a2013-08-26 17:22:23 +0200253 opt.output_format = OUTPUT_FORMAT_DER;
254 else
255 goto usage;
256 }
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000257 else if( strcmp( p, "filename" ) == 0 )
258 opt.filename = q;
259 else if( strcmp( p, "output_file" ) == 0 )
260 opt.output_file = q;
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000261 else
262 goto usage;
263 }
264
265 if( opt.mode == MODE_NONE && opt.output_mode != OUTPUT_MODE_NONE )
266 {
Rich Evansf90016a2015-01-19 14:26:37 +0000267 polarssl_printf( "\nCannot output a key without reading one.\n");
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000268 goto exit;
269 }
270
271 if( opt.mode == MODE_PUBLIC && opt.output_mode == OUTPUT_MODE_PRIVATE )
272 {
Rich Evansf90016a2015-01-19 14:26:37 +0000273 polarssl_printf( "\nCannot output a private key from a public key.\n");
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000274 goto exit;
275 }
276
277 if( opt.mode == MODE_PRIVATE )
278 {
279 /*
280 * 1.1. Load the key
281 */
Rich Evansf90016a2015-01-19 14:26:37 +0000282 polarssl_printf( "\n . Loading the private key ..." );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000283 fflush( stdout );
284
Paul Bakker1a7550a2013-09-15 13:01:22 +0200285 ret = pk_parse_keyfile( &key, opt.filename, NULL );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000286
287 if( ret != 0 )
288 {
Paul Bakker2e24ca72013-09-18 15:21:27 +0200289 polarssl_strerror( ret, (char *) buf, sizeof(buf) );
Rich Evansf90016a2015-01-19 14:26:37 +0000290 polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000291 goto exit;
292 }
293
Rich Evansf90016a2015-01-19 14:26:37 +0000294 polarssl_printf( " ok\n" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000295
296 /*
297 * 1.2 Print the key
298 */
Rich Evansf90016a2015-01-19 14:26:37 +0000299 polarssl_printf( " . Key information ...\n" );
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200300
301#if defined(POLARSSL_RSA_C)
302 if( pk_get_type( &key ) == POLARSSL_PK_RSA )
303 {
304 rsa_context *rsa = pk_rsa( key );
305 mpi_write_file( "N: ", &rsa->N, 16, NULL );
306 mpi_write_file( "E: ", &rsa->E, 16, NULL );
307 mpi_write_file( "D: ", &rsa->D, 16, NULL );
308 mpi_write_file( "P: ", &rsa->P, 16, NULL );
309 mpi_write_file( "Q: ", &rsa->Q, 16, NULL );
310 mpi_write_file( "DP: ", &rsa->DP, 16, NULL );
311 mpi_write_file( "DQ: ", &rsa->DQ, 16, NULL );
312 mpi_write_file( "QP: ", &rsa->QP, 16, NULL );
313 }
314 else
315#endif
Paul Bakker2e24ca72013-09-18 15:21:27 +0200316#if defined(POLARSSL_ECP_C)
317 if( pk_get_type( &key ) == POLARSSL_PK_ECKEY )
318 {
319 ecp_keypair *ecp = pk_ec( key );
320 mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
321 mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
322 mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
323 mpi_write_file( "D : ", &ecp->d , 16, NULL );
324 }
325 else
326#endif
Rich Evansf90016a2015-01-19 14:26:37 +0000327 polarssl_printf("key type not supported yet\n");
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000328
329 }
330 else if( opt.mode == MODE_PUBLIC )
331 {
332 /*
333 * 1.1. Load the key
334 */
Rich Evansf90016a2015-01-19 14:26:37 +0000335 polarssl_printf( "\n . Loading the public key ..." );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000336 fflush( stdout );
337
Paul Bakker1a7550a2013-09-15 13:01:22 +0200338 ret = pk_parse_public_keyfile( &key, opt.filename );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000339
340 if( ret != 0 )
341 {
Paul Bakker2e24ca72013-09-18 15:21:27 +0200342 polarssl_strerror( ret, (char *) buf, sizeof(buf) );
Rich Evansf90016a2015-01-19 14:26:37 +0000343 polarssl_printf( " failed\n ! pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000344 goto exit;
345 }
346
Rich Evansf90016a2015-01-19 14:26:37 +0000347 polarssl_printf( " ok\n" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000348
349 /*
350 * 1.2 Print the key
351 */
Rich Evansf90016a2015-01-19 14:26:37 +0000352 polarssl_printf( " . Key information ...\n" );
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200353
354#if defined(POLARSSL_RSA_C)
355 if( pk_get_type( &key ) == POLARSSL_PK_RSA )
356 {
357 rsa_context *rsa = pk_rsa( key );
358 mpi_write_file( "N: ", &rsa->N, 16, NULL );
359 mpi_write_file( "E: ", &rsa->E, 16, NULL );
360 }
361 else
362#endif
Paul Bakker2e24ca72013-09-18 15:21:27 +0200363#if defined(POLARSSL_ECP_C)
364 if( pk_get_type( &key ) == POLARSSL_PK_ECKEY )
365 {
366 ecp_keypair *ecp = pk_ec( key );
367 mpi_write_file( "Q(X): ", &ecp->Q.X, 16, NULL );
368 mpi_write_file( "Q(Y): ", &ecp->Q.Y, 16, NULL );
369 mpi_write_file( "Q(Z): ", &ecp->Q.Z, 16, NULL );
370 }
371 else
372#endif
Rich Evansf90016a2015-01-19 14:26:37 +0000373 polarssl_printf("key type not supported yet\n");
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000374 }
375 else
376 goto usage;
377
378 if( opt.output_mode == OUTPUT_MODE_PUBLIC )
379 {
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200380 write_public_key( &key, opt.output_file );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000381 }
382 if( opt.output_mode == OUTPUT_MODE_PRIVATE )
383 {
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200384 write_private_key( &key, opt.output_file );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000385 }
386
387exit:
388
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200389 if( ret != 0 && ret != 1)
390 {
391#ifdef POLARSSL_ERROR_C
392 polarssl_strerror( ret, buf, sizeof( buf ) );
Rich Evansf90016a2015-01-19 14:26:37 +0000393 polarssl_printf( " - %s\n", buf );
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200394#else
Rich Evansf90016a2015-01-19 14:26:37 +0000395 polarssl_printf("\n");
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200396#endif
397 }
398
399 pk_free( &key );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000400
401#if defined(_WIN32)
Rich Evansf90016a2015-01-19 14:26:37 +0000402 polarssl_printf( " + Press Enter to exit this program.\n" );
Paul Bakkerbdb912d2012-02-13 23:11:30 +0000403 fflush( stdout ); getchar();
404#endif
405
406 return( ret );
407}
Manuel Pégourié-Gonnard26b4d452013-09-12 06:56:06 +0200408#endif /* POLARSSL_X509_WRITE_C && POLARSSL_FS_IO */