Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test helpers to framework repo #37

Open
wants to merge 81 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
6e450c7
Updated the PR template with new checkboxes
minosgalanakis May 1, 2024
1deadf5
Update .github/pull_request_template.md
minosgalanakis May 3, 2024
ad94717
Update .github/pull_request_template.md
minosgalanakis May 20, 2024
fc37c10
psa: fix parameters' names of psa_key_derivation_verify_bytes()
valeriosetti Jun 24, 2024
f47b66e
Remove MBEDTLS_RSA_ALT
tom-daubney-arm Jun 4, 2024
5edad7f
Remove MBEDTLS_DHM_ALT
tom-daubney-arm Jun 5, 2024
e647d8f
Remove MBEDTLS_ECJPAKE_ALT
tom-daubney-arm Jun 5, 2024
9da1769
Remove MBEDTLS_ECP_ALT and associated options
tom-daubney-arm Jun 6, 2024
3507d76
Modify rsa_alt_helpers.h docs
tom-daubney-arm Jul 1, 2024
b744dd3
Move some files to framework repository
davidhorstmann-arm Jul 5, 2024
dcf18dd
Update paths pointing to tests/data_files
davidhorstmann-arm Jun 11, 2024
4481698
Update directory-climbing path in context-info.sh
davidhorstmann-arm Jun 19, 2024
eb8abda
Fix line-too-long in generate_tls13_compat_tests.py
davidhorstmann-arm Jun 19, 2024
441b66c
Correct redundant framework/../framework paths
davidhorstmann-arm Jul 1, 2024
d178031
Replace data_files path with variable in compat.sh
davidhorstmann-arm Jul 1, 2024
184c4f0
Use variable for data_files path in ssl-opt.sh
davidhorstmann-arm Jul 1, 2024
661c088
Simplify data_files path in compat test generation
davidhorstmann-arm Jul 1, 2024
f36b7bc
Simplify path in audit-validity-dates.py
davidhorstmann-arm Jul 1, 2024
b51ed61
Move variable into generated bash
davidhorstmann-arm Jul 3, 2024
0cbf8d5
Update generated tls13 testcase script
davidhorstmann-arm Jul 3, 2024
53ce048
Update framework submodule
davidhorstmann-arm Jul 5, 2024
1d25626
Merge pull request #9271 from tom-daubney-arm/remove_asymmetric_crypt…
ronald-cron-arm Jul 5, 2024
797e43b
Update .github/pull_request_template.md
minosgalanakis Jul 8, 2024
0ce9fa9
Update the framework submodule to the merge of PR18
ronald-cron-arm Jul 9, 2024
fe3ad99
Merge pull request #9249 from davidhorstmann-arm/move-test-data-files…
ronald-cron-arm Jul 9, 2024
90ca414
Move crypto modules
ronald-cron-arm Jul 1, 2024
c29afb6
Adjust build systems
ronald-cron-arm Jul 1, 2024
52cd108
Adapt make cscope
ronald-cron-arm Jul 2, 2024
b2bdb78
Adapt libtestdriver1 build
ronald-cron-arm Jul 2, 2024
6921d54
Adapt check_names.py
ronald-cron-arm Jul 2, 2024
381247e
Adapt check-generated-files.sh
ronald-cron-arm Jul 2, 2024
ad6d1ce
Adapt list_internal_identifiers.py
ronald-cron-arm Jul 3, 2024
709bbf0
all.sh: Update paths to builtin driver modules and objects
ronald-cron-arm Jul 3, 2024
5b41a65
all.sh: Update paths to PSA core modules and objects
ronald-cron-arm Jul 3, 2024
8280398
Adapt all.sh cleanup
ronald-cron-arm Jul 2, 2024
1606cff
Move everest and p256-m
ronald-cron-arm Jul 1, 2024
aef8cf3
Adjust build systems
ronald-cron-arm Jul 1, 2024
691f67f
Adapt make cscope
ronald-cron-arm Jul 2, 2024
4cc77a1
Adapt libtestdriver1 build
ronald-cron-arm Jul 2, 2024
0070d05
Adapt check_names.py
ronald-cron-arm Jul 2, 2024
2f44756
Adapt check_files.py
ronald-cron-arm Jul 2, 2024
2fd621e
Adapt code_style.py
ronald-cron-arm Jul 2, 2024
f37ff7f
Adapt all.sh cleanup
ronald-cron-arm Jul 2, 2024
bdd8df8
Adapt documentation
ronald-cron-arm Jul 2, 2024
9027955
all.sh: Move definitions of PSA core and builtin source paths
ronald-cron-arm Jul 4, 2024
f250cf6
common.make: Use dedicated env variable
ronald-cron-arm Jul 4, 2024
080ab4f
check_files.py: Exempt only everest from license checking
ronald-cron-arm Jul 4, 2024
1992c91
Update the framework submodule to the merge of PR32
ronald-cron-arm Jul 10, 2024
1004c9c
Merge pull request #9340 from ronald-cron-arm/move-mbedtls-crypto-mod…
ronald-cron-arm Jul 10, 2024
f7ca94a
Remove MBEDTLS_POLY1305_ALT
tom-daubney-arm Jun 5, 2024
af28a17
Remove MBEDTLS_CHACHAPOLY_ALT
tom-daubney-arm Jun 5, 2024
f60ff02
Remove MBEDTLS_CHACHA20_ALT
tom-daubney-arm Jun 5, 2024
0916cd7
Replace MBEDTLS_MD_CAN_SHA256 with PSA_WANT_ALG_SHA_256
eleuzi01 May 23, 2024
4e6a368
Replace MBEDTLS_MD_CAN_SHA256 in md.h, ssl.h, and entropy.h
eleuzi01 Jun 26, 2024
095fa2c
Merge pull request #9173 from eleuzi01/replace-mbedtls-md-can-sha256
paul-elliott-arm Jul 11, 2024
d53e889
Update .github/pull_request_template.md
minosgalanakis Jul 11, 2024
1e96705
Replace MBEDTLS_MD_CAN_SHA3_224 with PSA_WANT_ALG_SHA3_224
eleuzi01 May 31, 2024
9a8a9d3
Replace MBEDTLS_MD_CAN_SHA3_224 in md.h
eleuzi01 Jun 26, 2024
ac97c86
Merge pull request #9080 from minosgalanakis/dev_fix_checkboxes
gilles-peskine-arm Jul 12, 2024
6a5278b
Merge pull request #9211 from eleuzi01/replace-mbedtls-md-can-sha3-224
gilles-peskine-arm Jul 12, 2024
3f2d9b6
Merge pull request #9268 from tom-daubney-arm/remove_symmetric_crypto…
bensze01 Jul 12, 2024
db0421c
Replace MBEDTLS_MD_CAN_SHA3_384 with PSA_WANT_ALG_SHA3_384
eleuzi01 May 31, 2024
7a507d2
Replace MBEDTLS_MD_CAN_SHA3_384 in md.h
eleuzi01 Jun 26, 2024
4137609
Remove MBEDTLS_AES_ALT
tom-daubney-arm Jun 4, 2024
b4914cf
Remove MBEDTLS_CCM_ALT
tom-daubney-arm Jun 4, 2024
c7cb810
Remove MBEDTLS_GCM_ALT
tom-daubney-arm Jun 4, 2024
e9fe311
Remove MBEDTLS_CAMELLIA_ALT
tom-daubney-arm Jun 5, 2024
064f1df
Remove MBEDTLS_ARIA_ALT
tom-daubney-arm Jun 5, 2024
a9ea6f8
Remove MBEDTLS_DES_ALT
tom-daubney-arm Jun 5, 2024
25e2be1
Remove MBEDTLS_NIST_KW_ALT
tom-daubney-arm Jun 5, 2024
ebeef15
Remove MBEDTLS_TEST_HAVE_ALT_GCM
tom-daubney-arm Jun 17, 2024
478efd7
Improved AES comment
tom-daubney-arm Jun 17, 2024
356309f
Restore config option
tom-daubney-arm Jun 18, 2024
53377f1
Update comment in further places
tom-daubney-arm Jun 20, 2024
3f40127
Merge pull request #9213 from eleuzi01/replace-mbedtls-md-can-sha3-384
bensze01 Jul 12, 2024
f974bff
Merge pull request #9259 from tom-daubney-arm/remove_aes-like_alt_int…
bensze01 Jul 12, 2024
5f616e9
Merge pull request #9308 from valeriosetti/fix-psa_key_derivation_ver…
gilles-peskine-arm Jul 15, 2024
eff4db6
Move some files to framework repository
davidhorstmann-arm Jul 17, 2024
a3aae68
Merge branch 'tmp-branch-move-files-to-framework' into dev/davidhorst…
davidhorstmann-arm Jul 17, 2024
9819b04
Update references to tests/src
davidhorstmann-arm Jul 12, 2024
bde4a56
Update comment references to test helpers
davidhorstmann-arm Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/generate_psa_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ def _printf_parameters(self, typ: str, var: str) -> Tuple[str, List[str]]:
return super()._printf_parameters(typ, var)


