xref: /rk3399_ARM-atf/docs/design/auth-framework.rst (revision ae952c1e51ffa01bb01f81c3b97d1200ef08635b)
18aa05055SPaul BeesleyAuthentication Framework & Chain of Trust
28aa05055SPaul Beesley=========================================
340d553cfSPaul Beesley
440d553cfSPaul BeesleyThe aim of this document is to describe the authentication framework
540d553cfSPaul Beesleyimplemented in Trusted Firmware-A (TF-A). This framework fulfills the
640d553cfSPaul Beesleyfollowing requirements:
740d553cfSPaul Beesley
840d553cfSPaul Beesley#. It should be possible for a platform port to specify the Chain of Trust in
940d553cfSPaul Beesley   terms of certificate hierarchy and the mechanisms used to verify a
1040d553cfSPaul Beesley   particular image/certificate.
1140d553cfSPaul Beesley
1240d553cfSPaul Beesley#. The framework should distinguish between:
1340d553cfSPaul Beesley
1440d553cfSPaul Beesley   -  The mechanism used to encode and transport information, e.g. DER encoded
1540d553cfSPaul Beesley      X.509v3 certificates to ferry Subject Public Keys, hashes and non-volatile
1640d553cfSPaul Beesley      counters.
1740d553cfSPaul Beesley
1840d553cfSPaul Beesley   -  The mechanism used to verify the transported information i.e. the
1940d553cfSPaul Beesley      cryptographic libraries.
2040d553cfSPaul Beesley
2140d553cfSPaul BeesleyThe framework has been designed following a modular approach illustrated in the
2240d553cfSPaul Beesleynext diagram:
2340d553cfSPaul Beesley
2440d553cfSPaul Beesley::
2540d553cfSPaul Beesley
2640d553cfSPaul Beesley        +---------------+---------------+------------+
2740d553cfSPaul Beesley        | Trusted       | Trusted       | Trusted    |
2840d553cfSPaul Beesley        | Firmware      | Firmware      | Firmware   |
2940d553cfSPaul Beesley        | Generic       | IO Framework  | Platform   |
3040d553cfSPaul Beesley        | Code i.e.     | (IO)          | Port       |
3140d553cfSPaul Beesley        | BL1/BL2 (GEN) |               | (PP)       |
3240d553cfSPaul Beesley        +---------------+---------------+------------+
3340d553cfSPaul Beesley               ^               ^               ^
3440d553cfSPaul Beesley               |               |               |
3540d553cfSPaul Beesley               v               v               v
3640d553cfSPaul Beesley         +-----------+   +-----------+   +-----------+
3740d553cfSPaul Beesley         |           |   |           |   | Image     |
3840d553cfSPaul Beesley         | Crypto    |   | Auth      |   | Parser    |
3940d553cfSPaul Beesley         | Module    |<->| Module    |<->| Module    |
4040d553cfSPaul Beesley         | (CM)      |   | (AM)      |   | (IPM)     |
4140d553cfSPaul Beesley         |           |   |           |   |           |
4240d553cfSPaul Beesley         +-----------+   +-----------+   +-----------+
4340d553cfSPaul Beesley               ^                               ^
4440d553cfSPaul Beesley               |                               |
4540d553cfSPaul Beesley               v                               v
4640d553cfSPaul Beesley        +----------------+             +-----------------+
4740d553cfSPaul Beesley        | Cryptographic  |             | Image Parser    |
4840d553cfSPaul Beesley        | Libraries (CL) |             | Libraries (IPL) |
4940d553cfSPaul Beesley        +----------------+             +-----------------+
5040d553cfSPaul Beesley                      |                |
5140d553cfSPaul Beesley                      |                |
5240d553cfSPaul Beesley                      |                |
5340d553cfSPaul Beesley                      v                v
5440d553cfSPaul Beesley                     +-----------------+
5540d553cfSPaul Beesley                     | Misc. Libs e.g. |
5640d553cfSPaul Beesley                     | ASN.1 decoder   |
5740d553cfSPaul Beesley                     |                 |
5840d553cfSPaul Beesley                     +-----------------+
5940d553cfSPaul Beesley
6040d553cfSPaul Beesley        DIAGRAM 1.
6140d553cfSPaul Beesley
6240d553cfSPaul BeesleyThis document describes the inner details of the authentication framework and
6340d553cfSPaul Beesleythe abstraction mechanisms available to specify a Chain of Trust.
6440d553cfSPaul Beesley
6540d553cfSPaul BeesleyFramework design
6640d553cfSPaul Beesley----------------
6740d553cfSPaul Beesley
6840d553cfSPaul BeesleyThis section describes some aspects of the framework design and the rationale
6940d553cfSPaul Beesleybehind them. These aspects are key to verify a Chain of Trust.
7040d553cfSPaul Beesley
7140d553cfSPaul BeesleyChain of Trust
7240d553cfSPaul Beesley~~~~~~~~~~~~~~
7340d553cfSPaul Beesley
7440d553cfSPaul BeesleyA CoT is basically a sequence of authentication images which usually starts with
7540d553cfSPaul Beesleya root of trust and culminates in a single data image. The following diagram
7640d553cfSPaul Beesleyillustrates how this maps to a CoT for the BL31 image described in the
7740d553cfSPaul Beesley`TBBR-Client specification`_.
7840d553cfSPaul Beesley
7940d553cfSPaul Beesley::
8040d553cfSPaul Beesley
8140d553cfSPaul Beesley        +------------------+       +-------------------+
8240d553cfSPaul Beesley        | ROTPK/ROTPK Hash |------>| Trusted Key       |
8340d553cfSPaul Beesley        +------------------+       | Certificate       |
8440d553cfSPaul Beesley                                   | (Auth Image)      |
8540d553cfSPaul Beesley                                  /+-------------------+
8640d553cfSPaul Beesley                                 /            |
8740d553cfSPaul Beesley                                /             |
8840d553cfSPaul Beesley                               /              |
8940d553cfSPaul Beesley                              /               |
9040d553cfSPaul Beesley                             L                v
9140d553cfSPaul Beesley        +------------------+       +-------------------+
9240d553cfSPaul Beesley        | Trusted World    |------>| BL31 Key          |
9340d553cfSPaul Beesley        | Public Key       |       | Certificate       |
9440d553cfSPaul Beesley        +------------------+       | (Auth Image)      |
9540d553cfSPaul Beesley                                   +-------------------+
9640d553cfSPaul Beesley                                  /           |
9740d553cfSPaul Beesley                                 /            |
9840d553cfSPaul Beesley                                /             |
9940d553cfSPaul Beesley                               /              |
10040d553cfSPaul Beesley                              /               v
10140d553cfSPaul Beesley        +------------------+ L     +-------------------+
10240d553cfSPaul Beesley        | BL31 Content     |------>| BL31 Content      |
10340d553cfSPaul Beesley        | Certificate PK   |       | Certificate       |
10440d553cfSPaul Beesley        +------------------+       | (Auth Image)      |
10540d553cfSPaul Beesley                                   +-------------------+
10640d553cfSPaul Beesley                                  /           |
10740d553cfSPaul Beesley                                 /            |
10840d553cfSPaul Beesley                                /             |
10940d553cfSPaul Beesley                               /              |
11040d553cfSPaul Beesley                              /               v
11140d553cfSPaul Beesley        +------------------+ L     +-------------------+
11240d553cfSPaul Beesley        | BL31 Hash        |------>| BL31 Image        |
11340d553cfSPaul Beesley        |                  |       | (Data Image)      |
11440d553cfSPaul Beesley        +------------------+       |                   |
11540d553cfSPaul Beesley                                   +-------------------+
11640d553cfSPaul Beesley
11740d553cfSPaul Beesley        DIAGRAM 2.
11840d553cfSPaul Beesley
11940d553cfSPaul BeesleyThe root of trust is usually a public key (ROTPK) that has been burnt in the
12040d553cfSPaul Beesleyplatform and cannot be modified.
12140d553cfSPaul Beesley
12240d553cfSPaul BeesleyImage types
12340d553cfSPaul Beesley~~~~~~~~~~~
12440d553cfSPaul Beesley
12540d553cfSPaul BeesleyImages in a CoT are categorised as authentication and data images. An
12640d553cfSPaul Beesleyauthentication image contains information to authenticate a data image or
12740d553cfSPaul Beesleyanother authentication image. A data image is usually a boot loader binary, but
12840d553cfSPaul Beesleyit could be any other data that requires authentication.
12940d553cfSPaul Beesley
13040d553cfSPaul BeesleyComponent responsibilities
13140d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~
13240d553cfSPaul Beesley
13340d553cfSPaul BeesleyFor every image in a Chain of Trust, the following high level operations are
13440d553cfSPaul Beesleyperformed to verify it:
13540d553cfSPaul Beesley
13640d553cfSPaul Beesley#. Allocate memory for the image either statically or at runtime.
13740d553cfSPaul Beesley
13840d553cfSPaul Beesley#. Identify the image and load it in the allocated memory.
13940d553cfSPaul Beesley
14040d553cfSPaul Beesley#. Check the integrity of the image as per its type.
14140d553cfSPaul Beesley
14240d553cfSPaul Beesley#. Authenticate the image as per the cryptographic algorithms used.
14340d553cfSPaul Beesley
14440d553cfSPaul Beesley#. If the image is an authentication image, extract the information that will
14540d553cfSPaul Beesley   be used to authenticate the next image in the CoT.
14640d553cfSPaul Beesley
14740d553cfSPaul BeesleyIn Diagram 1, each component is responsible for one or more of these operations.
14840d553cfSPaul BeesleyThe responsibilities are briefly described below.
14940d553cfSPaul Beesley
15040d553cfSPaul BeesleyTF-A Generic code and IO framework (GEN/IO)
15140d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15240d553cfSPaul Beesley
15340d553cfSPaul BeesleyThese components are responsible for initiating the authentication process for a
15440d553cfSPaul Beesleyparticular image in BL1 or BL2. For each BL image that requires authentication,
15540d553cfSPaul Beesleythe Generic code asks recursively the Authentication module what is the parent
15640d553cfSPaul Beesleyimage until either an authenticated image or the ROT is reached. Then the
15740d553cfSPaul BeesleyGeneric code calls the IO framework to load the image and calls the
15840d553cfSPaul BeesleyAuthentication module to authenticate it, following the CoT from ROT to Image.
15940d553cfSPaul Beesley
16040d553cfSPaul BeesleyTF-A Platform Port (PP)
16140d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^
16240d553cfSPaul Beesley
16340d553cfSPaul BeesleyThe platform is responsible for:
16440d553cfSPaul Beesley
16540d553cfSPaul Beesley#. Specifying the CoT for each image that needs to be authenticated. Details of
16640d553cfSPaul Beesley   how a CoT can be specified by the platform are explained later. The platform
16740d553cfSPaul Beesley   also specifies the authentication methods and the parsing method used for
16840d553cfSPaul Beesley   each image.
16940d553cfSPaul Beesley
17040d553cfSPaul Beesley#. Statically allocating memory for each parameter in each image which is
17140d553cfSPaul Beesley   used for verifying the CoT, e.g. memory for public keys, hashes etc.
17240d553cfSPaul Beesley
17340d553cfSPaul Beesley#. Providing the ROTPK or a hash of it.
17440d553cfSPaul Beesley
17540d553cfSPaul Beesley#. Providing additional information to the IPM to enable it to identify and
17640d553cfSPaul Beesley   extract authentication parameters contained in an image, e.g. if the
17740d553cfSPaul Beesley   parameters are stored as X509v3 extensions, the corresponding OID must be
17840d553cfSPaul Beesley   provided.
17940d553cfSPaul Beesley
18040d553cfSPaul Beesley#. Fulfill any other memory requirements of the IPM and the CM (not currently
18140d553cfSPaul Beesley   described in this document).
18240d553cfSPaul Beesley
18340d553cfSPaul Beesley#. Export functions to verify an image which uses an authentication method that
18440d553cfSPaul Beesley   cannot be interpreted by the CM, e.g. if an image has to be verified using a
18540d553cfSPaul Beesley   NV counter, then the value of the counter to compare with can only be
18640d553cfSPaul Beesley   provided by the platform.
18740d553cfSPaul Beesley
18840d553cfSPaul Beesley#. Export a custom IPM if a proprietary image format is being used (described
18940d553cfSPaul Beesley   later).
19040d553cfSPaul Beesley
19140d553cfSPaul BeesleyAuthentication Module (AM)
19240d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^
19340d553cfSPaul Beesley
19440d553cfSPaul BeesleyIt is responsible for:
19540d553cfSPaul Beesley
19640d553cfSPaul Beesley#. Providing the necessary abstraction mechanisms to describe a CoT. Amongst
19740d553cfSPaul Beesley   other things, the authentication and image parsing methods must be specified
19840d553cfSPaul Beesley   by the PP in the CoT.
19940d553cfSPaul Beesley
20040d553cfSPaul Beesley#. Verifying the CoT passed by GEN by utilising functionality exported by the
20140d553cfSPaul Beesley   PP, IPM and CM.
20240d553cfSPaul Beesley
20340d553cfSPaul Beesley#. Tracking which images have been verified. In case an image is a part of
20440d553cfSPaul Beesley   multiple CoTs then it should be verified only once e.g. the Trusted World
20540d553cfSPaul Beesley   Key Certificate in the TBBR-Client spec. contains information to verify
20640d553cfSPaul Beesley   SCP_BL2, BL31, BL32 each of which have a separate CoT. (This
20740d553cfSPaul Beesley   responsibility has not been described in this document but should be
20840d553cfSPaul Beesley   trivial to implement).
20940d553cfSPaul Beesley
21040d553cfSPaul Beesley#. Reusing memory meant for a data image to verify authentication images e.g.
21140d553cfSPaul Beesley   in the CoT described in Diagram 2, each certificate can be loaded and
21240d553cfSPaul Beesley   verified in the memory reserved by the platform for the BL31 image. By the
21340d553cfSPaul Beesley   time BL31 (the data image) is loaded, all information to authenticate it
21440d553cfSPaul Beesley   will have been extracted from the parent image i.e. BL31 content
21540d553cfSPaul Beesley   certificate. It is assumed that the size of an authentication image will
21640d553cfSPaul Beesley   never exceed the size of a data image. It should be possible to verify this
21740d553cfSPaul Beesley   at build time using asserts.
21840d553cfSPaul Beesley
21940d553cfSPaul BeesleyCryptographic Module (CM)
22040d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^
22140d553cfSPaul Beesley
22240d553cfSPaul BeesleyThe CM is responsible for providing an API to:
22340d553cfSPaul Beesley
22440d553cfSPaul Beesley#. Verify a digital signature.
22540d553cfSPaul Beesley#. Verify a hash.
22640d553cfSPaul Beesley
22740d553cfSPaul BeesleyThe CM does not include any cryptography related code, but it relies on an
22840d553cfSPaul Beesleyexternal library to perform the cryptographic operations. A Crypto-Library (CL)
22940d553cfSPaul Beesleylinking the CM and the external library must be implemented. The following
23040d553cfSPaul Beesleyfunctions must be provided by the CL:
23140d553cfSPaul Beesley
23240d553cfSPaul Beesley.. code:: c
23340d553cfSPaul Beesley
23440d553cfSPaul Beesley    void (*init)(void);
235*8edd6c6fSRyan Everett    int (*verify_signature)(
236*8edd6c6fSRyan Everett                            /* Data to verify. */
237*8edd6c6fSRyan Everett                            void *data_ptr, unsigned int data_len,
238*8edd6c6fSRyan Everett                            /* Bit string of the signature in DER format. */
23940d553cfSPaul Beesley                            void *sig_ptr, unsigned int sig_len,
240*8edd6c6fSRyan Everett                            /* ASN1 SignatureAlgorithm struct. */
24140d553cfSPaul Beesley                            void *sig_alg, unsigned int sig_alg_len,
242*8edd6c6fSRyan Everett                            /* ASN1 SubjectPublicKeyInfo struct. */
24340d553cfSPaul Beesley                            void *pk_ptr, unsigned int pk_len);
244*8edd6c6fSRyan Everett    int (*calc_hash)(
245*8edd6c6fSRyan Everett                            /* SHA256, SHA384 and SHA512 can be used. */
246*8edd6c6fSRyan Everett                            enum crypto_md_algo alg
247*8edd6c6fSRyan Everett                            /* Data to hash. */
248*8edd6c6fSRyan Everett                            void *data_ptr, unsigned int data_len,
249*8edd6c6fSRyan Everett                            /* Buffer to store the output. */
250*8edd6c6fSRyan Everett                            unsigned char output[CRYPTO_MD_MAX_SIZE]);
251*8edd6c6fSRyan Everett    int (*verify_hash)(
252*8edd6c6fSRyan Everett                            /* Data to verify. */
253*8edd6c6fSRyan Everett                            void *data_ptr, unsigned int data_len,
254*8edd6c6fSRyan Everett                            /* ASN1 DigestInfo struct. */
25540d553cfSPaul Beesley                            void *digest_info_ptr, unsigned int digest_info_len);
256*8edd6c6fSRyan Everett    int (*auth_decrypt)(
257*8edd6c6fSRyan Everett                            /* Currently AES-GCM is the only supported alg. */
258*8edd6c6fSRyan Everett                            enum crypto_dec_algo dec_algo,
259*8edd6c6fSRyan Everett                            /* Data to decrypt. */
260*8edd6c6fSRyan Everett                            void *data_ptr, size_t len,
261*8edd6c6fSRyan Everett                            /* Decryption key. */
262*8edd6c6fSRyan Everett                            const void *key, unsigned int key_len,
263*8edd6c6fSRyan Everett                            unsigned int key_flags,
264*8edd6c6fSRyan Everett                            /* Initialization vector. */
265*8edd6c6fSRyan Everett                            const void *iv, unsigned int iv_len,
266*8edd6c6fSRyan Everett                            /* Authentication tag. */
267*8edd6c6fSRyan Everett                            const void *tag, unsigned int tag_len);
26840d553cfSPaul Beesley
269*8edd6c6fSRyan EverettThe above functions return values from the enum ``crypto_ret_value``.
270*8edd6c6fSRyan EverettThe functions are registered in the CM using the macro:
27140d553cfSPaul Beesley
27240d553cfSPaul Beesley.. code:: c
27340d553cfSPaul Beesley
274f28057a2SManish V Badarkhe    REGISTER_CRYPTO_LIB(_name,
275f28057a2SManish V Badarkhe                        _init,
276f28057a2SManish V Badarkhe                        _verify_signature,
2770ca7b326SYann Gautier                        _verify_hash,
2785710229fSzhiyang.shi                        _calc_hash,
2794ac5b394SYann Gautier                        _auth_decrypt,
2804ac5b394SYann Gautier                        _convert_pk);
28140d553cfSPaul Beesley
28240d553cfSPaul Beesley``_name`` must be a string containing the name of the CL. This name is used for
28340d553cfSPaul Beesleydebugging purposes.
28440d553cfSPaul Beesley
285*8edd6c6fSRyan EverettThe ``_init`` function is used to perform any initialization required for
286*8edd6c6fSRyan Everettthe specific CM and CL.
287*8edd6c6fSRyan Everett
288*8edd6c6fSRyan EverettThe ``_verify_signature`` function is used to verify certificates,
289*8edd6c6fSRyan Everettand ``_verify_hash`` is used to verify raw images.
290*8edd6c6fSRyan Everett
291*8edd6c6fSRyan EverettThe ``_calc_hash`` function is mainly used in the ``MEASURED_BOOT``
292*8edd6c6fSRyan Everettand ``DRTM_SUPPORT`` features to calculate the hashes of various images/data.
293*8edd6c6fSRyan Everett
294*8edd6c6fSRyan EverettThe ``_auth_decrypt`` function uses an authentication tag to perform
295*8edd6c6fSRyan Everettauthenticated decryption, providing guarantees on the authenticity
296*8edd6c6fSRyan Everettof encrypted data. This function is used when the optional encrypted
297*8edd6c6fSRyan Everettfirmware feature is enabled, that is when ``ENCRYPT_BL31`` or
298*8edd6c6fSRyan Everett``ENCRYPT_BL32`` are set to ``1`` and ``DECRYPTION_SUPPORT`` is
299*8edd6c6fSRyan Everettset to ``aes_gcm``.
300f28057a2SManish V Badarkhe
3014ac5b394SYann GautierOptionally, a platform function can be provided to convert public key
3024ac5b394SYann Gautier(_convert_pk). It is only used if the platform saves a hash of the ROTPK.
3034ac5b394SYann GautierMost platforms save the hash of the ROTPK, but some may save slightly different
3044ac5b394SYann Gautierinformation - e.g the hash of the ROTPK plus some related information.
3054ac5b394SYann GautierDefining this function allows to transform the ROTPK used to verify
3064ac5b394SYann Gautierthe signature to the buffer (a platform specific public key) which
3074ac5b394SYann Gautierhash is saved in OTP.
3084ac5b394SYann Gautier
3094ac5b394SYann Gautier.. code:: c
3104ac5b394SYann Gautier
3114ac5b394SYann Gautier    int (*convert_pk)(void *full_pk_ptr, unsigned int full_pk_len,
3124ac5b394SYann Gautier                      void **hashed_pk_ptr, unsigned int *hashed_pk_len);
3134ac5b394SYann Gautier
3144ac5b394SYann Gautier
3154ac5b394SYann Gautier-  ``full_pk_ptr``: Pointer to Distinguished Encoding Rules (DER) ROTPK.
3164ac5b394SYann Gautier-  ``full_pk_len``: DER ROTPK size.
3174ac5b394SYann Gautier-  ``hashed_pk_ptr``: to return a pointer to a buffer, which hash should be the one saved in OTP.
3184ac5b394SYann Gautier-  ``hashed_pk_len``: previous buffer size
3194ac5b394SYann Gautier
32040d553cfSPaul BeesleyImage Parser Module (IPM)
32140d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^
32240d553cfSPaul Beesley
32340d553cfSPaul BeesleyThe IPM is responsible for:
32440d553cfSPaul Beesley
32540d553cfSPaul Beesley#. Checking the integrity of each image loaded by the IO framework.
32640d553cfSPaul Beesley#. Extracting parameters used for authenticating an image based upon a
32740d553cfSPaul Beesley   description provided by the platform in the CoT descriptor.
32840d553cfSPaul Beesley
32940d553cfSPaul BeesleyImages may have different formats (for example, authentication images could be
33040d553cfSPaul Beesleyx509v3 certificates, signed ELF files or any other platform specific format).
33140d553cfSPaul BeesleyThe IPM allows to register an Image Parser Library (IPL) for every image format
33240d553cfSPaul Beesleyused in the CoT. This library must implement the specific methods to parse the
33340d553cfSPaul Beesleyimage. The IPM obtains the image format from the CoT and calls the right IPL to
33440d553cfSPaul Beesleycheck the image integrity and extract the authentication parameters.
33540d553cfSPaul Beesley
33640d553cfSPaul BeesleySee Section "Describing the image parsing methods" for more details about the
33740d553cfSPaul Beesleymechanism the IPM provides to define and register IPLs.
33840d553cfSPaul Beesley
33940d553cfSPaul BeesleyAuthentication methods
34040d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~
34140d553cfSPaul Beesley
34240d553cfSPaul BeesleyThe AM supports the following authentication methods:
34340d553cfSPaul Beesley
34440d553cfSPaul Beesley#. Hash
34540d553cfSPaul Beesley#. Digital signature
34640d553cfSPaul Beesley
34740d553cfSPaul BeesleyThe platform may specify these methods in the CoT in case it decides to define
34840d553cfSPaul Beesleya custom CoT instead of reusing a predefined one.
34940d553cfSPaul Beesley
35040d553cfSPaul BeesleyIf a data image uses multiple methods, then all the methods must be a part of
35140d553cfSPaul Beesleythe same CoT. The number and type of parameters are method specific. These
35240d553cfSPaul Beesleyparameters should be obtained from the parent image using the IPM.
35340d553cfSPaul Beesley
35440d553cfSPaul Beesley#. Hash
35540d553cfSPaul Beesley
35640d553cfSPaul Beesley   Parameters:
35740d553cfSPaul Beesley
35840d553cfSPaul Beesley   #. A pointer to data to hash
35940d553cfSPaul Beesley   #. Length of the data
36040d553cfSPaul Beesley   #. A pointer to the hash
36140d553cfSPaul Beesley   #. Length of the hash
36240d553cfSPaul Beesley
36340d553cfSPaul Beesley   The hash will be represented by the DER encoding of the following ASN.1
36440d553cfSPaul Beesley   type:
36540d553cfSPaul Beesley
36640d553cfSPaul Beesley   ::
36740d553cfSPaul Beesley
36840d553cfSPaul Beesley       DigestInfo ::= SEQUENCE {
36940d553cfSPaul Beesley           digestAlgorithm  DigestAlgorithmIdentifier,
37040d553cfSPaul Beesley           digest           Digest
37140d553cfSPaul Beesley       }
37240d553cfSPaul Beesley
37340d553cfSPaul Beesley   This ASN.1 structure makes it possible to remove any assumption about the
37440d553cfSPaul Beesley   type of hash algorithm used as this information accompanies the hash. This
37540d553cfSPaul Beesley   should allow the Cryptography Library (CL) to support multiple hash
37640d553cfSPaul Beesley   algorithm implementations.
37740d553cfSPaul Beesley
37840d553cfSPaul Beesley#. Digital Signature
37940d553cfSPaul Beesley
38040d553cfSPaul Beesley   Parameters:
38140d553cfSPaul Beesley
38240d553cfSPaul Beesley   #. A pointer to data to sign
38340d553cfSPaul Beesley   #. Length of the data
38440d553cfSPaul Beesley   #. Public Key Algorithm
38540d553cfSPaul Beesley   #. Public Key value
38640d553cfSPaul Beesley   #. Digital Signature Algorithm
38740d553cfSPaul Beesley   #. Digital Signature value
38840d553cfSPaul Beesley
38940d553cfSPaul Beesley   The Public Key parameters will be represented by the DER encoding of the
39040d553cfSPaul Beesley   following ASN.1 type:
39140d553cfSPaul Beesley
39240d553cfSPaul Beesley   ::
39340d553cfSPaul Beesley
39440d553cfSPaul Beesley       SubjectPublicKeyInfo  ::=  SEQUENCE  {
39540d553cfSPaul Beesley           algorithm         AlgorithmIdentifier{PUBLIC-KEY,{PublicKeyAlgorithms}},
39640d553cfSPaul Beesley           subjectPublicKey  BIT STRING  }
39740d553cfSPaul Beesley
39840d553cfSPaul Beesley   The Digital Signature Algorithm will be represented by the DER encoding of
39940d553cfSPaul Beesley   the following ASN.1 types.
40040d553cfSPaul Beesley
40140d553cfSPaul Beesley   ::
40240d553cfSPaul Beesley
40340d553cfSPaul Beesley       AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE {
40440d553cfSPaul Beesley           algorithm         ALGORITHM.&id({IOSet}),
40540d553cfSPaul Beesley           parameters        ALGORITHM.&Type({IOSet}{@algorithm}) OPTIONAL
40640d553cfSPaul Beesley       }
40740d553cfSPaul Beesley
40840d553cfSPaul Beesley   The digital signature will be represented by:
40940d553cfSPaul Beesley
41040d553cfSPaul Beesley   ::
41140d553cfSPaul Beesley
41240d553cfSPaul Beesley       signature  ::=  BIT STRING
41340d553cfSPaul Beesley
41440d553cfSPaul BeesleyThe authentication framework will use the image descriptor to extract all the
41540d553cfSPaul Beesleyinformation related to authentication.
41640d553cfSPaul Beesley
41740d553cfSPaul BeesleySpecifying a Chain of Trust
41840d553cfSPaul Beesley---------------------------
41940d553cfSPaul Beesley
42040d553cfSPaul BeesleyA CoT can be described as a set of image descriptors linked together in a
42140d553cfSPaul Beesleyparticular order. The order dictates the sequence in which they must be
42240d553cfSPaul Beesleyverified. Each image has a set of properties which allow the AM to verify it.
42340d553cfSPaul BeesleyThese properties are described below.
42440d553cfSPaul Beesley
42540d553cfSPaul BeesleyThe PP is responsible for defining a single or multiple CoTs for a data image.
42640d553cfSPaul BeesleyUnless otherwise specified, the data structures described in the following
42740d553cfSPaul Beesleysections are populated by the PP statically.
42840d553cfSPaul Beesley
42940d553cfSPaul BeesleyDescribing the image parsing methods
43040d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43140d553cfSPaul Beesley
43240d553cfSPaul BeesleyThe parsing method refers to the format of a particular image. For example, an
43340d553cfSPaul Beesleyauthentication image that represents a certificate could be in the X.509v3
43440d553cfSPaul Beesleyformat. A data image that represents a boot loader stage could be in raw binary
43540d553cfSPaul Beesleyor ELF format. The IPM supports three parsing methods. An image has to use one
43640d553cfSPaul Beesleyof the three methods described below. An IPL is responsible for interpreting a
43740d553cfSPaul Beesleysingle parsing method. There has to be one IPL for every method used by the
43840d553cfSPaul Beesleyplatform.
43940d553cfSPaul Beesley
44040d553cfSPaul Beesley#. Raw format: This format is effectively a nop as an image using this method
44140d553cfSPaul Beesley   is treated as being in raw binary format e.g. boot loader images used by
44240d553cfSPaul Beesley   TF-A. This method should only be used by data images.
44340d553cfSPaul Beesley
44440d553cfSPaul Beesley#. X509V3 method: This method uses industry standards like X.509 to represent
44540d553cfSPaul Beesley   PKI certificates (authentication images). It is expected that open source
44640d553cfSPaul Beesley   libraries will be available which can be used to parse an image represented
44740d553cfSPaul Beesley   by this method. Such libraries can be used to write the corresponding IPL
44840d553cfSPaul Beesley   e.g. the X.509 parsing library code in mbed TLS.
44940d553cfSPaul Beesley
45040d553cfSPaul Beesley#. Platform defined method: This method caters for platform specific
45140d553cfSPaul Beesley   proprietary standards to represent authentication or data images. For
45240d553cfSPaul Beesley   example, The signature of a data image could be appended to the data image
45340d553cfSPaul Beesley   raw binary. A header could be prepended to the combined blob to specify the
45440d553cfSPaul Beesley   extents of each component. The platform will have to implement the
45540d553cfSPaul Beesley   corresponding IPL to interpret such a format.
45640d553cfSPaul Beesley
45740d553cfSPaul BeesleyThe following enum can be used to define these three methods.
45840d553cfSPaul Beesley
45940d553cfSPaul Beesley.. code:: c
46040d553cfSPaul Beesley
46140d553cfSPaul Beesley    typedef enum img_type_enum {
46240d553cfSPaul Beesley        IMG_RAW,            /* Binary image */
46340d553cfSPaul Beesley        IMG_PLAT,           /* Platform specific format */
46440d553cfSPaul Beesley        IMG_CERT,           /* X509v3 certificate */
46540d553cfSPaul Beesley        IMG_MAX_TYPES,
46640d553cfSPaul Beesley    } img_type_t;
46740d553cfSPaul Beesley
46840d553cfSPaul BeesleyAn IPL must provide functions with the following prototypes:
46940d553cfSPaul Beesley
47040d553cfSPaul Beesley.. code:: c
47140d553cfSPaul Beesley
47240d553cfSPaul Beesley    void init(void);
47340d553cfSPaul Beesley    int check_integrity(void *img, unsigned int img_len);
47440d553cfSPaul Beesley    int get_auth_param(const auth_param_type_desc_t *type_desc,
47540d553cfSPaul Beesley                          void *img, unsigned int img_len,
47640d553cfSPaul Beesley                          void **param, unsigned int *param_len);
47740d553cfSPaul Beesley
47840d553cfSPaul BeesleyAn IPL for each type must be registered using the following macro:
47940d553cfSPaul Beesley
48029c02529SPaul Beesley.. code:: c
48140d553cfSPaul Beesley
48240d553cfSPaul Beesley    REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param)
48340d553cfSPaul Beesley
48440d553cfSPaul Beesley-  ``_type``: one of the types described above.
48540d553cfSPaul Beesley-  ``_name``: a string containing the IPL name for debugging purposes.
48640d553cfSPaul Beesley-  ``_init``: initialization function pointer.
48740d553cfSPaul Beesley-  ``_check_int``: check image integrity function pointer.
48840d553cfSPaul Beesley-  ``_get_param``: extract authentication parameter function pointer.
48940d553cfSPaul Beesley
49040d553cfSPaul BeesleyThe ``init()`` function will be used to initialize the IPL.
49140d553cfSPaul Beesley
49240d553cfSPaul BeesleyThe ``check_integrity()`` function is passed a pointer to the memory where the
49340d553cfSPaul Beesleyimage has been loaded by the IO framework and the image length. It should ensure
49440d553cfSPaul Beesleythat the image is in the format corresponding to the parsing method and has not
49540d553cfSPaul Beesleybeen tampered with. For example, RFC-2459 describes a validation sequence for an
49640d553cfSPaul BeesleyX.509 certificate.
49740d553cfSPaul Beesley
49840d553cfSPaul BeesleyThe ``get_auth_param()`` function is passed a parameter descriptor containing
49940d553cfSPaul Beesleyinformation about the parameter (``type_desc`` and ``cookie``) to identify and
50040d553cfSPaul Beesleyextract the data corresponding to that parameter from an image. This data will
50140d553cfSPaul Beesleybe used to verify either the current or the next image in the CoT sequence.
50240d553cfSPaul Beesley
50340d553cfSPaul BeesleyEach image in the CoT will specify the parsing method it uses. This information
50440d553cfSPaul Beesleywill be used by the IPM to find the right parser descriptor for the image.
50540d553cfSPaul Beesley
50640d553cfSPaul BeesleyDescribing the authentication method(s)
50740d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50840d553cfSPaul Beesley
50940d553cfSPaul BeesleyAs part of the CoT, each image has to specify one or more authentication methods
51040d553cfSPaul Beesleywhich will be used to verify it. As described in the Section "Authentication
51140d553cfSPaul Beesleymethods", there are three methods supported by the AM.
51240d553cfSPaul Beesley
51340d553cfSPaul Beesley.. code:: c
51440d553cfSPaul Beesley
51540d553cfSPaul Beesley    typedef enum {
51640d553cfSPaul Beesley        AUTH_METHOD_NONE,
51740d553cfSPaul Beesley        AUTH_METHOD_HASH,
51840d553cfSPaul Beesley        AUTH_METHOD_SIG,
51940d553cfSPaul Beesley        AUTH_METHOD_NUM
52040d553cfSPaul Beesley    } auth_method_type_t;
52140d553cfSPaul Beesley
52240d553cfSPaul BeesleyThe AM defines the type of each parameter used by an authentication method. It
52340d553cfSPaul Beesleyuses this information to:
52440d553cfSPaul Beesley
52540d553cfSPaul Beesley#. Specify to the ``get_auth_param()`` function exported by the IPM, which
52640d553cfSPaul Beesley   parameter should be extracted from an image.
52740d553cfSPaul Beesley
52840d553cfSPaul Beesley#. Correctly marshall the parameters while calling the verification function
52940d553cfSPaul Beesley   exported by the CM and PP.
53040d553cfSPaul Beesley
53140d553cfSPaul Beesley#. Extract authentication parameters from a parent image in order to verify a
53240d553cfSPaul Beesley   child image e.g. to verify the certificate image, the public key has to be
53340d553cfSPaul Beesley   obtained from the parent image.
53440d553cfSPaul Beesley
53540d553cfSPaul Beesley.. code:: c
53640d553cfSPaul Beesley
53740d553cfSPaul Beesley    typedef enum {
53840d553cfSPaul Beesley        AUTH_PARAM_NONE,
53940d553cfSPaul Beesley        AUTH_PARAM_RAW_DATA,    /* Raw image data */
54040d553cfSPaul Beesley        AUTH_PARAM_SIG,         /* The image signature */
54140d553cfSPaul Beesley        AUTH_PARAM_SIG_ALG,     /* The image signature algorithm */
54240d553cfSPaul Beesley        AUTH_PARAM_HASH,        /* A hash (including the algorithm) */
54340d553cfSPaul Beesley        AUTH_PARAM_PUB_KEY,     /* A public key */
544e3f9ed85SSandrine Bailleux        AUTH_PARAM_NV_CTR,      /* A non-volatile counter */
54540d553cfSPaul Beesley    } auth_param_type_t;
54640d553cfSPaul Beesley
54740d553cfSPaul BeesleyThe AM defines the following structure to identify an authentication parameter
54840d553cfSPaul Beesleyrequired to verify an image.
54940d553cfSPaul Beesley
55040d553cfSPaul Beesley.. code:: c
55140d553cfSPaul Beesley
55240d553cfSPaul Beesley    typedef struct auth_param_type_desc_s {
55340d553cfSPaul Beesley        auth_param_type_t type;
55440d553cfSPaul Beesley        void *cookie;
55540d553cfSPaul Beesley    } auth_param_type_desc_t;
55640d553cfSPaul Beesley
55740d553cfSPaul Beesley``cookie`` is used by the platform to specify additional information to the IPM
55840d553cfSPaul Beesleywhich enables it to uniquely identify the parameter that should be extracted
55940d553cfSPaul Beesleyfrom an image. For example, the hash of a BL3x image in its corresponding
56040d553cfSPaul Beesleycontent certificate is stored in an X509v3 custom extension field. An extension
56140d553cfSPaul Beesleyfield can only be identified using an OID. In this case, the ``cookie`` could
56240d553cfSPaul Beesleycontain the pointer to the OID defined by the platform for the hash extension
56340d553cfSPaul Beesleyfield while the ``type`` field could be set to ``AUTH_PARAM_HASH``. A value of 0 for
56440d553cfSPaul Beesleythe ``cookie`` field means that it is not used.
56540d553cfSPaul Beesley
56640d553cfSPaul BeesleyFor each method, the AM defines a structure with the parameters required to
56740d553cfSPaul Beesleyverify the image.
56840d553cfSPaul Beesley
56940d553cfSPaul Beesley.. code:: c
57040d553cfSPaul Beesley
57140d553cfSPaul Beesley    /*
57240d553cfSPaul Beesley     * Parameters for authentication by hash matching
57340d553cfSPaul Beesley     */
57440d553cfSPaul Beesley    typedef struct auth_method_param_hash_s {
57540d553cfSPaul Beesley        auth_param_type_desc_t *data;   /* Data to hash */
57640d553cfSPaul Beesley        auth_param_type_desc_t *hash;   /* Hash to match with */
57740d553cfSPaul Beesley    } auth_method_param_hash_t;
57840d553cfSPaul Beesley
57940d553cfSPaul Beesley    /*
58040d553cfSPaul Beesley     * Parameters for authentication by signature
58140d553cfSPaul Beesley     */
58240d553cfSPaul Beesley    typedef struct auth_method_param_sig_s {
58340d553cfSPaul Beesley        auth_param_type_desc_t *pk; /* Public key */
58440d553cfSPaul Beesley        auth_param_type_desc_t *sig;    /* Signature to check */
58540d553cfSPaul Beesley        auth_param_type_desc_t *alg;    /* Signature algorithm */
58640d553cfSPaul Beesley        auth_param_type_desc_t *tbs;    /* Data signed */
58740d553cfSPaul Beesley    } auth_method_param_sig_t;
58840d553cfSPaul Beesley
58940d553cfSPaul BeesleyThe AM defines the following structure to describe an authentication method for
59040d553cfSPaul Beesleyverifying an image
59140d553cfSPaul Beesley
59240d553cfSPaul Beesley.. code:: c
59340d553cfSPaul Beesley
59440d553cfSPaul Beesley    /*
59540d553cfSPaul Beesley     * Authentication method descriptor
59640d553cfSPaul Beesley     */
59740d553cfSPaul Beesley    typedef struct auth_method_desc_s {
59840d553cfSPaul Beesley        auth_method_type_t type;
59940d553cfSPaul Beesley        union {
60040d553cfSPaul Beesley            auth_method_param_hash_t hash;
60140d553cfSPaul Beesley            auth_method_param_sig_t sig;
60240d553cfSPaul Beesley        } param;
60340d553cfSPaul Beesley    } auth_method_desc_t;
60440d553cfSPaul Beesley
60540d553cfSPaul BeesleyUsing the method type specified in the ``type`` field, the AM finds out what field
60640d553cfSPaul Beesleyneeds to access within the ``param`` union.
60740d553cfSPaul Beesley
60840d553cfSPaul BeesleyStoring Authentication parameters
60940d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61040d553cfSPaul Beesley
61140d553cfSPaul BeesleyA parameter described by ``auth_param_type_desc_t`` to verify an image could be
61240d553cfSPaul Beesleyobtained from either the image itself or its parent image. The memory allocated
61340d553cfSPaul Beesleyfor loading the parent image will be reused for loading the child image. Hence
61440d553cfSPaul Beesleyparameters which are obtained from the parent for verifying a child image need
61540d553cfSPaul Beesleyto have memory allocated for them separately where they can be stored. This
61640d553cfSPaul Beesleymemory must be statically allocated by the platform port.
61740d553cfSPaul Beesley
61840d553cfSPaul BeesleyThe AM defines the following structure to store the data corresponding to an
61940d553cfSPaul Beesleyauthentication parameter.
62040d553cfSPaul Beesley
62140d553cfSPaul Beesley.. code:: c
62240d553cfSPaul Beesley
62340d553cfSPaul Beesley    typedef struct auth_param_data_desc_s {
62440d553cfSPaul Beesley        void *auth_param_ptr;
62540d553cfSPaul Beesley        unsigned int auth_param_len;
62640d553cfSPaul Beesley    } auth_param_data_desc_t;
62740d553cfSPaul Beesley
62840d553cfSPaul BeesleyThe ``auth_param_ptr`` field is initialized by the platform. The ``auth_param_len``
62940d553cfSPaul Beesleyfield is used to specify the length of the data in the memory.
63040d553cfSPaul Beesley
63140d553cfSPaul BeesleyFor parameters that can be obtained from the child image itself, the IPM is
63240d553cfSPaul Beesleyresponsible for populating the ``auth_param_ptr`` and ``auth_param_len`` fields
63340d553cfSPaul Beesleywhile executing the ``img_get_auth_param()`` function.
63440d553cfSPaul Beesley
63540d553cfSPaul BeesleyThe AM defines the following structure to enable an image to describe the
63640d553cfSPaul Beesleyparameters that should be extracted from it and used to verify the next image
63740d553cfSPaul Beesley(child) in a CoT.
63840d553cfSPaul Beesley
63940d553cfSPaul Beesley.. code:: c
64040d553cfSPaul Beesley
64140d553cfSPaul Beesley    typedef struct auth_param_desc_s {
64240d553cfSPaul Beesley        auth_param_type_desc_t type_desc;
64340d553cfSPaul Beesley        auth_param_data_desc_t data;
64440d553cfSPaul Beesley    } auth_param_desc_t;
64540d553cfSPaul Beesley
64640d553cfSPaul BeesleyDescribing an image in a CoT
64740d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64840d553cfSPaul Beesley
64940d553cfSPaul BeesleyAn image in a CoT is a consolidation of the following aspects of a CoT described
65040d553cfSPaul Beesleyabove.
65140d553cfSPaul Beesley
65240d553cfSPaul Beesley#. A unique identifier specified by the platform which allows the IO framework
65340d553cfSPaul Beesley   to locate the image in a FIP and load it in the memory reserved for the data
65440d553cfSPaul Beesley   image in the CoT.
65540d553cfSPaul Beesley
65640d553cfSPaul Beesley#. A parsing method which is used by the AM to find the appropriate IPM.
65740d553cfSPaul Beesley
65840d553cfSPaul Beesley#. Authentication methods and their parameters as described in the previous
65940d553cfSPaul Beesley   section. These are used to verify the current image.
66040d553cfSPaul Beesley
66140d553cfSPaul Beesley#. Parameters which are used to verify the next image in the current CoT. These
66240d553cfSPaul Beesley   parameters are specified only by authentication images and can be extracted
66340d553cfSPaul Beesley   from the current image once it has been verified.
66440d553cfSPaul Beesley
66540d553cfSPaul BeesleyThe following data structure describes an image in a CoT.
66640d553cfSPaul Beesley
66740d553cfSPaul Beesley.. code:: c
66840d553cfSPaul Beesley
66940d553cfSPaul Beesley    typedef struct auth_img_desc_s {
67040d553cfSPaul Beesley        unsigned int img_id;
67140d553cfSPaul Beesley        const struct auth_img_desc_s *parent;
67240d553cfSPaul Beesley        img_type_t img_type;
67340d553cfSPaul Beesley        const auth_method_desc_t *const img_auth_methods;
67440d553cfSPaul Beesley        const auth_param_desc_t *const authenticated_data;
67540d553cfSPaul Beesley    } auth_img_desc_t;
67640d553cfSPaul Beesley
67740d553cfSPaul BeesleyA CoT is defined as an array of pointers to ``auth_image_desc_t`` structures
67840d553cfSPaul Beesleylinked together by the ``parent`` field. Those nodes with no parent must be
67940d553cfSPaul Beesleyauthenticated using the ROTPK stored in the platform.
68040d553cfSPaul Beesley
68140d553cfSPaul BeesleyImplementation example
68240d553cfSPaul Beesley----------------------
68340d553cfSPaul Beesley
68440d553cfSPaul BeesleyThis section is a detailed guide explaining a trusted boot implementation using
68540d553cfSPaul Beesleythe authentication framework. This example corresponds to the Applicative
68640d553cfSPaul BeesleyFunctional Mode (AFM) as specified in the TBBR-Client document. It is
68740d553cfSPaul Beesleyrecommended to read this guide along with the source code.
68840d553cfSPaul Beesley
68940d553cfSPaul BeesleyThe TBBR CoT
69040d553cfSPaul Beesley~~~~~~~~~~~~
69140d553cfSPaul Beesley
692ad43c49eSManish V BadarkheCoT specific to BL1 and BL2 can be found in ``drivers/auth/tbbr/tbbr_cot_bl1.c``
693ad43c49eSManish V Badarkheand ``drivers/auth/tbbr/tbbr_cot_bl2.c`` respectively. The common CoT used across
694ad43c49eSManish V BadarkheBL1 and BL2 can be found in ``drivers/auth/tbbr/tbbr_cot_common.c``.
695ad43c49eSManish V BadarkheThis CoT consists of an array of pointers to image descriptors and it is
696ad43c49eSManish V Badarkheregistered in the framework using the macro ``REGISTER_COT(cot_desc)``, where
697ad43c49eSManish V Badarkhe``cot_desc`` must be the name of the array (passing a pointer or any other
698ad43c49eSManish V Badarkhetype of indirection will cause the registration process to fail).
69940d553cfSPaul Beesley
70040d553cfSPaul BeesleyThe number of images participating in the boot process depends on the CoT.
70140d553cfSPaul BeesleyThere is, however, a minimum set of images that are mandatory in TF-A and thus
70240d553cfSPaul Beesleyall CoTs must present:
70340d553cfSPaul Beesley
70440d553cfSPaul Beesley-  ``BL2``
70540d553cfSPaul Beesley-  ``SCP_BL2`` (platform specific)
70640d553cfSPaul Beesley-  ``BL31``
70740d553cfSPaul Beesley-  ``BL32`` (optional)
70840d553cfSPaul Beesley-  ``BL33``
70940d553cfSPaul Beesley
71040d553cfSPaul BeesleyThe TBBR specifies the additional certificates that must accompany these images
71140d553cfSPaul Beesleyfor a proper authentication. Details about the TBBR CoT may be found in the
71234760951SPaul Beesley:ref:`Trusted Board Boot` document.
71340d553cfSPaul Beesley
71434760951SPaul BeesleyFollowing the :ref:`Porting Guide`, a platform must provide unique
71540d553cfSPaul Beesleyidentifiers for all the images and certificates that will be loaded during the
71640d553cfSPaul Beesleyboot process. If a platform is using the TBBR as a reference for trusted boot,
71740d553cfSPaul Beesleythese identifiers can be obtained from ``include/common/tbbr/tbbr_img_def.h``.
71840d553cfSPaul BeesleyArm platforms include this file in ``include/plat/arm/common/arm_def.h``. Other
71940d553cfSPaul Beesleyplatforms may also include this file or provide their own identifiers.
72040d553cfSPaul Beesley
72140d553cfSPaul Beesley**Important**: the authentication module uses these identifiers to index the
72240d553cfSPaul BeesleyCoT array, so the descriptors location in the array must match the identifiers.
72340d553cfSPaul Beesley
72440d553cfSPaul BeesleyEach image descriptor must specify:
72540d553cfSPaul Beesley
72640d553cfSPaul Beesley-  ``img_id``: the corresponding image unique identifier defined by the platform.
72740d553cfSPaul Beesley-  ``img_type``: the image parser module uses the image type to call the proper
72840d553cfSPaul Beesley   parsing library to check the image integrity and extract the required
72940d553cfSPaul Beesley   authentication parameters. Three types of images are currently supported:
73040d553cfSPaul Beesley
73140d553cfSPaul Beesley   -  ``IMG_RAW``: image is a raw binary. No parsing functions are available,
73240d553cfSPaul Beesley      other than reading the whole image.
73340d553cfSPaul Beesley   -  ``IMG_PLAT``: image format is platform specific. The platform may use this
73440d553cfSPaul Beesley      type for custom images not directly supported by the authentication
73540d553cfSPaul Beesley      framework.
73640d553cfSPaul Beesley   -  ``IMG_CERT``: image is an x509v3 certificate.
73740d553cfSPaul Beesley
73840d553cfSPaul Beesley-  ``parent``: pointer to the parent image descriptor. The parent will contain
73940d553cfSPaul Beesley   the information required to authenticate the current image. If the parent
74040d553cfSPaul Beesley   is NULL, the authentication parameters will be obtained from the platform
74140d553cfSPaul Beesley   (i.e. the BL2 and Trusted Key certificates are signed with the ROT private
74240d553cfSPaul Beesley   key, whose public part is stored in the platform).
74340d553cfSPaul Beesley-  ``img_auth_methods``: this points to an array which defines the
74440d553cfSPaul Beesley   authentication methods that must be checked to consider an image
74540d553cfSPaul Beesley   authenticated. Each method consists of a type and a list of parameter
74640d553cfSPaul Beesley   descriptors. A parameter descriptor consists of a type and a cookie which
74740d553cfSPaul Beesley   will point to specific information required to extract that parameter from
74840d553cfSPaul Beesley   the image (i.e. if the parameter is stored in an x509v3 extension, the
74940d553cfSPaul Beesley   cookie will point to the extension OID). Depending on the method type, a
75040d553cfSPaul Beesley   different number of parameters must be specified. This pointer should not be
75140d553cfSPaul Beesley   NULL.
75240d553cfSPaul Beesley   Supported methods are:
75340d553cfSPaul Beesley
75440d553cfSPaul Beesley   -  ``AUTH_METHOD_HASH``: the hash of the image must match the hash extracted
75540d553cfSPaul Beesley      from the parent image. The following parameter descriptors must be
75640d553cfSPaul Beesley      specified:
75740d553cfSPaul Beesley
75840d553cfSPaul Beesley      -  ``data``: data to be hashed (obtained from current image)
75940d553cfSPaul Beesley      -  ``hash``: reference hash (obtained from parent image)
76040d553cfSPaul Beesley
76140d553cfSPaul Beesley   -  ``AUTH_METHOD_SIG``: the image (usually a certificate) must be signed with
76240d553cfSPaul Beesley      the private key whose public part is extracted from the parent image (or
76340d553cfSPaul Beesley      the platform if the parent is NULL). The following parameter descriptors
76440d553cfSPaul Beesley      must be specified:
76540d553cfSPaul Beesley
76640d553cfSPaul Beesley      -  ``pk``: the public key (obtained from parent image)
76740d553cfSPaul Beesley      -  ``sig``: the digital signature (obtained from current image)
76840d553cfSPaul Beesley      -  ``alg``: the signature algorithm used (obtained from current image)
76940d553cfSPaul Beesley      -  ``data``: the data to be signed (obtained from current image)
77040d553cfSPaul Beesley
77140d553cfSPaul Beesley-  ``authenticated_data``: this array pointer indicates what authentication
77240d553cfSPaul Beesley   parameters must be extracted from an image once it has been authenticated.
77340d553cfSPaul Beesley   Each parameter consists of a parameter descriptor and the buffer
77440d553cfSPaul Beesley   address/size to store the parameter. The CoT is responsible for allocating
77540d553cfSPaul Beesley   the required memory to store the parameters. This pointer may be NULL.
77640d553cfSPaul Beesley
777ad43c49eSManish V BadarkheIn the ``tbbr_cot*.c`` file, a set of buffers are allocated to store the parameters
77840d553cfSPaul Beesleyextracted from the certificates. In the case of the TBBR CoT, these parameters
779f29213d9SJustin Chadwellare hashes and public keys. In DER format, an RSA-4096 public key requires 550
78040d553cfSPaul Beesleybytes, and a hash requires 51 bytes. Depending on the CoT and the authentication
78140d553cfSPaul Beesleyprocess, some of the buffers may be reused at different stages during the boot.
78240d553cfSPaul Beesley
78340d553cfSPaul BeesleyNext in that file, the parameter descriptors are defined. These descriptors will
78440d553cfSPaul Beesleybe used to extract the parameter data from the corresponding image.
78540d553cfSPaul Beesley
78640d553cfSPaul BeesleyExample: the BL31 Chain of Trust
78740d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78840d553cfSPaul Beesley
78940d553cfSPaul BeesleyFour image descriptors form the BL31 Chain of Trust:
79040d553cfSPaul Beesley
79140d553cfSPaul Beesley.. code:: c
79240d553cfSPaul Beesley
79340d553cfSPaul Beesley    static const auth_img_desc_t trusted_key_cert = {
79440d553cfSPaul Beesley            .img_id = TRUSTED_KEY_CERT_ID,
79540d553cfSPaul Beesley            .img_type = IMG_CERT,
79640d553cfSPaul Beesley            .parent = NULL,
79740d553cfSPaul Beesley            .img_auth_methods =  (const auth_method_desc_t[AUTH_METHOD_NUM]) {
79840d553cfSPaul Beesley                    [0] = {
79940d553cfSPaul Beesley                            .type = AUTH_METHOD_SIG,
80040d553cfSPaul Beesley                            .param.sig = {
80140d553cfSPaul Beesley                                    .pk = &subject_pk,
80240d553cfSPaul Beesley                                    .sig = &sig,
80340d553cfSPaul Beesley                                    .alg = &sig_alg,
80440d553cfSPaul Beesley                                    .data = &raw_data
80540d553cfSPaul Beesley                            }
80640d553cfSPaul Beesley                    },
80740d553cfSPaul Beesley                    [1] = {
80840d553cfSPaul Beesley                            .type = AUTH_METHOD_NV_CTR,
80940d553cfSPaul Beesley                            .param.nv_ctr = {
81040d553cfSPaul Beesley                                    .cert_nv_ctr = &trusted_nv_ctr,
81140d553cfSPaul Beesley                                    .plat_nv_ctr = &trusted_nv_ctr
81240d553cfSPaul Beesley                            }
81340d553cfSPaul Beesley                    }
81440d553cfSPaul Beesley            },
81540d553cfSPaul Beesley            .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
81640d553cfSPaul Beesley                    [0] = {
81740d553cfSPaul Beesley                            .type_desc = &trusted_world_pk,
81840d553cfSPaul Beesley                            .data = {
81940d553cfSPaul Beesley                                    .ptr = (void *)trusted_world_pk_buf,
82040d553cfSPaul Beesley                                    .len = (unsigned int)PK_DER_LEN
82140d553cfSPaul Beesley                            }
82240d553cfSPaul Beesley                    },
82340d553cfSPaul Beesley                    [1] = {
82440d553cfSPaul Beesley                            .type_desc = &non_trusted_world_pk,
82540d553cfSPaul Beesley                            .data = {
82640d553cfSPaul Beesley                                    .ptr = (void *)non_trusted_world_pk_buf,
82740d553cfSPaul Beesley                                    .len = (unsigned int)PK_DER_LEN
82840d553cfSPaul Beesley                            }
82940d553cfSPaul Beesley                    }
83040d553cfSPaul Beesley            }
83140d553cfSPaul Beesley    };
83240d553cfSPaul Beesley    static const auth_img_desc_t soc_fw_key_cert = {
83340d553cfSPaul Beesley            .img_id = SOC_FW_KEY_CERT_ID,
83440d553cfSPaul Beesley            .img_type = IMG_CERT,
83540d553cfSPaul Beesley            .parent = &trusted_key_cert,
83640d553cfSPaul Beesley            .img_auth_methods =  (const auth_method_desc_t[AUTH_METHOD_NUM]) {
83740d553cfSPaul Beesley                    [0] = {
83840d553cfSPaul Beesley                            .type = AUTH_METHOD_SIG,
83940d553cfSPaul Beesley                            .param.sig = {
84040d553cfSPaul Beesley                                    .pk = &trusted_world_pk,
84140d553cfSPaul Beesley                                    .sig = &sig,
84240d553cfSPaul Beesley                                    .alg = &sig_alg,
84340d553cfSPaul Beesley                                    .data = &raw_data
84440d553cfSPaul Beesley                            }
84540d553cfSPaul Beesley                    },
84640d553cfSPaul Beesley                    [1] = {
84740d553cfSPaul Beesley                            .type = AUTH_METHOD_NV_CTR,
84840d553cfSPaul Beesley                            .param.nv_ctr = {
84940d553cfSPaul Beesley                                    .cert_nv_ctr = &trusted_nv_ctr,
85040d553cfSPaul Beesley                                    .plat_nv_ctr = &trusted_nv_ctr
85140d553cfSPaul Beesley                            }
85240d553cfSPaul Beesley                    }
85340d553cfSPaul Beesley            },
85440d553cfSPaul Beesley            .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
85540d553cfSPaul Beesley                    [0] = {
85640d553cfSPaul Beesley                            .type_desc = &soc_fw_content_pk,
85740d553cfSPaul Beesley                            .data = {
85840d553cfSPaul Beesley                                    .ptr = (void *)content_pk_buf,
85940d553cfSPaul Beesley                                    .len = (unsigned int)PK_DER_LEN
86040d553cfSPaul Beesley                            }
86140d553cfSPaul Beesley                    }
86240d553cfSPaul Beesley            }
86340d553cfSPaul Beesley    };
86440d553cfSPaul Beesley    static const auth_img_desc_t soc_fw_content_cert = {
86540d553cfSPaul Beesley            .img_id = SOC_FW_CONTENT_CERT_ID,
86640d553cfSPaul Beesley            .img_type = IMG_CERT,
86740d553cfSPaul Beesley            .parent = &soc_fw_key_cert,
86840d553cfSPaul Beesley            .img_auth_methods =  (const auth_method_desc_t[AUTH_METHOD_NUM]) {
86940d553cfSPaul Beesley                    [0] = {
87040d553cfSPaul Beesley                            .type = AUTH_METHOD_SIG,
87140d553cfSPaul Beesley                            .param.sig = {
87240d553cfSPaul Beesley                                    .pk = &soc_fw_content_pk,
87340d553cfSPaul Beesley                                    .sig = &sig,
87440d553cfSPaul Beesley                                    .alg = &sig_alg,
87540d553cfSPaul Beesley                                    .data = &raw_data
87640d553cfSPaul Beesley                            }
87740d553cfSPaul Beesley                    },
87840d553cfSPaul Beesley                    [1] = {
87940d553cfSPaul Beesley                            .type = AUTH_METHOD_NV_CTR,
88040d553cfSPaul Beesley                            .param.nv_ctr = {
88140d553cfSPaul Beesley                                    .cert_nv_ctr = &trusted_nv_ctr,
88240d553cfSPaul Beesley                                    .plat_nv_ctr = &trusted_nv_ctr
88340d553cfSPaul Beesley                            }
88440d553cfSPaul Beesley                    }
88540d553cfSPaul Beesley            },
88640d553cfSPaul Beesley            .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) {
88740d553cfSPaul Beesley                    [0] = {
88840d553cfSPaul Beesley                            .type_desc = &soc_fw_hash,
88940d553cfSPaul Beesley                            .data = {
89040d553cfSPaul Beesley                                    .ptr = (void *)soc_fw_hash_buf,
89140d553cfSPaul Beesley                                    .len = (unsigned int)HASH_DER_LEN
89240d553cfSPaul Beesley                            }
89340d553cfSPaul Beesley                    },
89440d553cfSPaul Beesley                    [1] = {
89540d553cfSPaul Beesley                            .type_desc = &soc_fw_config_hash,
89640d553cfSPaul Beesley                            .data = {
89740d553cfSPaul Beesley                                    .ptr = (void *)soc_fw_config_hash_buf,
89840d553cfSPaul Beesley                                    .len = (unsigned int)HASH_DER_LEN
89940d553cfSPaul Beesley                            }
90040d553cfSPaul Beesley                    }
90140d553cfSPaul Beesley            }
90240d553cfSPaul Beesley    };
90340d553cfSPaul Beesley    static const auth_img_desc_t bl31_image = {
90440d553cfSPaul Beesley            .img_id = BL31_IMAGE_ID,
90540d553cfSPaul Beesley            .img_type = IMG_RAW,
90640d553cfSPaul Beesley            .parent = &soc_fw_content_cert,
90740d553cfSPaul Beesley            .img_auth_methods =  (const auth_method_desc_t[AUTH_METHOD_NUM]) {
90840d553cfSPaul Beesley                    [0] = {
90940d553cfSPaul Beesley                            .type = AUTH_METHOD_HASH,
91040d553cfSPaul Beesley                            .param.hash = {
91140d553cfSPaul Beesley                                    .data = &raw_data,
91240d553cfSPaul Beesley                                    .hash = &soc_fw_hash
91340d553cfSPaul Beesley                            }
91440d553cfSPaul Beesley                    }
91540d553cfSPaul Beesley            }
91640d553cfSPaul Beesley    };
91740d553cfSPaul Beesley
91840d553cfSPaul BeesleyThe **Trusted Key certificate** is signed with the ROT private key and contains
91940d553cfSPaul Beesleythe Trusted World public key and the Non-Trusted World public key as x509v3
92040d553cfSPaul Beesleyextensions. This must be specified in the image descriptor using the
92140d553cfSPaul Beesley``img_auth_methods`` and ``authenticated_data`` arrays, respectively.
92240d553cfSPaul Beesley
92340d553cfSPaul BeesleyThe Trusted Key certificate is authenticated by checking its digital signature
92440d553cfSPaul Beesleyusing the ROTPK. Four parameters are required to check a signature: the public
92540d553cfSPaul Beesleykey, the algorithm, the signature and the data that has been signed. Therefore,
92640d553cfSPaul Beesleyfour parameter descriptors must be specified with the authentication method:
92740d553cfSPaul Beesley
92840d553cfSPaul Beesley-  ``subject_pk``: parameter descriptor of type ``AUTH_PARAM_PUB_KEY``. This type
92940d553cfSPaul Beesley   is used to extract a public key from the parent image. If the cookie is an
93040d553cfSPaul Beesley   OID, the key is extracted from the corresponding x509v3 extension. If the
93140d553cfSPaul Beesley   cookie is NULL, the subject public key is retrieved. In this case, because
93240d553cfSPaul Beesley   the parent image is NULL, the public key is obtained from the platform
93340d553cfSPaul Beesley   (this key will be the ROTPK).
93440d553cfSPaul Beesley-  ``sig``: parameter descriptor of type ``AUTH_PARAM_SIG``. It is used to extract
93540d553cfSPaul Beesley   the signature from the certificate.
93640d553cfSPaul Beesley-  ``sig_alg``: parameter descriptor of type ``AUTH_PARAM_SIG``. It is used to
93740d553cfSPaul Beesley   extract the signature algorithm from the certificate.
93840d553cfSPaul Beesley-  ``raw_data``: parameter descriptor of type ``AUTH_PARAM_RAW_DATA``. It is used
93940d553cfSPaul Beesley   to extract the data to be signed from the certificate.
94040d553cfSPaul Beesley
94140d553cfSPaul BeesleyOnce the signature has been checked and the certificate authenticated, the
94240d553cfSPaul BeesleyTrusted World public key needs to be extracted from the certificate. A new entry
94340d553cfSPaul Beesleyis created in the ``authenticated_data`` array for that purpose. In that entry,
94440d553cfSPaul Beesleythe corresponding parameter descriptor must be specified along with the buffer
94551d4e227SSandrine Bailleuxaddress to store the parameter value. In this case, the ``trusted_world_pk``
94651d4e227SSandrine Bailleuxdescriptor is used to extract the public key from an x509v3 extension with OID
94740d553cfSPaul Beesley``TRUSTED_WORLD_PK_OID``. The BL31 key certificate will use this descriptor as
94840d553cfSPaul Beesleyparameter in the signature authentication method. The key is stored in the
94951d4e227SSandrine Bailleux``trusted_world_pk_buf`` buffer.
95040d553cfSPaul Beesley
95140d553cfSPaul BeesleyThe **BL31 Key certificate** is authenticated by checking its digital signature
95240d553cfSPaul Beesleyusing the Trusted World public key obtained previously from the Trusted Key
95340d553cfSPaul Beesleycertificate. In the image descriptor, we specify a single authentication method
95451d4e227SSandrine Bailleuxby signature whose public key is the ``trusted_world_pk``. Once this certificate
95551d4e227SSandrine Bailleuxhas been authenticated, we have to extract the BL31 public key, stored in the
95651d4e227SSandrine Bailleuxextension specified by ``soc_fw_content_pk``. This key will be copied to the
95751d4e227SSandrine Bailleux``content_pk_buf`` buffer.
95840d553cfSPaul Beesley
95940d553cfSPaul BeesleyThe **BL31 certificate** is authenticated by checking its digital signature
96040d553cfSPaul Beesleyusing the BL31 public key obtained previously from the BL31 Key certificate.
96151d4e227SSandrine BailleuxWe specify the authentication method using ``soc_fw_content_pk`` as public key.
96240d553cfSPaul BeesleyAfter authentication, we need to extract the BL31 hash, stored in the extension
96351d4e227SSandrine Bailleuxspecified by ``soc_fw_hash``. This hash will be copied to the
96451d4e227SSandrine Bailleux``soc_fw_hash_buf`` buffer.
96540d553cfSPaul Beesley
96640d553cfSPaul BeesleyThe **BL31 image** is authenticated by calculating its hash and matching it
96740d553cfSPaul Beesleywith the hash obtained from the BL31 certificate. The image descriptor contains
96840d553cfSPaul Beesleya single authentication method by hash. The parameters to the hash method are
96951d4e227SSandrine Bailleuxthe reference hash, ``soc_fw_hash``, and the data to be hashed. In this case,
97051d4e227SSandrine Bailleuxit is the whole image, so we specify ``raw_data``.
97140d553cfSPaul Beesley
97240d553cfSPaul BeesleyThe image parser library
97340d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~
97440d553cfSPaul Beesley
97540d553cfSPaul BeesleyThe image parser module relies on libraries to check the image integrity and
97640d553cfSPaul Beesleyextract the authentication parameters. The number and type of parser libraries
97740d553cfSPaul Beesleydepend on the images used in the CoT. Raw images do not need a library, so
97840d553cfSPaul Beesleyonly an x509v3 library is required for the TBBR CoT.
97940d553cfSPaul Beesley
98040d553cfSPaul BeesleyArm platforms will use an x509v3 library based on mbed TLS. This library may be
98140d553cfSPaul Beesleyfound in ``drivers/auth/mbedtls/mbedtls_x509_parser.c``. It exports three
98240d553cfSPaul Beesleyfunctions:
98340d553cfSPaul Beesley
98440d553cfSPaul Beesley.. code:: c
98540d553cfSPaul Beesley
98640d553cfSPaul Beesley    void init(void);
98740d553cfSPaul Beesley    int check_integrity(void *img, unsigned int img_len);
98840d553cfSPaul Beesley    int get_auth_param(const auth_param_type_desc_t *type_desc,
98940d553cfSPaul Beesley                       void *img, unsigned int img_len,
99040d553cfSPaul Beesley                       void **param, unsigned int *param_len);
99140d553cfSPaul Beesley
99240d553cfSPaul BeesleyThe library is registered in the framework using the macro
99340d553cfSPaul Beesley``REGISTER_IMG_PARSER_LIB()``. Each time the image parser module needs to access
99440d553cfSPaul Beesleyan image of type ``IMG_CERT``, it will call the corresponding function exported
99540d553cfSPaul Beesleyin this file.
99640d553cfSPaul Beesley
99740d553cfSPaul BeesleyThe build system must be updated to include the corresponding library and
99840d553cfSPaul Beesleymbed TLS sources. Arm platforms use the ``arm_common.mk`` file to pull the
99940d553cfSPaul Beesleysources.
100040d553cfSPaul Beesley
100140d553cfSPaul BeesleyThe cryptographic library
100240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~
100340d553cfSPaul Beesley
1004*8edd6c6fSRyan EverettThe cryptographic module relies on a library to perform essential operations
1005*8edd6c6fSRyan Everettsuch as verifying a hash or a digital signature.
1006*8edd6c6fSRyan EverettArm platforms use a library based on mbedTLS located at
1007*8edd6c6fSRyan Everett``drivers/auth/mbedtls/mbedtls_crypto.c``.
1008*8edd6c6fSRyan EverettAdditionally, an experimental alternative library based on PSA Crypto
1009*8edd6c6fSRyan Everettis available at ``drivers/auth/mbedtls/mbedtls_psa_crypto.c``. In future,
1010*8edd6c6fSRyan Everett``mbedtls_psa_crypto.c`` will replace ``mbedtls_crypto.c`` as the default Arm
1011*8edd6c6fSRyan EverettCM. Both libraries are registered in the authentication framework using
1012*8edd6c6fSRyan Everettthe macro ``REGISTER_CRYPTO_LIB()``. These libraries implement the following
1013*8edd6c6fSRyan Everettexported functions, their implementations are compared side-by-side below:
101440d553cfSPaul Beesley
1015*8edd6c6fSRyan Everett.. list-table:: Comparison of exported CM function implementations
1016*8edd6c6fSRyan Everett   :widths: 20 40 40
1017*8edd6c6fSRyan Everett   :header-rows: 1
101840d553cfSPaul Beesley
1019*8edd6c6fSRyan Everett   * - CM function
1020*8edd6c6fSRyan Everett     - ``mbedtls_crypto.c``
1021*8edd6c6fSRyan Everett     - ``mbedtls_psa_crypto.c``
1022*8edd6c6fSRyan Everett   * - ``init``
1023*8edd6c6fSRyan Everett     - Initialize the heap for mbedTLS.
1024*8edd6c6fSRyan Everett     - Initialize the heap for mbedTLS and call ``psa_crypto_init``.
1025*8edd6c6fSRyan Everett   * - ``verify_signature``
1026*8edd6c6fSRyan Everett     - Use mbedTLS to parse the ASN1 inputs, and then use the mbedTLS pk module to verify the signature.
1027*8edd6c6fSRyan Everett     - Use mbedTLS to parse the ASN1 inputs, use the mbedTLS pk module to parse the key,
1028*8edd6c6fSRyan Everett       import it into the PSA key system and then use ``psa_verify_message`` to verify the signature.
1029*8edd6c6fSRyan Everett   * - ``calc_hash``
1030*8edd6c6fSRyan Everett     - Use the ``mbedtls_md`` API to calculate the hash of the given data.
1031*8edd6c6fSRyan Everett     - Use ``psa_hash_compute`` to calculate the hash of the given data.
1032*8edd6c6fSRyan Everett   * - ``verify_hash``
1033*8edd6c6fSRyan Everett     - Use the ``mbedtls_md`` API to calculate the hash of the given data,
1034*8edd6c6fSRyan Everett       and then compare it against the data which is to be verified.
1035*8edd6c6fSRyan Everett     - Call ``psa_hash_compare``, which both calculates the hash of the given data and
1036*8edd6c6fSRyan Everett       compares this hash against the data to be verified.
1037*8edd6c6fSRyan Everett   * - ``auth_decrypt``
1038*8edd6c6fSRyan Everett     - Use the ``mbedtls_gcm`` API to decrypt the data, and then verify the returned
1039*8edd6c6fSRyan Everett       tag by comparing it to the inputted tag.
1040*8edd6c6fSRyan Everett     - Load the key into the PSA key store, and then use ``psa_aead_verify`` to
1041*8edd6c6fSRyan Everett       decrypt and verify the tag.
104240d553cfSPaul Beesley
1043f29213d9SJustin ChadwellThe mbedTLS library algorithm support is configured by both the
1044f29213d9SJustin Chadwell``TF_MBEDTLS_KEY_ALG`` and ``TF_MBEDTLS_KEY_SIZE`` variables.
1045f29213d9SJustin Chadwell
1046f29213d9SJustin Chadwell-  ``TF_MBEDTLS_KEY_ALG`` can take in 3 values: `rsa`, `ecdsa` or `rsa+ecdsa`.
1047f29213d9SJustin Chadwell   This variable allows the Makefile to include the corresponding sources in
1048f29213d9SJustin Chadwell   the build for the various algorithms. Setting the variable to `rsa+ecdsa`
1049f29213d9SJustin Chadwell   enables support for both rsa and ecdsa algorithms in the mbedTLS library.
1050f29213d9SJustin Chadwell
1051f29213d9SJustin Chadwell-  ``TF_MBEDTLS_KEY_SIZE`` sets the supported RSA key size for TFA. Valid values
1052f29213d9SJustin Chadwell   include 1024, 2048, 3072 and 4096.
105340d553cfSPaul Beesley
1054f97062a5SSumit Garg-  ``TF_MBEDTLS_USE_AES_GCM`` enables the authenticated decryption support based
1055f97062a5SSumit Garg   on AES-GCM algorithm. Valid values are 0 and 1.
1056f97062a5SSumit Garg
1057e1c5026aSPaul Beesley.. note::
1058e1c5026aSPaul Beesley   If code size is a concern, the build option ``MBEDTLS_SHA256_SMALLER`` can
1059e1c5026aSPaul Beesley   be defined in the platform Makefile. It will make mbed TLS use an
1060e1c5026aSPaul Beesley   implementation of SHA-256 with smaller memory footprint (~1.5 KB less) but
1061e1c5026aSPaul Beesley   slower (~30%).
106240d553cfSPaul Beesley
106340d553cfSPaul Beesley--------------
106440d553cfSPaul Beesley
1065*8edd6c6fSRyan Everett*Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved.*
106640d553cfSPaul Beesley
10674290d343SSandrine Bailleux.. _TBBR-Client specification: https://developer.arm.com/docs/den0006/latest
1068