blob: a3e306ce91d2d2f6232a395761ea981aaa017dc1 [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/md2.h"
36#include "mbedtls/md4.h"
37#include "mbedtls/md5.h"
38#include "mbedtls/ripemd160.h"
39#include "mbedtls/sha1.h"
40#include "mbedtls/sha256.h"
41#include "mbedtls/sha512.h"
42#include "mbedtls/arc4.h"
43#include "mbedtls/des.h"
44#include "mbedtls/aes.h"
45#include "mbedtls/camellia.h"
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +000046#include "mbedtls/aria.h"
Daniel King4d8f87b2016-05-18 10:09:28 -030047#include "mbedtls/chacha20.h"
48#include "mbedtls/poly1305.h"
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020049#include "mbedtls/chachapoly.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000050#include "mbedtls/base64.h"
51#include "mbedtls/bignum.h"
52#include "mbedtls/rsa.h"
53#include "mbedtls/x509.h"
54#include "mbedtls/xtea.h"
55#include "mbedtls/pkcs5.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/ecp.h"
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +020057#include "mbedtls/ecjpake.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000058#include "mbedtls/timing.h"
Ron Eldor9ab746c2018-07-15 09:33:07 +030059#include "mbedtls/nist_kw.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000060
Rich Evans18b78c72015-02-11 14:06:19 +000061#include <string.h>
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000064#include "mbedtls/platform.h"
Rich Evans18b78c72015-02-11 14:06:19 +000065#else
66#include <stdio.h>
Janos Follath2e3aca22016-03-18 16:25:52 +000067#include <stdlib.h>
Gilles Peskine6fc21f62019-09-17 18:18:58 +020068#define mbedtls_calloc calloc
69#define mbedtls_free free
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070#define mbedtls_printf printf
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +020071#define mbedtls_snprintf snprintf
Janos Follath2e3aca22016-03-18 16:25:52 +000072#define mbedtls_exit exit
73#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
74#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
Rich Evans18b78c72015-02-11 14:06:19 +000075#endif
76
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000078#include "mbedtls/memory_buffer_alloc.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020079#endif
80
Simon Butcher63cb97e2018-12-06 17:43:31 +000081
Gilles Peskine6fc21f62019-09-17 18:18:58 +020082#if defined MBEDTLS_SELF_TEST
83/* Sanity check for malloc. This is not expected to fail, and is rather
84 * intended to display potentially useful information about the platform,
85 * in particular the behavior of malloc(0). */
86static int calloc_self_test( int verbose )
87{
88 int failures = 0;
89 void *empty1 = mbedtls_calloc( 0, 1 );
90 void *empty2 = mbedtls_calloc( 0, 1 );
91 void *buffer1 = mbedtls_calloc( 1, 1 );
92 void *buffer2 = mbedtls_calloc( 1, 1 );
93 uintptr_t old_buffer1;
94
95 if( empty1 == NULL && empty2 == NULL )
96 {
97 if( verbose )
98 mbedtls_printf( " CALLOC(0): passed (NULL)\n" );
99 }
100 else if( empty1 == NULL || empty2 == NULL )
101 {
102 if( verbose )
103 mbedtls_printf( " CALLOC(0): failed (mix of NULL and non-NULL)\n" );
104 ++failures;
105 }
106 else if( empty1 == empty2 )
107 {
108 if( verbose )
109 mbedtls_printf( " CALLOC(0): passed (same non-null)\n" );
110 }
111 else
112 {
113 if( verbose )
114 mbedtls_printf( " CALLOC(0): passed (distinct non-null)\n" );
115 }
116
117 if( buffer1 == NULL || buffer2 == NULL )
118 {
119 if( verbose )
120 mbedtls_printf( " CALLOC(1): failed (NULL)\n" );
121 ++failures;
122 }
123 else if( buffer1 == buffer2 )
124 {
125 if( verbose )
126 mbedtls_printf( " CALLOC(1): failed (same buffer twice)\n" );
127 ++failures;
128 }
129 else
130 {
131 if( verbose )
132 mbedtls_printf( " CALLOC(1): passed\n" );
133 }
134
135 old_buffer1 = (uintptr_t) buffer1;
136 mbedtls_free( buffer1 );
137 buffer1 = mbedtls_calloc( 1, 1 );
138 if( buffer1 == NULL )
139 {
140 if( verbose )
141 mbedtls_printf( " CALLOC(1 again): failed (NULL)\n" );
142 ++failures;
143 }
144 else
145 {
146 if( verbose )
147 mbedtls_printf( " CALLOC(1 again): passed (%s address)\n",
148 (uintptr_t) old_buffer1 == (uintptr_t) buffer1 ?
149 "same" : "different" );
150 }
151
152 if( verbose )
153 mbedtls_printf( "\n" );
154 mbedtls_free( empty1 );
155 mbedtls_free( empty2 );
156 mbedtls_free( buffer1 );
157 mbedtls_free( buffer2 );
158 return( failures );
159}
160#endif /* MBEDTLS_SELF_TEST */
161
Rodrigo Dias Correa80448aa2020-11-10 02:28:50 -0300162static int test_snprintf( size_t n, const char *ref_buf, int ref_ret )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200163{
164 int ret;
165 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200166 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200167
168 ret = mbedtls_snprintf( buf, n, "%s", "123" );
169 if( ret < 0 || (size_t) ret >= n )
170 ret = -1;
171
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200172 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
173 ref_ret != ret ||
174 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200175 {
176 return( 1 );
177 }
178
179 return( 0 );
180}
181
182static int run_test_snprintf( void )
183{
184 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200185 test_snprintf( 1, "", -1 ) != 0 ||
186 test_snprintf( 2, "1", -1 ) != 0 ||
187 test_snprintf( 3, "12", -1 ) != 0 ||
188 test_snprintf( 4, "123", 3 ) != 0 ||
189 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200190}
191
Simon Butcherb6a73c92016-06-18 22:45:37 +0100192/*
193 * Check if a seed file is present, and if not create one for the entropy
194 * self-test. If this fails, we attempt the test anyway, so no error is passed
195 * back.
196 */
Gilles Peskine319ac802017-12-15 14:57:18 +0100197#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
198#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Simon Butcherb6a73c92016-06-18 22:45:37 +0100199static void create_entropy_seed_file( void )
200{
201 int result;
202 size_t output_len = 0;
203 unsigned char seed_value[MBEDTLS_ENTROPY_BLOCK_SIZE];
204
205 /* Attempt to read the entropy seed file. If this fails - attempt to write
206 * to the file to ensure one is present. */
207 result = mbedtls_platform_std_nv_seed_read( seed_value,
208 MBEDTLS_ENTROPY_BLOCK_SIZE );
209 if( 0 == result )
210 return;
211
212 result = mbedtls_platform_entropy_poll( NULL,
213 seed_value,
214 MBEDTLS_ENTROPY_BLOCK_SIZE,
215 &output_len );
216 if( 0 != result )
217 return;
218
219 if( MBEDTLS_ENTROPY_BLOCK_SIZE != output_len )
220 return;
221
222 mbedtls_platform_std_nv_seed_write( seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE );
223}
224#endif
225
Gilles Peskine319ac802017-12-15 14:57:18 +0100226int mbedtls_entropy_self_test_wrapper( int verbose )
227{
228#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
229 create_entropy_seed_file( );
230#endif
231 return( mbedtls_entropy_self_test( verbose ) );
232}
233#endif
234
235#if defined(MBEDTLS_SELF_TEST)
236#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
237int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose )
238{
239 if( verbose != 0 )
240 {
241#if defined(MBEDTLS_MEMORY_DEBUG)
242 mbedtls_memory_buffer_alloc_status( );
243#endif
244 }
245 mbedtls_memory_buffer_alloc_free( );
246 return( mbedtls_memory_buffer_alloc_self_test( verbose ) );
247}
248#endif
249
250typedef struct
251{
252 const char *name;
253 int ( *function )( int );
254} selftest_t;
255
256const selftest_t selftests[] =
257{
Gilles Peskine6fc21f62019-09-17 18:18:58 +0200258 {"calloc", calloc_self_test},
Gilles Peskine319ac802017-12-15 14:57:18 +0100259#if defined(MBEDTLS_MD2_C)
260 {"md2", mbedtls_md2_self_test},
261#endif
262#if defined(MBEDTLS_MD4_C)
263 {"md4", mbedtls_md4_self_test},
264#endif
265#if defined(MBEDTLS_MD5_C)
266 {"md5", mbedtls_md5_self_test},
267#endif
268#if defined(MBEDTLS_RIPEMD160_C)
269 {"ripemd160", mbedtls_ripemd160_self_test},
270#endif
271#if defined(MBEDTLS_SHA1_C)
272 {"sha1", mbedtls_sha1_self_test},
273#endif
274#if defined(MBEDTLS_SHA256_C)
275 {"sha256", mbedtls_sha256_self_test},
276#endif
277#if defined(MBEDTLS_SHA512_C)
278 {"sha512", mbedtls_sha512_self_test},
279#endif
280#if defined(MBEDTLS_ARC4_C)
281 {"arc4", mbedtls_arc4_self_test},
282#endif
283#if defined(MBEDTLS_DES_C)
284 {"des", mbedtls_des_self_test},
285#endif
286#if defined(MBEDTLS_AES_C)
287 {"aes", mbedtls_aes_self_test},
288#endif
289#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
290 {"gcm", mbedtls_gcm_self_test},
291#endif
292#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
293 {"ccm", mbedtls_ccm_self_test},
294#endif
Ron Eldor9ab746c2018-07-15 09:33:07 +0300295#if defined(MBEDTLS_NIST_KW_C) && defined(MBEDTLS_AES_C)
296 {"nist_kw", mbedtls_nist_kw_self_test},
297#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100298#if defined(MBEDTLS_CMAC_C)
299 {"cmac", mbedtls_cmac_self_test},
300#endif
Daniel King4d8f87b2016-05-18 10:09:28 -0300301#if defined(MBEDTLS_CHACHA20_C)
302 {"chacha20", mbedtls_chacha20_self_test},
303#endif
304#if defined(MBEDTLS_POLY1305_C)
305 {"poly1305", mbedtls_poly1305_self_test},
306#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200307#if defined(MBEDTLS_CHACHAPOLY_C)
308 {"chacha20-poly1305", mbedtls_chachapoly_self_test},
Daniel King4d8f87b2016-05-18 10:09:28 -0300309#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100310#if defined(MBEDTLS_BASE64_C)
311 {"base64", mbedtls_base64_self_test},
312#endif
313#if defined(MBEDTLS_BIGNUM_C)
314 {"mpi", mbedtls_mpi_self_test},
315#endif
316#if defined(MBEDTLS_RSA_C)
317 {"rsa", mbedtls_rsa_self_test},
318#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100319#if defined(MBEDTLS_XTEA_C)
320 {"xtea", mbedtls_xtea_self_test},
321#endif
322#if defined(MBEDTLS_CAMELLIA_C)
323 {"camellia", mbedtls_camellia_self_test},
324#endif
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +0000325#if defined(MBEDTLS_ARIA_C)
326 {"aria", mbedtls_aria_self_test},
327#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100328#if defined(MBEDTLS_CTR_DRBG_C)
329 {"ctr_drbg", mbedtls_ctr_drbg_self_test},
330#endif
331#if defined(MBEDTLS_HMAC_DRBG_C)
332 {"hmac_drbg", mbedtls_hmac_drbg_self_test},
333#endif
334#if defined(MBEDTLS_ECP_C)
335 {"ecp", mbedtls_ecp_self_test},
336#endif
337#if defined(MBEDTLS_ECJPAKE_C)
338 {"ecjpake", mbedtls_ecjpake_self_test},
339#endif
340#if defined(MBEDTLS_DHM_C)
341 {"dhm", mbedtls_dhm_self_test},
342#endif
343#if defined(MBEDTLS_ENTROPY_C)
344 {"entropy", mbedtls_entropy_self_test_wrapper},
345#endif
346#if defined(MBEDTLS_PKCS5_C)
347 {"pkcs5", mbedtls_pkcs5_self_test},
348#endif
349/* Slower test after the faster ones */
350#if defined(MBEDTLS_TIMING_C)
351 {"timing", mbedtls_timing_self_test},
352#endif
353/* Heap test comes last */
354#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
355 {"memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test},
356#endif
357 {NULL, NULL}
358};
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100359#endif /* MBEDTLS_SELF_TEST */
Gilles Peskine319ac802017-12-15 14:57:18 +0100360
Paul Bakker5121ce52009-01-03 21:22:43 +0000361int main( int argc, char *argv[] )
362{
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100363#if defined(MBEDTLS_SELF_TEST)
Gilles Peskine319ac802017-12-15 14:57:18 +0100364 const selftest_t *test;
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100365#endif /* MBEDTLS_SELF_TEST */
Gilles Peskineff79d272017-12-20 18:09:27 +0100366 char **argp;
367 int v = 1; /* v=1 for verbose mode */
368 int exclude_mode = 0;
369 int suites_tested = 0, suites_failed = 0;
Paul Bakker70940ca2016-07-14 14:30:45 +0100370#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
Paul Bakker6e339b52013-07-03 13:37:05 +0200371 unsigned char buf[1000000];
372#endif
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200373 void *pointer;
374
375 /*
376 * The C standard doesn't guarantee that all-bits-0 is the representation
377 * of a NULL pointer. We do however use that in our code for initializing
378 * structures, which should work on every modern platform. Let's be sure.
379 */
380 memset( &pointer, 0, sizeof( void * ) );
381 if( pointer != NULL )
382 {
383 mbedtls_printf( "all-bits-zero is not a NULL pointer\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000384 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200385 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000386
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200387 /*
388 * Make sure we have a snprintf that correctly zero-terminates
389 */
390 if( run_test_snprintf() != 0 )
391 {
392 mbedtls_printf( "the snprintf implementation is broken\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000393 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200394 }
395
Gilles Peskineff79d272017-12-20 18:09:27 +0100396 for( argp = argv + ( argc >= 1 ? 1 : argc ); *argp != NULL; ++argp )
SimonB5a8afb82016-03-11 00:40:54 +0000397 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100398 if( strcmp( *argp, "--quiet" ) == 0 ||
399 strcmp( *argp, "-q" ) == 0 )
400 {
401 v = 0;
402 }
403 else if( strcmp( *argp, "--exclude" ) == 0 ||
404 strcmp( *argp, "-x" ) == 0 )
405 {
406 exclude_mode = 1;
407 }
408 else
409 break;
SimonB5a8afb82016-03-11 00:40:54 +0000410 }
Gilles Peskineff79d272017-12-20 18:09:27 +0100411
412 if( v != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200413 mbedtls_printf( "\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000414
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415#if defined(MBEDTLS_SELF_TEST)
Paul Bakker135b98e2011-05-25 11:13:47 +0000416
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200417#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
418 mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200419#endif
420
Gilles Peskineff79d272017-12-20 18:09:27 +0100421 if( *argp != NULL && exclude_mode == 0 )
SimonB5a8afb82016-03-11 00:40:54 +0000422 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100423 /* Run the specified tests */
424 for( ; *argp != NULL; argp++ )
Gilles Peskine319ac802017-12-15 14:57:18 +0100425 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100426 for( test = selftests; test->name != NULL; test++ )
427 {
428 if( !strcmp( *argp, test->name ) )
429 {
430 if( test->function( v ) != 0 )
431 {
432 suites_failed++;
433 }
434 suites_tested++;
435 break;
436 }
437 }
438 if( test->name == NULL )
439 {
440 mbedtls_printf( " Test suite %s not available -> failed\n\n", *argp );
441 suites_failed++;
442 }
Gilles Peskine319ac802017-12-15 14:57:18 +0100443 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100444 }
445 else
446 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100447 /* Run all the tests except excluded ones */
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100448 for( test = selftests; test->name != NULL; test++ )
449 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100450 if( exclude_mode )
451 {
452 char **excluded;
453 for( excluded = argp; *excluded != NULL; ++excluded )
454 {
455 if( !strcmp( *excluded, test->name ) )
456 break;
457 }
458 if( *excluded )
459 {
460 if( v )
461 mbedtls_printf( " Skip: %s\n", test->name );
462 continue;
463 }
464 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100465 if( test->function( v ) != 0 )
466 {
467 suites_failed++;
468 }
469 suites_tested++;
470 }
SimonB5a8afb82016-03-11 00:40:54 +0000471 }
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100472
Paul Bakker70940ca2016-07-14 14:30:45 +0100473#else
Gilles Peskineff79d272017-12-20 18:09:27 +0100474 (void) exclude_mode;
Paul Bakker70940ca2016-07-14 14:30:45 +0100475 mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
476#endif
477
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100478 if( v != 0 )
479 {
Simon Butcherf1547632016-03-14 23:09:39 +0000480 mbedtls_printf( " Executed %d test suites\n\n", suites_tested );
SimonB5a8afb82016-03-11 00:40:54 +0000481
482 if( suites_failed > 0)
483 {
484 mbedtls_printf( " [ %d tests FAIL ]\n\n", suites_failed );
485 }
486 else
487 {
488 mbedtls_printf( " [ All tests PASS ]\n\n" );
489 }
Paul Bakkercce9d772011-11-18 14:26:47 +0000490#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200491 mbedtls_printf( " Press Enter to exit this program.\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000492 fflush( stdout ); getchar();
493#endif
494 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000495
SimonB5a8afb82016-03-11 00:40:54 +0000496 if( suites_failed > 0)
Janos Follath2e3aca22016-03-18 16:25:52 +0000497 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
SimonB5a8afb82016-03-11 00:40:54 +0000498
Krzysztof Stachowiak5e1b1952019-04-24 14:24:46 +0200499 mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
Paul Bakker5121ce52009-01-03 21:22:43 +0000500}