Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto_platform.h |
| 3 | * |
Jaeden Amero | 95d8438 | 2019-05-30 13:14:00 +0100 | [diff] [blame] | 4 | * \brief PSA cryptography module: Mbed TLS platform definitions |
Gilles Peskine | 07c91f5 | 2018-06-28 18:02:53 +0200 | [diff] [blame] | 5 | * |
| 6 | * \note This file may not be included directly. Applications must |
| 7 | * include psa/crypto.h. |
| 8 | * |
| 9 | * This file contains platform-dependent type definitions. |
| 10 | * |
| 11 | * In implementations with isolation between the application and the |
| 12 | * cryptography module, implementers should take care to ensure that |
| 13 | * the definitions that are exposed to applications match what the |
| 14 | * module implements. |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 15 | */ |
| 16 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 17 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 18 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #ifndef PSA_CRYPTO_PLATFORM_H |
| 22 | #define PSA_CRYPTO_PLATFORM_H |
Mateusz Starzyk | 2abe51c | 2021-06-07 11:08:01 +0200 | [diff] [blame] | 23 | #include "mbedtls/private_access.h" |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 24 | |
Ronald Cron | f6236f0 | 2023-01-26 16:22:25 +0100 | [diff] [blame] | 25 | /* |
Ronald Cron | 7871cb1 | 2023-10-10 08:51:39 +0200 | [diff] [blame] | 26 | * Include the build-time configuration information header. Here, we do not |
Ronald Cron | f6236f0 | 2023-01-26 16:22:25 +0100 | [diff] [blame] | 27 | * include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which |
| 28 | * is basically just an alias to it. This is to ease the maintenance of the |
Ronald Cron | 070e865 | 2023-10-09 10:25:45 +0200 | [diff] [blame] | 29 | * TF-PSA-Crypto repository which has a different build system and |
Ronald Cron | f6236f0 | 2023-01-26 16:22:25 +0100 | [diff] [blame] | 30 | * configuration. |
| 31 | */ |
| 32 | #include "psa/build_info.h" |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 33 | |
| 34 | /* PSA requires several types which C99 provides in stdint.h. */ |
| 35 | #include <stdint.h> |
| 36 | |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 37 | #if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) |
Gilles Peskine | 69d7c8b | 2019-02-19 14:00:31 +0100 | [diff] [blame] | 38 | |
Ronald Cron | 9a2511e | 2020-09-14 10:02:56 +0200 | [diff] [blame] | 39 | /* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA |
| 40 | * partition identifier. |
| 41 | * |
| 42 | * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that |
| 43 | * translates a key identifier to a key storage file name assumes that |
Tom Cosgrove | ce7f18c | 2022-07-28 05:50:56 +0100 | [diff] [blame] | 44 | * mbedtls_key_owner_id_t is a 32-bit integer. This function thus needs |
| 45 | * reworking if mbedtls_key_owner_id_t is not defined as a 32-bit integer |
Ronald Cron | 9a2511e | 2020-09-14 10:02:56 +0200 | [diff] [blame] | 46 | * here anymore. |
| 47 | */ |
Ronald Cron | 72f65fc | 2020-09-01 15:50:17 +0200 | [diff] [blame] | 48 | typedef int32_t mbedtls_key_owner_id_t; |
Ronald Cron | ecfb237 | 2020-07-23 17:13:42 +0200 | [diff] [blame] | 49 | |
| 50 | /** Compare two key owner identifiers. |
| 51 | * |
| 52 | * \param id1 First key owner identifier. |
| 53 | * \param id2 Second key owner identifier. |
| 54 | * |
| 55 | * \return Non-zero if the two key owner identifiers are equal, zero otherwise. |
| 56 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 57 | static inline int mbedtls_key_owner_id_equal(mbedtls_key_owner_id_t id1, |
| 58 | mbedtls_key_owner_id_t id2) |
Ronald Cron | ecfb237 | 2020-07-23 17:13:42 +0200 | [diff] [blame] | 59 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 60 | return id1 == id2; |
Ronald Cron | ecfb237 | 2020-07-23 17:13:42 +0200 | [diff] [blame] | 61 | } |
Gilles Peskine | 572f067 | 2019-02-19 14:16:17 +0100 | [diff] [blame] | 62 | |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 63 | #endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */ |
Gilles Peskine | 69d7c8b | 2019-02-19 14:00:31 +0100 | [diff] [blame] | 64 | |
Gilles Peskine | e96c585 | 2021-06-15 18:36:05 +0200 | [diff] [blame] | 65 | /* |
| 66 | * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM |
| 67 | * (Secure Partition Manager) integration which separates the code into two |
| 68 | * parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing |
| 69 | * Environment). When building for the SPE, an additional header file should be |
| 70 | * included. |
| 71 | */ |
| 72 | #if defined(MBEDTLS_PSA_CRYPTO_SPM) |
| 73 | #define PSA_CRYPTO_SECURE 1 |
Gilles Peskine | 3529285 | 2023-09-27 15:41:56 +0200 | [diff] [blame] | 74 | #include "crypto_spe.h" |
Gilles Peskine | e96c585 | 2021-06-15 18:36:05 +0200 | [diff] [blame] | 75 | #endif // MBEDTLS_PSA_CRYPTO_SPM |
| 76 | |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 77 | #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
Gilles Peskine | 88fa5c4 | 2021-01-04 21:00:53 +0100 | [diff] [blame] | 78 | /** The type of the context passed to mbedtls_psa_external_get_random(). |
Gilles Peskine | c096301 | 2020-11-18 15:33:33 +0100 | [diff] [blame] | 79 | * |
| 80 | * Mbed TLS initializes the context to all-bits-zero before calling |
| 81 | * mbedtls_psa_external_get_random() for the first time. |
| 82 | * |
| 83 | * The definition of this type in the Mbed TLS source code is for |
| 84 | * demonstration purposes. Implementers of mbedtls_psa_external_get_random() |
| 85 | * are expected to replace it with a custom definition. |
| 86 | */ |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 87 | typedef struct { |
Mateusz Starzyk | 2abe51c | 2021-06-07 11:08:01 +0200 | [diff] [blame] | 88 | uintptr_t MBEDTLS_PRIVATE(opaque)[2]; |
Gilles Peskine | b8af228 | 2020-11-13 18:00:34 +0100 | [diff] [blame] | 89 | } mbedtls_psa_external_random_context_t; |
| 90 | #endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */ |
| 91 | |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 92 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 93 | /** The type of the client handle used in context structures |
| 94 | * |
| 95 | * When a client view of the multipart context structures is required, |
| 96 | * this handle is used to keep a mapping with the service side of the |
| 97 | * context which contains the actual data. |
| 98 | */ |
| 99 | typedef uint32_t mbedtls_psa_client_handle_t; |
| 100 | #endif |
| 101 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 102 | #endif /* PSA_CRYPTO_PLATFORM_H */ |