blob: 26c1997fbe3e6b63ecae29b4ddc74d0d41f8582c [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"
27#include "mbedtls/hmac_drbg.h"
28#include "mbedtls/ctr_drbg.h"
29#include "mbedtls/dhm.h"
30#include "mbedtls/gcm.h"
31#include "mbedtls/ccm.h"
Robert Cragiedc5c7b92015-12-11 15:49:45 +000032#include "mbedtls/cmac.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000033#include "mbedtls/md2.h"
34#include "mbedtls/md4.h"
35#include "mbedtls/md5.h"
36#include "mbedtls/ripemd160.h"
37#include "mbedtls/sha1.h"
38#include "mbedtls/sha256.h"
39#include "mbedtls/sha512.h"
40#include "mbedtls/arc4.h"
41#include "mbedtls/des.h"
42#include "mbedtls/aes.h"
43#include "mbedtls/camellia.h"
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +000044#include "mbedtls/aria.h"
Daniel King4d8f87b2016-05-18 10:09:28 -030045#include "mbedtls/chacha20.h"
46#include "mbedtls/poly1305.h"
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020047#include "mbedtls/chachapoly.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000048#include "mbedtls/base64.h"
49#include "mbedtls/bignum.h"
50#include "mbedtls/rsa.h"
51#include "mbedtls/x509.h"
52#include "mbedtls/xtea.h"
53#include "mbedtls/pkcs5.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000054#include "mbedtls/ecp.h"
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +020055#include "mbedtls/ecjpake.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/timing.h"
Ron Eldor9ab746c2018-07-15 09:33:07 +030057#include "mbedtls/nist_kw.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000058
Rich Evans18b78c72015-02-11 14:06:19 +000059#include <string.h>
60
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000062#include "mbedtls/platform.h"
Rich Evans18b78c72015-02-11 14:06:19 +000063#else
64#include <stdio.h>
Janos Follath2e3aca22016-03-18 16:25:52 +000065#include <stdlib.h>
Gilles Peskine6fc21f62019-09-17 18:18:58 +020066#define mbedtls_calloc calloc
67#define mbedtls_free free
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#define mbedtls_printf printf
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +020069#define mbedtls_snprintf snprintf
Janos Follath2e3aca22016-03-18 16:25:52 +000070#define mbedtls_exit exit
71#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
72#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
Rich Evans18b78c72015-02-11 14:06:19 +000073#endif
74
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000076#include "mbedtls/memory_buffer_alloc.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020077#endif
78
Simon Butcher63cb97e2018-12-06 17:43:31 +000079
Gilles Peskine6fc21f62019-09-17 18:18:58 +020080#if defined MBEDTLS_SELF_TEST
81/* Sanity check for malloc. This is not expected to fail, and is rather
82 * intended to display potentially useful information about the platform,
83 * in particular the behavior of malloc(0). */
84static int calloc_self_test( int verbose )
85{
86 int failures = 0;
87 void *empty1 = mbedtls_calloc( 0, 1 );
88 void *empty2 = mbedtls_calloc( 0, 1 );
89 void *buffer1 = mbedtls_calloc( 1, 1 );
90 void *buffer2 = mbedtls_calloc( 1, 1 );
91 uintptr_t old_buffer1;
92
93 if( empty1 == NULL && empty2 == NULL )
94 {
95 if( verbose )
96 mbedtls_printf( " CALLOC(0): passed (NULL)\n" );
97 }
98 else if( empty1 == NULL || empty2 == NULL )
99 {
100 if( verbose )
101 mbedtls_printf( " CALLOC(0): failed (mix of NULL and non-NULL)\n" );
102 ++failures;
103 }
104 else if( empty1 == empty2 )
105 {
106 if( verbose )
107 mbedtls_printf( " CALLOC(0): passed (same non-null)\n" );
108 }
109 else
110 {
111 if( verbose )
112 mbedtls_printf( " CALLOC(0): passed (distinct non-null)\n" );
113 }
114
115 if( buffer1 == NULL || buffer2 == NULL )
116 {
117 if( verbose )
118 mbedtls_printf( " CALLOC(1): failed (NULL)\n" );
119 ++failures;
120 }
121 else if( buffer1 == buffer2 )
122 {
123 if( verbose )
124 mbedtls_printf( " CALLOC(1): failed (same buffer twice)\n" );
125 ++failures;
126 }
127 else
128 {
129 if( verbose )
130 mbedtls_printf( " CALLOC(1): passed\n" );
131 }
132
133 old_buffer1 = (uintptr_t) buffer1;
134 mbedtls_free( buffer1 );
135 buffer1 = mbedtls_calloc( 1, 1 );
136 if( buffer1 == NULL )
137 {
138 if( verbose )
139 mbedtls_printf( " CALLOC(1 again): failed (NULL)\n" );
140 ++failures;
141 }
142 else
143 {
144 if( verbose )
145 mbedtls_printf( " CALLOC(1 again): passed (%s address)\n",
146 (uintptr_t) old_buffer1 == (uintptr_t) buffer1 ?
147 "same" : "different" );
148 }
149
150 if( verbose )
151 mbedtls_printf( "\n" );
152 mbedtls_free( empty1 );
153 mbedtls_free( empty2 );
154 mbedtls_free( buffer1 );
155 mbedtls_free( buffer2 );
156 return( failures );
157}
158#endif /* MBEDTLS_SELF_TEST */
159
Rodrigo Dias Correa80448aa2020-11-10 02:28:50 -0300160static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200161{
162 int ret;
163 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200164 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200165
166 ret = mbedtls_snprintf( buf, n, "%s", "123" );
167 if( ret < 0 || (size_t) ret >= n )
168 ret = -1;
169
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200170 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
171 ref_ret != ret ||
172 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200173 {
174 return( 1 );
175 }
176
177 return( 0 );
178}
179
180static int run_test_snprintf( void )
181{
182 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200183 test_snprintf( 1, "", -1 ) != 0 ||
184 test_snprintf( 2, "1", -1 ) != 0 ||
185 test_snprintf( 3, "12", -1 ) != 0 ||
186 test_snprintf( 4, "123", 3 ) != 0 ||
187 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200188}
189
Simon Butcherb6a73c92016-06-18 22:45:37 +0100190/*
191 * Check if a seed file is present, and if not create one for the entropy
192 * self-test. If this fails, we attempt the test anyway, so no error is passed
193 * back.
194 */
Gilles Peskine319ac802017-12-15 14:57:18 +0100195#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
196#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Simon Butcherb6a73c92016-06-18 22:45:37 +0100197static void create_entropy_seed_file( void )
198{
199 int result;
200 size_t output_len = 0;
201 unsigned char seed_value[MBEDTLS_ENTROPY_BLOCK_SIZE];
202
203 /* Attempt to read the entropy seed file. If this fails - attempt to write
204 * to the file to ensure one is present. */
205 result = mbedtls_platform_std_nv_seed_read( seed_value,
206 MBEDTLS_ENTROPY_BLOCK_SIZE );
207 if( 0 == result )
208 return;
209
210 result = mbedtls_platform_entropy_poll( NULL,
211 seed_value,
212 MBEDTLS_ENTROPY_BLOCK_SIZE,
213 &output_len );
214 if( 0 != result )
215 return;
216
217 if( MBEDTLS_ENTROPY_BLOCK_SIZE != output_len )
218 return;
219
220 mbedtls_platform_std_nv_seed_write( seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE );
221}
222#endif
223
Gilles Peskine319ac802017-12-15 14:57:18 +0100224int mbedtls_entropy_self_test_wrapper( int verbose )
225{
226#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
227 create_entropy_seed_file( );
228#endif
229 return( mbedtls_entropy_self_test( verbose ) );
230}
231#endif
232
233#if defined(MBEDTLS_SELF_TEST)
234#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
235int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose )
236{
237 if( verbose != 0 )
238 {
239#if defined(MBEDTLS_MEMORY_DEBUG)
240 mbedtls_memory_buffer_alloc_status( );
241#endif
242 }
243 mbedtls_memory_buffer_alloc_free( );
244 return( mbedtls_memory_buffer_alloc_self_test( verbose ) );
245}
246#endif
247
248typedef struct
249{
250 const char *name;
251 int ( *function )( int );
252} selftest_t;
253
254const selftest_t selftests[] =
255{
Gilles Peskine6fc21f62019-09-17 18:18:58 +0200256 {"calloc", calloc_self_test},
Gilles Peskine319ac802017-12-15 14:57:18 +0100257#if defined(MBEDTLS_MD2_C)
258 {"md2", mbedtls_md2_self_test},
259#endif
260#if defined(MBEDTLS_MD4_C)
261 {"md4", mbedtls_md4_self_test},
262#endif
263#if defined(MBEDTLS_MD5_C)
264 {"md5", mbedtls_md5_self_test},
265#endif
266#if defined(MBEDTLS_RIPEMD160_C)
267 {"ripemd160", mbedtls_ripemd160_self_test},
268#endif
269#if defined(MBEDTLS_SHA1_C)
270 {"sha1", mbedtls_sha1_self_test},
271#endif
272#if defined(MBEDTLS_SHA256_C)
273 {"sha256", mbedtls_sha256_self_test},
274#endif
275#if defined(MBEDTLS_SHA512_C)
276 {"sha512", mbedtls_sha512_self_test},
277#endif
278#if defined(MBEDTLS_ARC4_C)
279 {"arc4", mbedtls_arc4_self_test},
280#endif
281#if defined(MBEDTLS_DES_C)
282 {"des", mbedtls_des_self_test},
283#endif
284#if defined(MBEDTLS_AES_C)
285 {"aes", mbedtls_aes_self_test},
286#endif
287#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
288 {"gcm", mbedtls_gcm_self_test},
289#endif
290#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
291 {"ccm", mbedtls_ccm_self_test},
292#endif
Ron Eldor9ab746c2018-07-15 09:33:07 +0300293#if defined(MBEDTLS_NIST_KW_C) && defined(MBEDTLS_AES_C)
294 {"nist_kw", mbedtls_nist_kw_self_test},
295#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100296#if defined(MBEDTLS_CMAC_C)
297 {"cmac", mbedtls_cmac_self_test},
298#endif
Daniel King4d8f87b2016-05-18 10:09:28 -0300299#if defined(MBEDTLS_CHACHA20_C)
300 {"chacha20", mbedtls_chacha20_self_test},
301#endif
302#if defined(MBEDTLS_POLY1305_C)
303 {"poly1305", mbedtls_poly1305_self_test},
304#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200305#if defined(MBEDTLS_CHACHAPOLY_C)
306 {"chacha20-poly1305", mbedtls_chachapoly_self_test},
Daniel King4d8f87b2016-05-18 10:09:28 -0300307#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100308#if defined(MBEDTLS_BASE64_C)
309 {"base64", mbedtls_base64_self_test},
310#endif
311#if defined(MBEDTLS_BIGNUM_C)
312 {"mpi", mbedtls_mpi_self_test},
313#endif
314#if defined(MBEDTLS_RSA_C)
315 {"rsa", mbedtls_rsa_self_test},
316#endif
317#if defined(MBEDTLS_X509_USE_C)
318 {"x509", mbedtls_x509_self_test},
319#endif
320#if defined(MBEDTLS_XTEA_C)
321 {"xtea", mbedtls_xtea_self_test},
322#endif
323#if defined(MBEDTLS_CAMELLIA_C)
324 {"camellia", mbedtls_camellia_self_test},
325#endif
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +0000326#if defined(MBEDTLS_ARIA_C)
327 {"aria", mbedtls_aria_self_test},
328#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100329#if defined(MBEDTLS_CTR_DRBG_C)
330 {"ctr_drbg", mbedtls_ctr_drbg_self_test},
331#endif
332#if defined(MBEDTLS_HMAC_DRBG_C)
333 {"hmac_drbg", mbedtls_hmac_drbg_self_test},
334#endif
335#if defined(MBEDTLS_ECP_C)
336 {"ecp", mbedtls_ecp_self_test},
337#endif
338#if defined(MBEDTLS_ECJPAKE_C)
339 {"ecjpake", mbedtls_ecjpake_self_test},
340#endif
341#if defined(MBEDTLS_DHM_C)
342 {"dhm", mbedtls_dhm_self_test},
343#endif
344#if defined(MBEDTLS_ENTROPY_C)
345 {"entropy", mbedtls_entropy_self_test_wrapper},
346#endif
347#if defined(MBEDTLS_PKCS5_C)
348 {"pkcs5", mbedtls_pkcs5_self_test},
349#endif
350/* Slower test after the faster ones */
351#if defined(MBEDTLS_TIMING_C)
352 {"timing", mbedtls_timing_self_test},
353#endif
354/* Heap test comes last */
355#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
356 {"memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test},
357#endif
358 {NULL, NULL}
359};
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100360#endif /* MBEDTLS_SELF_TEST */
Gilles Peskine319ac802017-12-15 14:57:18 +0100361
Paul Bakker5121ce52009-01-03 21:22:43 +0000362int main( int argc, char *argv[] )
363{
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100364#if defined(MBEDTLS_SELF_TEST)
Gilles Peskine319ac802017-12-15 14:57:18 +0100365 const selftest_t *test;
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100366#endif /* MBEDTLS_SELF_TEST */
Gilles Peskineff79d272017-12-20 18:09:27 +0100367 char **argp;
368 int v = 1; /* v=1 for verbose mode */
369 int exclude_mode = 0;
370 int suites_tested = 0, suites_failed = 0;
Paul Bakker70940ca2016-07-14 14:30:45 +0100371#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
Paul Bakker6e339b52013-07-03 13:37:05 +0200372 unsigned char buf[1000000];
373#endif
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200374 void *pointer;
375
376 /*
377 * The C standard doesn't guarantee that all-bits-0 is the representation
378 * of a NULL pointer. We do however use that in our code for initializing
379 * structures, which should work on every modern platform. Let's be sure.
380 */
381 memset( &pointer, 0, sizeof( void * ) );
382 if( pointer != NULL )
383 {
384 mbedtls_printf( "all-bits-zero is not a NULL pointer\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000385 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200386 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000387
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200388 /*
389 * Make sure we have a snprintf that correctly zero-terminates
390 */
391 if( run_test_snprintf() != 0 )
392 {
393 mbedtls_printf( "the snprintf implementation is broken\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000394 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200395 }
396
Gilles Peskineff79d272017-12-20 18:09:27 +0100397 for( argp = argv + ( argc >= 1 ? 1 : argc ); *argp != NULL; ++argp )
SimonB5a8afb82016-03-11 00:40:54 +0000398 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100399 if( strcmp( *argp, "--quiet" ) == 0 ||
400 strcmp( *argp, "-q" ) == 0 )
401 {
402 v = 0;
403 }
404 else if( strcmp( *argp, "--exclude" ) == 0 ||
405 strcmp( *argp, "-x" ) == 0 )
406 {
407 exclude_mode = 1;
408 }
409 else
410 break;
SimonB5a8afb82016-03-11 00:40:54 +0000411 }
Gilles Peskineff79d272017-12-20 18:09:27 +0100412
413 if( v != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200414 mbedtls_printf( "\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000415
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200416#if defined(MBEDTLS_SELF_TEST)
Paul Bakker135b98e2011-05-25 11:13:47 +0000417
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200418#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
419 mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200420#endif
421
Gilles Peskineff79d272017-12-20 18:09:27 +0100422 if( *argp != NULL && exclude_mode == 0 )
SimonB5a8afb82016-03-11 00:40:54 +0000423 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100424 /* Run the specified tests */
425 for( ; *argp != NULL; argp++ )
Gilles Peskine319ac802017-12-15 14:57:18 +0100426 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100427 for( test = selftests; test->name != NULL; test++ )
428 {
429 if( !strcmp( *argp, test->name ) )
430 {
431 if( test->function( v ) != 0 )
432 {
433 suites_failed++;
434 }
435 suites_tested++;
436 break;
437 }
438 }
439 if( test->name == NULL )
440 {
441 mbedtls_printf( " Test suite %s not available -> failed\n\n", *argp );
442 suites_failed++;
443 }
Gilles Peskine319ac802017-12-15 14:57:18 +0100444 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100445 }
446 else
447 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100448 /* Run all the tests except excluded ones */
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100449 for( test = selftests; test->name != NULL; test++ )
450 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100451 if( exclude_mode )
452 {
453 char **excluded;
454 for( excluded = argp; *excluded != NULL; ++excluded )
455 {
456 if( !strcmp( *excluded, test->name ) )
457 break;
458 }
459 if( *excluded )
460 {
461 if( v )
462 mbedtls_printf( " Skip: %s\n", test->name );
463 continue;
464 }
465 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100466 if( test->function( v ) != 0 )
467 {
468 suites_failed++;
469 }
470 suites_tested++;
471 }
SimonB5a8afb82016-03-11 00:40:54 +0000472 }
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100473
Paul Bakker70940ca2016-07-14 14:30:45 +0100474#else
Gilles Peskineff79d272017-12-20 18:09:27 +0100475 (void) exclude_mode;
Paul Bakker70940ca2016-07-14 14:30:45 +0100476 mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
477#endif
478
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100479 if( v != 0 )
480 {
Simon Butcherf1547632016-03-14 23:09:39 +0000481 mbedtls_printf( " Executed %d test suites\n\n", suites_tested );
SimonB5a8afb82016-03-11 00:40:54 +0000482
483 if( suites_failed > 0)
484 {
485 mbedtls_printf( " [ %d tests FAIL ]\n\n", suites_failed );
486 }
487 else
488 {
489 mbedtls_printf( " [ All tests PASS ]\n\n" );
490 }
Paul Bakkercce9d772011-11-18 14:26:47 +0000491#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200492 mbedtls_printf( " Press Enter to exit this program.\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000493 fflush( stdout ); getchar();
494#endif
495 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000496
SimonB5a8afb82016-03-11 00:40:54 +0000497 if( suites_failed > 0)
Janos Follath2e3aca22016-03-18 16:25:52 +0000498 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
SimonB5a8afb82016-03-11 00:40:54 +0000499
Krzysztof Stachowiak5e1b1952019-04-24 14:24:46 +0200500 mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
Paul Bakker5121ce52009-01-03 21:22:43 +0000501}