blob: 4065930235227f1e308c26eba8179129c97e2f9d [file] [log] [blame]
Galanakis, Minos41f85972019-09-30 15:56:40 +01001################################
2Crypto Service Integration Guide
3################################
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02004
5************
6Introduction
7************
8TF-M Crypto service allows application to use cryptography primitives such as
9symmetric and asymmetric ciphers, hash, message authentication codes (MACs) and
10authenticated encryption with associated data (AEAD).
11
12**************
13Code structure
14**************
Jamie Foxcee7bd92020-03-17 19:04:04 +000015The PSA interfaces for the Crypto service are located in ``interface/include``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020016The only header to be included by applications that want to use functions from
Jamie Foxcc31d402019-01-28 17:13:52 +000017the PSA API is ``psa/crypto.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020018The TF-M Crypto service source files are located in
Ken Liu738a4b02020-06-04 14:52:38 +080019``secure_fw/partitions/crypto``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020020
21PSA interfaces
22==============
23The TF-M Crypto service exposes the PSA interfaces detailed in the header
Jamie Foxcc31d402019-01-28 17:13:52 +000024``psa/crypto.h``. This header, in turn, includes several other headers which
Antonio de Angelisee774c22019-05-03 13:44:01 +010025are not meant to be included directly by user applications. For a detailed
26description of the PSA API interface, please refer to the comments in the
Jamie Foxcc31d402019-01-28 17:13:52 +000027``psa/crypto.h`` header itself.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020028
29Service source files
30====================
Antonio de Angelisee774c22019-05-03 13:44:01 +010031- ``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 Foxcee7bd92020-03-17 19:04:04 +000036- ``crypto_key_derivation.c`` : This module handles requests for key derivation
37 related operations
Antonio de Angelisee774c22019-05-03 13:44:01 +010038- ``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 Bane7efdc62019-06-05 13:14:52 +010057- ``tfm_crypto_secure_api.c`` : This module implements the PSA Crypto API
Antonio de Angelisee774c22019-05-03 13:44:01 +010058 client interface exposed to the Secure Processing Environment
Jamie Foxcee7bd92020-03-17 19:04:04 +000059- ``tfm_crypto_api.c`` : This module is contained in ``interface/src`` and
Antonio de Angelisee774c22019-05-03 13:44:01 +010060 implements the PSA Crypto API client interface exposed to the Non-Secure
61 Processing Environment.
David Hue954d6b2020-04-23 13:06:00 +080062- ``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 Szingdb9783c2019-04-17 21:08:48 +020065
Galanakis, Minosf56baf62019-11-11 13:57:42 +000066**************************
67Crypto service integration
68**************************
Antonio de Angelisee774c22019-05-03 13:44:01 +010069In this section, a brief description of the required flow of operation for the
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020070functionalities exported by the PSA Crypto interface is given, with particular
71focus on the TF-M Crypto service specific operations. For the details of the
72generic PSA Crypto interface operations, please refer directly to the header
Jamie Foxcc31d402019-01-28 17:13:52 +000073``psa/crypto.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020074
Antonio de Angelisee774c22019-05-03 13:44:01 +010075Most of the PSA Crypto multipart APIs require an operation context to be
76allocated by the application and then to be passed as a pointer during the
77following API calls. These operation contexts are of four main types described
78below:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020079
Antonio de Angelis04debbd2019-10-14 12:12:52 +010080- ``psa_key_derivation_operation_t`` - Operation context for key derivation
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020081- ``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
85The user applications are not allowed to make any assumption about the original
Jamie Foxcc31d402019-01-28 17:13:52 +000086types behind these typedefs, which are defined inside ``psa/crypto.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020087In the scope of the TF-M Crypto service, these types are regarded as handles to
88the corresponding implementation defined structures which are stored in the
89Secure world.
90
91--------------
92
Antonio de Angelis04debbd2019-10-14 12:12:52 +010093*Copyright (c) 2018-2020, Arm Limited. All rights reserved.*