mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-06-05 21:15:09 +00:00
Merge pull request #279 from gilles-peskine-arm/unix-detection-202601-framework
Simplify platform requirements before 1.1/4.1: framework support
This commit is contained in:
@@ -69,7 +69,7 @@ int psa_key_agreement_main(void)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
mbedtls_printf("Client Public Key (%" MBEDTLS_PRINTF_SIZET " bytes):\n", client_pk_len);
|
||||
mbedtls_printf("Client Public Key (%zu bytes):\n", client_pk_len);
|
||||
|
||||
for (size_t j = 0; j < client_pk_len; j++) {
|
||||
if (j % 8 == 0) {
|
||||
@@ -108,7 +108,7 @@ int psa_key_agreement_main(void)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
mbedtls_printf("Server Public Key (%" MBEDTLS_PRINTF_SIZET " bytes):\n", sizeof(server_pk));
|
||||
mbedtls_printf("Server Public Key (%zu bytes):\n", sizeof(server_pk));
|
||||
|
||||
for (size_t j = 0; j < sizeof(server_pk); j++) {
|
||||
if (j % 8 == 0) {
|
||||
@@ -129,7 +129,7 @@ int psa_key_agreement_main(void)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
mbedtls_printf("Derived Key (%" MBEDTLS_PRINTF_SIZET " bytes):\n", derived_key_len);
|
||||
mbedtls_printf("Derived Key (%zu bytes):\n", derived_key_len);
|
||||
|
||||
for (size_t j = 0; j < derived_key_len; j++) {
|
||||
if (j % 8 == 0) {
|
||||
|
||||
@@ -93,11 +93,6 @@ class ChangelogFormat:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def version_title_text(cls, version_title):
|
||||
"""Return the text of a formatted version section title."""
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def split_categories(cls, version_body):
|
||||
"""Split a changelog version section body into categories.
|
||||
@@ -141,10 +136,6 @@ class TextChangelogFormat(ChangelogFormat):
|
||||
top_version_title, top_version_body,
|
||||
changelog_file_content[top_version_end:])
|
||||
|
||||
@classmethod
|
||||
def version_title_text(cls, version_title):
|
||||
return re.sub(r'\n.*', version_title, re.DOTALL)
|
||||
|
||||
_category_title_re = re.compile(r'(^\w.*)\n+', re.MULTILINE)
|
||||
@classmethod
|
||||
def split_categories(cls, version_body):
|
||||
|
||||
@@ -1159,6 +1159,14 @@ class NameChecker():
|
||||
|
||||
If you add an exception, make sure to explain why!
|
||||
"""
|
||||
# The platform requirements headers define macros that are meant to
|
||||
# be consumed by system headers. These macros are in a namespace
|
||||
# reserved by the C language (two initial underscores, or an
|
||||
# initial underscore followed by an uppercase letter).
|
||||
if group == 'internal_macros' and \
|
||||
'_platform_requirements.h' in match.filename and \
|
||||
re.match(r'_[A-Z_]', match.name):
|
||||
return True
|
||||
# We use some short macros that start with a lowercase letter
|
||||
# internally in bignum code. They are grandfathered in. They
|
||||
# may be in a header file, but only in a source directory, not
|
||||
|
||||
@@ -762,7 +762,7 @@ def escaped_split(inp_str, split_char):
|
||||
raise ValueError('Expected split character. Found string!')
|
||||
out = re.sub(r'(\\.)|' + split_char,
|
||||
lambda m: m.group(1) or '\n', inp_str,
|
||||
len(inp_str)).split('\n')
|
||||
count=len(inp_str)).split('\n')
|
||||
out = [x for x in out if x]
|
||||
return out
|
||||
|
||||
|
||||
@@ -110,6 +110,17 @@ class Base:
|
||||
|
||||
''')
|
||||
|
||||
if not header:
|
||||
# On Mingw-w64, force the use of a C99-compliant printf() and friends.
|
||||
# This is necessary on older versions of Mingw and/or Windows runtimes
|
||||
# where snprintf does not always zero-terminate the buffer, and does
|
||||
# not support formats such as "%zu" for size_t and "%lld" for long long.
|
||||
prologue += strip_indentation(f'''
|
||||
#if !defined(__USE_MINGW_ANSI_STDIO)
|
||||
#define __USE_MINGW_ANSI_STDIO 1
|
||||
#endif
|
||||
''')
|
||||
|
||||
for include in self._INCLUDES:
|
||||
prologue += "#include {}\n".format(include)
|
||||
|
||||
@@ -359,7 +370,7 @@ class Base:
|
||||
"""Preprocessor symbol used as a guard against multiple inclusion."""
|
||||
# Heuristic to strip irrelevant leading directories
|
||||
filename = re.sub(r'.*include[\\/]', r'', filename)
|
||||
return re.sub(r'[^0-9A-Za-z]', r'_', filename, re.A).upper()
|
||||
return re.sub(r'[^0-9A-Za-z]', r'_', filename, flags=re.A).upper()
|
||||
|
||||
def write_h_file(self, filename: str) -> None:
|
||||
"""Output a header file with function wrapper declarations and macro definitions."""
|
||||
@@ -403,7 +414,6 @@ class Logging(Base):
|
||||
#if defined(MBEDTLS_FS_IO) && defined(MBEDTLS_TEST_HOOKS)
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <mbedtls/debug.h> // for MBEDTLS_PRINTF_SIZET
|
||||
#include <mbedtls/platform.h> // for mbedtls_fprintf
|
||||
#endif /* defined(MBEDTLS_FS_IO) && defined(MBEDTLS_TEST_HOOKS) */
|
||||
""")
|
||||
@@ -412,7 +422,7 @@ class Logging(Base):
|
||||
'int': '%d',
|
||||
'long': '%ld',
|
||||
'long long': '%lld',
|
||||
'size_t': '%"MBEDTLS_PRINTF_SIZET"',
|
||||
'size_t': '%zu',
|
||||
'unsigned': '0x%08x',
|
||||
'unsigned int': '0x%08x',
|
||||
'unsigned long': '0x%08lx',
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#ifndef TEST_ARGUMENTS_H
|
||||
#define TEST_ARGUMENTS_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#ifndef ASN1_HELPERS_H
|
||||
#define ASN1_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test/helpers.h"
|
||||
|
||||
/** Skip past an INTEGER in an ASN.1 buffer.
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef BIGNUM_CODEPATH_CHECK_H
|
||||
#define BIGNUM_CODEPATH_CHECK_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include "bignum_core.h"
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#ifndef TEST_BIGNUM_HELPERS_H
|
||||
#define TEST_BIGNUM_HELPERS_H
|
||||
|
||||
#include <mbedtls/build_info.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef TEST_CONSTANT_FLOW_H
|
||||
#define TEST_CONSTANT_FLOW_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
/*
|
||||
* This file defines the two macros
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef FAKE_EXTERNAL_RNG_FOR_TEST_H
|
||||
#define FAKE_EXTERNAL_RNG_FOR_TEST_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
/** Enable the insecure implementation of mbedtls_psa_external_get_random().
|
||||
|
||||
@@ -13,12 +13,7 @@
|
||||
#ifndef TEST_HELPERS_H
|
||||
#define TEST_HELPERS_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
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(__SANITIZE_ADDRESS__) /* gcc -fsanitize=address */
|
||||
# define MBEDTLS_TEST_HAVE_ASAN
|
||||
@@ -240,6 +235,19 @@ void mbedtls_test_platform_teardown(void);
|
||||
*/
|
||||
void mbedtls_test_fail(const char *test, int line_no, const char *filename);
|
||||
|
||||
/**
|
||||
* \brief Record the current test case as a failure
|
||||
* and show the value of errno.
|
||||
*
|
||||
* This function is usually called via #TEST_ASSERT_ERRNO.
|
||||
*
|
||||
* \param test Description of the failure or assertion that failed. This
|
||||
* MUST be a string literal.
|
||||
* \param line_no Line number where the failure originated.
|
||||
* \param filename Filename where the failure originated.
|
||||
*/
|
||||
void mbedtls_test_fail_errno(const char *test, int line_no, const char *filename);
|
||||
|
||||
/**
|
||||
* \brief Record the current test case as skipped.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef TEST_MACROS_H
|
||||
#define TEST_MACROS_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -54,6 +54,21 @@
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/** \brief Evaluate an integer expression. If the value is 0 (i.e. false),
|
||||
* mark the test case as failed and display errno.
|
||||
*
|
||||
* This is intended for functions that follow the Unix API convention of
|
||||
* returning a particular value (often -1) and setting errno on failure,
|
||||
* e.g. `TEST_ASSERT_ERRNO(open(...) != -1)`.
|
||||
*/
|
||||
#define TEST_ASSERT_ERRNO(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
mbedtls_test_fail_errno(#expr, __LINE__, __FILE__); \
|
||||
goto exit; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/** This macro asserts fails the test with given output message.
|
||||
*
|
||||
* \param MESSAGE The message to be outputed on assertion
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#ifndef TEST_MEMORY_H
|
||||
#define TEST_MEMORY_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
#include "test/helpers.h"
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef PK_HELPERS_H
|
||||
#define PK_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
|
||||
#include <psa/crypto.h>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#ifndef PSA_CRYPTO_HELPERS_H
|
||||
#define PSA_CRYPTO_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test/helpers.h"
|
||||
|
||||
#if (MBEDTLS_VERSION_MAJOR < 4 && defined(MBEDTLS_PSA_CRYPTO_C)) || \
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#ifndef PSA_EXERCISE_KEY_H
|
||||
#define PSA_EXERCISE_KEY_H
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test/helpers.h"
|
||||
#include "test/psa_crypto_helpers.h"
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#ifndef PSA_HELPERS_H
|
||||
#define PSA_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_SPM)
|
||||
#include "spm/psa_defs.h"
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#ifndef PSA_MEMORY_POISONING_WRAPPERS_H
|
||||
#define PSA_MEMORY_POISONING_WRAPPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include "psa/crypto.h"
|
||||
|
||||
#include "test/memory.h"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#ifndef TEST_RANDOM_H
|
||||
#define TEST_RANDOM_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* \file test_common.h
|
||||
*
|
||||
* \brief Common things for all Mbed TLS and TF-PSA-Crypto test code.
|
||||
*
|
||||
* Include this header first in all headers in `include/test/`.
|
||||
* Include this or another header from `include/test/` in all test C files.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef TEST_TEST_COMMON_H
|
||||
#define TEST_TEST_COMMON_H
|
||||
|
||||
/* On Mingw-w64, force the use of a C99-compliant printf() and friends.
|
||||
* This is necessary on older versions of Mingw and/or Windows runtimes
|
||||
* where snprintf does not always zero-terminate the buffer, and does
|
||||
* not support formats such as "%zu" for size_t and "%lld" for long long.
|
||||
*/
|
||||
#if !defined(__USE_MINGW_ANSI_STDIO)
|
||||
#define __USE_MINGW_ANSI_STDIO 1
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#endif /* TEST_TEST_COMMON_H */
|
||||
@@ -13,18 +13,12 @@
|
||||
#ifndef THREADING_HELPERS_H
|
||||
#define THREADING_HELPERS_H
|
||||
|
||||
#include "mbedtls/private_access.h"
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined MBEDTLS_THREADING_C
|
||||
|
||||
#include <mbedtls/threading.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
|
||||
|
||||
/* Error in thread management */
|
||||
#define MBEDTLS_ERR_THREADING_THREAD_ERROR -0x001F
|
||||
|
||||
|
||||
+12
-10
@@ -26,6 +26,14 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
/* On Mingw-w64, force the use of a C99-compliant printf() and friends.
|
||||
* This is necessary on older versions of Mingw and/or Windows runtimes
|
||||
* where snprintf does not always zero-terminate the buffer, and does
|
||||
* not support formats such as "%zu" for size_t and "%lld" for long long.
|
||||
*/
|
||||
#if !defined(__USE_MINGW_ANSI_STDIO)
|
||||
#define __USE_MINGW_ANSI_STDIO 1
|
||||
#endif
|
||||
|
||||
#include <mbedtls/debug.h>
|
||||
#include <mbedtls/platform.h>
|
||||
@@ -200,10 +208,7 @@ static void test_memory_poison(const char *name)
|
||||
size_t start = 0, offset = 0, count = 0;
|
||||
char direction = 'r';
|
||||
if (sscanf(name,
|
||||
"%*[^0-9]%" MBEDTLS_PRINTF_SIZET
|
||||
"%*[^0-9]%" MBEDTLS_PRINTF_SIZET
|
||||
"%*[^0-9]%" MBEDTLS_PRINTF_SIZET
|
||||
"_%c",
|
||||
"%*[^0-9]%zu%*[^0-9]%zu%*[^0-9]%zu_%c",
|
||||
&start, &offset, &count, &direction) != 4) {
|
||||
mbedtls_fprintf(stderr, "%s: Bad name format: %s\n", __func__, name);
|
||||
return;
|
||||
@@ -217,22 +222,19 @@ static void test_memory_poison(const char *name)
|
||||
|
||||
if (start > sizeof(aligned.buf)) {
|
||||
mbedtls_fprintf(stderr,
|
||||
"%s: start=%" MBEDTLS_PRINTF_SIZET
|
||||
" > size=%" MBEDTLS_PRINTF_SIZET,
|
||||
"%s: start=%zu > size=%zu",
|
||||
__func__, start, sizeof(aligned.buf));
|
||||
return;
|
||||
}
|
||||
if (start + count > sizeof(aligned.buf)) {
|
||||
mbedtls_fprintf(stderr,
|
||||
"%s: start+count=%" MBEDTLS_PRINTF_SIZET
|
||||
" > size=%" MBEDTLS_PRINTF_SIZET,
|
||||
"%s: start+count=%zu > size=%zu",
|
||||
__func__, start + count, sizeof(aligned.buf));
|
||||
return;
|
||||
}
|
||||
if (offset >= count) {
|
||||
mbedtls_fprintf(stderr,
|
||||
"%s: offset=%" MBEDTLS_PRINTF_SIZET
|
||||
" >= count=%" MBEDTLS_PRINTF_SIZET,
|
||||
"%s: offset=%zu >= count=%zu",
|
||||
__func__, offset, count);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <test/constant_flow.h>
|
||||
#include <test/helpers.h>
|
||||
#include <test/macros.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
|
||||
@@ -571,6 +572,31 @@ int mbedtls_test_le_s(const char *test, int line_no, const char *filename,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mbedtls_test_fail_errno(const char *test,
|
||||
int line_no, const char *filename)
|
||||
{
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_lock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
|
||||
/* Don't use accessor, we already hold mutex. */
|
||||
if (mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* If we've already recorded the test as having failed then don't
|
||||
* overwrite any previous information about the failure. */
|
||||
|
||||
char buf[MBEDTLS_TEST_LINE_LENGTH];
|
||||
mbedtls_test_fail_internal(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(buf, sizeof(buf),
|
||||
"errno = %d (%s)",
|
||||
errno, strerror(errno));
|
||||
mbedtls_test_set_line1_internal(buf);
|
||||
}
|
||||
|
||||
#ifdef MBEDTLS_THREADING_C
|
||||
mbedtls_mutex_unlock(&mbedtls_test_info_mutex);
|
||||
#endif /* MBEDTLS_THREADING_C */
|
||||
}
|
||||
|
||||
int mbedtls_test_unhexify(unsigned char *obuf,
|
||||
size_t obufmax,
|
||||
const char *ibuf,
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <mbedtls/pk.h>
|
||||
#include <test/macros.h>
|
||||
#include <test/helpers.h>
|
||||
#include <test/pk_helpers.h>
|
||||
#include <test/psa_helpers.h>
|
||||
#include <test/test_keys.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include "psa_util_internal.h"
|
||||
|
||||
/* Functions like mbedtls_pk_wrap_psa() are only available in tf-psa-crypto and
|
||||
|
||||
Reference in New Issue
Block a user