|
| 1 | +/** |
| 2 | + * \file config_psa_ext.h |
| 3 | + * \brief PSA crypto configurations to Mbed TLS configurations extension |
| 4 | + * |
| 5 | + * Extension of the translation of the PSA crypto configurations to the Mbed |
| 6 | + * TLS ones handling the PSA-Crypto specific configuration options. |
| 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_KEY_ID_ENCODES_OWNER) |
| 26 | +#define MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
| 27 | +#endif |
| 28 | + |
| 29 | +#if defined(PSA_CRYPTO_SPM) |
| 30 | +#define MBEDTLS_PSA_CRYPTO_SPM |
| 31 | +#endif |
| 32 | + |
| 33 | +#if !defined(PSA_CRYPTO_STD_FUNCTIONS) |
| 34 | +#include <psa/platform.h> |
| 35 | +#define MBEDTLS_PLATFORM_C |
| 36 | +#define MBEDTLS_PLATFORM_MEMORY |
| 37 | +#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS |
| 38 | +#define MBEDTLS_PLATFORM_PRINTF_MACRO psa_crypto_printf |
| 39 | +#define MBEDTLS_PLATFORM_FPRINTF_MACRO psa_crypto_fprintf |
| 40 | +#define MBEDTLS_PLATFORM_SNPRINTF_MACRO psa_crypto_snprintf |
| 41 | +#define MBEDTLS_PLATFORM_SETBUF_MACRO psa_crypto_setbuf |
| 42 | +#if defined(PSA_CRYPTO_MEMORY_BUFFER_ALLOC) |
| 43 | +#define MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 44 | +#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 8 |
| 45 | +#else |
| 46 | +#define MBEDTLS_PLATFORM_CALLOC_MACRO psa_crypto_calloc |
| 47 | +#define MBEDTLS_PLATFORM_FREE_MACRO psa_crypto_free |
| 48 | +#endif |
| 49 | +#endif /* !PSA_CRYPTO_STD_FUNCTIONS */ |
| 50 | + |
| 51 | +#if defined(PSA_CRYPTO_FS_IO) |
| 52 | +#define MBEDTLS_FS_IO |
| 53 | +#endif |
| 54 | + |
| 55 | +#if defined(PSA_CRYPTO_PLATFORM_ZEROIZE) |
| 56 | +#define MBEDTLS_PLATFORM_ZEROIZE_ALT |
| 57 | +#define mbedtls_platform_zeroize psa_crypto_platform_zeroize |
| 58 | +#endif |
| 59 | + |
| 60 | +#if defined(PSA_CRYPTO_BUILTIN_KEYS) |
| 61 | +#define MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS |
| 62 | +#endif |
| 63 | + |
| 64 | +#if defined(PSA_CRYPTO_STORAGE_C) |
| 65 | +#define MBEDTLS_PSA_CRYPTO_STORAGE_C |
| 66 | +#endif |
| 67 | + |
| 68 | +#if defined(PSA_CRYPTO_ITS_FILE_C) |
| 69 | +#define MBEDTLS_PSA_ITS_FILE_C |
| 70 | +#endif |
| 71 | + |
| 72 | +#if defined(PSA_CRYPTO_EXTERNAL_RNG) |
| 73 | +#define MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG |
| 74 | +#else /* PSA_CRYPTO_EXTERNAL_RNG */ |
| 75 | +#define MBEDTLS_ENTROPY_C |
| 76 | + |
| 77 | +#if defined(PSA_CRYPTO_HMAC_DRBG_HASH) |
| 78 | +#define MBEDTLS_HMAC_DRBG_C |
| 79 | +#define MBEDTLS_MD_C |
| 80 | + |
| 81 | +/* |
| 82 | + * The macro PSA_CRYPTO_HMAC_DRBG_HASH defines the hash algorithm (SHA-256 or |
| 83 | + * SHA-512) to be used for HMAC for the PSA DRBG. It defines it using the PSA |
| 84 | + * macro identifying the hash algorithm. Those macros are not part of the |
| 85 | + * configuration macros thus they may not be defined at that point. As we need |
| 86 | + * to use the value of PSA_CRYPTO_HMAC_DRBG_HASH, which is equal to |
| 87 | + * PSA_ALG_SHA_256 or PSA_ALG_SHA_512 we need those macros to be defined. Their |
| 88 | + * specific values are not important here, they just have to be different. |
| 89 | + */ |
| 90 | +#if !defined(PSA_ALG_SHA_256) |
| 91 | +#define PSA_ALG_SHA_256 1 |
| 92 | +#define PSA_ALG_SHA_512 2 |
| 93 | +#define UNDEFINE_PSA_ALG_SHA_256_512 |
| 94 | +#endif |
| 95 | + |
| 96 | +#if (PSA_CRYPTO_HMAC_DRBG_HASH == PSA_ALG_SHA_256) |
| 97 | +#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA256 |
| 98 | +#if !defined(MBEDTLS_SHA256_C) |
| 99 | +#define MBEDTLS_SHA256_C |
| 100 | +#endif |
| 101 | +#endif /* PSA_CRYPTO_HMAC_DRBG_HASH == PSA_ALG_SHA_256 */ |
| 102 | + |
| 103 | +#if (PSA_CRYPTO_HMAC_DRBG_HASH == PSA_ALG_SHA_512) |
| 104 | +#if !defined(MBEDTLS_SHA512_C) |
| 105 | +#define MBEDTLS_SHA512_C |
| 106 | +#endif |
| 107 | +#define MBEDTLS_PSA_HMAC_DRBG_MD_TYPE MBEDTLS_MD_SHA512 |
| 108 | +#endif /* PSA_CRYPTO_HMAC_DRBG_HASH == PSA_ALG_SHA_512 */ |
| 109 | + |
| 110 | +/* Clean-up of the dummy values for PSA_ALG_SHA_256 and PSA_ALG_SHA_512 */ |
| 111 | +#if defined(UNDEFINE_PSA_ALG_SHA_256_512) |
| 112 | +#undef PSA_ALG_SHA_256 |
| 113 | +#undef PSA_ALG_SHA_512 |
| 114 | +#undef UNDEFINE_PSA_ALG_SHA_256_512 |
| 115 | +#endif |
| 116 | + |
| 117 | +#else /* PSA_CRYPTO_HMAC_DRBG_HASH */ |
| 118 | + |
| 119 | +#define MBEDTLS_CTR_DRBG_C |
| 120 | +#if !defined(MBEDTLS_AES_C) |
| 121 | +#define MBEDTLS_AES_C |
| 122 | +#endif |
| 123 | + |
| 124 | +#endif /* !PSA_CRYPTO_HMAC_DRBG_HASH */ |
| 125 | + |
| 126 | +#if !defined(PSA_CRYPTO_PLATFORM_ENTROPY) |
| 127 | +#define MBEDTLS_NO_PLATFORM_ENTROPY |
| 128 | +#endif |
| 129 | + |
| 130 | +#if defined(PSA_CRYPTO_HARDWARE_ENTROPY) |
| 131 | +#define MBEDTLS_ENTROPY_HARDWARE_ALT |
| 132 | +#define mbedtls_hardware_poll psa_crypto_hardware_entropy |
| 133 | +#endif |
| 134 | + |
| 135 | +#if defined(PSA_CRYPTO_ENTROPY_NV_SEED) |
| 136 | +#define MBEDTLS_PLATFORM_C |
| 137 | +#define MBEDTLS_ENTROPY_NV_SEED |
| 138 | +#if !defined(PSA_CRYPTO_STD_FUNCTIONS) || !defined(PSA_CRYPTO_FS_IO) |
| 139 | +#include <psa/platform.h> |
| 140 | +#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO psa_crypto_platform_entropy_nv_seed_read |
| 141 | +#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO psa_crypto_platform_entropy_nv_seed_write |
| 142 | +#endif |
| 143 | +#endif /* PSA_CRYPTO_ENTROPY_NV_SEED */ |
| 144 | + |
| 145 | +#endif /* !PSA_CRYPTO_EXTERNAL_RNG */ |
| 146 | + |
| 147 | +#if defined(PSA_CRYPTO_KEY_SLOT_COUNT) |
| 148 | +#define MBEDTLS_PSA_KEY_SLOT_COUNT PSA_CRYPTO_KEY_SLOT_COUNT |
| 149 | +#endif |
| 150 | + |
| 151 | +#if defined(PSA_CRYPTO_ENTROPY_NV_SEED_FILE) |
| 152 | +#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE PSA_CRYPTO_ENTROPY_NV_SEED_FILE |
| 153 | +#endif |
0 commit comments