blob: 8a9c401c2ee9907873c1e4563988011549ab4daa [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/*
17 * Copyright (C) 2018, ARM Limited, All Rights Reserved
18 * 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.
31 *
32 * This file is part of mbed TLS (https://tls.mbed.org)
33 */
34
35#ifndef PSA_CRYPTO_PLATFORM_H
36#define PSA_CRYPTO_PLATFORM_H
37
38/* Include the Mbed TLS configuration file, the way Mbed TLS does it
39 * in each of its header files. */
40#if !defined(MBEDTLS_CONFIG_FILE)
41#include "../mbedtls/config.h"
42#else
43#include MBEDTLS_CONFIG_FILE
44#endif
45
46/* PSA requires several types which C99 provides in stdint.h. */
47#include <stdint.h>
48
Gilles Peskinef535eb22018-11-30 14:08:36 +010049/* Integral type representing a key handle. */
50typedef uint16_t psa_key_handle_t;
51
Gilles Peskine5b229a02019-02-19 13:24:37 +010052/* This implementation distinguishes *application key identifiers*, which
53 * are the key identifiers specified by the application, from
54 * *key file identifiers*, which are the key identifiers that the library
55 * sees internally. The two types can be different if there is a remote
56 * call layer between the application and the library which supports
57 * multiple client applications that do not have access to each others'
58 * keys. The point of having different types is that the key file
59 * identifier may encode not only the key identifier specified by the
60 * application, but also the the identity of the application.
61 *
62 * Note that this is an internal concept of the library and the remote
63 * call layer. The application itself never sees anything other than
64 * #psa_app_key_id_t with its standard definition.
65 */
66
67/* The application key identifier is always what the application sees as
68 * #psa_key_id_t. */
69typedef uint32_t psa_app_key_id_t;
70
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010071#if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER)
72
Gilles Peskine572f0672019-02-19 14:16:17 +010073#if defined(PSA_CRYPTO_SECURE)
74/* Building for the PSA Crypto service on a PSA platform. */
75/* A key owner is a PSA partition identifier. */
76typedef int32_t psa_key_owner_id_t;
77#endif
78
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010079typedef struct
80{
81 uint32_t key_id;
82 psa_key_owner_id_t owner;
83} psa_key_file_id_t;
84#define PSA_KEY_FILE_GET_KEY_ID( file_id ) ( ( file_id ).key_id )
85
86/* Since crypto.h is used as part of the PSA Cryptography API specification,
87 * it must use standard types for things like the argument of psa_open_key().
88 * If it wasn't for that constraint, psa_open_key() would take a
89 * `psa_key_file_id_t` argument. As a workaround, make `psa_key_id_t` an
90 * alias for `psa_key_file_id_t` when building for a multi-client service. */
91typedef psa_key_file_id_t psa_key_id_t;
92
93#else /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
94
Gilles Peskine5b229a02019-02-19 13:24:37 +010095/* By default, a key file identifier is just the application key identifier. */
96typedef psa_app_key_id_t psa_key_file_id_t;
97#define PSA_KEY_FILE_GET_KEY_ID( id ) ( id )
98
Gilles Peskine69d7c8b2019-02-19 14:00:31 +010099#endif /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
100
Gilles Peskinee59236f2018-01-27 23:32:46 +0100101#endif /* PSA_CRYPTO_PLATFORM_H */