2017-05-09 17:20:21 +01:00
|
|
|
#line 2 "suites/helpers.function"
|
2016-02-17 23:34:30 +00: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
|
|
|
|
2022-12-04 13:18:58 +01:00
|
|
|
#include <stdint.h>
|
2016-05-17 13:35:51 +01:00
|
|
|
#include <stdlib.h>
|
2022-12-04 13:18:58 +01:00
|
|
|
#include <string.h>
|
2016-05-17 13:35:51 +01:00
|
|
|
|
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 17:05:11 +00:00
|
|
|
#include "mbedtls/platform.h"
|
2014-06-06 14:48:09 +02:00
|
|
|
|
2016-02-17 23:34:30 +00:00
|
|
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
|
|
#include "mbedtls/memory_buffer_alloc.h"
|
|
|
|
#endif
|
|
|
|
|
2016-10-05 10:57:49 +01:00
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2016-02-17 23:34:30 +00:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-06-29 10:02:54 +01:00
|
|
|
/* Status and error constants */
|
2016-02-17 23:34:30 +00:00
|
|
|
|
2018-06-29 10:02:54 +01: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-17 23:24:50 +01:00
|
|
|
|
2018-06-29 10:02:54 +01: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-17 23:34:30 +00:00
|
|
|
|
2016-04-17 23:24:50 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Global variables */
|
|
|
|
|
2017-07-24 12:27:09 +01: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 08:09:33 +01:00
|
|
|
#define ENTROPY_HAVE_STRONG
|
2017-07-24 12:27:09 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-02-17 23:34:30 +00:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Helper Functions */
|
2019-01-31 08:20:20 -05:00
|
|
|
|
2016-10-05 10:57:49 +01: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 10:57:49 +01: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 10:57:49 +01: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 10:57:49 +01: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 10:57:49 +01: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 10:57:49 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
fclose(path_stream);
|
|
|
|
return dup_fd;
|
2016-10-05 10:57:49 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static int restore_output(FILE *out_stream, int dup_fd)
|
2016-10-05 10:57:49 +01: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 10:57:49 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
close(dup_fd);
|
|
|
|
return 0;
|
2016-10-12 23:07:30 +01:00
|
|
|
}
|
2016-10-05 10:57:49 +01:00
|
|
|
#endif /* __unix__ || __APPLE__ __MACH__ */
|