mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge remote-tracking branch 'upstream/development' into make_tests_thread_safe
This commit is contained in:
@ -192,6 +192,46 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_DH_RFC7919_2048)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_DH_RFC7919_2048)
|
||||
#undef MBEDTLS_PSA_ACCEL_DH_RFC7919_2048
|
||||
#else
|
||||
#define MBEDTLS_PSA_ACCEL_DH_RFC7919_2048
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_DH_RFC7919_3072)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_DH_RFC7919_3072)
|
||||
#undef MBEDTLS_PSA_ACCEL_DH_RFC7919_3072
|
||||
#else
|
||||
#define MBEDTLS_PSA_ACCEL_DH_RFC7919_3072
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_DH_RFC7919_4096)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_DH_RFC7919_4096)
|
||||
#undef MBEDTLS_PSA_ACCEL_DH_RFC7919_4096
|
||||
#else
|
||||
#define MBEDTLS_PSA_ACCEL_DH_RFC7919_4096
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_DH_RFC7919_6144)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_DH_RFC7919_6144)
|
||||
#undef MBEDTLS_PSA_ACCEL_DH_RFC7919_6144
|
||||
#else
|
||||
#define MBEDTLS_PSA_ACCEL_DH_RFC7919_6144
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_DH_RFC7919_8192)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_DH_RFC7919_8192)
|
||||
#undef MBEDTLS_PSA_ACCEL_DH_RFC7919_8192
|
||||
#else
|
||||
#define MBEDTLS_PSA_ACCEL_DH_RFC7919_8192
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PSA_WANT_ALG_FFDH)
|
||||
#if defined(MBEDTLS_PSA_ACCEL_ALG_FFDH)
|
||||
#undef MBEDTLS_PSA_ACCEL_ALG_FFDH
|
||||
|
@ -67,6 +67,10 @@ void mbedtls_test_transparent_free(void);
|
||||
psa_status_t mbedtls_test_opaque_init(void);
|
||||
void mbedtls_test_opaque_free(void);
|
||||
|
||||
psa_status_t mbedtls_test_opaque_unwrap_key(
|
||||
const uint8_t *wrapped_key, size_t wrapped_key_length, uint8_t *key_buffer,
|
||||
size_t key_buffer_size, size_t *key_buffer_length);
|
||||
|
||||
psa_status_t mbedtls_test_transparent_generate_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *key, size_t key_size, size_t *key_length);
|
||||
|
@ -23,6 +23,10 @@
|
||||
#if defined(__SANITIZE_ADDRESS__) /* gcc -fsanitize=address */
|
||||
# define MBEDTLS_TEST_HAVE_ASAN
|
||||
#endif
|
||||
#if defined(__SANITIZE_THREAD__) /* gcc -fsanitize-thread */
|
||||
# define MBEDTLS_TEST_HAVE_TSAN
|
||||
#endif
|
||||
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(address_sanitizer) /* clang -fsanitize=address */
|
||||
# define MBEDTLS_TEST_HAVE_ASAN
|
||||
@ -35,10 +39,10 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_THREADING_PTHREAD) && \
|
||||
defined(MBEDTLS_TEST_HOOKS)
|
||||
#include "test/threading_helpers.h"
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
#include "mbedtls/threading.h"
|
||||
#define MBEDTLS_TEST_MUTEX_USAGE
|
||||
#endif
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
@ -381,24 +385,6 @@ int mbedtls_test_hexcmp(uint8_t *a, uint8_t *b,
|
||||
#include "test/fake_external_rng_for_test.h"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
/**
|
||||
* Activate the mutex usage verification framework. See threading_helpers.c for
|
||||
* information.
|
||||
* */
|
||||
void mbedtls_test_mutex_usage_init(void);
|
||||
|
||||
/**
|
||||
* Deactivate the mutex usage verification framework. See threading_helpers.c
|
||||
* for information.
|
||||
*/
|
||||
void mbedtls_test_mutex_usage_end(void);
|
||||
|
||||
/** Call this function after executing a test case to check for mutex usage
|
||||
* errors. */
|
||||
void mbedtls_test_mutex_usage_check(void);
|
||||
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
/**
|
||||
* \brief Check that only a pure high-level error code is being combined with
|
||||
|
@ -125,8 +125,8 @@
|
||||
do { \
|
||||
TEST_ASSERT((pointer) == NULL); \
|
||||
if ((item_count) != 0) { \
|
||||
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
|
||||
(item_count)); \
|
||||
(pointer) = mbedtls_calloc((item_count), \
|
||||
sizeof(*(pointer))); \
|
||||
TEST_ASSERT((pointer) != NULL); \
|
||||
} \
|
||||
} while (0)
|
||||
@ -155,8 +155,8 @@
|
||||
#define TEST_CALLOC_NONNULL(pointer, item_count) \
|
||||
do { \
|
||||
TEST_ASSERT((pointer) == NULL); \
|
||||
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
|
||||
(item_count)); \
|
||||
(pointer) = mbedtls_calloc((item_count), \
|
||||
sizeof(*(pointer))); \
|
||||
if (((pointer) == NULL) && ((item_count) == 0)) { \
|
||||
(pointer) = mbedtls_calloc(1, 1); \
|
||||
} \
|
||||
@ -175,8 +175,8 @@
|
||||
do { \
|
||||
TEST_ASSERT((pointer) == NULL); \
|
||||
if ((item_count) != 0) { \
|
||||
(pointer) = mbedtls_calloc(sizeof(*(pointer)), \
|
||||
(item_count)); \
|
||||
(pointer) = mbedtls_calloc((item_count), \
|
||||
sizeof(*(pointer))); \
|
||||
TEST_ASSUME((pointer) != NULL); \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -367,6 +367,30 @@ uint64_t mbedtls_test_parse_binary_string(data_t *bin_string);
|
||||
#define MD_PSA_DONE() ((void) 0)
|
||||
#endif /* MBEDTLS_MD_SOME_PSA */
|
||||
|
||||
/** \def BLOCK_CIPHER_PSA_INIT
|
||||
*
|
||||
* Call this macro to initialize the PSA subsystem if BLOCK_CIPHER uses a driver,
|
||||
* and do nothing otherwise.
|
||||
*
|
||||
* If the initialization fails, mark the test case as failed and jump to the
|
||||
* \p exit label.
|
||||
*/
|
||||
/** \def BLOCK_CIPHER_PSA_DONE
|
||||
*
|
||||
* Call this macro at the end of a test case if you called #BLOCK_CIPHER_PSA_INIT.
|
||||
*
|
||||
* This is like #PSA_DONE except it does nothing under the same conditions as
|
||||
* #BLOCK_CIPHER_PSA_INIT.
|
||||
*/
|
||||
#if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA)
|
||||
#define BLOCK_CIPHER_PSA_INIT() PSA_INIT()
|
||||
#define BLOCK_CIPHER_PSA_DONE() PSA_DONE()
|
||||
#else /* MBEDTLS_MD_SOME_PSA */
|
||||
#define BLOCK_CIPHER_PSA_INIT() ((void) 0)
|
||||
#define BLOCK_CIPHER_PSA_DONE() ((void) 0)
|
||||
#endif /* MBEDTLS_MD_SOME_PSA */
|
||||
|
||||
|
||||
/** \def MD_OR_USE_PSA_INIT
|
||||
*
|
||||
* Call this macro to initialize the PSA subsystem if MD uses a driver,
|
||||
|
@ -589,6 +589,16 @@ int mbedtls_test_tweak_tls13_certificate_msg_vector_len(
|
||||
int *expected_result, mbedtls_ssl_chk_buf_ptr_args *args);
|
||||
#endif /* MBEDTLS_TEST_HOOKS */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||
int mbedtls_test_ticket_write(
|
||||
void *p_ticket, const mbedtls_ssl_session *session,
|
||||
unsigned char *start, const unsigned char *end,
|
||||
size_t *tlen, uint32_t *ticket_lifetime);
|
||||
|
||||
int mbedtls_test_ticket_parse(void *p_ticket, mbedtls_ssl_session *session,
|
||||
unsigned char *buf, size_t len);
|
||||
#endif /* MBEDTLS_SSL_SESSION_TICKETS */
|
||||
|
||||
#define ECJPAKE_TEST_PWD "bla"
|
||||
|
||||
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
||||
|
112
tests/include/test/threading_helpers.h
Normal file
112
tests/include/test/threading_helpers.h
Normal file
@ -0,0 +1,112 @@
|
||||
/**
|
||||
* \file threading_helpers.h
|
||||
*
|
||||
* \brief This file contains the prototypes of helper functions for the purpose
|
||||
* of testing threading.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef THREADING_HELPERS_H
|
||||
#define THREADING_HELPERS_H
|
||||
|
||||
#if defined MBEDTLS_THREADING_C
|
||||
|
||||
#include "mbedtls/private_access.h"
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
/* Most fields of publicly available structs are private and are wrapped with
|
||||
* MBEDTLS_PRIVATE macro. This define allows tests to access the private fields
|
||||
* directly (without using the MBEDTLS_PRIVATE wrapper). */
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
|
||||
#define MBEDTLS_ERR_THREADING_THREAD_ERROR -0x001F
|
||||
|
||||
#if defined(MBEDTLS_THREADING_PTHREAD)
|
||||
#include <pthread.h>
|
||||
#endif /* MBEDTLS_THREADING_PTHREAD */
|
||||
|
||||
#if defined(MBEDTLS_THREADING_ALT)
|
||||
/* You should define the mbedtls_test_thread_t type in your header */
|
||||
#include "threading_alt.h"
|
||||
|
||||
/**
|
||||
* \brief Set your alternate threading implementation
|
||||
* function pointers for test threads. If used, this
|
||||
* function must be called once in the main thread
|
||||
* before any other MbedTLS function is called.
|
||||
*
|
||||
* \note These functions are part of the testing API only and
|
||||
* thus not considered part of the public API of
|
||||
* MbedTLS and thus may change without notice.
|
||||
*
|
||||
* \param thread_create The thread create function implementation.
|
||||
* \param thread_join The thread join function implementation.
|
||||
|
||||
*/
|
||||
void mbedtls_test_thread_set_alt(int (*thread_create)(mbedtls_test_thread_t *thread,
|
||||
void *(*thread_func)(
|
||||
void *),
|
||||
void *thread_data),
|
||||
int (*thread_join)(mbedtls_test_thread_t *thread));
|
||||
|
||||
#else /* MBEDTLS_THREADING_ALT*/
|
||||
|
||||
typedef struct mbedtls_test_thread_t {
|
||||
|
||||
#if defined(MBEDTLS_THREADING_PTHREAD)
|
||||
pthread_t MBEDTLS_PRIVATE(thread);
|
||||
#else /* MBEDTLS_THREADING_PTHREAD */
|
||||
/* Make sure this struct is always non-empty */
|
||||
unsigned dummy;
|
||||
#endif
|
||||
|
||||
} mbedtls_test_thread_t;
|
||||
|
||||
#endif /* MBEDTLS_THREADING_ALT*/
|
||||
|
||||
/**
|
||||
* \brief The function pointers for thread create and thread
|
||||
* join.
|
||||
*
|
||||
* \note These functions are part of the testing API only
|
||||
* and thus not considered part of the public API of
|
||||
* MbedTLS and thus may change without notice.
|
||||
*
|
||||
* \note All these functions are expected to work or
|
||||
* the result will be undefined.
|
||||
*/
|
||||
extern int (*mbedtls_test_thread_create)(mbedtls_test_thread_t *thread,
|
||||
void *(*thread_func)(void *), void *thread_data);
|
||||
extern int (*mbedtls_test_thread_join)(mbedtls_test_thread_t *thread);
|
||||
|
||||
#if defined(MBEDTLS_THREADING_PTHREAD) && defined(MBEDTLS_TEST_HOOKS)
|
||||
#define MBEDTLS_TEST_MUTEX_USAGE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
/**
|
||||
* Activate the mutex usage verification framework. See threading_helpers.c for
|
||||
* information.
|
||||
*/
|
||||
void mbedtls_test_mutex_usage_init(void);
|
||||
|
||||
/**
|
||||
* Deactivate the mutex usage verification framework. See threading_helpers.c
|
||||
* for information.
|
||||
*/
|
||||
void mbedtls_test_mutex_usage_end(void);
|
||||
|
||||
/**
|
||||
* Call this function after executing a test case to check for mutex usage
|
||||
* errors.
|
||||
*/
|
||||
void mbedtls_test_mutex_usage_check(void);
|
||||
#endif /* MBEDTLS_TEST_MUTEX_USAGE */
|
||||
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
#endif /* THREADING_HELPERS_H */
|
Reference in New Issue
Block a user