xref: /aosp_15_r20/external/mbedtls/tests/configs/user-config-for-test.h (revision 62c56f9862f102b96d72393aff6076c951fb8148)
1 /* 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 OR GPL-2.0-or-later
11  */
12 
13 #if defined(PSA_CRYPTO_DRIVER_TEST_ALL)
14 /* 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  */
27 
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 
32 /* 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 
39 /* 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_PUBLIC_KEY
44 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC
45 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT
46 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT
47 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_GENERATE
48 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR
49 #define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING
50 #define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7
51 #define MBEDTLS_PSA_ACCEL_ALG_CTR
52 #define MBEDTLS_PSA_ACCEL_ALG_CFB
53 #define MBEDTLS_PSA_ACCEL_ALG_ECDSA
54 #define MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA
55 #define MBEDTLS_PSA_ACCEL_ALG_MD5
56 #define MBEDTLS_PSA_ACCEL_ALG_OFB
57 #define MBEDTLS_PSA_ACCEL_ALG_RIPEMD160
58 #define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN
59 #define MBEDTLS_PSA_ACCEL_ALG_RSA_PSS
60 #define MBEDTLS_PSA_ACCEL_ALG_SHA_1
61 #define MBEDTLS_PSA_ACCEL_ALG_SHA_224
62 #define MBEDTLS_PSA_ACCEL_ALG_SHA_256
63 #define MBEDTLS_PSA_ACCEL_ALG_SHA_384
64 #define MBEDTLS_PSA_ACCEL_ALG_SHA_512
65 #define MBEDTLS_PSA_ACCEL_ALG_XTS
66 #define MBEDTLS_PSA_ACCEL_ALG_CMAC
67 #define MBEDTLS_PSA_ACCEL_ALG_HMAC
68 
69 #endif  /* PSA_CRYPTO_DRIVER_TEST_ALL */
70 
71 
72 
73 #if defined(MBEDTLS_PSA_INJECT_ENTROPY)
74 /* The #MBEDTLS_PSA_INJECT_ENTROPY feature requires two extra platform
75  * functions, which must be configured as #MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
76  * and #MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO. The job of these functions
77  * is to read and write from the entropy seed file, which is located
78  * in the PSA ITS file whose uid is #PSA_CRYPTO_ITS_RANDOM_SEED_UID.
79  * (These could have been provided as library functions, but for historical
80  * reasons, they weren't, and so each integrator has to provide a copy
81  * of these functions.)
82  *
83  * Provide implementations of these functions for testing. */
84 #include <stddef.h>
85 int mbedtls_test_inject_entropy_seed_read(unsigned char *buf, size_t len);
86 int mbedtls_test_inject_entropy_seed_write(unsigned char *buf, size_t len);
87 #define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_test_inject_entropy_seed_read
88 #define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_test_inject_entropy_seed_write
89 #endif /* MBEDTLS_PSA_INJECT_ENTROPY */
90