2009-01-03 22:22:43 +01:00
|
|
|
/*
|
|
|
|
* Self-test demonstration program
|
|
|
|
*
|
2015-07-27 11:11:48 +02:00
|
|
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
2015-09-04 14:21:07 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* 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
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-01-03 22:22:43 +01:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* 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.
|
2009-01-03 22:22:43 +01:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/config.h"
|
2014-04-29 12:39:06 +02:00
|
|
|
#else
|
2015-04-08 12:49:31 +02:00
|
|
|
#include MBEDTLS_CONFIG_FILE
|
2014-04-29 12:39:06 +02:00
|
|
|
#endif
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/entropy.h"
|
2016-06-18 23:45:37 +02:00
|
|
|
#include "mbedtls/entropy_poll.h"
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/hmac_drbg.h"
|
|
|
|
#include "mbedtls/ctr_drbg.h"
|
|
|
|
#include "mbedtls/dhm.h"
|
|
|
|
#include "mbedtls/gcm.h"
|
|
|
|
#include "mbedtls/ccm.h"
|
2015-12-11 16:49:45 +01:00
|
|
|
#include "mbedtls/cmac.h"
|
2015-03-09 18:05:11 +01:00
|
|
|
#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"
|
2015-08-05 15:44:42 +02:00
|
|
|
#include "mbedtls/ecjpake.h"
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/timing.h"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2015-02-11 15:06:19 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_PLATFORM_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/platform.h"
|
2015-02-11 15:06:19 +01:00
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
2016-03-18 17:25:52 +01:00
|
|
|
#include <stdlib.h>
|
2015-04-08 12:49:31 +02:00
|
|
|
#define mbedtls_printf printf
|
2015-06-22 10:48:01 +02:00
|
|
|
#define mbedtls_snprintf snprintf
|
2016-03-18 17:25:52 +01:00
|
|
|
#define mbedtls_exit exit
|
|
|
|
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
|
|
|
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
2015-02-11 15:06:19 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/memory_buffer_alloc.h"
|
2013-07-03 13:37:05 +02:00
|
|
|
#endif
|
|
|
|
|
2015-06-22 10:48:01 +02:00
|
|
|
static int test_snprintf( size_t n, const char ref_buf[10], int ref_ret )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char buf[10] = "xxxxxxxxx";
|
2015-06-26 11:24:32 +02:00
|
|
|
const char ref[10] = "xxxxxxxxx";
|
2015-06-22 10:48:01 +02:00
|
|
|
|
|
|
|
ret = mbedtls_snprintf( buf, n, "%s", "123" );
|
|
|
|
if( ret < 0 || (size_t) ret >= n )
|
|
|
|
ret = -1;
|
|
|
|
|
2015-06-26 11:24:32 +02:00
|
|
|
if( strncmp( ref_buf, buf, sizeof( buf ) ) != 0 ||
|
|
|
|
ref_ret != ret ||
|
|
|
|
memcmp( buf + n, ref + n, sizeof( buf ) - n ) != 0 )
|
2015-06-22 10:48:01 +02:00
|
|
|
{
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int run_test_snprintf( void )
|
|
|
|
{
|
|
|
|
return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 ||
|
2015-06-26 11:24:32 +02:00
|
|
|
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 );
|
2015-06-22 10:48:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-18 23:45:37 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-07-14 15:30:45 +02:00
|
|
|
#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_ENTROPY_C) && \
|
|
|
|
defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
2016-06-18 23:45:37 +02:00
|
|
|
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
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
2016-03-18 17:25:52 +01:00
|
|
|
int v, suites_tested = 0, suites_failed = 0;
|
2016-07-14 15:30:45 +02:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_SELF_TEST)
|
2013-07-03 13:37:05 +02:00
|
|
|
unsigned char buf[1000000];
|
|
|
|
#endif
|
2015-05-29 11:26:37 +02:00
|
|
|
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" );
|
2016-03-18 17:25:52 +01:00
|
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
2015-05-29 11:26:37 +02:00
|
|
|
}
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2015-06-22 10:48:01 +02:00
|
|
|
/*
|
|
|
|
* Make sure we have a snprintf that correctly zero-terminates
|
|
|
|
*/
|
|
|
|
if( run_test_snprintf() != 0 )
|
|
|
|
{
|
|
|
|
mbedtls_printf( "the snprintf implementation is broken\n" );
|
2016-03-18 17:25:52 +01:00
|
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
2015-06-22 10:48:01 +02:00
|
|
|
}
|
|
|
|
|
2016-03-11 01:40:54 +01:00
|
|
|
if( argc == 2 && ( strcmp( argv[1], "--quiet" ) == 0 ||
|
|
|
|
strcmp( argv[1], "-q" ) == 0 ) )
|
|
|
|
{
|
2009-01-03 22:22:43 +01:00
|
|
|
v = 0;
|
2016-03-11 01:40:54 +01:00
|
|
|
}
|
2009-01-03 22:22:43 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
v = 1;
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_printf( "\n" );
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_SELF_TEST)
|
2011-05-25 13:13:47 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
|
|
mbedtls_memory_buffer_alloc_init( buf, sizeof(buf) );
|
2013-07-03 13:37:05 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_MD2_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_md2_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_MD4_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_md4_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_MD5_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_md5_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_RIPEMD160_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_ripemd160_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2014-01-17 14:44:38 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_SHA1_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_sha1_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_SHA256_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_sha256_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_SHA512_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_sha512_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_ARC4_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_arc4_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_DES_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_des_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_AES_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_aes_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_gcm_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2012-03-20 14:50:09 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_ccm_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2014-05-02 15:17:29 +02:00
|
|
|
#endif
|
|
|
|
|
2016-05-20 01:38:36 +02:00
|
|
|
#if defined(MBEDTLS_CMAC_C) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
|
2016-09-14 00:58:46 +02:00
|
|
|
if( ( mbedtls_cmac_self_test( v ) ) != 0 )
|
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2015-12-11 16:49:45 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_BASE64_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_base64_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_BIGNUM_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_mpi_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_RSA_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_rsa_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_X509_USE_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_x509_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_XTEA_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_xtea_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-04 19:15:48 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CAMELLIA_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_camellia_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2009-01-11 00:31:23 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CTR_DRBG_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_ctr_drbg_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2011-11-27 15:46:59 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_HMAC_DRBG_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_hmac_drbg_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2014-01-31 11:12:09 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_ECP_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_ecp_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2012-11-13 20:57:00 +01:00
|
|
|
#endif
|
|
|
|
|
2015-08-05 15:44:42 +02:00
|
|
|
#if defined(MBEDTLS_ECJPAKE_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_ecjpake_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2015-08-05 15:44:42 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_DHM_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_dhm_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2013-09-15 17:43:54 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_ENTROPY_C)
|
2016-06-18 23:45:37 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_ENTROPY_NV_SEED) && !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
|
|
|
|
create_entropy_seed_file();
|
|
|
|
#endif
|
|
|
|
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_entropy_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2014-05-30 10:34:15 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_PKCS5_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_pkcs5_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2014-03-27 20:12:44 +01:00
|
|
|
#endif
|
2015-03-11 12:20:43 +01:00
|
|
|
|
|
|
|
/* Slow tests last */
|
2014-03-27 20:12:44 +01:00
|
|
|
|
2015-06-26 16:17:30 +02:00
|
|
|
#if defined(MBEDTLS_TIMING_C)
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_timing_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2014-03-27 20:07:08 +01:00
|
|
|
#endif
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
if( v != 0 )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
|
|
|
|
mbedtls_memory_buffer_alloc_status();
|
2013-07-03 13:37:05 +02:00
|
|
|
#endif
|
2014-11-27 11:33:55 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
|
|
mbedtls_memory_buffer_alloc_free();
|
2016-03-18 17:25:52 +01:00
|
|
|
if( mbedtls_memory_buffer_alloc_self_test( v ) != 0 )
|
2016-03-11 01:40:54 +01:00
|
|
|
{
|
|
|
|
suites_failed++;
|
|
|
|
}
|
|
|
|
suites_tested++;
|
2014-11-27 11:33:55 +01:00
|
|
|
#endif
|
2013-07-03 13:37:05 +02:00
|
|
|
|
2016-07-14 15:30:45 +02:00
|
|
|
#else
|
|
|
|
mbedtls_printf( " MBEDTLS_SELF_TEST not defined.\n" );
|
|
|
|
#endif
|
|
|
|
|
2014-11-27 11:33:55 +01:00
|
|
|
if( v != 0 )
|
|
|
|
{
|
2016-03-15 00:09:39 +01:00
|
|
|
mbedtls_printf( " Executed %d test suites\n\n", suites_tested );
|
2016-03-11 01:40:54 +01:00
|
|
|
|
|
|
|
if( suites_failed > 0)
|
|
|
|
{
|
|
|
|
mbedtls_printf( " [ %d tests FAIL ]\n\n", suites_failed );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mbedtls_printf( " [ All tests PASS ]\n\n" );
|
|
|
|
}
|
2011-11-18 15:26:47 +01:00
|
|
|
#if defined(_WIN32)
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_printf( " Press Enter to exit this program.\n" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout ); getchar();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-03-11 01:40:54 +01:00
|
|
|
if( suites_failed > 0)
|
2016-03-18 17:25:52 +01:00
|
|
|
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
2016-03-11 01:40:54 +01:00
|
|
|
|
2016-05-31 15:03:54 +02:00
|
|
|
/* return() is here to prevent compiler warnings */
|
2016-04-18 10:59:16 +02:00
|
|
|
return( MBEDTLS_EXIT_SUCCESS );
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
2016-03-11 01:40:54 +01:00
|
|
|
|