blob: 3fa05f315651a43bdd30b6948576a58b69a2012d [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Self-test demonstration program
3 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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 Bakkerb96f1542010-07-18 20:36:00 +000018 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000019 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000020 */
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"
Simon Butcherb6a73c92016-06-18 22:45:37 +010029#include "mbedtls/entropy_poll.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000030#include "mbedtls/hmac_drbg.h"
31#include "mbedtls/ctr_drbg.h"
32#include "mbedtls/dhm.h"
33#include "mbedtls/gcm.h"
34#include "mbedtls/ccm.h"
Robert Cragiedc5c7b92015-12-11 15:49:45 +000035#include "mbedtls/cmac.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000036#include "mbedtls/md2.h"
37#include "mbedtls/md4.h"
38#include "mbedtls/md5.h"
39#include "mbedtls/ripemd160.h"
40#include "mbedtls/sha1.h"
41#include "mbedtls/sha256.h"
42#include "mbedtls/sha512.h"
43#include "mbedtls/arc4.h"
44#include "mbedtls/des.h"
45#include "mbedtls/aes.h"
46#include "mbedtls/camellia.h"
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +000047#include "mbedtls/aria.h"
Daniel King4d8f87b2016-05-18 10:09:28 -030048#include "mbedtls/chacha20.h"
49#include "mbedtls/poly1305.h"
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020050#include "mbedtls/chachapoly.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000051#include "mbedtls/base64.h"
52#include "mbedtls/bignum.h"
53#include "mbedtls/rsa.h"
54#include "mbedtls/x509.h"
55#include "mbedtls/xtea.h"
56#include "mbedtls/pkcs5.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/ecp.h"
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +020058#include "mbedtls/ecjpake.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000059#include "mbedtls/timing.h"
Ron Eldor9ab746c2018-07-15 09:33:07 +030060#include "mbedtls/nist_kw.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000061
Rich Evans18b78c72015-02-11 14:06:19 +000062#include <string.h>
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/platform.h"
Rich Evans18b78c72015-02-11 14:06:19 +000066#else
67#include <stdio.h>
Janos Follath2e3aca22016-03-18 16:25:52 +000068#include <stdlib.h>
Gilles Peskine6fc21f62019-09-17 18:18:58 +020069#define mbedtls_calloc calloc
70#define mbedtls_free free
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#define mbedtls_printf printf
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +020072#define mbedtls_snprintf snprintf
Janos Follath2e3aca22016-03-18 16:25:52 +000073#define mbedtls_exit exit
74#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
75#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
Rich Evans18b78c72015-02-11 14:06:19 +000076#endif
77
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000079#include "mbedtls/memory_buffer_alloc.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020080#endif
81
Simon Butcher63cb97e2018-12-06 17:43:31 +000082
Gilles Peskine6fc21f62019-09-17 18:18:58 +020083#if defined MBEDTLS_SELF_TEST
84/* Sanity check for malloc. This is not expected to fail, and is rather
85 * intended to display potentially useful information about the platform,
86 * in particular the behavior of malloc(0). */
87static int calloc_self_test( int verbose )
88{
89 int failures = 0;
90 void *empty1 = mbedtls_calloc( 0, 1 );
91 void *empty2 = mbedtls_calloc( 0, 1 );
92 void *buffer1 = mbedtls_calloc( 1, 1 );
93 void *buffer2 = mbedtls_calloc( 1, 1 );
94 uintptr_t old_buffer1;
95
96 if( empty1 == NULL && empty2 == NULL )
97 {
98 if( verbose )
99 mbedtls_printf( " CALLOC(0): passed (NULL)\n" );
100 }
101 else if( empty1 == NULL || empty2 == NULL )
102 {
103 if( verbose )
104 mbedtls_printf( " CALLOC(0): failed (mix of NULL and non-NULL)\n" );
105 ++failures;
106 }
107 else if( empty1 == empty2 )
108 {
109 if( verbose )
110 mbedtls_printf( " CALLOC(0): passed (same non-null)\n" );
111 }
112 else
113 {
114 if( verbose )
115 mbedtls_printf( " CALLOC(0): passed (distinct non-null)\n" );
116 }
117
118 if( buffer1 == NULL || buffer2 == NULL )
119 {
120 if( verbose )
121 mbedtls_printf( " CALLOC(1): failed (NULL)\n" );
122 ++failures;
123 }
124 else if( buffer1 == buffer2 )
125 {
126 if( verbose )
127 mbedtls_printf( " CALLOC(1): failed (same buffer twice)\n" );
128 ++failures;
129 }
130 else
131 {
132 if( verbose )
133 mbedtls_printf( " CALLOC(1): passed\n" );
134 }
135
136 old_buffer1 = (uintptr_t) buffer1;
137 mbedtls_free( buffer1 );
138 buffer1 = mbedtls_calloc( 1, 1 );
139 if( buffer1 == NULL )
140 {
141 if( verbose )
142 mbedtls_printf( " CALLOC(1 again): failed (NULL)\n" );
143 ++failures;
144 }
145 else
146 {
147 if( verbose )
148 mbedtls_printf( " CALLOC(1 again): passed (%s address)\n",
149 (uintptr_t) old_buffer1 == (uintptr_t) buffer1 ?
150 "same" : "different" );
151 }
152
153 if( verbose )
154 mbedtls_printf( "\n" );
155 mbedtls_free( empty1 );
156 mbedtls_free( empty2 );
157 mbedtls_free( buffer1 );
158 mbedtls_free( buffer2 );
159 return( failures );
160}
161#endif /* MBEDTLS_SELF_TEST */
162
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200163static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
164{
165 int ret;
166 char buf[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200167 const char ref[10] = "xxxxxxxxx";
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200168
169 ret = mbedtls_snprintf( buf, n, "%s", "123" );
170 if( ret < 0 || (size_t) ret >= n )
171 ret = -1;
172
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200173 if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
174 ref_ret != ret ||
175 memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200176 {
177 return( 1 );
178 }
179
180 return( 0 );
181}
182
183static int run_test_snprintf( void )
184{
185 return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
Manuel Pégourié-Gonnard4b00f082015-06-26 11:24:32 +0200186 test_snprintf( 1, "", -1 ) != 0 ||
187 test_snprintf( 2, "1", -1 ) != 0 ||
188 test_snprintf( 3, "12", -1 ) != 0 ||
189 test_snprintf( 4, "123", 3 ) != 0 ||
190 test_snprintf( 5, "123", 3 ) != 0 );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200191}
192
Simon Butcherb6a73c92016-06-18 22:45:37 +0100193/*
194 * Check if a seed file is present, and if not create one for the entropy
195 * self-test. If this fails, we attempt the test anyway, so no error is passed
196 * back.
197 */
Gilles Peskine319ac802017-12-15 14:57:18 +0100198#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
199#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
Simon Butcherb6a73c92016-06-18 22:45:37 +0100200static void create_entropy_seed_file( void )
201{
202 int result;
203 size_t output_len = 0;
204 unsigned char seed_value[MBEDTLS_ENTROPY_BLOCK_SIZE];
205
206 /* Attempt to read the entropy seed file. If this fails - attempt to write
207 * to the file to ensure one is present. */
208 result = mbedtls_platform_std_nv_seed_read( seed_value,
209 MBEDTLS_ENTROPY_BLOCK_SIZE );
210 if( 0 == result )
211 return;
212
213 result = mbedtls_platform_entropy_poll( NULL,
214 seed_value,
215 MBEDTLS_ENTROPY_BLOCK_SIZE,
216 &output_len );
217 if( 0 != result )
218 return;
219
220 if( MBEDTLS_ENTROPY_BLOCK_SIZE != output_len )
221 return;
222
223 mbedtls_platform_std_nv_seed_write( seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE );
224}
225#endif
226
Gilles Peskine319ac802017-12-15 14:57:18 +0100227int mbedtls_entropy_self_test_wrapper( int verbose )
228{
229#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
230 create_entropy_seed_file( );
231#endif
232 return( mbedtls_entropy_self_test( verbose ) );
233}
234#endif
235
236#if defined(MBEDTLS_SELF_TEST)
237#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
238int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose )
239{
240 if( verbose != 0 )
241 {
242#if defined(MBEDTLS_MEMORY_DEBUG)
243 mbedtls_memory_buffer_alloc_status( );
244#endif
245 }
246 mbedtls_memory_buffer_alloc_free( );
247 return( mbedtls_memory_buffer_alloc_self_test( verbose ) );
248}
249#endif
250
251typedef struct
252{
253 const char *name;
254 int ( *function )( int );
255} selftest_t;
256
257const selftest_t selftests[] =
258{
Gilles Peskine6fc21f62019-09-17 18:18:58 +0200259 {"calloc", calloc_self_test},
Gilles Peskine319ac802017-12-15 14:57:18 +0100260#if defined(MBEDTLS_MD2_C)
261 {"md2", mbedtls_md2_self_test},
262#endif
263#if defined(MBEDTLS_MD4_C)
264 {"md4", mbedtls_md4_self_test},
265#endif
266#if defined(MBEDTLS_MD5_C)
267 {"md5", mbedtls_md5_self_test},
268#endif
269#if defined(MBEDTLS_RIPEMD160_C)
270 {"ripemd160", mbedtls_ripemd160_self_test},
271#endif
272#if defined(MBEDTLS_SHA1_C)
273 {"sha1", mbedtls_sha1_self_test},
274#endif
275#if defined(MBEDTLS_SHA256_C)
276 {"sha256", mbedtls_sha256_self_test},
277#endif
278#if defined(MBEDTLS_SHA512_C)
279 {"sha512", mbedtls_sha512_self_test},
280#endif
281#if defined(MBEDTLS_ARC4_C)
282 {"arc4", mbedtls_arc4_self_test},
283#endif
284#if defined(MBEDTLS_DES_C)
285 {"des", mbedtls_des_self_test},
286#endif
287#if defined(MBEDTLS_AES_C)
288 {"aes", mbedtls_aes_self_test},
289#endif
290#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
291 {"gcm", mbedtls_gcm_self_test},
292#endif
293#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
294 {"ccm", mbedtls_ccm_self_test},
295#endif
Ron Eldor9ab746c2018-07-15 09:33:07 +0300296#if defined(MBEDTLS_NIST_KW_C) && defined(MBEDTLS_AES_C)
297 {"nist_kw", mbedtls_nist_kw_self_test},
298#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100299#if defined(MBEDTLS_CMAC_C)
300 {"cmac", mbedtls_cmac_self_test},
301#endif
Daniel King4d8f87b2016-05-18 10:09:28 -0300302#if defined(MBEDTLS_CHACHA20_C)
303 {"chacha20", mbedtls_chacha20_self_test},
304#endif
305#if defined(MBEDTLS_POLY1305_C)
306 {"poly1305", mbedtls_poly1305_self_test},
307#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +0200308#if defined(MBEDTLS_CHACHAPOLY_C)
309 {"chacha20-poly1305", mbedtls_chachapoly_self_test},
Daniel King4d8f87b2016-05-18 10:09:28 -0300310#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100311#if defined(MBEDTLS_BASE64_C)
312 {"base64", mbedtls_base64_self_test},
313#endif
314#if defined(MBEDTLS_BIGNUM_C)
315 {"mpi", mbedtls_mpi_self_test},
316#endif
317#if defined(MBEDTLS_RSA_C)
318 {"rsa", mbedtls_rsa_self_test},
319#endif
320#if defined(MBEDTLS_X509_USE_C)
321 {"x509", mbedtls_x509_self_test},
322#endif
323#if defined(MBEDTLS_XTEA_C)
324 {"xtea", mbedtls_xtea_self_test},
325#endif
326#if defined(MBEDTLS_CAMELLIA_C)
327 {"camellia", mbedtls_camellia_self_test},
328#endif
Markku-Juhani O. Saarinen3c0b53b2017-11-30 16:00:34 +0000329#if defined(MBEDTLS_ARIA_C)
330 {"aria", mbedtls_aria_self_test},
331#endif
Gilles Peskine319ac802017-12-15 14:57:18 +0100332#if defined(MBEDTLS_CTR_DRBG_C)
333 {"ctr_drbg", mbedtls_ctr_drbg_self_test},
334#endif
335#if defined(MBEDTLS_HMAC_DRBG_C)
336 {"hmac_drbg", mbedtls_hmac_drbg_self_test},
337#endif
338#if defined(MBEDTLS_ECP_C)
339 {"ecp", mbedtls_ecp_self_test},
340#endif
341#if defined(MBEDTLS_ECJPAKE_C)
342 {"ecjpake", mbedtls_ecjpake_self_test},
343#endif
344#if defined(MBEDTLS_DHM_C)
345 {"dhm", mbedtls_dhm_self_test},
346#endif
347#if defined(MBEDTLS_ENTROPY_C)
348 {"entropy", mbedtls_entropy_self_test_wrapper},
349#endif
350#if defined(MBEDTLS_PKCS5_C)
351 {"pkcs5", mbedtls_pkcs5_self_test},
352#endif
353/* Slower test after the faster ones */
354#if defined(MBEDTLS_TIMING_C)
355 {"timing", mbedtls_timing_self_test},
356#endif
357/* Heap test comes last */
358#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
359 {"memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test},
360#endif
361 {NULL, NULL}
362};
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100363#endif /* MBEDTLS_SELF_TEST */
Gilles Peskine319ac802017-12-15 14:57:18 +0100364
Paul Bakker5121ce52009-01-03 21:22:43 +0000365int main( int argc, char *argv[] )
366{
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100367#if defined(MBEDTLS_SELF_TEST)
Gilles Peskine319ac802017-12-15 14:57:18 +0100368 const selftest_t *test;
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100369#endif /* MBEDTLS_SELF_TEST */
Gilles Peskineff79d272017-12-20 18:09:27 +0100370 char **argp;
371 int v = 1; /* v=1 for verbose mode */
372 int exclude_mode = 0;
373 int suites_tested = 0, suites_failed = 0;
Paul Bakker70940ca2016-07-14 14:30:45 +0100374#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
Paul Bakker6e339b52013-07-03 13:37:05 +0200375 unsigned char buf[1000000];
376#endif
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200377 void *pointer;
378
379 /*
380 * The C standard doesn't guarantee that all-bits-0 is the representation
381 * of a NULL pointer. We do however use that in our code for initializing
382 * structures, which should work on every modern platform. Let's be sure.
383 */
384 memset( &pointer, 0, sizeof( void * ) );
385 if( pointer != NULL )
386 {
387 mbedtls_printf( "all-bits-zero is not a NULL pointer\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000388 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnardd14acbc2015-05-29 11:26:37 +0200389 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000390
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200391 /*
392 * Make sure we have a snprintf that correctly zero-terminates
393 */
394 if( run_test_snprintf() != 0 )
395 {
396 mbedtls_printf( "the snprintf implementation is broken\n" );
Janos Follath2e3aca22016-03-18 16:25:52 +0000397 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
Manuel Pégourié-Gonnard7b6dcbe2015-06-22 10:48:01 +0200398 }
399
Gilles Peskineff79d272017-12-20 18:09:27 +0100400 for( argp = argv + ( argc >= 1 ? 1 : argc ); *argp != NULL; ++argp )
SimonB5a8afb82016-03-11 00:40:54 +0000401 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100402 if( strcmp( *argp, "--quiet" ) == 0 ||
403 strcmp( *argp, "-q" ) == 0 )
404 {
405 v = 0;
406 }
407 else if( strcmp( *argp, "--exclude" ) == 0 ||
408 strcmp( *argp, "-x" ) == 0 )
409 {
410 exclude_mode = 1;
411 }
412 else
413 break;
SimonB5a8afb82016-03-11 00:40:54 +0000414 }
Gilles Peskineff79d272017-12-20 18:09:27 +0100415
416 if( v != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200417 mbedtls_printf( "\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000418
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200419#if defined(MBEDTLS_SELF_TEST)
Paul Bakker135b98e2011-05-25 11:13:47 +0000420
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200421#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
422 mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200423#endif
424
Gilles Peskineff79d272017-12-20 18:09:27 +0100425 if( *argp != NULL && exclude_mode == 0 )
SimonB5a8afb82016-03-11 00:40:54 +0000426 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100427 /* Run the specified tests */
428 for( ; *argp != NULL; argp++ )
Gilles Peskine319ac802017-12-15 14:57:18 +0100429 {
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100430 for( test = selftests; test->name != NULL; test++ )
431 {
432 if( !strcmp( *argp, test->name ) )
433 {
434 if( test->function( v ) != 0 )
435 {
436 suites_failed++;
437 }
438 suites_tested++;
439 break;
440 }
441 }
442 if( test->name == NULL )
443 {
444 mbedtls_printf( " Test suite %s not available -> failed\n\n", *argp );
445 suites_failed++;
446 }
Gilles Peskine319ac802017-12-15 14:57:18 +0100447 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100448 }
449 else
450 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100451 /* Run all the tests except excluded ones */
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100452 for( test = selftests; test->name != NULL; test++ )
453 {
Gilles Peskineff79d272017-12-20 18:09:27 +0100454 if( exclude_mode )
455 {
456 char **excluded;
457 for( excluded = argp; *excluded != NULL; ++excluded )
458 {
459 if( !strcmp( *excluded, test->name ) )
460 break;
461 }
462 if( *excluded )
463 {
464 if( v )
465 mbedtls_printf( " Skip: %s\n", test->name );
466 continue;
467 }
468 }
Gilles Peskinec82fbb42017-12-15 15:01:27 +0100469 if( test->function( v ) != 0 )
470 {
471 suites_failed++;
472 }
473 suites_tested++;
474 }
SimonB5a8afb82016-03-11 00:40:54 +0000475 }
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100476
Paul Bakker70940ca2016-07-14 14:30:45 +0100477#else
Gilles Peskineff79d272017-12-20 18:09:27 +0100478 (void) exclude_mode;
Paul Bakker70940ca2016-07-14 14:30:45 +0100479 mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
480#endif
481
Manuel Pégourié-Gonnard5ba1d522014-11-27 11:33:55 +0100482 if( v != 0 )
483 {
Simon Butcherf1547632016-03-14 23:09:39 +0000484 mbedtls_printf( " Executed %d test suites\n\n", suites_tested );
SimonB5a8afb82016-03-11 00:40:54 +0000485
486 if( suites_failed > 0)
487 {
488 mbedtls_printf( " [ %d tests FAIL ]\n\n", suites_failed );
489 }
490 else
491 {
492 mbedtls_printf( " [ All tests PASS ]\n\n" );
493 }
Paul Bakkercce9d772011-11-18 14:26:47 +0000494#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200495 mbedtls_printf( " Press Enter to exit this program.\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000496 fflush( stdout ); getchar();
497#endif
498 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000499
SimonB5a8afb82016-03-11 00:40:54 +0000500 if( suites_failed > 0)
Janos Follath2e3aca22016-03-18 16:25:52 +0000501 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
SimonB5a8afb82016-03-11 00:40:54 +0000502
Krzysztof Stachowiak5e1b1952019-04-24 14:24:46 +0200503 mbedtls_exit( MBEDTLS_EXIT_SUCCESS );
Paul Bakker5121ce52009-01-03 21:22:43 +0000504}