2017-05-09 18:20:21 +02:00
|
|
|
#line 2 "suites/helpers.function"
|
2016-02-18 00:34:30 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Headers */
|
|
|
|
|
2020-06-03 10:11:18 +02:00
|
|
|
#include <test/helpers.h>
|
2021-05-27 14:44:31 +02:00
|
|
|
#include <test/macros.h>
|
2020-06-09 16:57:42 +02:00
|
|
|
#include <test/random.h>
|
2022-12-08 15:24:52 +01:00
|
|
|
#include <test/bignum_helpers.h>
|
2020-11-24 18:33:13 +01:00
|
|
|
#include <test/psa_crypto_helpers.h>
|
2020-06-09 13:52:23 +02:00
|
|
|
|
2016-05-17 14:35:51 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#if defined(MBEDTLS_ERROR_C)
|
2021-05-21 09:48:03 +02:00
|
|
|
#include "mbedtls/error.h"
|
|
|
|
#endif
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/platform.h"
|
2014-06-06 14:48:09 +02:00
|
|
|
|
2016-02-18 00:34:30 +01:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
|
|
#include "mbedtls/memory_buffer_alloc.h"
|
|
|
|
#endif
|
|
|
|
|
2011-03-13 17:57:25 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <basetsd.h>
|
2018-06-22 12:34:33 +02:00
|
|
|
typedef UINT8 uint8_t;
|
|
|
|
typedef INT32 int32_t;
|
2011-03-13 17:57:25 +01:00
|
|
|
typedef UINT32 uint32_t;
|
2015-11-14 14:09:01 +01:00
|
|
|
#define strncasecmp _strnicmp
|
|
|
|
#define strcasecmp _stricmp
|
2011-03-13 17:57:25 +01:00
|
|
|
#else
|
2015-06-22 19:21:23 +02:00
|
|
|
#include <stdint.h>
|
2011-03-13 17:57:25 +01:00
|
|
|
#endif
|
|
|
|
|
2013-08-16 13:31:10 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-03-09 00:29:26 +01:00
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__MINGW32__)
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2016-10-05 11:57:49 +02:00
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2016-02-18 00:34:30 +01:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-06-29 11:02:54 +02:00
|
|
|
/* Status and error constants */
|
2016-02-18 00:34:30 +01:00
|
|
|
|
2018-06-29 11:02:54 +02:00
|
|
|
#define DEPENDENCY_SUPPORTED 0 /* Dependency supported by build */
|
|
|
|
#define KEY_VALUE_MAPPING_FOUND 0 /* Integer expression found */
|
|
|
|
#define DISPATCH_TEST_SUCCESS 0 /* Test dispatch successful */
|
2016-04-18 00:24:50 +02:00
|
|
|
|
2018-06-29 11:02:54 +02:00
|
|
|
#define KEY_VALUE_MAPPING_NOT_FOUND -1 /* Integer expression not found */
|
|
|
|
#define DEPENDENCY_NOT_SUPPORTED -2 /* Dependency not supported */
|
|
|
|
#define DISPATCH_TEST_FN_NOT_FOUND -3 /* Test function not found */
|
|
|
|
#define DISPATCH_INVALID_TEST_DATA -4 /* Invalid test parameter type.
|
|
|
|
Only int, string, binary data
|
|
|
|
and integer expressions are
|
|
|
|
allowed */
|
|
|
|
#define DISPATCH_UNSUPPORTED_SUITE -5 /* Test suite not supported by the
|
|
|
|
build */
|
2016-02-18 00:34:30 +01:00
|
|
|
|
2016-04-18 00:24:50 +02:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Global variables */
|
|
|
|
|
2017-07-24 13:27:09 +02:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Helper flags for complex dependencies */
|
|
|
|
|
|
|
|
/* Indicates whether we expect mbedtls_entropy_init
|
|
|
|
* to initialize some strong entropy source. */
|
2021-04-30 13:28:22 +02:00
|
|
|
#if !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) && \
|
2023-01-11 14:50:10 +01:00
|
|
|
(!defined(MBEDTLS_NO_PLATFORM_ENTROPY) || \
|
|
|
|
defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
|
|
|
|
defined(ENTROPY_NV_SEED))
|
2017-09-07 09:09:33 +02:00
|
|
|
#define ENTROPY_HAVE_STRONG
|
2017-07-24 13:27:09 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-02-18 00:34:30 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Helper Functions */
|
2019-01-31 14:20:20 +01:00
|
|
|
|
2016-10-05 11:57:49 +02:00
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
2023-01-11 14:50:10 +01:00
|
|
|
static int redirect_output(FILE *out_stream, const char *path)
|
2016-10-05 11:57:49 +02:00
|
|
|
{
|
2020-07-30 09:02:27 +02:00
|
|
|
int out_fd, dup_fd;
|
2023-01-11 14:50:10 +01:00
|
|
|
FILE *path_stream;
|
2016-10-05 11:57:49 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
out_fd = fileno(out_stream);
|
|
|
|
dup_fd = dup(out_fd);
|
2020-07-30 09:02:27 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (dup_fd == -1) {
|
|
|
|
return -1;
|
2016-10-05 11:57:49 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
path_stream = fopen(path, "w");
|
|
|
|
if (path_stream == NULL) {
|
|
|
|
close(dup_fd);
|
|
|
|
return -1;
|
2020-07-30 09:02:27 +02:00
|
|
|
}
|
2016-10-05 11:57:49 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
fflush(out_stream);
|
|
|
|
if (dup2(fileno(path_stream), out_fd) == -1) {
|
|
|
|
close(dup_fd);
|
|
|
|
fclose(path_stream);
|
|
|
|
return -1;
|
2016-10-05 11:57:49 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
fclose(path_stream);
|
|
|
|
return dup_fd;
|
2016-10-05 11:57:49 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static int restore_output(FILE *out_stream, int dup_fd)
|
2016-10-05 11:57:49 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
int out_fd = fileno(out_stream);
|
|
|
|
|
|
|
|
fflush(out_stream);
|
|
|
|
if (dup2(dup_fd, out_fd) == -1) {
|
|
|
|
close(out_fd);
|
|
|
|
close(dup_fd);
|
|
|
|
return -1;
|
2016-10-05 11:57:49 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
close(dup_fd);
|
|
|
|
return 0;
|
2016-10-13 00:07:30 +02:00
|
|
|
}
|
2016-10-05 11:57:49 +02:00
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|