2017-05-09 18:20:21 +02:00
|
|
|
#line 2 "suites/helpers.function"
|
2016-02-18 00:34:30 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
/* Headers */
|
|
|
|
|
2022-12-04 13:10:55 +01:00
|
|
|
#include <test/arguments.h>
|
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
|
|
|
|
Simplify parsing of integers in .datax files
In the .datax parser, since we're calling strtol() anyway, rely on it for
verification. This makes the .datax parser very slightly more
liberal (leading spaces and '+' are now accepted), and changes the
interpretation of numbers with leading zeros to octal.
Before, an argument like :0123: was parsed as decimal, but an argument like
:0123+1: was parsed as a C expression and hence the leading zero marked an
octal representation. Now, a leading zero is always interpreted according to
C syntax, namely indicating octal. There are no nonzero integer constants
with a leading zero in a .data file, so this does not affect existing test
cases.
In the .datax generator, allow negative arguments to be 'int' (before, they
were systematically treated as 'exp' even though they didn't need to be).
In the .datax parser, validate the range of integer constants. They have to
fit in int32_t. In the .datax generator, use 'exp' instead of 'int' for
integer constants that are out of range.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-04 00:28:56 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2022-12-04 13:18:58 +01:00
|
|
|
#include <stdint.h>
|
2016-05-17 14:35:51 +02:00
|
|
|
#include <stdlib.h>
|
2022-12-04 13:18:58 +01:00
|
|
|
#include <string.h>
|
2016-05-17 14:35:51 +02: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 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
|
|
|
|
|
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__ */
|