blob: 10f109e4c1b766ff2fe2aa17b16ed49a6635d6a2 [file] [log] [blame]
Gilles Peskinee59236f2018-01-27 23:32:46 +01001/**
2 * \file psa/crypto_platform.h
3 *
Jaeden Amero95d84382019-05-30 13:14:00 +01004 * \brief PSA cryptography module: Mbed TLS platform definitions
Gilles Peskine07c91f52018-06-28 18:02:53 +02005 *
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 Peskinee59236f2018-01-27 23:32:46 +010015 */
16/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020017 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +000018 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskinee59236f2018-01-27 23:32:46 +010019 */
20
21#ifndef PSA_CRYPTO_PLATFORM_H
22#define PSA_CRYPTO_PLATFORM_H
Mateusz Starzyk2abe51c2021-06-07 11:08:01 +020023#include "mbedtls/private_access.h"
Ronald Cronf6d17ca2024-11-06 14:11:15 +010024#include "tf-psa-crypto/build_info.h"
Gilles Peskinee59236f2018-01-27 23:32:46 +010025
26/* PSA requires several types which C99 provides in stdint.h. */
27#include <stdint.h>
28
Ronald Cron71016a92020-08-28 19:01:50 +020029#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010030
Ronald Cron9a2511e2020-09-14 10:02:56 +020031/* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA
32 * partition identifier.
33 *
34 * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that
35 * translates a key identifier to a key storage file name assumes that
Tom Cosgrovece7f18c2022-07-28 05:50:56 +010036 * mbedtls_key_owner_id_t is a 32-bit integer. This function thus needs
37 * reworking if mbedtls_key_owner_id_t is not defined as a 32-bit integer
Ronald Cron9a2511e2020-09-14 10:02:56 +020038 * here anymore.
39 */
Ronald Cron72f65fc2020-09-01 15:50:17 +020040typedef int32_t mbedtls_key_owner_id_t;
Ronald Cronecfb2372020-07-23 17:13:42 +020041
42/** Compare two key owner identifiers.
43 *
44 * \param id1 First key owner identifier.
45 * \param id2 Second key owner identifier.
46 *
47 * \return Non-zero if the two key owner identifiers are equal, zero otherwise.
48 */
Gilles Peskine449bd832023-01-11 14:50:10 +010049static inline int mbedtls_key_owner_id_equal(mbedtls_key_owner_id_t id1,
50 mbedtls_key_owner_id_t id2)
Ronald Cronecfb2372020-07-23 17:13:42 +020051{
Gilles Peskine449bd832023-01-11 14:50:10 +010052 return id1 == id2;
Ronald Cronecfb2372020-07-23 17:13:42 +020053}
Gilles Peskine572f0672019-02-19 14:16:17 +010054
Ronald Cron71016a92020-08-28 19:01:50 +020055#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010056
Gilles Peskinee96c5852021-06-15 18:36:05 +020057/*
58 * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM
59 * (Secure Partition Manager) integration which separates the code into two
60 * parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing
61 * Environment). When building for the SPE, an additional header file should be
62 * included.
63 */
64#if defined(MBEDTLS_PSA_CRYPTO_SPM)
65#define PSA_CRYPTO_SECURE 1
Gilles Peskine35292852023-09-27 15:41:56 +020066#include "crypto_spe.h"
Gilles Peskinee96c5852021-06-15 18:36:05 +020067#endif // MBEDTLS_PSA_CRYPTO_SPM
68
Gilles Peskineb8af2282020-11-13 18:00:34 +010069#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
Gilles Peskine88fa5c42021-01-04 21:00:53 +010070/** The type of the context passed to mbedtls_psa_external_get_random().
Gilles Peskinec0963012020-11-18 15:33:33 +010071 *
72 * Mbed TLS initializes the context to all-bits-zero before calling
73 * mbedtls_psa_external_get_random() for the first time.
74 *
75 * The definition of this type in the Mbed TLS source code is for
76 * demonstration purposes. Implementers of mbedtls_psa_external_get_random()
77 * are expected to replace it with a custom definition.
78 */
Gilles Peskineb8af2282020-11-13 18:00:34 +010079typedef struct {
Mateusz Starzyk2abe51c2021-06-07 11:08:01 +020080 uintptr_t MBEDTLS_PRIVATE(opaque)[2];
Gilles Peskineb8af2282020-11-13 18:00:34 +010081} mbedtls_psa_external_random_context_t;
82#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
83
Antonio de Angelis6425a182024-01-22 11:39:34 +000084#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
85/** The type of the client handle used in context structures
86 *
87 * When a client view of the multipart context structures is required,
88 * this handle is used to keep a mapping with the service side of the
89 * context which contains the actual data.
90 */
91typedef uint32_t mbedtls_psa_client_handle_t;
92#endif
93
Gilles Peskinee59236f2018-01-27 23:32:46 +010094#endif /* PSA_CRYPTO_PLATFORM_H */