blob: d60b7732f3cfdc718b327bfa4307ab69ba72d425 [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
Gilles Peskinee59236f2018-01-27 23:32:46 +010018 * SPDX-License-Identifier: Apache-2.0
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may
21 * not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
Gilles Peskinee59236f2018-01-27 23:32:46 +010031 */
32
33#ifndef PSA_CRYPTO_PLATFORM_H
34#define PSA_CRYPTO_PLATFORM_H
Mateusz Starzyk2abe51c2021-06-07 11:08:01 +020035#include "mbedtls/private_access.h"
Gilles Peskinee59236f2018-01-27 23:32:46 +010036
37/* Include the Mbed TLS configuration file, the way Mbed TLS does it
38 * in each of its header files. */
39#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Amerod58a00d2019-06-07 11:49:59 +010040#include "mbedtls/config.h"
Gilles Peskinee59236f2018-01-27 23:32:46 +010041#else
42#include MBEDTLS_CONFIG_FILE
43#endif
44
Gilles Peskinebce4dc02020-11-09 15:06:57 +010045/* Translate between classic MBEDTLS_xxx feature symbols and PSA_xxx
46 * feature symbols. */
47#include "mbedtls/config_psa.h"
48
Gilles Peskinee59236f2018-01-27 23:32:46 +010049/* PSA requires several types which C99 provides in stdint.h. */
50#include <stdint.h>
51
Ronald Cronecfb2372020-07-23 17:13:42 +020052#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
53 !defined(inline) && !defined(__cplusplus)
54#define inline __inline
55#endif
56
Ronald Cron71016a92020-08-28 19:01:50 +020057#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010058
Ronald Cron9a2511e2020-09-14 10:02:56 +020059/* Building for the PSA Crypto service on a PSA platform, a key owner is a PSA
60 * partition identifier.
61 *
62 * The function psa_its_identifier_of_slot() in psa_crypto_storage.c that
63 * translates a key identifier to a key storage file name assumes that
64 * mbedtls_key_owner_id_t is an 32 bits integer. This function thus needs
65 * reworking if mbedtls_key_owner_id_t is not defined as a 32 bits integer
66 * here anymore.
67 */
Ronald Cron72f65fc2020-09-01 15:50:17 +020068typedef int32_t mbedtls_key_owner_id_t;
Ronald Cronecfb2372020-07-23 17:13:42 +020069
70/** Compare two key owner identifiers.
71 *
72 * \param id1 First key owner identifier.
73 * \param id2 Second key owner identifier.
74 *
75 * \return Non-zero if the two key owner identifiers are equal, zero otherwise.
76 */
77static inline int mbedtls_key_owner_id_equal( mbedtls_key_owner_id_t id1,
78 mbedtls_key_owner_id_t id2 )
79{
80 return( id1 == id2 );
81}
Gilles Peskine572f0672019-02-19 14:16:17 +010082
Ronald Cron71016a92020-08-28 19:01:50 +020083#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010084
Gilles Peskineb8af2282020-11-13 18:00:34 +010085#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
Gilles Peskine88fa5c42021-01-04 21:00:53 +010086/** The type of the context passed to mbedtls_psa_external_get_random().
Gilles Peskinec0963012020-11-18 15:33:33 +010087 *
88 * Mbed TLS initializes the context to all-bits-zero before calling
89 * mbedtls_psa_external_get_random() for the first time.
90 *
91 * The definition of this type in the Mbed TLS source code is for
92 * demonstration purposes. Implementers of mbedtls_psa_external_get_random()
93 * are expected to replace it with a custom definition.
94 */
Gilles Peskineb8af2282020-11-13 18:00:34 +010095typedef struct {
Mateusz Starzyk2abe51c2021-06-07 11:08:01 +020096 uintptr_t MBEDTLS_PRIVATE(opaque)[2];
Gilles Peskineb8af2282020-11-13 18:00:34 +010097} mbedtls_psa_external_random_context_t;
98#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
99
Gilles Peskinee59236f2018-01-27 23:32:46 +0100100#endif /* PSA_CRYPTO_PLATFORM_H */