blob: ab6f1e84464a4f6a4f37fa668d2ab72a1eac5a1c [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 Rodgman7ff79652023-11-03 12:04:52 +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
23
24/* Include the Mbed TLS configuration file, the way Mbed TLS does it
25 * in each of its header files. */
26#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amerod58a00d2019-06-07 11:49:59 +010027#include "mbedtls/config.h"
Gilles Peskinee59236f2018-01-27 23:32:46 +010028#else
29#include MBEDTLS_CONFIG_FILE
30#endif
31
Gilles Peskinebce4dc02020-11-09 15:06:57 +010032/* Translate between classic MBEDTLS_xxx feature symbols and PSA_xxx
33 * feature symbols. */
34#include "mbedtls/config_psa.h"
35
Gilles Peskinee59236f2018-01-27 23:32:46 +010036/* PSA requires several types which C99 provides in stdint.h. */
37#include <stdint.h>
38
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010039#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
Ronald Cronecfb2372020-07-23 17:13:42 +020040 !defined(inline) && !defined(__cplusplus)
41#define inline __inline
42#endif
43
Ronald Cron71016a92020-08-28 19:01:50 +020044#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010045
Ronald Cron9a2511e2020-09-14 10:02:56 +020046/* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA
47 * partition identifier.
48 *
49 * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that
50 * translates a key identifier to a key storage file name assumes that
Tom Cosgrove5205c972022-07-28 06:12:08 +010051 * mbedtls_key_owner_id_t is a 32-bit integer. This function thus needs
52 * reworking if mbedtls_key_owner_id_t is not defined as a 32-bit integer
Ronald Cron9a2511e2020-09-14 10:02:56 +020053 * here anymore.
54 */
Ronald Cron72f65fc2020-09-01 15:50:17 +020055typedef int32_t mbedtls_key_owner_id_t;
Ronald Cronecfb2372020-07-23 17:13:42 +020056
57/** Compare two key owner identifiers.
58 *
59 * \param id1 First key owner identifier.
60 * \param id2 Second key owner identifier.
61 *
62 * \return Non-zero if the two key owner identifiers are equal, zero otherwise.
63 */
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010064static inline int mbedtls_key_owner_id_equal(mbedtls_key_owner_id_t id1,
65 mbedtls_key_owner_id_t id2)
Ronald Cronecfb2372020-07-23 17:13:42 +020066{
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010067 return id1 == id2;
Ronald Cronecfb2372020-07-23 17:13:42 +020068}
Gilles Peskine572f0672019-02-19 14:16:17 +010069
Ronald Cron71016a92020-08-28 19:01:50 +020070#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010071
Gilles Peskine76dec152021-06-15 18:36:05 +020072/*
73 * When MBEDTLS_PSA_CRYPTO_SPM is defined, the code is being built for SPM
74 * (Secure Partition Manager) integration which separates the code into two
75 * parts: NSPE (Non-Secure Processing Environment) and SPE (Secure Processing
76 * Environment). When building for the SPE, an additional header file should be
77 * included.
78 */
79#if defined(MBEDTLS_PSA_CRYPTO_SPM)
80#define PSA_CRYPTO_SECURE 1
81#include "crypto_spe.h"
82#endif // MBEDTLS_PSA_CRYPTO_SPM
83
Gilles Peskineb8af2282020-11-13 18:00:34 +010084#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
Gilles Peskine88fa5c42021-01-04 21:00:53 +010085/** The type of the context passed to mbedtls_psa_external_get_random().
Gilles Peskinec0963012020-11-18 15:33:33 +010086 *
87 * Mbed TLS initializes the context to all-bits-zero before calling
88 * mbedtls_psa_external_get_random() for the first time.
89 *
90 * The definition of this type in the Mbed TLS source code is for
91 * demonstration purposes. Implementers of mbedtls_psa_external_get_random()
92 * are expected to replace it with a custom definition.
93 */
Gilles Peskineb8af2282020-11-13 18:00:34 +010094typedef struct {
Gilles Peskinec0963012020-11-18 15:33:33 +010095 uintptr_t opaque[2];
Gilles Peskineb8af2282020-11-13 18:00:34 +010096} mbedtls_psa_external_random_context_t;
97#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
98
Gilles Peskinee59236f2018-01-27 23:32:46 +010099#endif /* PSA_CRYPTO_PLATFORM_H */