Gilles Peskine | 3587dfd | 2021-09-20 19:20:04 +0200 | [diff] [blame] | 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 |
| 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 Peskine | 1997f30 | 2023-07-26 18:45:20 +0200 | [diff] [blame] | 26 | /* 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 Peskine | 3587dfd | 2021-09-20 19:20:04 +0200 | [diff] [blame] | 39 | |
| 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 Peskine | 1997f30 | 2023-07-26 18:45:20 +0200 | [diff] [blame] | 44 | /* 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 Peskine | 3587dfd | 2021-09-20 19:20:04 +0200 | [diff] [blame] | 51 | /* 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 |
| 55 | #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR |
| 56 | #define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR |
| 57 | #define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING |
| 58 | #define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7 |
| 59 | #define MBEDTLS_PSA_ACCEL_ALG_CTR |
| 60 | #define MBEDTLS_PSA_ACCEL_ALG_CFB |
| 61 | #define MBEDTLS_PSA_ACCEL_ALG_ECDSA |
| 62 | #define MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA |
| 63 | #define MBEDTLS_PSA_ACCEL_ALG_MD5 |
| 64 | #define MBEDTLS_PSA_ACCEL_ALG_OFB |
| 65 | #define MBEDTLS_PSA_ACCEL_ALG_RIPEMD160 |
| 66 | #define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN |
| 67 | #define MBEDTLS_PSA_ACCEL_ALG_RSA_PSS |
| 68 | #define MBEDTLS_PSA_ACCEL_ALG_SHA_1 |
| 69 | #define MBEDTLS_PSA_ACCEL_ALG_SHA_224 |
| 70 | #define MBEDTLS_PSA_ACCEL_ALG_SHA_256 |
| 71 | #define MBEDTLS_PSA_ACCEL_ALG_SHA_384 |
| 72 | #define MBEDTLS_PSA_ACCEL_ALG_SHA_512 |
| 73 | #define MBEDTLS_PSA_ACCEL_ALG_XTS |
| 74 | #define MBEDTLS_PSA_ACCEL_ALG_CMAC |
| 75 | #define MBEDTLS_PSA_ACCEL_ALG_HMAC |
| 76 | |
| 77 | #endif /* PSA_CRYPTO_DRIVER_TEST_ALL */ |
Gilles Peskine | a08def9 | 2023-04-28 21:01:49 +0200 | [diff] [blame] | 78 | |
| 79 | |
| 80 | |
| 81 | #if defined(MBEDTLS_PSA_INJECT_ENTROPY) |
| 82 | /* The #MBEDTLS_PSA_INJECT_ENTROPY feature requires two extra platform |
| 83 | * functions, which must be configured as #MBEDTLS_PLATFORM_NV_SEED_READ_MACRO |
| 84 | * and #MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO. The job of these functions |
| 85 | * is to read and write from the entropy seed file, which is located |
| 86 | * in the PSA ITS file whose uid is #PSA_CRYPTO_ITS_RANDOM_SEED_UID. |
| 87 | * (These could have been provided as library functions, but for historical |
| 88 | * reasons, they weren't, and so each integrator has to provide a copy |
| 89 | * of these functions.) |
| 90 | * |
| 91 | * Provide implementations of these functions for testing. */ |
| 92 | #include <stddef.h> |
| 93 | int mbedtls_test_inject_entropy_seed_read(unsigned char *buf, size_t len); |
| 94 | int mbedtls_test_inject_entropy_seed_write(unsigned char *buf, size_t len); |
| 95 | #define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_test_inject_entropy_seed_read |
| 96 | #define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_test_inject_entropy_seed_write |
| 97 | #endif /* MBEDTLS_PSA_INJECT_ENTROPY */ |