blob: 6eaa5e0306043abd0a87a1a943844b1ef1d2c9b9 [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
71CC-312 or a software crypto library which by default is MbedTLS. If using
72MbedTLS as backend, then the library configuration is supplied using the
73MBEDTLS_CONFIG_FILE header option. TF-M Crypto provides a default
74configuration header ``tfm_mbedcrypto_config.h`` and this can be overridden
75based on TF-M configuration or platform. Platforms can also use
76``MBEDTLS_USER_CONFIG_FILE`` to override specific options from default.
77
78.. Note::
79
80 The default entropy source configured for MbedTLS is
81 MBEDTLS_TEST_NULL_ENTROPY and this does not provide randomness
82 for production devices. It is must for production devices to select
83 either a hardware entropy source via MBEDTLS_ENTROPY_HARDWARE_ALT or
84 provision a unique seed for the device during production and use
85 MBEDTLS_ENTROPY_NV_SEED option.
86
Galanakis, Minosf56baf62019-11-11 13:57:42 +000087**************************
88Crypto service integration
89**************************
Antonio de Angelisee774c22019-05-03 13:44:01 +010090In this section, a brief description of the required flow of operation for the
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020091functionalities exported by the PSA Crypto interface is given, with particular
92focus on the TF-M Crypto service specific operations. For the details of the
93generic PSA Crypto interface operations, please refer directly to the header
Jamie Foxcc31d402019-01-28 17:13:52 +000094``psa/crypto.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020095
Antonio de Angelisee774c22019-05-03 13:44:01 +010096Most of the PSA Crypto multipart APIs require an operation context to be
97allocated by the application and then to be passed as a pointer during the
98following API calls. These operation contexts are of four main types described
99below:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200100
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100101- ``psa_key_derivation_operation_t`` - Operation context for key derivation
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200102- ``psa_hash_operation_t`` - Operation context for multipart hash operations
103- ``psa_mac_operation_t`` - Operation context for multipart MAC operations
104- ``psa_cipher_operation_t`` - Operation context for multipart cipher operations
105
106The user applications are not allowed to make any assumption about the original
Jamie Foxcc31d402019-01-28 17:13:52 +0000107types behind these typedefs, which are defined inside ``psa/crypto.h``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200108In the scope of the TF-M Crypto service, these types are regarded as handles to
109the corresponding implementation defined structures which are stored in the
110Secure world.
111
112--------------
113
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100114*Copyright (c) 2018-2020, Arm Limited. All rights reserved.*