mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-05-13 00:04:14 +08:00
029ba813cd
d8180f8d84 Merge remote-tracking branch 'origin/mbedtls-2.7' into mbedtls-2.7-restricted db649896e6 Merge pull request #2895 from gilles-peskine-arm/drbg-set_entropy_len-2.7 373a7097eb Merge pull request #673 from gilles-peskine-arm/ctr_drbg-aes_fail-2.7 b2be1fca2c Catch AES failure in mbedtls_ctr_drbg_random df1b3e54c7 Merge pull request #2937 from gilles-peskine-arm/memory_buffer_alloc-fatal-pass-2.7 02fbc08d2e Enable more test cases without MBEDTLS_MEMORY_DEBUG 786f068ec0 More accurate test case description 04d45c98e8 Clarify that the "FATAL" message is expected c5a016dde1 Merge remote-tracking branch 'restricted/pr/666' into mbedtls-2.7-restricted e70059df85 Merge remote-tracking branch 'restricted/pr/668' into mbedtls-2.7-restricted 10fcdd25d4 Merge pull request #664 from ARMmbed/dev/yanesca/iotcrypt-958-ecdsa-side-channel-fix-2.7 07597365cd Zeroize local AES variables before exiting the function dfa4d71873 Add ChangeLog entry b4edac5616 mpi_lt_mpi_ct: fix condition handling f4482aaccc mpi_lt_mpi_ct: Add further tests a776aea91a mpi_lt_mpi_ct: Fix test numbering 1b86eeb06b mpi_lt_mpi_ct perform tests for both limb size 5823961558 ct_lt_mpi_uint: cast the return value explicitely 6adff06e50 mbedtls_mpi_lt_mpi_ct: add tests for 32 bit limbs cff9e6e03d mbedtls_mpi_lt_mpi_ct: simplify condition 8ec2a953af Rename variable for better readability a2b9a96fb8 mbedtls_mpi_lt_mpi_ct: Improve documentation 51ed14e20f Make mbedtls_mpi_lt_mpi_ct more portable 9741fa6e2b Bignum: Document assumptions about the sign field 9332ecefc8 Add more tests for mbedtls_mpi_lt_mpi_ct aaa3f22b76 mpi_lt_mpi_ct test: hardcode base 16 3173a53fe9 Document ct_lt_mpi_uint 782cbe592d mpi_lt_mpi_ct: make use of unsigned consistent db9f449409 ct_lt_mpi_uint: make use of biL c3b376e2f2 Change mbedtls_mpi_cmp_mpi_ct to check less than 8461c0e2a8 mbedtls_mpi_cmp_mpi_ct: remove multiplications 8de2d45cd7 Remove excess vertical space c587a32a9c Remove declaration after statement 5f3019b298 Fix side channel vulnerability in ECDSA 883801d3ec Add tests to constant time mpi comparison e0187b95f0 Add new, constant time mpi comparison 4c575c0270 Note that mbedtls_ctr_drbg_seed() must not be called twice eab4d701ca Fix CTR_DRBG benchmark 5cf41f80a4 Add ChangeLog entry 82debf8332 ECDSA: Fix side channel vulnerability 093aa517c4 Changelog entry for xxx_drbg_set_entropy_len before xxx_drbg_seed b729e1b9ba CTR_DRBG: support set_entropy_len() before seed() 845ac103a9 CTR_DRBG: Don't use functions before they're defined 9c742249cf HMAC_DRBG: support set_entropy_len() before seed() c87a54683b Merge pull request #2900 from gilles-peskine-arm/asan-test-fail-2.7 cc656ac96b Merge pull request #2872 from gilles-peskine-arm/test_malloc_0_null-2.7 5ee14d70d2 'make test' must fail if Asan fails 4c2697f43f Asan make builds: avoid sanitizer recovery 260921d3f2 Use UBsan in addition to Asan with 'make test' c20a4053c3 Unify ASan options in make builds 395d8c1222 Merge remote-tracking branch 'origin/pr/2878' into mbedtls-2.7 55e120b9b2 mbedtls_hmac_drbg_set_entropy_len() only matters when reseeding dff3682477 mbedtls_ctr_drbg_set_entropy_len() only matters when reseeding 2abefefec2 mbedtls_ctr_drbg_seed: correct maximum for len 406d25878c Add a note about CTR_DRBG security strength to config.h f0b3dcb14b CTR_DRBG: more consistent formatting and wording b9cfe58180 DRBG documentation: Relate f_entropy arguments to the entropy module 97edf5e1e2 Add ChangeLog entry for the DRBG documentation improvements 5cc748e58f Merge remote-tracking branch 'origin/pr/2866' into mbedtls-2.7 d89173066c HMAC_DRBG documentation improvements 2fc6cf5da7 Merge remote-tracking branch 'origin/pr/2704' into mbedtls-2.7 eb99c1028f CTR_DRBG: explain the security strength and the entropy input length 25e1945321 CTR_DRBG documentation improvements 0ab4092e2d Reduce stack usage of test_suite_pkcs1_v15 dd4277f70d Reduce stack usage of test_suite_pkcs1_v21 b3d3973264 Reduce stack usage of test_suite_rsa 6827d1c588 Reduce stack usage of test_suite_pk 0981a5d7ab Add a test component with malloc(0) returning NULL ea5d3571b0 Add a calloc self-test d28b9b3c5d Merge remote-tracking branch 'origin/pr/2828' into mbedtls-2.7 9b1c248209 Enable MBEDTLS_MEMORY_DEBUG in memory buffer alloc test in all.sh 7eb7f8db8b Remove unnecessary memory buffer alloc unsets 6addfdd190 Disable DTLS proxy tests for MEMORY_BUFFER_ALLOC test 9a461a1cd7 all.sh: restructure memory allocator tests 7aad93c9da Add missing dependency in memory buffer alloc set in all.sh 19aa89ad47 Don't set MBEDTLS_MEMORY_DEBUG through `scripts/config.pl full` 8561115cb8 Add cfg dep MBEDTLS_MEMORY_DEBUG->MBEDTLS_MEMORY_BUFFER_ALLOC_C 167ae43852 Add all.sh run with full config and ASan enabled f5baaaaf89 Add all.sh run with MBEDTLS_MEMORY_BUFFER_ALLOC_C enabled e1c62e6641 Update documentation of exceptions for `config.pl full` c7f97f1c8d Adapt all.sh to removal of buffer allocator from full config 26c333ac01 Disable memory buffer allocator in full config 76ef31116b Check dependencies of MBEDTLS_MEMORY_BACKTRACE in check_config.h 9bf1509ef3 Adapt auth_crypt_tv usage to 2.7 dd91b24764 Add missing dependencies in test_suite_cipher.gcm d62577fa74 Adapt ChangeLog 311276c871 Add NIST AES GCM test vectors to single-step cipher API test suite git-subtree-dir: Sources/mbedTLS git-subtree-split: f8199650a9d49b3982a7b7f3d448899b67b09571
487 lines
13 KiB
C
487 lines
13 KiB
C
/*
|
|
* Self-test demonstration program
|
|
*
|
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
* not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
|
*/
|
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
#include "mbedtls/config.h"
|
|
#else
|
|
#include MBEDTLS_CONFIG_FILE
|
|
#endif
|
|
|
|
#include "mbedtls/entropy.h"
|
|
#include "mbedtls/entropy_poll.h"
|
|
#include "mbedtls/hmac_drbg.h"
|
|
#include "mbedtls/ctr_drbg.h"
|
|
#include "mbedtls/dhm.h"
|
|
#include "mbedtls/gcm.h"
|
|
#include "mbedtls/ccm.h"
|
|
#include "mbedtls/cmac.h"
|
|
#include "mbedtls/md2.h"
|
|
#include "mbedtls/md4.h"
|
|
#include "mbedtls/md5.h"
|
|
#include "mbedtls/ripemd160.h"
|
|
#include "mbedtls/sha1.h"
|
|
#include "mbedtls/sha256.h"
|
|
#include "mbedtls/sha512.h"
|
|
#include "mbedtls/arc4.h"
|
|
#include "mbedtls/des.h"
|
|
#include "mbedtls/aes.h"
|
|
#include "mbedtls/camellia.h"
|
|
#include "mbedtls/base64.h"
|
|
#include "mbedtls/bignum.h"
|
|
#include "mbedtls/rsa.h"
|
|
#include "mbedtls/x509.h"
|
|
#include "mbedtls/xtea.h"
|
|
#include "mbedtls/pkcs5.h"
|
|
#include "mbedtls/ecp.h"
|
|
#include "mbedtls/ecjpake.h"
|
|
#include "mbedtls/timing.h"
|
|
|
|
#include <string.h>
|
|
|
|
#if defined(MBEDTLS_PLATFORM_C)
|
|
#include "mbedtls/platform.h"
|
|
#else
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#define mbedtls_calloc calloc
|
|
#define mbedtls_free free
|
|
#define mbedtls_printf printf
|
|
#define mbedtls_snprintf snprintf
|
|
#define mbedtls_exit exit
|
|
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
|
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
#include "mbedtls/memory_buffer_alloc.h"
|
|
#endif
|
|
|
|
|
|
#if defined MBEDTLS_SELF_TEST
|
|
/* Sanity check for malloc. This is not expected to fail, and is rather
|
|
* intended to display potentially useful information about the platform,
|
|
* in particular the behavior of malloc(0). */
|
|
static int calloc_self_test( int verbose )
|
|
{
|
|
int failures = 0;
|
|
void *empty1 = mbedtls_calloc( 0, 1 );
|
|
void *empty2 = mbedtls_calloc( 0, 1 );
|
|
void *buffer1 = mbedtls_calloc( 1, 1 );
|
|
void *buffer2 = mbedtls_calloc( 1, 1 );
|
|
uintptr_t old_buffer1;
|
|
|
|
if( empty1 == NULL && empty2 == NULL )
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(0): passed (NULL)\n" );
|
|
}
|
|
else if( empty1 == NULL || empty2 == NULL )
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(0): failed (mix of NULL and non-NULL)\n" );
|
|
++failures;
|
|
}
|
|
else if( empty1 == empty2 )
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(0): passed (same non-null)\n" );
|
|
}
|
|
else
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(0): passed (distinct non-null)\n" );
|
|
}
|
|
|
|
if( buffer1 == NULL || buffer2 == NULL )
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(1): failed (NULL)\n" );
|
|
++failures;
|
|
}
|
|
else if( buffer1 == buffer2 )
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(1): failed (same buffer twice)\n" );
|
|
++failures;
|
|
}
|
|
else
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(1): passed\n" );
|
|
}
|
|
|
|
old_buffer1 = (uintptr_t) buffer1;
|
|
mbedtls_free( buffer1 );
|
|
buffer1 = mbedtls_calloc( 1, 1 );
|
|
if( buffer1 == NULL )
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(1 again): failed (NULL)\n" );
|
|
++failures;
|
|
}
|
|
else
|
|
{
|
|
if( verbose )
|
|
mbedtls_printf( " CALLOC(1 again): passed (%s address)\n",
|
|
(uintptr_t) old_buffer1 == (uintptr_t) buffer1 ?
|
|
"same" : "different" );
|
|
}
|
|
|
|
if( verbose )
|
|
mbedtls_printf( "\n" );
|
|
mbedtls_free( empty1 );
|
|
mbedtls_free( empty2 );
|
|
mbedtls_free( buffer1 );
|
|
mbedtls_free( buffer2 );
|
|
return( failures );
|
|
}
|
|
#endif /* MBEDTLS_SELF_TEST */
|
|
|
|
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
|
|
{
|
|
int ret;
|
|
char buf[10] = "xxxxxxxxx";
|
|
const char ref[10] = "xxxxxxxxx";
|
|
|
|
ret = mbedtls_snprintf( buf, n, "%s", "123" );
|
|
if( ret < 0 || (size_t) ret >= n )
|
|
ret = -1;
|
|
|
|
if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
|
|
ref_ret != ret ||
|
|
memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
|
|
{
|
|
return( 1 );
|
|
}
|
|
|
|
return( 0 );
|
|
}
|
|
|
|
static int run_test_snprintf( void )
|
|
{
|
|
return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
|
|
test_snprintf( 1, "", -1 ) != 0 ||
|
|
test_snprintf( 2, "1", -1 ) != 0 ||
|
|
test_snprintf( 3, "12", -1 ) != 0 ||
|
|
test_snprintf( 4, "123", 3 ) != 0 ||
|
|
test_snprintf( 5, "123", 3 ) != 0 );
|
|
}
|
|
|
|
/*
|
|
* Check if a seed file is present, and if not create one for the entropy
|
|
* self-test. If this fails, we attempt the test anyway, so no error is passed
|
|
* back.
|
|
*/
|
|
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C)
|
|
#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
|
static void create_entropy_seed_file( void )
|
|
{
|
|
int result;
|
|
size_t output_len = 0;
|
|
unsigned char seed_value[MBEDTLS_ENTROPY_BLOCK_SIZE];
|
|
|
|
/* Attempt to read the entropy seed file. If this fails - attempt to write
|
|
* to the file to ensure one is present. */
|
|
result = mbedtls_platform_std_nv_seed_read( seed_value,
|
|
MBEDTLS_ENTROPY_BLOCK_SIZE );
|
|
if( 0 == result )
|
|
return;
|
|
|
|
result = mbedtls_platform_entropy_poll( NULL,
|
|
seed_value,
|
|
MBEDTLS_ENTROPY_BLOCK_SIZE,
|
|
&output_len );
|
|
if( 0 != result )
|
|
return;
|
|
|
|
if( MBEDTLS_ENTROPY_BLOCK_SIZE != output_len )
|
|
return;
|
|
|
|
mbedtls_platform_std_nv_seed_write( seed_value, MBEDTLS_ENTROPY_BLOCK_SIZE );
|
|
}
|
|
#endif
|
|
|
|
int mbedtls_entropy_self_test_wrapper( int verbose )
|
|
{
|
|
#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
|
create_entropy_seed_file( );
|
|
#endif
|
|
return( mbedtls_entropy_self_test( verbose ) );
|
|
}
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_SELF_TEST)
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
int mbedtls_memory_buffer_alloc_free_and_self_test( int verbose )
|
|
{
|
|
if( verbose != 0 )
|
|
{
|
|
#if defined(MBEDTLS_MEMORY_DEBUG)
|
|
mbedtls_memory_buffer_alloc_status( );
|
|
#endif
|
|
}
|
|
mbedtls_memory_buffer_alloc_free( );
|
|
return( mbedtls_memory_buffer_alloc_self_test( verbose ) );
|
|
}
|
|
#endif
|
|
|
|
typedef struct
|
|
{
|
|
const char *name;
|
|
int ( *function )( int );
|
|
} selftest_t;
|
|
|
|
const selftest_t selftests[] =
|
|
{
|
|
{"calloc", calloc_self_test},
|
|
#if defined(MBEDTLS_MD2_C)
|
|
{"md2", mbedtls_md2_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_MD4_C)
|
|
{"md4", mbedtls_md4_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_MD5_C)
|
|
{"md5", mbedtls_md5_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_RIPEMD160_C)
|
|
{"ripemd160", mbedtls_ripemd160_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_SHA1_C)
|
|
{"sha1", mbedtls_sha1_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_SHA256_C)
|
|
{"sha256", mbedtls_sha256_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_SHA512_C)
|
|
{"sha512", mbedtls_sha512_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_ARC4_C)
|
|
{"arc4", mbedtls_arc4_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_DES_C)
|
|
{"des", mbedtls_des_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_AES_C)
|
|
{"aes", mbedtls_aes_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
|
|
{"gcm", mbedtls_gcm_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
|
|
{"ccm", mbedtls_ccm_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_CMAC_C)
|
|
{"cmac", mbedtls_cmac_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_BASE64_C)
|
|
{"base64", mbedtls_base64_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_BIGNUM_C)
|
|
{"mpi", mbedtls_mpi_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_RSA_C)
|
|
{"rsa", mbedtls_rsa_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_X509_USE_C)
|
|
{"x509", mbedtls_x509_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_XTEA_C)
|
|
{"xtea", mbedtls_xtea_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_CAMELLIA_C)
|
|
{"camellia", mbedtls_camellia_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_CTR_DRBG_C)
|
|
{"ctr_drbg", mbedtls_ctr_drbg_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_HMAC_DRBG_C)
|
|
{"hmac_drbg", mbedtls_hmac_drbg_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_ECP_C)
|
|
{"ecp", mbedtls_ecp_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_ECJPAKE_C)
|
|
{"ecjpake", mbedtls_ecjpake_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_DHM_C)
|
|
{"dhm", mbedtls_dhm_self_test},
|
|
#endif
|
|
#if defined(MBEDTLS_ENTROPY_C)
|
|
{"entropy", mbedtls_entropy_self_test_wrapper},
|
|
#endif
|
|
#if defined(MBEDTLS_PKCS5_C)
|
|
{"pkcs5", mbedtls_pkcs5_self_test},
|
|
#endif
|
|
/* Slower test after the faster ones */
|
|
#if defined(MBEDTLS_TIMING_C)
|
|
{"timing", mbedtls_timing_self_test},
|
|
#endif
|
|
/* Heap test comes last */
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
{"memory_buffer_alloc", mbedtls_memory_buffer_alloc_free_and_self_test},
|
|
#endif
|
|
{NULL, NULL}
|
|
};
|
|
#endif /* MBEDTLS_SELF_TEST */
|
|
|
|
int main( int argc, char *argv[] )
|
|
{
|
|
#if defined(MBEDTLS_SELF_TEST)
|
|
const selftest_t *test;
|
|
#endif /* MBEDTLS_SELF_TEST */
|
|
char **argp;
|
|
int v = 1; /* v=1 for verbose mode */
|
|
int exclude_mode = 0;
|
|
int suites_tested = 0, suites_failed = 0;
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
|
|
unsigned char buf[1000000];
|
|
#endif
|
|
void *pointer;
|
|
|
|
/*
|
|
* The C standard doesn't guarantee that all-bits-0 is the representation
|
|
* of a NULL pointer. We do however use that in our code for initializing
|
|
* structures, which should work on every modern platform. Let's be sure.
|
|
*/
|
|
memset( &pointer, 0, sizeof( void * ) );
|
|
if( pointer != NULL )
|
|
{
|
|
mbedtls_printf( "all-bits-zero is not a NULL pointer\n" );
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
|
}
|
|
|
|
/*
|
|
* Make sure we have a snprintf that correctly zero-terminates
|
|
*/
|
|
if( run_test_snprintf() != 0 )
|
|
{
|
|
mbedtls_printf( "the snprintf implementation is broken\n" );
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
|
}
|
|
|
|
for( argp = argv + ( argc >= 1 ? 1 : argc ); *argp != NULL; ++argp )
|
|
{
|
|
if( strcmp( *argp, "--quiet" ) == 0 ||
|
|
strcmp( *argp, "-q" ) == 0 )
|
|
{
|
|
v = 0;
|
|
}
|
|
else if( strcmp( *argp, "--exclude" ) == 0 ||
|
|
strcmp( *argp, "-x" ) == 0 )
|
|
{
|
|
exclude_mode = 1;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
if( v != 0 )
|
|
mbedtls_printf( "\n" );
|
|
|
|
#if defined(MBEDTLS_SELF_TEST)
|
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
|
|
#endif
|
|
|
|
if( *argp != NULL && exclude_mode == 0 )
|
|
{
|
|
/* Run the specified tests */
|
|
for( ; *argp != NULL; argp++ )
|
|
{
|
|
for( test = selftests; test->name != NULL; test++ )
|
|
{
|
|
if( !strcmp( *argp, test->name ) )
|
|
{
|
|
if( test->function( v ) != 0 )
|
|
{
|
|
suites_failed++;
|
|
}
|
|
suites_tested++;
|
|
break;
|
|
}
|
|
}
|
|
if( test->name == NULL )
|
|
{
|
|
mbedtls_printf( " Test suite %s not available -> failed\n\n", *argp );
|
|
suites_failed++;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* Run all the tests except excluded ones */
|
|
for( test = selftests; test->name != NULL; test++ )
|
|
{
|
|
if( exclude_mode )
|
|
{
|
|
char **excluded;
|
|
for( excluded = argp; *excluded != NULL; ++excluded )
|
|
{
|
|
if( !strcmp( *excluded, test->name ) )
|
|
break;
|
|
}
|
|
if( *excluded )
|
|
{
|
|
if( v )
|
|
mbedtls_printf( " Skip: %s\n", test->name );
|
|
continue;
|
|
}
|
|
}
|
|
if( test->function( v ) != 0 )
|
|
{
|
|
suites_failed++;
|
|
}
|
|
suites_tested++;
|
|
}
|
|
}
|
|
|
|
#else
|
|
(void) exclude_mode;
|
|
mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
|
|
#endif
|
|
|
|
if( v != 0 )
|
|
{
|
|
mbedtls_printf( " Executed %d test suites\n\n", suites_tested );
|
|
|
|
if( suites_failed > 0)
|
|
{
|
|
mbedtls_printf( " [ %d tests FAIL ]\n\n", suites_failed );
|
|
}
|
|
else
|
|
{
|
|
mbedtls_printf( " [ All tests PASS ]\n\n" );
|
|
}
|
|
#if defined(_WIN32)
|
|
mbedtls_printf( " Press Enter to exit this program.\n" );
|
|
fflush( stdout ); getchar();
|
|
#endif
|
|
}
|
|
|
|
if( suites_failed > 0)
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
|
|
|
/* return() is here to prevent compiler warnings */
|
|
return( MBEDTLS_EXIT_SUCCESS );
|
|
}
|
|
|