blob: 479a153067bd8aa67ddebaa1dde5173ee502fcbe [file] [log] [blame]
Gilles Peskine3587dfd2021-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 Rodgman16799db2023-11-02 19:47:20 +000010 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine3587dfd2021-09-20 19:20:04 +020011 */
12
13#if defined(PSA_CRYPTO_DRIVER_TEST_ALL)
Gilles Peskine1997f302023-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 Peskine3587dfd2021-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 Peskine1997f302023-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 Peskine3587dfd2021-09-20 19:20:04 +020039/* Use the accelerator driver for all cryptographic mechanisms for which
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010040 * the test driver is implemented. This is copied from psa/crypto_config.h
41 * with the parts not implmented by the test driver commented out. */
42#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DERIVE
43#define MBEDTLS_PSA_ACCEL_KEY_TYPE_PASSWORD
44#define MBEDTLS_PSA_ACCEL_KEY_TYPE_PASSWORD_HASH
45#define MBEDTLS_PSA_ACCEL_KEY_TYPE_HMAC
Gilles Peskine3587dfd2021-09-20 19:20:04 +020046#define MBEDTLS_PSA_ACCEL_KEY_TYPE_AES
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010047#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ARIA
Gilles Peskine3587dfd2021-09-20 19:20:04 +020048#define MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010049#define MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20
50#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DES
Manuel Pégourié-Gonnard680b48e2023-09-28 12:49:23 +020051#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY
52#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC
53#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT
54#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT
55#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_GENERATE
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010056//#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_DERIVE
57#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_PUBLIC_KEY
58#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_BASIC
59#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_IMPORT
60#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_EXPORT
61#define MBEDTLS_PSA_ACCEL_KEY_TYPE_DH_KEY_PAIR_GENERATE
62#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RAW_DATA
63#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_BASIC
64#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_IMPORT
65#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_EXPORT
66#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_GENERATE
67#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY
68
Gilles Peskine3587dfd2021-09-20 19:20:04 +020069#define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING
70#define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010071#define MBEDTLS_PSA_ACCEL_ALG_CCM
72#define MBEDTLS_PSA_ACCEL_ALG_CCM_STAR_NO_TAG
73#define MBEDTLS_PSA_ACCEL_ALG_CMAC
Gilles Peskine3587dfd2021-09-20 19:20:04 +020074#define MBEDTLS_PSA_ACCEL_ALG_CFB
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010075#define MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305
76#define MBEDTLS_PSA_ACCEL_ALG_CTR
Gilles Peskine3587dfd2021-09-20 19:20:04 +020077#define MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010078#define MBEDTLS_PSA_ACCEL_ALG_ECB_NO_PADDING
79#define MBEDTLS_PSA_ACCEL_ALG_ECDH
80#define MBEDTLS_PSA_ACCEL_ALG_FFDH
81#define MBEDTLS_PSA_ACCEL_ALG_ECDSA
82#define MBEDTLS_PSA_ACCEL_ALG_JPAKE
83#define MBEDTLS_PSA_ACCEL_ALG_GCM
84//#define MBEDTLS_PSA_ACCEL_ALG_HKDF
85//#define MBEDTLS_PSA_ACCEL_ALG_HKDF_EXTRACT
86//#define MBEDTLS_PSA_ACCEL_ALG_HKDF_EXPAND
87#define MBEDTLS_PSA_ACCEL_ALG_HMAC
Gilles Peskine3587dfd2021-09-20 19:20:04 +020088#define MBEDTLS_PSA_ACCEL_ALG_MD5
89#define MBEDTLS_PSA_ACCEL_ALG_OFB
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010090//#define MBEDTLS_PSA_ACCEL_ALG_PBKDF2_HMAC
91//#define MBEDTLS_PSA_ACCEL_ALG_PBKDF2_AES_CMAC_PRF_128
Gilles Peskine3587dfd2021-09-20 19:20:04 +020092#define MBEDTLS_PSA_ACCEL_ALG_RIPEMD160
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +010093#define MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP
94#define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT
Gilles Peskine3587dfd2021-09-20 19:20:04 +020095#define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN
96#define MBEDTLS_PSA_ACCEL_ALG_RSA_PSS
97#define MBEDTLS_PSA_ACCEL_ALG_SHA_1
98#define MBEDTLS_PSA_ACCEL_ALG_SHA_224
99#define MBEDTLS_PSA_ACCEL_ALG_SHA_256
100#define MBEDTLS_PSA_ACCEL_ALG_SHA_384
101#define MBEDTLS_PSA_ACCEL_ALG_SHA_512
Manuel Pégourié-Gonnard3dbd2362023-11-15 12:32:49 +0100102#define MBEDTLS_PSA_ACCEL_ALG_SHA3_224
103#define MBEDTLS_PSA_ACCEL_ALG_SHA3_256
104#define MBEDTLS_PSA_ACCEL_ALG_SHA3_384
105#define MBEDTLS_PSA_ACCEL_ALG_SHA3_512
106#define MBEDTLS_PSA_ACCEL_ALG_STREAM_CIPHER
107//#define MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF
108//#define MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS
109//#define MBEDTLS_PSA_ACCEL_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskine3587dfd2021-09-20 19:20:04 +0200110
111#endif /* PSA_CRYPTO_DRIVER_TEST_ALL */
Gilles Peskinea08def92023-04-28 21:01:49 +0200112
113
114
115#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
116/* The #MBEDTLS_PSA_INJECT_ENTROPY feature requires two extra platform
117 * functions, which must be configured as #MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
118 * and #MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO. The job of these functions
119 * is to read and write from the entropy seed file, which is located
120 * in the PSA ITS file whose uid is #PSA_CRYPTO_ITS_RANDOM_SEED_UID.
121 * (These could have been provided as library functions, but for historical
122 * reasons, they weren't, and so each integrator has to provide a copy
123 * of these functions.)
124 *
125 * Provide implementations of these functions for testing. */
126#include <stddef.h>
127int mbedtls_test_inject_entropy_seed_read(unsigned char *buf, size_t len);
128int mbedtls_test_inject_entropy_seed_write(unsigned char *buf, size_t len);
129#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_test_inject_entropy_seed_read
130#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_test_inject_entropy_seed_write
131#endif /* MBEDTLS_PSA_INJECT_ENTROPY */