DEFAULT_C_OUTPUT_FILE_NAME = 'tests/src/psa_test_wrappers.c'
DEFAULT_H_OUTPUT_FILE_NAME = 'tests/include/test/psa_test_wrappers.h'
DEFAULT_C_OUTPUT_FILE_NAME = 'framework/tests/src/psa_test_wrappers.c'
DEFAULT_H_OUTPUT_FILE_NAME = 'framework/tests/include/test/psa_test_wrappers.h'

def main() -> None:
parser = argparse.ArgumentParser(description=globals()['__doc__'])
Expand Down
5 changes: 3 additions & 2 deletions scripts/generate_test_cert_macros.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3

"""
Generate `tests/src/test_certs.h` which includes certficaties/keys/certificate list for testing.
Generate `framework/tests/src/test_certs.h` which includes
certficates/keys/certificate list for testing.
"""

#
Expand All @@ -15,8 +16,8 @@
import jinja2
from mbedtls_framework.build_tree import guess_project_root

TESTS_DIR = os.path.join(guess_project_root(), 'tests')
FRAMEWORK_DIR = os.path.join(guess_project_root(), 'framework')
TESTS_DIR = os.path.join(FRAMEWORK_DIR, 'tests')
DATA_FILES_PATH = os.path.join(FRAMEWORK_DIR, 'data_files')

