blob: a9386a2369c4466935374faba96972eedfc61e59 [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
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License"); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 */
24
25#if defined(PSA_CRYPTO_DRIVER_TEST_ALL)
Gilles Peskine1997f302023-07-26 18:45:20 +020026/* PSA_CRYPTO_DRIVER_TEST_ALL activates test drivers while keeping the
27 * built-in implementations active. Normally setting MBEDTLS_PSA_ACCEL_xxx
28 * would disable MBEDTLS_PSA_BUILTIN_xxx unless fallback is activated, but
29 * here we arrange to have both active so that psa_crypto_*.c includes
30 * the built-in implementations and the driver code can call the built-in
31 * implementations.
32 *
33 * The point of this test mode is to verify that the
34 * driver entry points are called when they should be in a lightweight
35 * way, without requiring an actual driver. This is different from builds
36 * with libtestdriver1, where we make a copy of the library source code
37 * and use that as an external driver.
38 */
Gilles Peskine3587dfd2021-09-20 19:20:04 +020039
40/* Enable the use of the test driver in the library, and build the generic
41 * part of the test driver. */
42#define PSA_CRYPTO_DRIVER_TEST
43
Gilles Peskine1997f302023-07-26 18:45:20 +020044/* With MBEDTLS_PSA_CRYPTO_CONFIG, if we set up the acceleration, the
45 * built-in implementations won't be enabled. */
46#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
47#error \
48 "PSA_CRYPTO_DRIVER_TEST_ALL sets up a nonstandard configuration that is incompatible with MBEDTLS_PSA_CRYPTO_CONFIG"
49#endif
50
Gilles Peskine3587dfd2021-09-20 19:20:04 +020051/* Use the accelerator driver for all cryptographic mechanisms for which
52 * the test driver implemented. */
53#define MBEDTLS_PSA_ACCEL_KEY_TYPE_AES
54#define MBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA
Manuel Pégourié-Gonnard680b48e2023-09-28 12:49:23 +020055#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY
56#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC
57#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT
58#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT
59#define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_GENERATE
Gilles Peskine3587dfd2021-09-20 19:20:04 +020060#define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR
61#define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING
62#define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7
63#define MBEDTLS_PSA_ACCEL_ALG_CTR
64#define MBEDTLS_PSA_ACCEL_ALG_CFB
65#define MBEDTLS_PSA_ACCEL_ALG_ECDSA
66#define MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA
67#define MBEDTLS_PSA_ACCEL_ALG_MD5
68#define MBEDTLS_PSA_ACCEL_ALG_OFB
69#define MBEDTLS_PSA_ACCEL_ALG_RIPEMD160
70#define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN
71#define MBEDTLS_PSA_ACCEL_ALG_RSA_PSS
72#define MBEDTLS_PSA_ACCEL_ALG_SHA_1
73#define MBEDTLS_PSA_ACCEL_ALG_SHA_224
74#define MBEDTLS_PSA_ACCEL_ALG_SHA_256
75#define MBEDTLS_PSA_ACCEL_ALG_SHA_384
76#define MBEDTLS_PSA_ACCEL_ALG_SHA_512
77#define MBEDTLS_PSA_ACCEL_ALG_XTS
78#define MBEDTLS_PSA_ACCEL_ALG_CMAC
79#define MBEDTLS_PSA_ACCEL_ALG_HMAC
80
81#endif /* PSA_CRYPTO_DRIVER_TEST_ALL */
Gilles Peskinea08def92023-04-28 21:01:49 +020082
83
84
85#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
86/* The #MBEDTLS_PSA_INJECT_ENTROPY feature requires two extra platform
87 * functions, which must be configured as #MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
88 * and #MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO. The job of these functions
89 * is to read and write from the entropy seed file, which is located
90 * in the PSA ITS file whose uid is #PSA_CRYPTO_ITS_RANDOM_SEED_UID.
91 * (These could have been provided as library functions, but for historical
92 * reasons, they weren't, and so each integrator has to provide a copy
93 * of these functions.)
94 *
95 * Provide implementations of these functions for testing. */
96#include <stddef.h>
97int mbedtls_test_inject_entropy_seed_read(unsigned char *buf, size_t len);
98int mbedtls_test_inject_entropy_seed_write(unsigned char *buf, size_t len);
99#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_test_inject_entropy_seed_read
100#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_test_inject_entropy_seed_write
101#endif /* MBEDTLS_PSA_INJECT_ENTROPY */