Galanakis, Minos | 41f8597 | 2019-09-30 15:56:40 +0100 | [diff] [blame] | 1 | ################################ |
| 2 | Crypto Service Integration Guide |
| 3 | ################################ |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 4 | |
| 5 | ************ |
| 6 | Introduction |
| 7 | ************ |
| 8 | TF-M Crypto service allows application to use cryptography primitives such as |
| 9 | symmetric and asymmetric ciphers, hash, message authentication codes (MACs) and |
| 10 | authenticated encryption with associated data (AEAD). |
| 11 | |
| 12 | ************** |
| 13 | Code structure |
| 14 | ************** |
Jamie Fox | cee7bd9 | 2020-03-17 19:04:04 +0000 | [diff] [blame] | 15 | The PSA interfaces for the Crypto service are located in ``interface/include``. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 16 | The only header to be included by applications that want to use functions from |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 17 | the PSA API is ``psa/crypto.h``. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 18 | The TF-M Crypto service source files are located in |
Ken Liu | 738a4b0 | 2020-06-04 14:52:38 +0800 | [diff] [blame] | 19 | ``secure_fw/partitions/crypto``. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 20 | |
| 21 | PSA interfaces |
| 22 | ============== |
| 23 | The TF-M Crypto service exposes the PSA interfaces detailed in the header |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 24 | ``psa/crypto.h``. This header, in turn, includes several other headers which |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 25 | are not meant to be included directly by user applications. For a detailed |
| 26 | description of the PSA API interface, please refer to the comments in the |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 27 | ``psa/crypto.h`` header itself. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 28 | |
| 29 | Service source files |
| 30 | ==================== |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 31 | - ``crypto_cipher.c`` : This module handles requests for symmetric cipher |
| 32 | operations |
| 33 | - ``crypto_hash.c`` : This module handles requests for hashing operations |
| 34 | - ``crypto_mac.c`` : This module handles requests for MAC operations |
| 35 | - ``crypto_aead.c`` : This module handles requests for AEAD operations |
Jamie Fox | cee7bd9 | 2020-03-17 19:04:04 +0000 | [diff] [blame] | 36 | - ``crypto_key_derivation.c`` : This module handles requests for key derivation |
| 37 | related operations |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 38 | - ``crypto_key.c`` : This module handles requests for key related operations |
| 39 | - ``crypto_asymmetric.c`` : This module handles requests for asymmetric |
| 40 | cryptographic operations |
| 41 | - ``crypto_init.c`` : This module provides basic functions to initialise the |
| 42 | secure service during TF-M boot. When the service is built for IPC mode |
| 43 | compatibility, this layer handles as well the connection requests and the |
| 44 | proper dispatching of requests to the corresponding functions, and it holds |
| 45 | the internal buffer used to allocate temporarily the IOVECs needed. The size |
| 46 | of this buffer is controlled by the ``TFM_CRYPTO_IOVEC_BUFFER_SIZE`` define. |
| 47 | This module also provides a static buffer which is used by the Mbed Crypto |
| 48 | library for its own allocations. The size of this buffer is controlled by |
| 49 | the ``TFM_CRYPTO_ENGINE_BUF_SIZE`` define |
| 50 | - ``crypto_alloc.c`` : This module is required for the allocation and release of |
| 51 | crypto operation contexts in the SPE. The ``TFM_CRYPTO_CONC_OPER_NUM``, |
| 52 | defined in this file, determines how many concurrent contexts are supported |
| 53 | for multipart operations (8 for the current implementation). For multipart |
| 54 | cipher/hash/MAC/generator operations, a context is associated to the handle |
| 55 | provided during the setup phase, and is explicitly cleared only following a |
| 56 | termination or an abort |
Tamas Ban | e7efdc6 | 2019-06-05 13:14:52 +0100 | [diff] [blame] | 57 | - ``tfm_crypto_secure_api.c`` : This module implements the PSA Crypto API |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 58 | client interface exposed to the Secure Processing Environment |
Jamie Fox | cee7bd9 | 2020-03-17 19:04:04 +0000 | [diff] [blame] | 59 | - ``tfm_crypto_api.c`` : This module is contained in ``interface/src`` and |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 60 | implements the PSA Crypto API client interface exposed to the Non-Secure |
| 61 | Processing Environment. |
David Hu | e954d6b | 2020-04-23 13:06:00 +0800 | [diff] [blame] | 62 | - ``tfm_mbedcrypto_alt.c`` : This module contains alternative implementations of |
| 63 | Mbed Crypto functions. Decryption code is skipped in AES CCM mode in Profile |
| 64 | Small by default. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 65 | |
Galanakis, Minos | f56baf6 | 2019-11-11 13:57:42 +0000 | [diff] [blame] | 66 | ************************** |
| 67 | Crypto service integration |
| 68 | ************************** |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 69 | In this section, a brief description of the required flow of operation for the |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 70 | functionalities exported by the PSA Crypto interface is given, with particular |
| 71 | focus on the TF-M Crypto service specific operations. For the details of the |
| 72 | generic PSA Crypto interface operations, please refer directly to the header |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 73 | ``psa/crypto.h``. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 74 | |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 75 | Most of the PSA Crypto multipart APIs require an operation context to be |
| 76 | allocated by the application and then to be passed as a pointer during the |
| 77 | following API calls. These operation contexts are of four main types described |
| 78 | below: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 79 | |
Antonio de Angelis | 04debbd | 2019-10-14 12:12:52 +0100 | [diff] [blame] | 80 | - ``psa_key_derivation_operation_t`` - Operation context for key derivation |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 81 | - ``psa_hash_operation_t`` - Operation context for multipart hash operations |
| 82 | - ``psa_mac_operation_t`` - Operation context for multipart MAC operations |
| 83 | - ``psa_cipher_operation_t`` - Operation context for multipart cipher operations |
| 84 | |
| 85 | The user applications are not allowed to make any assumption about the original |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 86 | types behind these typedefs, which are defined inside ``psa/crypto.h``. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 87 | In the scope of the TF-M Crypto service, these types are regarded as handles to |
| 88 | the corresponding implementation defined structures which are stored in the |
| 89 | Secure world. |
| 90 | |
| 91 | -------------- |
| 92 | |
Antonio de Angelis | 04debbd | 2019-10-14 12:12:52 +0100 | [diff] [blame] | 93 | *Copyright (c) 2018-2020, Arm Limited. All rights reserved.* |