blob: b0c2988ca03be89f857912fc9af548e4fe2da5e4 [file] [log] [blame]
Gilles Peskinefe0acc62021-09-20 19:20:04 +02001/* MBEDTLS_USER_CONFIG_FILE for testing.
2 * Only used for a few test configurations.
3 *
4 * Typical usage (note multiple levels of quoting):
5 * make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
6 */
7
8/*
9 * Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000010 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskinefe0acc62021-09-20 19:20:04 +020011 */
12
13#if defined(PSA_CRYPTO_DRIVER_TEST_ALL)
Gilles Peskine8d77ec22023-07-26 18:45:20 +020014/* PSA_CRYPTO_DRIVER_TEST_ALL activates test drivers while keeping the
15 * built-in implementations active. Normally setting MBEDTLS_PSA_ACCEL_xxx
16 * would disable MBEDTLS_PSA_BUILTIN_xxx unless fallback is activated, but
17 * here we arrange to have both active so that psa_crypto_*.c includes
18 * the built-in implementations and the driver code can call the built-in
19 * implementations.
20 *
21 * The point of this test mode is to verify that the
22 * driver entry points are called when they should be in a lightweight
23 * way, without requiring an actual driver. This is different from builds
24 * with libtestdriver1, where we make a copy of the library source code
25 * and use that as an external driver.
26 */
Gilles Peskinefe0acc62021-09-20 19:20:04 +020027
28/* Enable the use of the test driver in the library, and build the generic
29 * part of the test driver. */
30#define PSA_CRYPTO_DRIVER_TEST
31
Gilles Peskine8d77ec22023-07-26 18:45:20 +020032/* With MBEDTLS_PSA_CRYPTO_CONFIG, if we set up the acceleration, the
33 * built-in implementations won't be enabled. */
34#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
35#error \
36 "PSA_CRYPTO_DRIVER_TEST_ALL sets up a nonstandard configuration that is incompatible with MBEDTLS_PSA_CRYPTO_CONFIG"
37#endif
38
Gilles Peskinefe0acc62021-09-20 19:20:04 +020039/* Use the accelerator driver for all cryptographic mechanisms for which
40 * the test driver implemented. */
41#define MBEDTLS_PSA_ACCEL_KEY_TYPE_AES
42#define MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA
43#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR
44#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR
45#define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING
46#define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7
47#define MBEDTLS_PSA_ACCEL_ALG_CTR
48#define MBEDTLS_PSA_ACCEL_ALG_CFB
49#define MBEDTLS_PSA_ACCEL_ALG_ECDSA
50#define MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA
51#define MBEDTLS_PSA_ACCEL_ALG_MD2
52#define MBEDTLS_PSA_ACCEL_ALG_MD4
53#define MBEDTLS_PSA_ACCEL_ALG_MD5
54#define MBEDTLS_PSA_ACCEL_ALG_OFB
55#define MBEDTLS_PSA_ACCEL_ALG_RIPEMD160
56#define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN
57#define MBEDTLS_PSA_ACCEL_ALG_RSA_PSS
58#define MBEDTLS_PSA_ACCEL_ALG_SHA_1
59#define MBEDTLS_PSA_ACCEL_ALG_SHA_224
60#define MBEDTLS_PSA_ACCEL_ALG_SHA_256
61#define MBEDTLS_PSA_ACCEL_ALG_SHA_384
62#define MBEDTLS_PSA_ACCEL_ALG_SHA_512
63#define MBEDTLS_PSA_ACCEL_ALG_XTS
64#define MBEDTLS_PSA_ACCEL_ALG_CMAC
65#define MBEDTLS_PSA_ACCEL_ALG_HMAC
66
67#endif /* PSA_CRYPTO_DRIVER_TEST_ALL */
Gilles Peskine73521b02023-04-28 21:01:49 +020068
69
70
71#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
72/* The #MBEDTLS_PSA_INJECT_ENTROPY feature requires two extra platform
73 * functions, which must be configured as #MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
74 * and #MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO. The job of these functions
75 * is to read and write from the entropy seed file, which is located
76 * in the PSA ITS file whose uid is #PSA_CRYPTO_ITS_RANDOM_SEED_UID.
77 * (These could have been provided as library functions, but for historical
78 * reasons, they weren't, and so each integrator has to provide a copy
79 * of these functions.)
80 *
81 * Provide implementations of these functions for testing. */
82#include <stddef.h>
83int mbedtls_test_inject_entropy_seed_read(unsigned char *buf, size_t len);
84int mbedtls_test_inject_entropy_seed_write(unsigned char *buf, size_t len);
85#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_test_inject_entropy_seed_read
86#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_test_inject_entropy_seed_write
87#endif /* MBEDTLS_PSA_INJECT_ENTROPY */