Feature/mbedtls (#84)
* try to import mbedtls and build it * add stubs socket class * some boilterplate, read and write function implemented * more boilterplate / current error in handshake because no CA cert is setup * add something so skip ca verification, can ws curl https://google.com ! * cleanup / close implemented * tweak CMakefiles * typo in include * update readme * disable unittests
This commit is contained in:
committed by
GitHub
parent
977e8794ec
commit
57976cf613
25
third_party/mbedtls/crypto/programs/test/CMakeLists.txt
vendored
Normal file
25
third_party/mbedtls/crypto/programs/test/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
set(libs
|
||||
mbedcrypto
|
||||
)
|
||||
|
||||
add_executable(selftest selftest.c)
|
||||
target_link_libraries(selftest ${libs})
|
||||
|
||||
add_executable(benchmark benchmark.c)
|
||||
target_link_libraries(benchmark ${libs})
|
||||
|
||||
if(TEST_CPP)
|
||||
add_executable(cpp_dummy_build cpp_dummy_build.cpp)
|
||||
target_link_libraries(cpp_dummy_build ${libs})
|
||||
endif()
|
||||
|
||||
add_executable(zeroize zeroize.c)
|
||||
target_link_libraries(zeroize ${libs})
|
||||
|
||||
add_executable(query_compile_time_config query_compile_time_config.c)
|
||||
target_sources(query_compile_time_config PUBLIC query_config.c)
|
||||
target_link_libraries(query_compile_time_config ${libs})
|
||||
|
||||
install(TARGETS selftest benchmark query_compile_time_config
|
||||
DESTINATION "bin"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
1016
third_party/mbedtls/crypto/programs/test/benchmark.c
vendored
Normal file
1016
third_party/mbedtls/crypto/programs/test/benchmark.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
105
third_party/mbedtls/crypto/programs/test/cpp_dummy_build.cpp
vendored
Normal file
105
third_party/mbedtls/crypto/programs/test/cpp_dummy_build.cpp
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* This program is a dummy C++ program to ensure Mbed TLS library header files
|
||||
* can be included and built with a C++ compiler.
|
||||
*
|
||||
* Copyright (C) 2018, 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/aes.h"
|
||||
#include "mbedtls/aesni.h"
|
||||
#include "mbedtls/arc4.h"
|
||||
#include "mbedtls/aria.h"
|
||||
#include "mbedtls/asn1.h"
|
||||
#include "mbedtls/asn1write.h"
|
||||
#include "mbedtls/base64.h"
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/blowfish.h"
|
||||
#include "mbedtls/bn_mul.h"
|
||||
#include "mbedtls/camellia.h"
|
||||
#include "mbedtls/ccm.h"
|
||||
#include "mbedtls/certs.h"
|
||||
#include "mbedtls/chacha20.h"
|
||||
#include "mbedtls/chachapoly.h"
|
||||
#include "mbedtls/check_config.h"
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/cipher_internal.h"
|
||||
#include "mbedtls/cmac.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/des.h"
|
||||
#include "mbedtls/dhm.h"
|
||||
#include "mbedtls/ecdh.h"
|
||||
#include "mbedtls/ecdsa.h"
|
||||
#include "mbedtls/ecjpake.h"
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/ecp_internal.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/entropy_poll.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
#include "mbedtls/havege.h"
|
||||
#include "mbedtls/hkdf.h"
|
||||
#include "mbedtls/hmac_drbg.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/md2.h"
|
||||
#include "mbedtls/md4.h"
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/md_internal.h"
|
||||
#include "mbedtls/nist_kw.h"
|
||||
#include "mbedtls/oid.h"
|
||||
#include "mbedtls/padlock.h"
|
||||
#include "mbedtls/pem.h"
|
||||
#include "mbedtls/pk.h"
|
||||
#include "mbedtls/pk_internal.h"
|
||||
#include "mbedtls/pkcs12.h"
|
||||
#include "mbedtls/pkcs5.h"
|
||||
#include "mbedtls/platform_time.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/poly1305.h"
|
||||
#include "mbedtls/psa_util.h"
|
||||
#include "mbedtls/ripemd160.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/rsa_internal.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
#include "mbedtls/threading.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "mbedtls/version.h"
|
||||
#include "mbedtls/xtea.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||
#include "mbedtls/memory_buffer_alloc.h"
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
mbedtls_platform_context *ctx = NULL;
|
||||
mbedtls_platform_setup(ctx);
|
||||
mbedtls_printf("CPP Build test\n");
|
||||
mbedtls_platform_teardown(ctx);
|
||||
}
|
56
third_party/mbedtls/crypto/programs/test/query_compile_time_config.c
vendored
Normal file
56
third_party/mbedtls/crypto/programs/test/query_compile_time_config.c
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Query the Mbed TLS compile time configuration
|
||||
*
|
||||
* Copyright (C) 2018, 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
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_printf printf
|
||||
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
||||
#endif
|
||||
|
||||
#define USAGE \
|
||||
"usage: %s <MBEDTLS_CONFIG>\n\n" \
|
||||
"This program takes one command line argument which corresponds to\n" \
|
||||
"the string representation of a Mbed TLS compile time configuration.\n" \
|
||||
"The value 0 will be returned if this configuration is defined in the\n" \
|
||||
"Mbed TLS build and the macro expansion of that configuration will be\n" \
|
||||
"printed (if any). Otherwise, 1 will be returned.\n"
|
||||
|
||||
int query_config( const char *config );
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
if ( argc != 2 )
|
||||
{
|
||||
mbedtls_printf( USAGE, argv[0] );
|
||||
return( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
|
||||
return( query_config( argv[1] ) );
|
||||
}
|
1966
third_party/mbedtls/crypto/programs/test/query_config.c
vendored
Normal file
1966
third_party/mbedtls/crypto/programs/test/query_config.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
430
third_party/mbedtls/crypto/programs/test/selftest.c
vendored
Normal file
430
third_party/mbedtls/crypto/programs/test/selftest.c
vendored
Normal file
@ -0,0 +1,430 @@
|
||||
/*
|
||||
* 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/aria.h"
|
||||
#include "mbedtls/chacha20.h"
|
||||
#include "mbedtls/poly1305.h"
|
||||
#include "mbedtls/chachapoly.h"
|
||||
#include "mbedtls/base64.h"
|
||||
#include "mbedtls/bignum.h"
|
||||
#include "mbedtls/rsa.h"
|
||||
#include "mbedtls/xtea.h"
|
||||
#include "mbedtls/pkcs5.h"
|
||||
#include "mbedtls/ecp.h"
|
||||
#include "mbedtls/ecjpake.h"
|
||||
#include "mbedtls/timing.h"
|
||||
#include "mbedtls/nist_kw.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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_CHECK_PARAMS)
|
||||
#include "mbedtls/platform_util.h"
|
||||
void mbedtls_param_failed( const char *failure_condition,
|
||||
const char *file,
|
||||
int line )
|
||||
{
|
||||
mbedtls_printf( "%s:%i: Input param failed - %s\n",
|
||||
file, line, failure_condition );
|
||||
mbedtls_exit( MBEDTLS_EXIT_FAILURE );
|
||||
}
|
||||
#endif
|
||||
|
||||
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[] =
|
||||
{
|
||||
#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_NIST_KW_C) && defined(MBEDTLS_AES_C)
|
||||
{"nist_kw", mbedtls_nist_kw_self_test},
|
||||
#endif
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
{"cmac", mbedtls_cmac_self_test},
|
||||
#endif
|
||||
#if defined(MBEDTLS_CHACHA20_C)
|
||||
{"chacha20", mbedtls_chacha20_self_test},
|
||||
#endif
|
||||
#if defined(MBEDTLS_POLY1305_C)
|
||||
{"poly1305", mbedtls_poly1305_self_test},
|
||||
#endif
|
||||
#if defined(MBEDTLS_CHACHAPOLY_C)
|
||||
{"chacha20-poly1305", mbedtls_chachapoly_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_XTEA_C)
|
||||
{"xtea", mbedtls_xtea_self_test},
|
||||
#endif
|
||||
#if defined(MBEDTLS_CAMELLIA_C)
|
||||
{"camellia", mbedtls_camellia_self_test},
|
||||
#endif
|
||||
#if defined(MBEDTLS_ARIA_C)
|
||||
{"aria", mbedtls_aria_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 );
|
||||
}
|
||||
|
101
third_party/mbedtls/crypto/programs/test/zeroize.c
vendored
Normal file
101
third_party/mbedtls/crypto/programs/test/zeroize.c
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Zeroize application for debugger-driven testing
|
||||
*
|
||||
* This is a simple test application used for debugger-driven testing to check
|
||||
* whether calls to mbedtls_platform_zeroize() are being eliminated by compiler
|
||||
* optimizations. This application is used by the GDB script at
|
||||
* tests/scripts/test_zeroize.gdb under the assumption that the code does not
|
||||
* change often (as opposed to the library code) because the script sets a
|
||||
* breakpoint at the last return statement in the main() function of this
|
||||
* program. The debugger facilities are then used to manually inspect the
|
||||
* memory and verify that the call to mbedtls_platform_zeroize() was not
|
||||
* eliminated.
|
||||
*
|
||||
* Copyright (C) 2018, 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 <stdio.h>
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_printf printf
|
||||
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
||||
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#define BUFFER_LEN 1024
|
||||
|
||||
void usage( void )
|
||||
{
|
||||
mbedtls_printf( "Zeroize is a simple program to assist with testing\n" );
|
||||
mbedtls_printf( "the mbedtls_platform_zeroize() function by using the\n" );
|
||||
mbedtls_printf( "debugger. This program takes a file as input and\n" );
|
||||
mbedtls_printf( "prints the first %d characters. Usage:\n\n", BUFFER_LEN );
|
||||
mbedtls_printf( " zeroize <FILE>\n" );
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||
FILE *fp;
|
||||
char buf[BUFFER_LEN];
|
||||
char *p = buf;
|
||||
char *end = p + BUFFER_LEN;
|
||||
int c;
|
||||
|
||||
if( argc != 2 )
|
||||
{
|
||||
mbedtls_printf( "This program takes exactly 1 agument\n" );
|
||||
usage();
|
||||
return( exit_code );
|
||||
}
|
||||
|
||||
fp = fopen( argv[1], "r" );
|
||||
if( fp == NULL )
|
||||
{
|
||||
mbedtls_printf( "Could not open file '%s'\n", argv[1] );
|
||||
return( exit_code );
|
||||
}
|
||||
|
||||
while( ( c = fgetc( fp ) ) != EOF && p < end - 1 )
|
||||
*p++ = (char)c;
|
||||
*p = '\0';
|
||||
|
||||
if( p - buf != 0 )
|
||||
{
|
||||
mbedtls_printf( "%s\n", buf );
|
||||
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||
}
|
||||
else
|
||||
mbedtls_printf( "The file is empty!\n" );
|
||||
|
||||
fclose( fp );
|
||||
mbedtls_platform_zeroize( buf, sizeof( buf ) );
|
||||
|
||||
return( exit_code );
|
||||
}
|
Reference in New Issue
Block a user