blob: a124bdf4913875e0a0535677e67575d17ea7e218 [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
Soby Mathew803886d2020-08-10 12:18:03 +010066****************************
67Crypto Backend configuration
68****************************
69
70The Crypto service can use either a hardware crypto accelerator backend like
Anton Komlevb8e3af02020-08-28 10:23:57 +010071CC-312 or a software crypto library which by default is MbedTLS.
72
73If using MbedTLS as backend, then the library configuration is supplied using
74the ``TFM_MBEDCRYPTO_CONFIG_PATH`` cmake option.
75
76Platforms can specify an extra config file by setting the
77``TFM_MBEDCRYPTO_PLATFORM_EXTRA_CONFIG_PATH`` variable (which is a wrapper
78around the ``MBEDTLS_USER_CONFIG_FILE`` option). This is preferred for platform
79configuration over ``TFM_MBEDCRYPTO_CONFIG_PATH`` as it does not interfere with
80config changes due to TFM Profile.
Soby Mathew803886d2020-08-10 12:18:03 +010081
82.. Note::
83
84 The default entropy source configured for MbedTLS is
85 MBEDTLS_TEST_NULL_ENTROPY and this does not provide randomness
Anton Komlevb8e3af02020-08-28 10:23:57 +010086 for production devices. It is required for production devices to select
Soby Mathew803886d2020-08-10 12:18:03 +010087 either a hardware entropy source via MBEDTLS_ENTROPY_HARDWARE_ALT or
Anton Komlevb8e3af02020-08-28 10:23:57 +010088 provision a unique seed for the device during production and use the
Soby Mathew803886d2020-08-10 12:18:03 +010089 MBEDTLS_ENTROPY_NV_SEED option.
90
Galanakis, Minosf56baf62019-11-11 13:57:42 +000091**************************
92Crypto service integration
93**************************
Antonio de Angelisee774c22019-05-03 13:44:01 +010094In this section, a brief description of the required flow of operation for the
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020095functionalities exported by the PSA Crypto interface is given, with particular
96focus on the TF-M Crypto service specific operations. For the details of the
97generic PSA Crypto interface operations, please refer directly to the header
Jamie Foxcc31d402019-01-28 17:13:52 +000098``psa/crypto.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020099
Antonio de Angelisee774c22019-05-03 13:44:01 +0100100Most of the PSA Crypto multipart APIs require an operation context to be
101allocated by the application and then to be passed as a pointer during the
102following API calls. These operation contexts are of four main types described
103below:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200104
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100105- ``psa_key_derivation_operation_t`` - Operation context for key derivation
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200106- ``psa_hash_operation_t`` - Operation context for multipart hash operations
107- ``psa_mac_operation_t`` - Operation context for multipart MAC operations
108- ``psa_cipher_operation_t`` - Operation context for multipart cipher operations
109
110The user applications are not allowed to make any assumption about the original
Jamie Foxcc31d402019-01-28 17:13:52 +0000111types behind these typedefs, which are defined inside ``psa/crypto.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200112In the scope of the TF-M Crypto service, these types are regarded as handles to
113the corresponding implementation defined structures which are stored in the
114Secure world.
115
116--------------
117
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100118*Copyright (c) 2018-2020, Arm Limited. All rights reserved.*