blob: 89299f8498a20674bda1c742d37bb322c4322d26 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker5121ce52009-01-03 21:22:43 +000018 */
19
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020020#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000021#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020022#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020024#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000026#include "mbedtls/entropy.h"
Simon Butcherb6a73c92016-06-18 22:45:37 +010027#include "mbedtls/entropy_poll.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000028#include "mbedtls/hmac_drbg.h"
29#include "mbedtls/ctr_drbg.h"
30#include "mbedtls/dhm.h"
31#include "mbedtls/gcm.h"
32#include "mbedtls/ccm.h"
Robert Cragiedc5c7b92015-12-11 15:49:45 +000033#include "mbedtls/cmac.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000034#include "mbedtls/md2.h"
35#include "mbedtls/md4.h"
36#include "mbedtls/md5.h"
37#include "mbedtls/ripemd160.h"
38#include "mbedtls/sha1.h"
39#include "mbedtls/sha256.h"
40#include "mbedtls/sha512.h"
41#include "mbedtls/arc4.h"
42#include "mbedtls/des.h"
43#include "mbedtls/aes.h"
44#include "mbedtls/camellia.h"
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +000045#include "mbedtls/aria.h"
Daniel King4d8f87b2016-05-18 10:09:28 -030046#include "mbedtls/chacha20.h"
47#include "mbedtls/poly1305.h"
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020048#include "mbedtls/chachapoly.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/base64.h"
50#include "mbedtls/bignum.h"
51#include "mbedtls/rsa.h"
52#include "mbedtls/x509.h"
53#include "mbedtls/xtea.h"
54#include "mbedtls/pkcs5.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000055#include "mbedtls/ecp.h"
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +020056#include "mbedtls/ecjpake.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/timing.h"
Ron Eldor9ab746c2018-07-15 09:33:07 +030058#include "mbedtls/nist_kw.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000059
Rich Evans18b78c72015-02-11 14:06:19 +000060#include <string.h>
61
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000062#include "mbedtls/platform.h"
Rich Evans18b78c72015-02-11 14:06:19 +000063
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/memory_buffer_alloc.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020066#endif
67
Simon Butcher63cb97e2018-12-06 17:43:31 +000068
Gilles Peskine6fc21f62019-09-17 18:18:58 +020069#if defined MBEDTLS_SELF_TEST
70/* Sanity check for malloc. This is not expected to fail, and is rather
71 * intended to display potentially useful information about the platform,
72 * in particular the behavior of malloc(0). */
73static int calloc_self_test( int verbose )
74{
75 int failures = 0;
76 void *empty1 = mbedtls_calloc( 0, 1 );
77 void *empty2 = mbedtls_calloc( 0, 1 );
78 void *buffer1 = mbedtls_calloc( 1, 1 );
79 void *buffer2 = mbedtls_calloc( 1, 1 );
Gilles Peskine6fc21f62019-09-17 18:18:58 +020080
81 if( empty1 == NULL && empty2 == NULL )
82 {
83 if( verbose )
84 mbedtls_printf( " CALLOC(0): passed (NULL)\n" );
85 }
86 else if( empty1 == NULL || empty2 == NULL )
87 {
88 if( verbose )
89 mbedtls_printf( " CALLOC(0): failed (mix of NULL and non-NULL)\n" );
90 ++failures;
91 }
92 else if( empty1 == empty2 )
93 {
94 if( verbose )
95 mbedtls_printf( " CALLOC(0): passed (same non-null)\n" );
96 }
97 else
98 {
99 if( verbose )
100 mbedtls_printf( " CALLOC(0): passed (distinct non-null)\n" );
101 }
102
103 if( buffer1 == NULL || buffer2 == NULL )
104 {
105 if( verbose )
106 mbedtls_printf( " CALLOC(1): failed (NULL)\n" );
107 ++failures;
108 }
109 else if( buffer1 == buffer2 )
110 {
111 if( verbose )
112 mbedtls_printf( " CALLOC(1): failed (same buffer twice)\n" );
113 ++failures;
114 }
115 else
116 {
117 if( verbose )
118 mbedtls_printf( " CALLOC(1): passed\n" );
119 }
120
Gilles Peskine6fc21f62019-09-17 18:18:58 +0200121 mbedtls_free( buffer1 );
122 buffer1 = mbedtls_calloc( 1, 1 );
123 if( buffer1 == NULL )
124 {
125 if( verbose )
126 mbedtls_printf( " CALLOC(1 again): failed (NULL)\n" );
127 ++failures;
128 }
129 else
130 {
131 if( verbose )
Gilles Peskine52396ef2022-06-25 14:29:23 +0200132 mbedtls_printf( " CALLOC(1 again): passed\n" );
Gilles Peskine6fc21f62019-09-17 18:18:58 +0200133 }
134
135 if( verbose )
136 mbedtls_printf( "\n" );
137 mbedtls_free( empty1 );
138 mbedtls_free( empty2 );
139 mbedtls_free( buffer1 );
140 mbedtls_free( buffer2 );
141 return( failures );
142}
143#endif /* MBEDTLS_SELF_TEST */
144
Rodrigo Dias Correa80448aa2020-11-10 02:28:50 -0300145static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200146{
147 int ret;
148 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200149 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200150
151 ret = mbedtls_snprintf( buf, n, "%s", "123" );
152 if( ret < 0 || (size_t) ret >= n )
153 ret = -1;
154
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200155 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
156 ref_ret != ret ||
157 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200158 {
159 return( 1 );
160 }
161
162 return( 0 );
163}
164
165static int run_test_snprintf( void )
166{
167 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200168 test_snprintf( 1, "", -1 ) != 0 ||
169 test_snprintf( 2, "1", -1 ) != 0 ||
170 test_snprintf( 3, "12", -1 ) != 0 ||
171 test_snprintf( 4, "123", 3 ) != 0 ||
172 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200173}
174
Simon Butcherb6a73c92016-06-18 22:45:37 +0100175/*
176 * Check if a seed file is present, and if not create one for the entropy
177 * self-test. If this fails, we attempt the test anyway, so no error is passed
178 * back.
179 */
Gilles Peskine319ac802017-12-15 14:57:18 +0100180#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
181#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Simon Butcherb6a73c92016-06-18 22:45:37 +0100182static void create_entropy_seed_file( void )
183{
184 int result;
185 size_t output_len = 0;
186 unsigned char seed_value[MBEDTLS_ENTROPY_BLOCK_SIZE];
187
188 /* Attempt to read the entropy seed file. If this fails - attempt to write
189 * to the file to ensure one is present. */
190 result = mbedtls_platform_std_nv_seed_read( seed_value,
191 MBEDTLS_ENTROPY_BLOCK_SIZE );
192 if( 0 == result )
193 return;
194
195 result = mbedtls_platform_entropy_poll( NULL,
196 seed_value,
197 MBEDTLS_ENTROPY_BLOCK_SIZE,
198 &output_len );
199 if( 0 != result )
200 return;
201
202 if( MBEDTLS_ENTROPY_BLOCK_SIZE != output_len )
203 return;
204
205 mbedtls_platform_std_nv_seed_write( seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE );
206}
207#endif
208
Gilles Peskine319ac802017-12-15 14:57:18 +0100209int mbedtls_entropy_self_test_wrapper( int verbose )
210{
211#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
212 create_entropy_seed_file( );
213#endif
214 return( mbedtls_entropy_self_test( verbose ) );
215}
216#endif
217
218#if defined(MBEDTLS_SELF_TEST)
219#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
220int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose )
221{
222 if( verbose != 0 )
223 {
224#if defined(MBEDTLS_MEMORY_DEBUG)
225 mbedtls_memory_buffer_alloc_status( );
226#endif
227 }
228 mbedtls_memory_buffer_alloc_free( );
229 return( mbedtls_memory_buffer_alloc_self_test( verbose ) );
230}
231#endif
232
233typedef struct
234{
235 const char *name;
236 int ( *function )( int );
237} selftest_t;
238
239const selftest_t selftests[] =
240{
Gilles Peskine6fc21f62019-09-17 18:18:58 +0200241 {"calloc", calloc_self_test},
Gilles Peskine319ac802017-12-15 14:57:18 +0100242#if defined(MBEDTLS_MD2_C)
243 {"md2", mbedtls_md2_self_test},
244#endif
245#if defined(MBEDTLS_MD4_C)
246 {"md4", mbedtls_md4_self_test},
247#endif
248#if defined(MBEDTLS_MD5_C)
249 {"md5", mbedtls_md5_self_test},
250#endif
251#if defined(MBEDTLS_RIPEMD160_C)
252 {"ripemd160", mbedtls_ripemd160_self_test},
253#endif
254#if defined(MBEDTLS_SHA1_C)
255 {"sha1", mbedtls_sha1_self_test},
256#endif
257#if defined(MBEDTLS_SHA256_C)
258 {"sha256", mbedtls_sha256_self_test},
259#endif
260#if defined(MBEDTLS_SHA512_C)
261 {"sha512", mbedtls_sha512_self_test},
262#endif
263#if defined(MBEDTLS_ARC4_C)
264 {"arc4", mbedtls_arc4_self_test},
265#endif
266#if defined(MBEDTLS_DES_C)
267 {"des", mbedtls_des_self_test},
268#endif
269#if defined(MBEDTLS_AES_C)
270 {"aes", mbedtls_aes_self_test},
271#endif
272#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
273 {"gcm", mbedtls_gcm_self_test},
274#endif
275#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
276 {"ccm", mbedtls_ccm_self_test},
277#endif
Ron Eldor9ab746c2018-07-15 09:33:07 +0300278#if defined(MBEDTLS_NIST_KW_C) && defined(MBEDTLS_AES_C)
279 {"nist_kw", mbedtls_nist_kw_self_test},
280#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100281#if defined(MBEDTLS_CMAC_C)
282 {"cmac", mbedtls_cmac_self_test},
283#endif
Daniel King4d8f87b2016-05-18 10:09:28 -0300284#if defined(MBEDTLS_CHACHA20_C)
285 {"chacha20", mbedtls_chacha20_self_test},
286#endif
287#if defined(MBEDTLS_POLY1305_C)
288 {"poly1305", mbedtls_poly1305_self_test},
289#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200290#if defined(MBEDTLS_CHACHAPOLY_C)
291 {"chacha20-poly1305", mbedtls_chachapoly_self_test},
Daniel King4d8f87b2016-05-18 10:09:28 -0300292#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100293#if defined(MBEDTLS_BASE64_C)
294 {"base64", mbedtls_base64_self_test},
295#endif
296#if defined(MBEDTLS_BIGNUM_C)
297 {"mpi", mbedtls_mpi_self_test},
298#endif
299#if defined(MBEDTLS_RSA_C)
300 {"rsa", mbedtls_rsa_self_test},
301#endif
302#if defined(MBEDTLS_X509_USE_C)
303 {"x509", mbedtls_x509_self_test},
304#endif
305#if defined(MBEDTLS_XTEA_C)
306 {"xtea", mbedtls_xtea_self_test},
307#endif
308#if defined(MBEDTLS_CAMELLIA_C)
309 {"camellia", mbedtls_camellia_self_test},
310#endif
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +0000311#if defined(MBEDTLS_ARIA_C)
312 {"aria", mbedtls_aria_self_test},
313#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100314#if defined(MBEDTLS_CTR_DRBG_C)
315 {"ctr_drbg", mbedtls_ctr_drbg_self_test},
316#endif
317#if defined(MBEDTLS_HMAC_DRBG_C)
318 {"hmac_drbg", mbedtls_hmac_drbg_self_test},
319#endif
320#if defined(MBEDTLS_ECP_C)
321 {"ecp", mbedtls_ecp_self_test},
322#endif
323#if defined(MBEDTLS_ECJPAKE_C)
324 {"ecjpake", mbedtls_ecjpake_self_test},
325#endif
326#if defined(MBEDTLS_DHM_C)
327 {"dhm", mbedtls_dhm_self_test},
328#endif
329#if defined(MBEDTLS_ENTROPY_C)
330 {"entropy", mbedtls_entropy_self_test_wrapper},
331#endif
332#if defined(MBEDTLS_PKCS5_C)
333 {"pkcs5", mbedtls_pkcs5_self_test},
334#endif
335/* Slower test after the faster ones */
336#if defined(MBEDTLS_TIMING_C)
337 {"timing", mbedtls_timing_self_test},
338#endif
339/* Heap test comes last */
340#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
341 {"memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test},
342#endif
343 {NULL, NULL}
344};
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100345#endif /* MBEDTLS_SELF_TEST */
Gilles Peskine319ac802017-12-15 14:57:18 +0100346
Paul Bakker5121ce52009-01-03 21:22:43 +0000347int main( int argc, char *argv[] )
348{
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100349#if defined(MBEDTLS_SELF_TEST)
Gilles Peskine319ac802017-12-15 14:57:18 +0100350 const selftest_t *test;
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100351#endif /* MBEDTLS_SELF_TEST */
Gilles Peskineff79d272017-12-20 18:09:27 +0100352 char **argp;
353 int v = 1; /* v=1 for verbose mode */
354 int exclude_mode = 0;
355 int suites_tested = 0, suites_failed = 0;
Paul Bakker70940ca2016-07-14 14:30:45 +0100356#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
Paul Bakker6e339b52013-07-03 13:37:05 +0200357 unsigned char buf[1000000];
358#endif
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200359 void *pointer;
360
361 /*
362 * The C standard doesn't guarantee that all-bits-0 is the representation
363 * of a NULL pointer. We do however use that in our code for initializing
364 * structures, which should work on every modern platform. Let's be sure.
365 */
366 memset( &pointer, 0, sizeof( void * ) );
367 if( pointer != NULL )
368 {
369 mbedtls_printf( "all-bits-zero is not a NULL pointer\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000370 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200371 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000372
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200373 /*
374 * Make sure we have a snprintf that correctly zero-terminates
375 */
376 if( run_test_snprintf() != 0 )
377 {
378 mbedtls_printf( "the snprintf implementation is broken\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000379 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200380 }
381
Gilles Peskineff79d272017-12-20 18:09:27 +0100382 for( argp = argv + ( argc >= 1 ? 1 : argc ); *argp != NULL; ++argp )
SimonB5a8afb82016-03-11 00:40:54 +0000383 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100384 if( strcmp( *argp, "--quiet" ) == 0 ||
385 strcmp( *argp, "-q" ) == 0 )
386 {
387 v = 0;
388 }
389 else if( strcmp( *argp, "--exclude" ) == 0 ||
390 strcmp( *argp, "-x" ) == 0 )
391 {
392 exclude_mode = 1;
393 }
394 else
395 break;
SimonB5a8afb82016-03-11 00:40:54 +0000396 }
Gilles Peskineff79d272017-12-20 18:09:27 +0100397
398 if( v != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399 mbedtls_printf( "\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000400
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200401#if defined(MBEDTLS_SELF_TEST)
Paul Bakker135b98e2011-05-25 11:13:47 +0000402
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200403#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
404 mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200405#endif
406
Gilles Peskineff79d272017-12-20 18:09:27 +0100407 if( *argp != NULL && exclude_mode == 0 )
SimonB5a8afb82016-03-11 00:40:54 +0000408 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100409 /* Run the specified tests */
410 for( ; *argp != NULL; argp++ )
Gilles Peskine319ac802017-12-15 14:57:18 +0100411 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100412 for( test = selftests; test->name != NULL; test++ )
413 {
414 if( !strcmp( *argp, test->name ) )
415 {
416 if( test->function( v ) != 0 )
417 {
418 suites_failed++;
419 }
420 suites_tested++;
421 break;
422 }
423 }
424 if( test->name == NULL )
425 {
426 mbedtls_printf( " Test suite %s not available -> failed\n\n", *argp );
427 suites_failed++;
428 }
Gilles Peskine319ac802017-12-15 14:57:18 +0100429 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100430 }
431 else
432 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100433 /* Run all the tests except excluded ones */
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100434 for( test = selftests; test->name != NULL; test++ )
435 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100436 if( exclude_mode )
437 {
438 char **excluded;
439 for( excluded = argp; *excluded != NULL; ++excluded )
440 {
441 if( !strcmp( *excluded, test->name ) )
442 break;
443 }
444 if( *excluded )
445 {
446 if( v )
447 mbedtls_printf( " Skip: %s\n", test->name );
448 continue;
449 }
450 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100451 if( test->function( v ) != 0 )
452 {
453 suites_failed++;
454 }
455 suites_tested++;
456 }
SimonB5a8afb82016-03-11 00:40:54 +0000457 }
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100458
Paul Bakker70940ca2016-07-14 14:30:45 +0100459#else
Gilles Peskineff79d272017-12-20 18:09:27 +0100460 (void) exclude_mode;
Paul Bakker70940ca2016-07-14 14:30:45 +0100461 mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
462#endif
463
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100464 if( v != 0 )
465 {
Simon Butcherf1547632016-03-14 23:09:39 +0000466 mbedtls_printf( " Executed %d test suites\n\n", suites_tested );
SimonB5a8afb82016-03-11 00:40:54 +0000467
468 if( suites_failed > 0)
469 {
470 mbedtls_printf( " [ %d tests FAIL ]\n\n", suites_failed );
471 }
472 else
473 {
474 mbedtls_printf( " [ All tests PASS ]\n\n" );
475 }
Paul Bakkercce9d772011-11-18 14:26:47 +0000476#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200477 mbedtls_printf( " Press Enter to exit this program.\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000478 fflush( stdout ); getchar();
479#endif
480 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000481
SimonB5a8afb82016-03-11 00:40:54 +0000482 if( suites_failed > 0)
Janos Follath2e3aca22016-03-18 16:25:52 +0000483 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
SimonB5a8afb82016-03-11 00:40:54 +0000484
Krzysztof Stachowiak5e1b1952019-04-24 14:24:46 +0200485 mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
Paul Bakker5121ce52009-01-03 21:22:43 +0000486}