blob: 87d8a13b75fb11a581e44ec9150c61d1ac56c271 [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
Mateusz Starzyk6c2e9b62021-05-19 17:54:54 +020020#define MBEDTLS_ALLOW_PRIVATE_ACCESS
21
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000023#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020024#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020026#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000028#include "mbedtls/entropy.h"
29#include "mbedtls/hmac_drbg.h"
30#include "mbedtls/ctr_drbg.h"
31#include "mbedtls/dhm.h"
32#include "mbedtls/gcm.h"
33#include "mbedtls/ccm.h"
Robert Cragiedc5c7b92015-12-11 15:49:45 +000034#include "mbedtls/cmac.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000035#include "mbedtls/md5.h"
36#include "mbedtls/ripemd160.h"
37#include "mbedtls/sha1.h"
38#include "mbedtls/sha256.h"
39#include "mbedtls/sha512.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000040#include "mbedtls/des.h"
41#include "mbedtls/aes.h"
42#include "mbedtls/camellia.h"
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +000043#include "mbedtls/aria.h"
Daniel King4d8f87b2016-05-18 10:09:28 -030044#include "mbedtls/chacha20.h"
45#include "mbedtls/poly1305.h"
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020046#include "mbedtls/chachapoly.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000047#include "mbedtls/base64.h"
48#include "mbedtls/bignum.h"
49#include "mbedtls/rsa.h"
50#include "mbedtls/x509.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000051#include "mbedtls/pkcs5.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000052#include "mbedtls/ecp.h"
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +020053#include "mbedtls/ecjpake.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000054#include "mbedtls/timing.h"
Ron Eldor9ab746c2018-07-15 09:33:07 +030055#include "mbedtls/nist_kw.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Rich Evans18b78c72015-02-11 14:06:19 +000057#include <string.h>
58
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000060#include "mbedtls/platform.h"
Rich Evans18b78c72015-02-11 14:06:19 +000061#else
62#include <stdio.h>
Janos Follath2e3aca22016-03-18 16:25:52 +000063#include <stdlib.h>
Gilles Peskine6fc21f62019-09-17 18:18:58 +020064#define mbedtls_calloc calloc
65#define mbedtls_free free
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066#define mbedtls_printf printf
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +020067#define mbedtls_snprintf snprintf
Janos Follath2e3aca22016-03-18 16:25:52 +000068#define mbedtls_exit exit
69#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
70#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
Rich Evans18b78c72015-02-11 14:06:19 +000071#endif
72
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000074#include "mbedtls/memory_buffer_alloc.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020075#endif
76
Simon Butcher63cb97e2018-12-06 17:43:31 +000077
Gilles Peskine6fc21f62019-09-17 18:18:58 +020078#if defined MBEDTLS_SELF_TEST
79/* Sanity check for malloc. This is not expected to fail, and is rather
80 * intended to display potentially useful information about the platform,
81 * in particular the behavior of malloc(0). */
82static int calloc_self_test( int verbose )
83{
84 int failures = 0;
85 void *empty1 = mbedtls_calloc( 0, 1 );
86 void *empty2 = mbedtls_calloc( 0, 1 );
87 void *buffer1 = mbedtls_calloc( 1, 1 );
88 void *buffer2 = mbedtls_calloc( 1, 1 );
89 uintptr_t old_buffer1;
90
91 if( empty1 == NULL && empty2 == NULL )
92 {
93 if( verbose )
94 mbedtls_printf( " CALLOC(0): passed (NULL)\n" );
95 }
96 else if( empty1 == NULL || empty2 == NULL )
97 {
98 if( verbose )
99 mbedtls_printf( " CALLOC(0): failed (mix of NULL and non-NULL)\n" );
100 ++failures;
101 }
102 else if( empty1 == empty2 )
103 {
104 if( verbose )
105 mbedtls_printf( " CALLOC(0): passed (same non-null)\n" );
106 }
107 else
108 {
109 if( verbose )
110 mbedtls_printf( " CALLOC(0): passed (distinct non-null)\n" );
111 }
112
113 if( buffer1 == NULL || buffer2 == NULL )
114 {
115 if( verbose )
116 mbedtls_printf( " CALLOC(1): failed (NULL)\n" );
117 ++failures;
118 }
119 else if( buffer1 == buffer2 )
120 {
121 if( verbose )
122 mbedtls_printf( " CALLOC(1): failed (same buffer twice)\n" );
123 ++failures;
124 }
125 else
126 {
127 if( verbose )
128 mbedtls_printf( " CALLOC(1): passed\n" );
129 }
130
131 old_buffer1 = (uintptr_t) buffer1;
132 mbedtls_free( buffer1 );
133 buffer1 = mbedtls_calloc( 1, 1 );
134 if( buffer1 == NULL )
135 {
136 if( verbose )
137 mbedtls_printf( " CALLOC(1 again): failed (NULL)\n" );
138 ++failures;
139 }
140 else
141 {
142 if( verbose )
143 mbedtls_printf( " CALLOC(1 again): passed (%s address)\n",
144 (uintptr_t) old_buffer1 == (uintptr_t) buffer1 ?
145 "same" : "different" );
146 }
147
148 if( verbose )
149 mbedtls_printf( "\n" );
150 mbedtls_free( empty1 );
151 mbedtls_free( empty2 );
152 mbedtls_free( buffer1 );
153 mbedtls_free( buffer2 );
154 return( failures );
155}
156#endif /* MBEDTLS_SELF_TEST */
157
Rodrigo Dias Correa80448aa2020-11-10 02:28:50 -0300158static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200159{
160 int ret;
161 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200162 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200163
164 ret = mbedtls_snprintf( buf, n, "%s", "123" );
165 if( ret < 0 || (size_t) ret >= n )
166 ret = -1;
167
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200168 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
169 ref_ret != ret ||
170 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200171 {
172 return( 1 );
173 }
174
175 return( 0 );
176}
177
178static int run_test_snprintf( void )
179{
180 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200181 test_snprintf( 1, "", -1 ) != 0 ||
182 test_snprintf( 2, "1", -1 ) != 0 ||
183 test_snprintf( 3, "12", -1 ) != 0 ||
184 test_snprintf( 4, "123", 3 ) != 0 ||
185 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200186}
187
Simon Butcherb6a73c92016-06-18 22:45:37 +0100188/*
189 * Check if a seed file is present, and if not create one for the entropy
190 * self-test. If this fails, we attempt the test anyway, so no error is passed
191 * back.
192 */
Gilles Peskine319ac802017-12-15 14:57:18 +0100193#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
194#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Simon Butcherb6a73c92016-06-18 22:45:37 +0100195static void create_entropy_seed_file( void )
196{
197 int result;
198 size_t output_len = 0;
199 unsigned char seed_value[MBEDTLS_ENTROPY_BLOCK_SIZE];
200
201 /* Attempt to read the entropy seed file. If this fails - attempt to write
202 * to the file to ensure one is present. */
203 result = mbedtls_platform_std_nv_seed_read( seed_value,
204 MBEDTLS_ENTROPY_BLOCK_SIZE );
205 if( 0 == result )
206 return;
207
208 result = mbedtls_platform_entropy_poll( NULL,
209 seed_value,
210 MBEDTLS_ENTROPY_BLOCK_SIZE,
211 &output_len );
212 if( 0 != result )
213 return;
214
215 if( MBEDTLS_ENTROPY_BLOCK_SIZE != output_len )
216 return;
217
218 mbedtls_platform_std_nv_seed_write( seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE );
219}
220#endif
221
Gilles Peskine319ac802017-12-15 14:57:18 +0100222int mbedtls_entropy_self_test_wrapper( int verbose )
223{
224#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
225 create_entropy_seed_file( );
226#endif
227 return( mbedtls_entropy_self_test( verbose ) );
228}
229#endif
230
231#if defined(MBEDTLS_SELF_TEST)
232#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
233int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose )
234{
235 if( verbose != 0 )
236 {
237#if defined(MBEDTLS_MEMORY_DEBUG)
238 mbedtls_memory_buffer_alloc_status( );
239#endif
240 }
241 mbedtls_memory_buffer_alloc_free( );
242 return( mbedtls_memory_buffer_alloc_self_test( verbose ) );
243}
244#endif
245
246typedef struct
247{
248 const char *name;
249 int ( *function )( int );
250} selftest_t;
251
252const selftest_t selftests[] =
253{
Gilles Peskine6fc21f62019-09-17 18:18:58 +0200254 {"calloc", calloc_self_test},
Gilles Peskine319ac802017-12-15 14:57:18 +0100255#if defined(MBEDTLS_MD5_C)
256 {"md5", mbedtls_md5_self_test},
257#endif
258#if defined(MBEDTLS_RIPEMD160_C)
259 {"ripemd160", mbedtls_ripemd160_self_test},
260#endif
261#if defined(MBEDTLS_SHA1_C)
262 {"sha1", mbedtls_sha1_self_test},
263#endif
264#if defined(MBEDTLS_SHA256_C)
265 {"sha256", mbedtls_sha256_self_test},
266#endif
267#if defined(MBEDTLS_SHA512_C)
268 {"sha512", mbedtls_sha512_self_test},
269#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100270#if defined(MBEDTLS_DES_C)
271 {"des", mbedtls_des_self_test},
272#endif
273#if defined(MBEDTLS_AES_C)
274 {"aes", mbedtls_aes_self_test},
275#endif
276#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
277 {"gcm", mbedtls_gcm_self_test},
278#endif
279#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
280 {"ccm", mbedtls_ccm_self_test},
281#endif
Ron Eldor9ab746c2018-07-15 09:33:07 +0300282#if defined(MBEDTLS_NIST_KW_C) && defined(MBEDTLS_AES_C)
283 {"nist_kw", mbedtls_nist_kw_self_test},
284#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100285#if defined(MBEDTLS_CMAC_C)
286 {"cmac", mbedtls_cmac_self_test},
287#endif
Daniel King4d8f87b2016-05-18 10:09:28 -0300288#if defined(MBEDTLS_CHACHA20_C)
289 {"chacha20", mbedtls_chacha20_self_test},
290#endif
291#if defined(MBEDTLS_POLY1305_C)
292 {"poly1305", mbedtls_poly1305_self_test},
293#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200294#if defined(MBEDTLS_CHACHAPOLY_C)
295 {"chacha20-poly1305", mbedtls_chachapoly_self_test},
Daniel King4d8f87b2016-05-18 10:09:28 -0300296#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100297#if defined(MBEDTLS_BASE64_C)
298 {"base64", mbedtls_base64_self_test},
299#endif
300#if defined(MBEDTLS_BIGNUM_C)
301 {"mpi", mbedtls_mpi_self_test},
302#endif
303#if defined(MBEDTLS_RSA_C)
304 {"rsa", mbedtls_rsa_self_test},
305#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100306#if defined(MBEDTLS_CAMELLIA_C)
307 {"camellia", mbedtls_camellia_self_test},
308#endif
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +0000309#if defined(MBEDTLS_ARIA_C)
310 {"aria", mbedtls_aria_self_test},
311#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100312#if defined(MBEDTLS_CTR_DRBG_C)
313 {"ctr_drbg", mbedtls_ctr_drbg_self_test},
314#endif
315#if defined(MBEDTLS_HMAC_DRBG_C)
316 {"hmac_drbg", mbedtls_hmac_drbg_self_test},
317#endif
318#if defined(MBEDTLS_ECP_C)
319 {"ecp", mbedtls_ecp_self_test},
320#endif
321#if defined(MBEDTLS_ECJPAKE_C)
322 {"ecjpake", mbedtls_ecjpake_self_test},
323#endif
324#if defined(MBEDTLS_DHM_C)
325 {"dhm", mbedtls_dhm_self_test},
326#endif
327#if defined(MBEDTLS_ENTROPY_C)
328 {"entropy", mbedtls_entropy_self_test_wrapper},
329#endif
330#if defined(MBEDTLS_PKCS5_C)
331 {"pkcs5", mbedtls_pkcs5_self_test},
332#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100333/* Heap test comes last */
334#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
335 {"memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test},
336#endif
337 {NULL, NULL}
338};
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100339#endif /* MBEDTLS_SELF_TEST */
Gilles Peskine319ac802017-12-15 14:57:18 +0100340
Paul Bakker5121ce52009-01-03 21:22:43 +0000341int main( int argc, char *argv[] )
342{
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100343#if defined(MBEDTLS_SELF_TEST)
Gilles Peskine319ac802017-12-15 14:57:18 +0100344 const selftest_t *test;
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100345#endif /* MBEDTLS_SELF_TEST */
Gilles Peskineff79d272017-12-20 18:09:27 +0100346 char **argp;
347 int v = 1; /* v=1 for verbose mode */
348 int exclude_mode = 0;
349 int suites_tested = 0, suites_failed = 0;
Paul Bakker70940ca2016-07-14 14:30:45 +0100350#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
Paul Bakker6e339b52013-07-03 13:37:05 +0200351 unsigned char buf[1000000];
352#endif
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200353 void *pointer;
354
355 /*
356 * The C standard doesn't guarantee that all-bits-0 is the representation
357 * of a NULL pointer. We do however use that in our code for initializing
358 * structures, which should work on every modern platform. Let's be sure.
359 */
360 memset( &pointer, 0, sizeof( void * ) );
361 if( pointer != NULL )
362 {
363 mbedtls_printf( "all-bits-zero is not a NULL pointer\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000364 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200365 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000366
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200367 /*
368 * Make sure we have a snprintf that correctly zero-terminates
369 */
370 if( run_test_snprintf() != 0 )
371 {
372 mbedtls_printf( "the snprintf implementation is broken\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000373 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200374 }
375
Gilles Peskineff79d272017-12-20 18:09:27 +0100376 for( argp = argv + ( argc >= 1 ? 1 : argc ); *argp != NULL; ++argp )
SimonB5a8afb82016-03-11 00:40:54 +0000377 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100378 if( strcmp( *argp, "--quiet" ) == 0 ||
379 strcmp( *argp, "-q" ) == 0 )
380 {
381 v = 0;
382 }
383 else if( strcmp( *argp, "--exclude" ) == 0 ||
384 strcmp( *argp, "-x" ) == 0 )
385 {
386 exclude_mode = 1;
387 }
388 else
389 break;
SimonB5a8afb82016-03-11 00:40:54 +0000390 }
Gilles Peskineff79d272017-12-20 18:09:27 +0100391
392 if( v != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200393 mbedtls_printf( "\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000394
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200395#if defined(MBEDTLS_SELF_TEST)
Paul Bakker135b98e2011-05-25 11:13:47 +0000396
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200397#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
398 mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200399#endif
400
Gilles Peskineff79d272017-12-20 18:09:27 +0100401 if( *argp != NULL && exclude_mode == 0 )
SimonB5a8afb82016-03-11 00:40:54 +0000402 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100403 /* Run the specified tests */
404 for( ; *argp != NULL; argp++ )
Gilles Peskine319ac802017-12-15 14:57:18 +0100405 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100406 for( test = selftests; test->name != NULL; test++ )
407 {
408 if( !strcmp( *argp, test->name ) )
409 {
410 if( test->function( v ) != 0 )
411 {
412 suites_failed++;
413 }
414 suites_tested++;
415 break;
416 }
417 }
418 if( test->name == NULL )
419 {
420 mbedtls_printf( " Test suite %s not available -> failed\n\n", *argp );
421 suites_failed++;
422 }
Gilles Peskine319ac802017-12-15 14:57:18 +0100423 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100424 }
425 else
426 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100427 /* Run all the tests except excluded ones */
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100428 for( test = selftests; test->name != NULL; test++ )
429 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100430 if( exclude_mode )
431 {
432 char **excluded;
433 for( excluded = argp; *excluded != NULL; ++excluded )
434 {
435 if( !strcmp( *excluded, test->name ) )
436 break;
437 }
438 if( *excluded )
439 {
440 if( v )
441 mbedtls_printf( " Skip: %s\n", test->name );
442 continue;
443 }
444 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100445 if( test->function( v ) != 0 )
446 {
447 suites_failed++;
448 }
449 suites_tested++;
450 }
SimonB5a8afb82016-03-11 00:40:54 +0000451 }
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100452
Paul Bakker70940ca2016-07-14 14:30:45 +0100453#else
Gilles Peskineff79d272017-12-20 18:09:27 +0100454 (void) exclude_mode;
Paul Bakker70940ca2016-07-14 14:30:45 +0100455 mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
456#endif
457
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100458 if( v != 0 )
459 {
Simon Butcherf1547632016-03-14 23:09:39 +0000460 mbedtls_printf( " Executed %d test suites\n\n", suites_tested );
SimonB5a8afb82016-03-11 00:40:54 +0000461
462 if( suites_failed > 0)
463 {
464 mbedtls_printf( " [ %d tests FAIL ]\n\n", suites_failed );
465 }
466 else
467 {
468 mbedtls_printf( " [ All tests PASS ]\n\n" );
469 }
Paul Bakkercce9d772011-11-18 14:26:47 +0000470#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200471 mbedtls_printf( " Press Enter to exit this program.\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000472 fflush( stdout ); getchar();
473#endif
474 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000475
SimonB5a8afb82016-03-11 00:40:54 +0000476 if( suites_failed > 0)
Janos Follath2e3aca22016-03-18 16:25:52 +0000477 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
SimonB5a8afb82016-03-11 00:40:54 +0000478
Krzysztof Stachowiak5e1b1952019-04-24 14:24:46 +0200479 mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
Paul Bakker5121ce52009-01-03 21:22:43 +0000480}