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 | /* |
| 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) |
Jaeden Amero | d58a00d | 2019-06-07 11:49:59 +0100 | [diff] [blame] | 41 | #include "mbedtls/config.h" |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 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 Peskine | f535eb2 | 2018-11-30 14:08:36 +0100 | [diff] [blame] | 49 | /* Integral type representing a key handle. */ |
| 50 | typedef uint16_t psa_key_handle_t; |
| 51 | |
Gilles Peskine | 5b229a0 | 2019-02-19 13:24:37 +0100 | [diff] [blame] | 52 | /* 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. */ |
| 69 | typedef uint32_t psa_app_key_id_t; |
| 70 | |
Gilles Peskine | 69d7c8b | 2019-02-19 14:00:31 +0100 | [diff] [blame] | 71 | #if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER) |
| 72 | |
Gilles Peskine | 572f067 | 2019-02-19 14:16:17 +0100 | [diff] [blame] | 73 | #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. */ |
| 76 | typedef int32_t psa_key_owner_id_t; |
| 77 | #endif |
| 78 | |
Gilles Peskine | 69d7c8b | 2019-02-19 14:00:31 +0100 | [diff] [blame] | 79 | typedef 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. */ |
| 91 | typedef psa_key_file_id_t psa_key_id_t; |
Jaeden Amero | 39f03fc | 2019-08-20 11:11:55 +0100 | [diff] [blame] | 92 | #define PSA_KEY_ID_INIT {0, 0} |
Gilles Peskine | 69d7c8b | 2019-02-19 14:00:31 +0100 | [diff] [blame] | 93 | |
| 94 | #else /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */ |
| 95 | |
Gilles Peskine | 5b229a0 | 2019-02-19 13:24:37 +0100 | [diff] [blame] | 96 | /* By default, a key file identifier is just the application key identifier. */ |
| 97 | typedef psa_app_key_id_t psa_key_file_id_t; |
| 98 | #define PSA_KEY_FILE_GET_KEY_ID( id ) ( id ) |
| 99 | |
Gilles Peskine | 69d7c8b | 2019-02-19 14:00:31 +0100 | [diff] [blame] | 100 | #endif /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */ |
| 101 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 102 | #endif /* PSA_CRYPTO_PLATFORM_H */ |