INPUT_ARGS = [
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def collect_keys() -> Tuple[str, str]:
return ''.join(arrays), '\n'.join(look_up_table)

def main() -> None:
default_output_path = guess_project_root() + "/tests/src/test_keys.h"
default_output_path = guess_project_root() + "/framework/tests/src/test_keys.h"

argparser = argparse.ArgumentParser()
argparser.add_argument("--output", help="Output file", default=default_output_path)
Expand Down
7 changes: 7 additions & 0 deletions tests/include/alt-extra/psa/crypto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* The goal of the include/alt-extra directory is to test what happens
* if certain files come _after_ the normal include directory.
* Make sure that if the alt-extra directory comes before the normal
* directory (so we wouldn't be achieving our test objective), the build
* will fail.
*/
#error "The normal include directory must come first in the include path"
6 changes: 6 additions & 0 deletions tests/include/baremetal-override/time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#error "time.h included in a configuration without MBEDTLS_HAVE_TIME"
131 changes: 131 additions & 0 deletions tests/include/spe/crypto_spe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*
*/

/**
* \file crypto_spe.h
*
* \brief When Mbed TLS is built with the MBEDTLS_PSA_CRYPTO_SPM option
* enabled, this header is included by all .c files in Mbed TLS that
* use PSA Crypto function names. This avoids duplication of symbols
* between TF-M and Mbed TLS.
*
* \note This file should be included before including any PSA Crypto headers
* from Mbed TLS.
*/

#ifndef CRYPTO_SPE_H
#define CRYPTO_SPE_H

#define PSA_FUNCTION_NAME(x) mbedcrypto__ ## x

#define psa_crypto_init \
PSA_FUNCTION_NAME(psa_crypto_init)
#define psa_key_derivation_get_capacity \
PSA_FUNCTION_NAME(psa_key_derivation_get_capacity)
#define psa_key_derivation_set_capacity \
PSA_FUNCTION_NAME(psa_key_derivation_set_capacity)
#define psa_key_derivation_input_bytes \
PSA_FUNCTION_NAME(psa_key_derivation_input_bytes)
#define psa_key_derivation_output_bytes \
PSA_FUNCTION_NAME(psa_key_derivation_output_bytes)
#define psa_key_derivation_input_key \
PSA_FUNCTION_NAME(psa_key_derivation_input_key)
#define psa_key_derivation_output_key \
PSA_FUNCTION_NAME(psa_key_derivation_output_key)
#define psa_key_derivation_setup \
PSA_FUNCTION_NAME(psa_key_derivation_setup)
#define psa_key_derivation_abort \
PSA_FUNCTION_NAME(psa_key_derivation_abort)
#define psa_key_derivation_key_agreement \
PSA_FUNCTION_NAME(psa_key_derivation_key_agreement)
#define psa_raw_key_agreement \
PSA_FUNCTION_NAME(psa_raw_key_agreement)
#define psa_generate_random \
PSA_FUNCTION_NAME(psa_generate_random)
#define psa_aead_encrypt \
PSA_FUNCTION_NAME(psa_aead_encrypt)
#define psa_aead_decrypt \
PSA_FUNCTION_NAME(psa_aead_decrypt)
#define psa_open_key \
PSA_FUNCTION_NAME(psa_open_key)
#define psa_close_key \
PSA_FUNCTION_NAME(psa_close_key)
#define psa_import_key \
PSA_FUNCTION_NAME(psa_import_key)
#define psa_destroy_key \
PSA_FUNCTION_NAME(psa_destroy_key)
#define psa_get_key_attributes \
PSA_FUNCTION_NAME(psa_get_key_attributes)
#define psa_reset_key_attributes \
PSA_FUNCTION_NAME(psa_reset_key_attributes)
#define psa_export_key \
PSA_FUNCTION_NAME(psa_export_key)
#define psa_export_public_key \
PSA_FUNCTION_NAME(psa_export_public_key)
#define psa_purge_key \
PSA_FUNCTION_NAME(psa_purge_key)
#define psa_copy_key \
PSA_FUNCTION_NAME(psa_copy_key)
#define psa_cipher_operation_init \
PSA_FUNCTION_NAME(psa_cipher_operation_init)
#define psa_cipher_generate_iv \
PSA_FUNCTION_NAME(psa_cipher_generate_iv)
#define psa_cipher_set_iv \
PSA_FUNCTION_NAME(psa_cipher_set_iv)
#define psa_cipher_encrypt_setup \
PSA_FUNCTION_NAME(psa_cipher_encrypt_setup)
#define psa_cipher_decrypt_setup \
PSA_FUNCTION_NAME(psa_cipher_decrypt_setup)
#define psa_cipher_update \
PSA_FUNCTION_NAME(psa_cipher_update)
#define psa_cipher_finish \
PSA_FUNCTION_NAME(psa_cipher_finish)
#define psa_cipher_abort \
PSA_FUNCTION_NAME(psa_cipher_abort)
#define psa_hash_operation_init \
PSA_FUNCTION_NAME(psa_hash_operation_init)
#define psa_hash_setup \
PSA_FUNCTION_NAME(psa_hash_setup)
#define psa_hash_update \
PSA_FUNCTION_NAME(psa_hash_update)
#define psa_hash_finish \
PSA_FUNCTION_NAME(psa_hash_finish)
#define psa_hash_verify \
PSA_FUNCTION_NAME(psa_hash_verify)
#define psa_hash_abort \
PSA_FUNCTION_NAME(psa_hash_abort)
#define psa_hash_clone \
PSA_FUNCTION_NAME(psa_hash_clone)
#define psa_hash_compute \
PSA_FUNCTION_NAME(psa_hash_compute)
#define psa_hash_compare \
PSA_FUNCTION_NAME(psa_hash_compare)
#define psa_mac_operation_init \
PSA_FUNCTION_NAME(psa_mac_operation_init)
#define psa_mac_sign_setup \
PSA_FUNCTION_NAME(psa_mac_sign_setup)
#define psa_mac_verify_setup \
PSA_FUNCTION_NAME(psa_mac_verify_setup)
#define psa_mac_update \
PSA_FUNCTION_NAME(psa_mac_update)
#define psa_mac_sign_finish \
PSA_FUNCTION_NAME(psa_mac_sign_finish)
#define psa_mac_verify_finish \
PSA_FUNCTION_NAME(psa_mac_verify_finish)
#define psa_mac_abort \
PSA_FUNCTION_NAME(psa_mac_abort)
#define psa_sign_hash \
PSA_FUNCTION_NAME(psa_sign_hash)
#define psa_verify_hash \
PSA_FUNCTION_NAME(psa_verify_hash)
#define psa_asymmetric_encrypt \
PSA_FUNCTION_NAME(psa_asymmetric_encrypt)
#define psa_asymmetric_decrypt \
PSA_FUNCTION_NAME(psa_asymmetric_decrypt)
#define psa_generate_key \
PSA_FUNCTION_NAME(psa_generate_key)

#endif /* CRYPTO_SPE_H */
26 changes: 26 additions & 0 deletions tests/include/test/arguments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* \file arguments.h
*
* \brief Manipulation of test arguments.
*
* Much of the code is in host_test.function, to be migrated here later.
*/

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef TEST_ARGUMENTS_H
#define TEST_ARGUMENTS_H

#include "mbedtls/build_info.h"
#include <stdint.h>
#include <stdlib.h>

typedef union {
size_t len;
intmax_t sint;
} mbedtls_test_argument_t;

#endif /* TEST_ARGUMENTS_H */
38 changes: 38 additions & 0 deletions tests/include/test/asn1_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** Helper functions for tests that manipulate ASN.1 data.
*/
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef ASN1_HELPERS_H
#define ASN1_HELPERS_H

#include "test/helpers.h"

/** Skip past an INTEGER in an ASN.1 buffer.
*
* Mark the current test case as failed in any of the following conditions:
* - The buffer does not start with an ASN.1 INTEGER.
* - The integer's size or parity does not match the constraints expressed
* through \p min_bits, \p max_bits and \p must_be_odd.
*
* \param p Upon entry, `*p` points to the first byte of the
* buffer to parse.
* On successful return, `*p` points to the first byte
* after the parsed INTEGER.
* On failure, `*p` is unspecified.
* \param end The end of the ASN.1 buffer.
* \param min_bits Fail the test case if the integer does not have at
* least this many significant bits.
* \param max_bits Fail the test case if the integer has more than
* this many significant bits.
* \param must_be_odd Fail the test case if the integer is even.
*
* \return \c 0 if the test failed, otherwise 1.
*/
int mbedtls_test_asn1_skip_integer(unsigned char **p, const unsigned char *end,
size_t min_bits, size_t max_bits,
int must_be_odd);

#endif /* ASN1_HELPERS_H */
98 changes: 98 additions & 0 deletions tests/include/test/bignum_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* \file bignum_helpers.h
*
* \brief This file contains the prototypes of helper functions for
* bignum-related testing.
*/

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef TEST_BIGNUM_HELPERS_H
#define TEST_BIGNUM_HELPERS_H

#include <mbedtls/build_info.h>

#if defined(MBEDTLS_BIGNUM_C)

#include <mbedtls/bignum.h>
#include <bignum_mod.h>

/** Allocate and populate a core MPI from a test case argument.
*
* This function allocates exactly as many limbs as necessary to fit
* the length of the input. In other words, it preserves leading zeros.
*
* The limb array is allocated with mbedtls_calloc() and must later be
* freed with mbedtls_free().
*
* \param[in,out] pX The address where a pointer to the allocated limb
* array will be stored.
* \c *pX must be null on entry.
* On exit, \c *pX is null on error or if the number
* of limbs is 0.
* \param[out] plimbs The address where the number of limbs will be stored.
* \param[in] input The test argument to read.
* It is interpreted as a hexadecimal representation
* of a non-negative integer.
*
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
*/
int mbedtls_test_read_mpi_core(mbedtls_mpi_uint **pX, size_t *plimbs,
const char *input);

/** Read a modulus from a hexadecimal string.
*
* This function allocates exactly as many limbs as necessary to fit
* the length of the input. In other words, it preserves leading zeros.
*
* The limb array is allocated with mbedtls_calloc() and must later be
* freed with mbedtls_free(). You can do that by calling
* mbedtls_test_mpi_mod_modulus_free_with_limbs().
*
* \param[in,out] N A modulus structure. It must be initialized, but
* not set up.
* \param[in] s The null-terminated hexadecimal string to read from.
* \param int_rep The desired representation of residues.
*
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
*/
int mbedtls_test_read_mpi_modulus(mbedtls_mpi_mod_modulus *N,
const char *s,
mbedtls_mpi_mod_rep_selector int_rep);

/** Free a modulus and its limbs.
*
* \param[in] N A modulus structure such that there is no other
* reference to `N->p`.
*/
void mbedtls_test_mpi_mod_modulus_free_with_limbs(mbedtls_mpi_mod_modulus *N);

/** Read an MPI from a hexadecimal string.
*
* Like mbedtls_mpi_read_string(), but with tighter guarantees around
* edge cases.
*
* - This function guarantees that if \p s begins with '-' then the sign
* bit of the result will be negative, even if the value is 0.
* When this function encounters such a "negative 0", it calls
* mbedtls_test_increment_case_uses_negative_0().
* - The size of the result is exactly the minimum number of limbs needed to fit
* the digits in the input. In particular, this function constructs a bignum
* with 0 limbs for an empty string, and a bignum with leading 0 limbs if the
* string has sufficiently many leading 0 digits. This is important so that
* the "0 (null)" and "0 (1 limb)" and "leading zeros" test cases do what they
* claim.
*
* \param[out] X The MPI object to populate. It must be initialized.
* \param[in] s The null-terminated hexadecimal string to read from.
*
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
*/
int mbedtls_test_read_mpi(mbedtls_mpi *X, const char *s);

#endif /* MBEDTLS_BIGNUM_C */

#endif /* TEST_BIGNUM_HELPERS_H */
Loading