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); 23540d553cfSPaul Beesley int (*verify_signature)(void *data_ptr, unsigned int data_len, 23640d553cfSPaul Beesley void *sig_ptr, unsigned int sig_len, 23740d553cfSPaul Beesley void *sig_alg, unsigned int sig_alg_len, 23840d553cfSPaul Beesley void *pk_ptr, unsigned int pk_len); 239f28057a2SManish V Badarkhe int (*calc_hash)(enum crypto_md_algo alg, void *data_ptr, 240f28057a2SManish V Badarkhe unsigned int data_len, 241f28057a2SManish V Badarkhe unsigned char output[CRYPTO_MD_MAX_SIZE]) 24240d553cfSPaul Beesley int (*verify_hash)(void *data_ptr, unsigned int data_len, 24340d553cfSPaul Beesley void *digest_info_ptr, unsigned int digest_info_len); 2440ca7b326SYann Gautier int (*auth_decrypt)(enum crypto_dec_algo dec_algo, void *data_ptr, 2450ca7b326SYann Gautier size_t len, const void *key, unsigned int key_len, 2460ca7b326SYann Gautier unsigned int key_flags, const void *iv, 2470ca7b326SYann Gautier unsigned int iv_len, const void *tag, 2480ca7b326SYann Gautier unsigned int tag_len); 24940d553cfSPaul Beesley 25040d553cfSPaul BeesleyThese functions are registered in the CM using the macro: 25140d553cfSPaul Beesley 25240d553cfSPaul Beesley.. code:: c 25340d553cfSPaul Beesley 254f28057a2SManish V Badarkhe REGISTER_CRYPTO_LIB(_name, 255f28057a2SManish V Badarkhe _init, 256f28057a2SManish V Badarkhe _verify_signature, 257f28057a2SManish V Badarkhe _calc_hash, 2580ca7b326SYann Gautier _verify_hash, 259*4ac5b394SYann Gautier _auth_decrypt, 260*4ac5b394SYann Gautier _convert_pk); 26140d553cfSPaul Beesley 26240d553cfSPaul Beesley``_name`` must be a string containing the name of the CL. This name is used for 26340d553cfSPaul Beesleydebugging purposes. 26440d553cfSPaul Beesley 265f28057a2SManish V BadarkheCrypto module provides a function ``_calc_hash`` to calculate and 266f28057a2SManish V Badarkhereturn the hash of the given data using the provided hash algorithm. 267f28057a2SManish V BadarkheThis function is mainly used in the ``MEASURED_BOOT`` and ``DRTM_SUPPORT`` 268f28057a2SManish V Badarkhefeatures to calculate the hashes of various images/data. 269f28057a2SManish V Badarkhe 270*4ac5b394SYann GautierOptionally, a platform function can be provided to convert public key 271*4ac5b394SYann Gautier(_convert_pk). It is only used if the platform saves a hash of the ROTPK. 272*4ac5b394SYann GautierMost platforms save the hash of the ROTPK, but some may save slightly different 273*4ac5b394SYann Gautierinformation - e.g the hash of the ROTPK plus some related information. 274*4ac5b394SYann GautierDefining this function allows to transform the ROTPK used to verify 275*4ac5b394SYann Gautierthe signature to the buffer (a platform specific public key) which 276*4ac5b394SYann Gautierhash is saved in OTP. 277*4ac5b394SYann Gautier 278*4ac5b394SYann Gautier.. code:: c 279*4ac5b394SYann Gautier 280*4ac5b394SYann Gautier int (*convert_pk)(void *full_pk_ptr, unsigned int full_pk_len, 281*4ac5b394SYann Gautier void **hashed_pk_ptr, unsigned int *hashed_pk_len); 282*4ac5b394SYann Gautier 283*4ac5b394SYann Gautier 284*4ac5b394SYann Gautier- ``full_pk_ptr``: Pointer to Distinguished Encoding Rules (DER) ROTPK. 285*4ac5b394SYann Gautier- ``full_pk_len``: DER ROTPK size. 286*4ac5b394SYann Gautier- ``hashed_pk_ptr``: to return a pointer to a buffer, which hash should be the one saved in OTP. 287*4ac5b394SYann Gautier- ``hashed_pk_len``: previous buffer size 288*4ac5b394SYann Gautier 28940d553cfSPaul BeesleyImage Parser Module (IPM) 29040d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^ 29140d553cfSPaul Beesley 29240d553cfSPaul BeesleyThe IPM is responsible for: 29340d553cfSPaul Beesley 29440d553cfSPaul Beesley#. Checking the integrity of each image loaded by the IO framework. 29540d553cfSPaul Beesley#. Extracting parameters used for authenticating an image based upon a 29640d553cfSPaul Beesley description provided by the platform in the CoT descriptor. 29740d553cfSPaul Beesley 29840d553cfSPaul BeesleyImages may have different formats (for example, authentication images could be 29940d553cfSPaul Beesleyx509v3 certificates, signed ELF files or any other platform specific format). 30040d553cfSPaul BeesleyThe IPM allows to register an Image Parser Library (IPL) for every image format 30140d553cfSPaul Beesleyused in the CoT. This library must implement the specific methods to parse the 30240d553cfSPaul Beesleyimage. The IPM obtains the image format from the CoT and calls the right IPL to 30340d553cfSPaul Beesleycheck the image integrity and extract the authentication parameters. 30440d553cfSPaul Beesley 30540d553cfSPaul BeesleySee Section "Describing the image parsing methods" for more details about the 30640d553cfSPaul Beesleymechanism the IPM provides to define and register IPLs. 30740d553cfSPaul Beesley 30840d553cfSPaul BeesleyAuthentication methods 30940d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~ 31040d553cfSPaul Beesley 31140d553cfSPaul BeesleyThe AM supports the following authentication methods: 31240d553cfSPaul Beesley 31340d553cfSPaul Beesley#. Hash 31440d553cfSPaul Beesley#. Digital signature 31540d553cfSPaul Beesley 31640d553cfSPaul BeesleyThe platform may specify these methods in the CoT in case it decides to define 31740d553cfSPaul Beesleya custom CoT instead of reusing a predefined one. 31840d553cfSPaul Beesley 31940d553cfSPaul BeesleyIf a data image uses multiple methods, then all the methods must be a part of 32040d553cfSPaul Beesleythe same CoT. The number and type of parameters are method specific. These 32140d553cfSPaul Beesleyparameters should be obtained from the parent image using the IPM. 32240d553cfSPaul Beesley 32340d553cfSPaul Beesley#. Hash 32440d553cfSPaul Beesley 32540d553cfSPaul Beesley Parameters: 32640d553cfSPaul Beesley 32740d553cfSPaul Beesley #. A pointer to data to hash 32840d553cfSPaul Beesley #. Length of the data 32940d553cfSPaul Beesley #. A pointer to the hash 33040d553cfSPaul Beesley #. Length of the hash 33140d553cfSPaul Beesley 33240d553cfSPaul Beesley The hash will be represented by the DER encoding of the following ASN.1 33340d553cfSPaul Beesley type: 33440d553cfSPaul Beesley 33540d553cfSPaul Beesley :: 33640d553cfSPaul Beesley 33740d553cfSPaul Beesley DigestInfo ::= SEQUENCE { 33840d553cfSPaul Beesley digestAlgorithm DigestAlgorithmIdentifier, 33940d553cfSPaul Beesley digest Digest 34040d553cfSPaul Beesley } 34140d553cfSPaul Beesley 34240d553cfSPaul Beesley This ASN.1 structure makes it possible to remove any assumption about the 34340d553cfSPaul Beesley type of hash algorithm used as this information accompanies the hash. This 34440d553cfSPaul Beesley should allow the Cryptography Library (CL) to support multiple hash 34540d553cfSPaul Beesley algorithm implementations. 34640d553cfSPaul Beesley 34740d553cfSPaul Beesley#. Digital Signature 34840d553cfSPaul Beesley 34940d553cfSPaul Beesley Parameters: 35040d553cfSPaul Beesley 35140d553cfSPaul Beesley #. A pointer to data to sign 35240d553cfSPaul Beesley #. Length of the data 35340d553cfSPaul Beesley #. Public Key Algorithm 35440d553cfSPaul Beesley #. Public Key value 35540d553cfSPaul Beesley #. Digital Signature Algorithm 35640d553cfSPaul Beesley #. Digital Signature value 35740d553cfSPaul Beesley 35840d553cfSPaul Beesley The Public Key parameters will be represented by the DER encoding of the 35940d553cfSPaul Beesley following ASN.1 type: 36040d553cfSPaul Beesley 36140d553cfSPaul Beesley :: 36240d553cfSPaul Beesley 36340d553cfSPaul Beesley SubjectPublicKeyInfo ::= SEQUENCE { 36440d553cfSPaul Beesley algorithm AlgorithmIdentifier{PUBLIC-KEY,{PublicKeyAlgorithms}}, 36540d553cfSPaul Beesley subjectPublicKey BIT STRING } 36640d553cfSPaul Beesley 36740d553cfSPaul Beesley The Digital Signature Algorithm will be represented by the DER encoding of 36840d553cfSPaul Beesley the following ASN.1 types. 36940d553cfSPaul Beesley 37040d553cfSPaul Beesley :: 37140d553cfSPaul Beesley 37240d553cfSPaul Beesley AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE { 37340d553cfSPaul Beesley algorithm ALGORITHM.&id({IOSet}), 37440d553cfSPaul Beesley parameters ALGORITHM.&Type({IOSet}{@algorithm}) OPTIONAL 37540d553cfSPaul Beesley } 37640d553cfSPaul Beesley 37740d553cfSPaul Beesley The digital signature will be represented by: 37840d553cfSPaul Beesley 37940d553cfSPaul Beesley :: 38040d553cfSPaul Beesley 38140d553cfSPaul Beesley signature ::= BIT STRING 38240d553cfSPaul Beesley 38340d553cfSPaul BeesleyThe authentication framework will use the image descriptor to extract all the 38440d553cfSPaul Beesleyinformation related to authentication. 38540d553cfSPaul Beesley 38640d553cfSPaul BeesleySpecifying a Chain of Trust 38740d553cfSPaul Beesley--------------------------- 38840d553cfSPaul Beesley 38940d553cfSPaul BeesleyA CoT can be described as a set of image descriptors linked together in a 39040d553cfSPaul Beesleyparticular order. The order dictates the sequence in which they must be 39140d553cfSPaul Beesleyverified. Each image has a set of properties which allow the AM to verify it. 39240d553cfSPaul BeesleyThese properties are described below. 39340d553cfSPaul Beesley 39440d553cfSPaul BeesleyThe PP is responsible for defining a single or multiple CoTs for a data image. 39540d553cfSPaul BeesleyUnless otherwise specified, the data structures described in the following 39640d553cfSPaul Beesleysections are populated by the PP statically. 39740d553cfSPaul Beesley 39840d553cfSPaul BeesleyDescribing the image parsing methods 39940d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 40040d553cfSPaul Beesley 40140d553cfSPaul BeesleyThe parsing method refers to the format of a particular image. For example, an 40240d553cfSPaul Beesleyauthentication image that represents a certificate could be in the X.509v3 40340d553cfSPaul Beesleyformat. A data image that represents a boot loader stage could be in raw binary 40440d553cfSPaul Beesleyor ELF format. The IPM supports three parsing methods. An image has to use one 40540d553cfSPaul Beesleyof the three methods described below. An IPL is responsible for interpreting a 40640d553cfSPaul Beesleysingle parsing method. There has to be one IPL for every method used by the 40740d553cfSPaul Beesleyplatform. 40840d553cfSPaul Beesley 40940d553cfSPaul Beesley#. Raw format: This format is effectively a nop as an image using this method 41040d553cfSPaul Beesley is treated as being in raw binary format e.g. boot loader images used by 41140d553cfSPaul Beesley TF-A. This method should only be used by data images. 41240d553cfSPaul Beesley 41340d553cfSPaul Beesley#. X509V3 method: This method uses industry standards like X.509 to represent 41440d553cfSPaul Beesley PKI certificates (authentication images). It is expected that open source 41540d553cfSPaul Beesley libraries will be available which can be used to parse an image represented 41640d553cfSPaul Beesley by this method. Such libraries can be used to write the corresponding IPL 41740d553cfSPaul Beesley e.g. the X.509 parsing library code in mbed TLS. 41840d553cfSPaul Beesley 41940d553cfSPaul Beesley#. Platform defined method: This method caters for platform specific 42040d553cfSPaul Beesley proprietary standards to represent authentication or data images. For 42140d553cfSPaul Beesley example, The signature of a data image could be appended to the data image 42240d553cfSPaul Beesley raw binary. A header could be prepended to the combined blob to specify the 42340d553cfSPaul Beesley extents of each component. The platform will have to implement the 42440d553cfSPaul Beesley corresponding IPL to interpret such a format. 42540d553cfSPaul Beesley 42640d553cfSPaul BeesleyThe following enum can be used to define these three methods. 42740d553cfSPaul Beesley 42840d553cfSPaul Beesley.. code:: c 42940d553cfSPaul Beesley 43040d553cfSPaul Beesley typedef enum img_type_enum { 43140d553cfSPaul Beesley IMG_RAW, /* Binary image */ 43240d553cfSPaul Beesley IMG_PLAT, /* Platform specific format */ 43340d553cfSPaul Beesley IMG_CERT, /* X509v3 certificate */ 43440d553cfSPaul Beesley IMG_MAX_TYPES, 43540d553cfSPaul Beesley } img_type_t; 43640d553cfSPaul Beesley 43740d553cfSPaul BeesleyAn IPL must provide functions with the following prototypes: 43840d553cfSPaul Beesley 43940d553cfSPaul Beesley.. code:: c 44040d553cfSPaul Beesley 44140d553cfSPaul Beesley void init(void); 44240d553cfSPaul Beesley int check_integrity(void *img, unsigned int img_len); 44340d553cfSPaul Beesley int get_auth_param(const auth_param_type_desc_t *type_desc, 44440d553cfSPaul Beesley void *img, unsigned int img_len, 44540d553cfSPaul Beesley void **param, unsigned int *param_len); 44640d553cfSPaul Beesley 44740d553cfSPaul BeesleyAn IPL for each type must be registered using the following macro: 44840d553cfSPaul Beesley 44929c02529SPaul Beesley.. code:: c 45040d553cfSPaul Beesley 45140d553cfSPaul Beesley REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param) 45240d553cfSPaul Beesley 45340d553cfSPaul Beesley- ``_type``: one of the types described above. 45440d553cfSPaul Beesley- ``_name``: a string containing the IPL name for debugging purposes. 45540d553cfSPaul Beesley- ``_init``: initialization function pointer. 45640d553cfSPaul Beesley- ``_check_int``: check image integrity function pointer. 45740d553cfSPaul Beesley- ``_get_param``: extract authentication parameter function pointer. 45840d553cfSPaul Beesley 45940d553cfSPaul BeesleyThe ``init()`` function will be used to initialize the IPL. 46040d553cfSPaul Beesley 46140d553cfSPaul BeesleyThe ``check_integrity()`` function is passed a pointer to the memory where the 46240d553cfSPaul Beesleyimage has been loaded by the IO framework and the image length. It should ensure 46340d553cfSPaul Beesleythat the image is in the format corresponding to the parsing method and has not 46440d553cfSPaul Beesleybeen tampered with. For example, RFC-2459 describes a validation sequence for an 46540d553cfSPaul BeesleyX.509 certificate. 46640d553cfSPaul Beesley 46740d553cfSPaul BeesleyThe ``get_auth_param()`` function is passed a parameter descriptor containing 46840d553cfSPaul Beesleyinformation about the parameter (``type_desc`` and ``cookie``) to identify and 46940d553cfSPaul Beesleyextract the data corresponding to that parameter from an image. This data will 47040d553cfSPaul Beesleybe used to verify either the current or the next image in the CoT sequence. 47140d553cfSPaul Beesley 47240d553cfSPaul BeesleyEach image in the CoT will specify the parsing method it uses. This information 47340d553cfSPaul Beesleywill be used by the IPM to find the right parser descriptor for the image. 47440d553cfSPaul Beesley 47540d553cfSPaul BeesleyDescribing the authentication method(s) 47640d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47740d553cfSPaul Beesley 47840d553cfSPaul BeesleyAs part of the CoT, each image has to specify one or more authentication methods 47940d553cfSPaul Beesleywhich will be used to verify it. As described in the Section "Authentication 48040d553cfSPaul Beesleymethods", there are three methods supported by the AM. 48140d553cfSPaul Beesley 48240d553cfSPaul Beesley.. code:: c 48340d553cfSPaul Beesley 48440d553cfSPaul Beesley typedef enum { 48540d553cfSPaul Beesley AUTH_METHOD_NONE, 48640d553cfSPaul Beesley AUTH_METHOD_HASH, 48740d553cfSPaul Beesley AUTH_METHOD_SIG, 48840d553cfSPaul Beesley AUTH_METHOD_NUM 48940d553cfSPaul Beesley } auth_method_type_t; 49040d553cfSPaul Beesley 49140d553cfSPaul BeesleyThe AM defines the type of each parameter used by an authentication method. It 49240d553cfSPaul Beesleyuses this information to: 49340d553cfSPaul Beesley 49440d553cfSPaul Beesley#. Specify to the ``get_auth_param()`` function exported by the IPM, which 49540d553cfSPaul Beesley parameter should be extracted from an image. 49640d553cfSPaul Beesley 49740d553cfSPaul Beesley#. Correctly marshall the parameters while calling the verification function 49840d553cfSPaul Beesley exported by the CM and PP. 49940d553cfSPaul Beesley 50040d553cfSPaul Beesley#. Extract authentication parameters from a parent image in order to verify a 50140d553cfSPaul Beesley child image e.g. to verify the certificate image, the public key has to be 50240d553cfSPaul Beesley obtained from the parent image. 50340d553cfSPaul Beesley 50440d553cfSPaul Beesley.. code:: c 50540d553cfSPaul Beesley 50640d553cfSPaul Beesley typedef enum { 50740d553cfSPaul Beesley AUTH_PARAM_NONE, 50840d553cfSPaul Beesley AUTH_PARAM_RAW_DATA, /* Raw image data */ 50940d553cfSPaul Beesley AUTH_PARAM_SIG, /* The image signature */ 51040d553cfSPaul Beesley AUTH_PARAM_SIG_ALG, /* The image signature algorithm */ 51140d553cfSPaul Beesley AUTH_PARAM_HASH, /* A hash (including the algorithm) */ 51240d553cfSPaul Beesley AUTH_PARAM_PUB_KEY, /* A public key */ 51340d553cfSPaul Beesley } auth_param_type_t; 51440d553cfSPaul Beesley 51540d553cfSPaul BeesleyThe AM defines the following structure to identify an authentication parameter 51640d553cfSPaul Beesleyrequired to verify an image. 51740d553cfSPaul Beesley 51840d553cfSPaul Beesley.. code:: c 51940d553cfSPaul Beesley 52040d553cfSPaul Beesley typedef struct auth_param_type_desc_s { 52140d553cfSPaul Beesley auth_param_type_t type; 52240d553cfSPaul Beesley void *cookie; 52340d553cfSPaul Beesley } auth_param_type_desc_t; 52440d553cfSPaul Beesley 52540d553cfSPaul Beesley``cookie`` is used by the platform to specify additional information to the IPM 52640d553cfSPaul Beesleywhich enables it to uniquely identify the parameter that should be extracted 52740d553cfSPaul Beesleyfrom an image. For example, the hash of a BL3x image in its corresponding 52840d553cfSPaul Beesleycontent certificate is stored in an X509v3 custom extension field. An extension 52940d553cfSPaul Beesleyfield can only be identified using an OID. In this case, the ``cookie`` could 53040d553cfSPaul Beesleycontain the pointer to the OID defined by the platform for the hash extension 53140d553cfSPaul Beesleyfield while the ``type`` field could be set to ``AUTH_PARAM_HASH``. A value of 0 for 53240d553cfSPaul Beesleythe ``cookie`` field means that it is not used. 53340d553cfSPaul Beesley 53440d553cfSPaul BeesleyFor each method, the AM defines a structure with the parameters required to 53540d553cfSPaul Beesleyverify the image. 53640d553cfSPaul Beesley 53740d553cfSPaul Beesley.. code:: c 53840d553cfSPaul Beesley 53940d553cfSPaul Beesley /* 54040d553cfSPaul Beesley * Parameters for authentication by hash matching 54140d553cfSPaul Beesley */ 54240d553cfSPaul Beesley typedef struct auth_method_param_hash_s { 54340d553cfSPaul Beesley auth_param_type_desc_t *data; /* Data to hash */ 54440d553cfSPaul Beesley auth_param_type_desc_t *hash; /* Hash to match with */ 54540d553cfSPaul Beesley } auth_method_param_hash_t; 54640d553cfSPaul Beesley 54740d553cfSPaul Beesley /* 54840d553cfSPaul Beesley * Parameters for authentication by signature 54940d553cfSPaul Beesley */ 55040d553cfSPaul Beesley typedef struct auth_method_param_sig_s { 55140d553cfSPaul Beesley auth_param_type_desc_t *pk; /* Public key */ 55240d553cfSPaul Beesley auth_param_type_desc_t *sig; /* Signature to check */ 55340d553cfSPaul Beesley auth_param_type_desc_t *alg; /* Signature algorithm */ 55440d553cfSPaul Beesley auth_param_type_desc_t *tbs; /* Data signed */ 55540d553cfSPaul Beesley } auth_method_param_sig_t; 55640d553cfSPaul Beesley 55740d553cfSPaul BeesleyThe AM defines the following structure to describe an authentication method for 55840d553cfSPaul Beesleyverifying an image 55940d553cfSPaul Beesley 56040d553cfSPaul Beesley.. code:: c 56140d553cfSPaul Beesley 56240d553cfSPaul Beesley /* 56340d553cfSPaul Beesley * Authentication method descriptor 56440d553cfSPaul Beesley */ 56540d553cfSPaul Beesley typedef struct auth_method_desc_s { 56640d553cfSPaul Beesley auth_method_type_t type; 56740d553cfSPaul Beesley union { 56840d553cfSPaul Beesley auth_method_param_hash_t hash; 56940d553cfSPaul Beesley auth_method_param_sig_t sig; 57040d553cfSPaul Beesley } param; 57140d553cfSPaul Beesley } auth_method_desc_t; 57240d553cfSPaul Beesley 57340d553cfSPaul BeesleyUsing the method type specified in the ``type`` field, the AM finds out what field 57440d553cfSPaul Beesleyneeds to access within the ``param`` union. 57540d553cfSPaul Beesley 57640d553cfSPaul BeesleyStoring Authentication parameters 57740d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 57840d553cfSPaul Beesley 57940d553cfSPaul BeesleyA parameter described by ``auth_param_type_desc_t`` to verify an image could be 58040d553cfSPaul Beesleyobtained from either the image itself or its parent image. The memory allocated 58140d553cfSPaul Beesleyfor loading the parent image will be reused for loading the child image. Hence 58240d553cfSPaul Beesleyparameters which are obtained from the parent for verifying a child image need 58340d553cfSPaul Beesleyto have memory allocated for them separately where they can be stored. This 58440d553cfSPaul Beesleymemory must be statically allocated by the platform port. 58540d553cfSPaul Beesley 58640d553cfSPaul BeesleyThe AM defines the following structure to store the data corresponding to an 58740d553cfSPaul Beesleyauthentication parameter. 58840d553cfSPaul Beesley 58940d553cfSPaul Beesley.. code:: c 59040d553cfSPaul Beesley 59140d553cfSPaul Beesley typedef struct auth_param_data_desc_s { 59240d553cfSPaul Beesley void *auth_param_ptr; 59340d553cfSPaul Beesley unsigned int auth_param_len; 59440d553cfSPaul Beesley } auth_param_data_desc_t; 59540d553cfSPaul Beesley 59640d553cfSPaul BeesleyThe ``auth_param_ptr`` field is initialized by the platform. The ``auth_param_len`` 59740d553cfSPaul Beesleyfield is used to specify the length of the data in the memory. 59840d553cfSPaul Beesley 59940d553cfSPaul BeesleyFor parameters that can be obtained from the child image itself, the IPM is 60040d553cfSPaul Beesleyresponsible for populating the ``auth_param_ptr`` and ``auth_param_len`` fields 60140d553cfSPaul Beesleywhile executing the ``img_get_auth_param()`` function. 60240d553cfSPaul Beesley 60340d553cfSPaul BeesleyThe AM defines the following structure to enable an image to describe the 60440d553cfSPaul Beesleyparameters that should be extracted from it and used to verify the next image 60540d553cfSPaul Beesley(child) in a CoT. 60640d553cfSPaul Beesley 60740d553cfSPaul Beesley.. code:: c 60840d553cfSPaul Beesley 60940d553cfSPaul Beesley typedef struct auth_param_desc_s { 61040d553cfSPaul Beesley auth_param_type_desc_t type_desc; 61140d553cfSPaul Beesley auth_param_data_desc_t data; 61240d553cfSPaul Beesley } auth_param_desc_t; 61340d553cfSPaul Beesley 61440d553cfSPaul BeesleyDescribing an image in a CoT 61540d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 61640d553cfSPaul Beesley 61740d553cfSPaul BeesleyAn image in a CoT is a consolidation of the following aspects of a CoT described 61840d553cfSPaul Beesleyabove. 61940d553cfSPaul Beesley 62040d553cfSPaul Beesley#. A unique identifier specified by the platform which allows the IO framework 62140d553cfSPaul Beesley to locate the image in a FIP and load it in the memory reserved for the data 62240d553cfSPaul Beesley image in the CoT. 62340d553cfSPaul Beesley 62440d553cfSPaul Beesley#. A parsing method which is used by the AM to find the appropriate IPM. 62540d553cfSPaul Beesley 62640d553cfSPaul Beesley#. Authentication methods and their parameters as described in the previous 62740d553cfSPaul Beesley section. These are used to verify the current image. 62840d553cfSPaul Beesley 62940d553cfSPaul Beesley#. Parameters which are used to verify the next image in the current CoT. These 63040d553cfSPaul Beesley parameters are specified only by authentication images and can be extracted 63140d553cfSPaul Beesley from the current image once it has been verified. 63240d553cfSPaul Beesley 63340d553cfSPaul BeesleyThe following data structure describes an image in a CoT. 63440d553cfSPaul Beesley 63540d553cfSPaul Beesley.. code:: c 63640d553cfSPaul Beesley 63740d553cfSPaul Beesley typedef struct auth_img_desc_s { 63840d553cfSPaul Beesley unsigned int img_id; 63940d553cfSPaul Beesley const struct auth_img_desc_s *parent; 64040d553cfSPaul Beesley img_type_t img_type; 64140d553cfSPaul Beesley const auth_method_desc_t *const img_auth_methods; 64240d553cfSPaul Beesley const auth_param_desc_t *const authenticated_data; 64340d553cfSPaul Beesley } auth_img_desc_t; 64440d553cfSPaul Beesley 64540d553cfSPaul BeesleyA CoT is defined as an array of pointers to ``auth_image_desc_t`` structures 64640d553cfSPaul Beesleylinked together by the ``parent`` field. Those nodes with no parent must be 64740d553cfSPaul Beesleyauthenticated using the ROTPK stored in the platform. 64840d553cfSPaul Beesley 64940d553cfSPaul BeesleyImplementation example 65040d553cfSPaul Beesley---------------------- 65140d553cfSPaul Beesley 65240d553cfSPaul BeesleyThis section is a detailed guide explaining a trusted boot implementation using 65340d553cfSPaul Beesleythe authentication framework. This example corresponds to the Applicative 65440d553cfSPaul BeesleyFunctional Mode (AFM) as specified in the TBBR-Client document. It is 65540d553cfSPaul Beesleyrecommended to read this guide along with the source code. 65640d553cfSPaul Beesley 65740d553cfSPaul BeesleyThe TBBR CoT 65840d553cfSPaul Beesley~~~~~~~~~~~~ 65940d553cfSPaul Beesley 660ad43c49eSManish V BadarkheCoT specific to BL1 and BL2 can be found in ``drivers/auth/tbbr/tbbr_cot_bl1.c`` 661ad43c49eSManish V Badarkheand ``drivers/auth/tbbr/tbbr_cot_bl2.c`` respectively. The common CoT used across 662ad43c49eSManish V BadarkheBL1 and BL2 can be found in ``drivers/auth/tbbr/tbbr_cot_common.c``. 663ad43c49eSManish V BadarkheThis CoT consists of an array of pointers to image descriptors and it is 664ad43c49eSManish V Badarkheregistered in the framework using the macro ``REGISTER_COT(cot_desc)``, where 665ad43c49eSManish V Badarkhe``cot_desc`` must be the name of the array (passing a pointer or any other 666ad43c49eSManish V Badarkhetype of indirection will cause the registration process to fail). 66740d553cfSPaul Beesley 66840d553cfSPaul BeesleyThe number of images participating in the boot process depends on the CoT. 66940d553cfSPaul BeesleyThere is, however, a minimum set of images that are mandatory in TF-A and thus 67040d553cfSPaul Beesleyall CoTs must present: 67140d553cfSPaul Beesley 67240d553cfSPaul Beesley- ``BL2`` 67340d553cfSPaul Beesley- ``SCP_BL2`` (platform specific) 67440d553cfSPaul Beesley- ``BL31`` 67540d553cfSPaul Beesley- ``BL32`` (optional) 67640d553cfSPaul Beesley- ``BL33`` 67740d553cfSPaul Beesley 67840d553cfSPaul BeesleyThe TBBR specifies the additional certificates that must accompany these images 67940d553cfSPaul Beesleyfor a proper authentication. Details about the TBBR CoT may be found in the 68034760951SPaul Beesley:ref:`Trusted Board Boot` document. 68140d553cfSPaul Beesley 68234760951SPaul BeesleyFollowing the :ref:`Porting Guide`, a platform must provide unique 68340d553cfSPaul Beesleyidentifiers for all the images and certificates that will be loaded during the 68440d553cfSPaul Beesleyboot process. If a platform is using the TBBR as a reference for trusted boot, 68540d553cfSPaul Beesleythese identifiers can be obtained from ``include/common/tbbr/tbbr_img_def.h``. 68640d553cfSPaul BeesleyArm platforms include this file in ``include/plat/arm/common/arm_def.h``. Other 68740d553cfSPaul Beesleyplatforms may also include this file or provide their own identifiers. 68840d553cfSPaul Beesley 68940d553cfSPaul Beesley**Important**: the authentication module uses these identifiers to index the 69040d553cfSPaul BeesleyCoT array, so the descriptors location in the array must match the identifiers. 69140d553cfSPaul Beesley 69240d553cfSPaul BeesleyEach image descriptor must specify: 69340d553cfSPaul Beesley 69440d553cfSPaul Beesley- ``img_id``: the corresponding image unique identifier defined by the platform. 69540d553cfSPaul Beesley- ``img_type``: the image parser module uses the image type to call the proper 69640d553cfSPaul Beesley parsing library to check the image integrity and extract the required 69740d553cfSPaul Beesley authentication parameters. Three types of images are currently supported: 69840d553cfSPaul Beesley 69940d553cfSPaul Beesley - ``IMG_RAW``: image is a raw binary. No parsing functions are available, 70040d553cfSPaul Beesley other than reading the whole image. 70140d553cfSPaul Beesley - ``IMG_PLAT``: image format is platform specific. The platform may use this 70240d553cfSPaul Beesley type for custom images not directly supported by the authentication 70340d553cfSPaul Beesley framework. 70440d553cfSPaul Beesley - ``IMG_CERT``: image is an x509v3 certificate. 70540d553cfSPaul Beesley 70640d553cfSPaul Beesley- ``parent``: pointer to the parent image descriptor. The parent will contain 70740d553cfSPaul Beesley the information required to authenticate the current image. If the parent 70840d553cfSPaul Beesley is NULL, the authentication parameters will be obtained from the platform 70940d553cfSPaul Beesley (i.e. the BL2 and Trusted Key certificates are signed with the ROT private 71040d553cfSPaul Beesley key, whose public part is stored in the platform). 71140d553cfSPaul Beesley- ``img_auth_methods``: this points to an array which defines the 71240d553cfSPaul Beesley authentication methods that must be checked to consider an image 71340d553cfSPaul Beesley authenticated. Each method consists of a type and a list of parameter 71440d553cfSPaul Beesley descriptors. A parameter descriptor consists of a type and a cookie which 71540d553cfSPaul Beesley will point to specific information required to extract that parameter from 71640d553cfSPaul Beesley the image (i.e. if the parameter is stored in an x509v3 extension, the 71740d553cfSPaul Beesley cookie will point to the extension OID). Depending on the method type, a 71840d553cfSPaul Beesley different number of parameters must be specified. This pointer should not be 71940d553cfSPaul Beesley NULL. 72040d553cfSPaul Beesley Supported methods are: 72140d553cfSPaul Beesley 72240d553cfSPaul Beesley - ``AUTH_METHOD_HASH``: the hash of the image must match the hash extracted 72340d553cfSPaul Beesley from the parent image. The following parameter descriptors must be 72440d553cfSPaul Beesley specified: 72540d553cfSPaul Beesley 72640d553cfSPaul Beesley - ``data``: data to be hashed (obtained from current image) 72740d553cfSPaul Beesley - ``hash``: reference hash (obtained from parent image) 72840d553cfSPaul Beesley 72940d553cfSPaul Beesley - ``AUTH_METHOD_SIG``: the image (usually a certificate) must be signed with 73040d553cfSPaul Beesley the private key whose public part is extracted from the parent image (or 73140d553cfSPaul Beesley the platform if the parent is NULL). The following parameter descriptors 73240d553cfSPaul Beesley must be specified: 73340d553cfSPaul Beesley 73440d553cfSPaul Beesley - ``pk``: the public key (obtained from parent image) 73540d553cfSPaul Beesley - ``sig``: the digital signature (obtained from current image) 73640d553cfSPaul Beesley - ``alg``: the signature algorithm used (obtained from current image) 73740d553cfSPaul Beesley - ``data``: the data to be signed (obtained from current image) 73840d553cfSPaul Beesley 73940d553cfSPaul Beesley- ``authenticated_data``: this array pointer indicates what authentication 74040d553cfSPaul Beesley parameters must be extracted from an image once it has been authenticated. 74140d553cfSPaul Beesley Each parameter consists of a parameter descriptor and the buffer 74240d553cfSPaul Beesley address/size to store the parameter. The CoT is responsible for allocating 74340d553cfSPaul Beesley the required memory to store the parameters. This pointer may be NULL. 74440d553cfSPaul Beesley 745ad43c49eSManish V BadarkheIn the ``tbbr_cot*.c`` file, a set of buffers are allocated to store the parameters 74640d553cfSPaul Beesleyextracted from the certificates. In the case of the TBBR CoT, these parameters 747f29213d9SJustin Chadwellare hashes and public keys. In DER format, an RSA-4096 public key requires 550 74840d553cfSPaul Beesleybytes, and a hash requires 51 bytes. Depending on the CoT and the authentication 74940d553cfSPaul Beesleyprocess, some of the buffers may be reused at different stages during the boot. 75040d553cfSPaul Beesley 75140d553cfSPaul BeesleyNext in that file, the parameter descriptors are defined. These descriptors will 75240d553cfSPaul Beesleybe used to extract the parameter data from the corresponding image. 75340d553cfSPaul Beesley 75440d553cfSPaul BeesleyExample: the BL31 Chain of Trust 75540d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 75640d553cfSPaul Beesley 75740d553cfSPaul BeesleyFour image descriptors form the BL31 Chain of Trust: 75840d553cfSPaul Beesley 75940d553cfSPaul Beesley.. code:: c 76040d553cfSPaul Beesley 76140d553cfSPaul Beesley static const auth_img_desc_t trusted_key_cert = { 76240d553cfSPaul Beesley .img_id = TRUSTED_KEY_CERT_ID, 76340d553cfSPaul Beesley .img_type = IMG_CERT, 76440d553cfSPaul Beesley .parent = NULL, 76540d553cfSPaul Beesley .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { 76640d553cfSPaul Beesley [0] = { 76740d553cfSPaul Beesley .type = AUTH_METHOD_SIG, 76840d553cfSPaul Beesley .param.sig = { 76940d553cfSPaul Beesley .pk = &subject_pk, 77040d553cfSPaul Beesley .sig = &sig, 77140d553cfSPaul Beesley .alg = &sig_alg, 77240d553cfSPaul Beesley .data = &raw_data 77340d553cfSPaul Beesley } 77440d553cfSPaul Beesley }, 77540d553cfSPaul Beesley [1] = { 77640d553cfSPaul Beesley .type = AUTH_METHOD_NV_CTR, 77740d553cfSPaul Beesley .param.nv_ctr = { 77840d553cfSPaul Beesley .cert_nv_ctr = &trusted_nv_ctr, 77940d553cfSPaul Beesley .plat_nv_ctr = &trusted_nv_ctr 78040d553cfSPaul Beesley } 78140d553cfSPaul Beesley } 78240d553cfSPaul Beesley }, 78340d553cfSPaul Beesley .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) { 78440d553cfSPaul Beesley [0] = { 78540d553cfSPaul Beesley .type_desc = &trusted_world_pk, 78640d553cfSPaul Beesley .data = { 78740d553cfSPaul Beesley .ptr = (void *)trusted_world_pk_buf, 78840d553cfSPaul Beesley .len = (unsigned int)PK_DER_LEN 78940d553cfSPaul Beesley } 79040d553cfSPaul Beesley }, 79140d553cfSPaul Beesley [1] = { 79240d553cfSPaul Beesley .type_desc = &non_trusted_world_pk, 79340d553cfSPaul Beesley .data = { 79440d553cfSPaul Beesley .ptr = (void *)non_trusted_world_pk_buf, 79540d553cfSPaul Beesley .len = (unsigned int)PK_DER_LEN 79640d553cfSPaul Beesley } 79740d553cfSPaul Beesley } 79840d553cfSPaul Beesley } 79940d553cfSPaul Beesley }; 80040d553cfSPaul Beesley static const auth_img_desc_t soc_fw_key_cert = { 80140d553cfSPaul Beesley .img_id = SOC_FW_KEY_CERT_ID, 80240d553cfSPaul Beesley .img_type = IMG_CERT, 80340d553cfSPaul Beesley .parent = &trusted_key_cert, 80440d553cfSPaul Beesley .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { 80540d553cfSPaul Beesley [0] = { 80640d553cfSPaul Beesley .type = AUTH_METHOD_SIG, 80740d553cfSPaul Beesley .param.sig = { 80840d553cfSPaul Beesley .pk = &trusted_world_pk, 80940d553cfSPaul Beesley .sig = &sig, 81040d553cfSPaul Beesley .alg = &sig_alg, 81140d553cfSPaul Beesley .data = &raw_data 81240d553cfSPaul Beesley } 81340d553cfSPaul Beesley }, 81440d553cfSPaul Beesley [1] = { 81540d553cfSPaul Beesley .type = AUTH_METHOD_NV_CTR, 81640d553cfSPaul Beesley .param.nv_ctr = { 81740d553cfSPaul Beesley .cert_nv_ctr = &trusted_nv_ctr, 81840d553cfSPaul Beesley .plat_nv_ctr = &trusted_nv_ctr 81940d553cfSPaul Beesley } 82040d553cfSPaul Beesley } 82140d553cfSPaul Beesley }, 82240d553cfSPaul Beesley .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) { 82340d553cfSPaul Beesley [0] = { 82440d553cfSPaul Beesley .type_desc = &soc_fw_content_pk, 82540d553cfSPaul Beesley .data = { 82640d553cfSPaul Beesley .ptr = (void *)content_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_content_cert = { 83340d553cfSPaul Beesley .img_id = SOC_FW_CONTENT_CERT_ID, 83440d553cfSPaul Beesley .img_type = IMG_CERT, 83540d553cfSPaul Beesley .parent = &soc_fw_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 = &soc_fw_content_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_hash, 85740d553cfSPaul Beesley .data = { 85840d553cfSPaul Beesley .ptr = (void *)soc_fw_hash_buf, 85940d553cfSPaul Beesley .len = (unsigned int)HASH_DER_LEN 86040d553cfSPaul Beesley } 86140d553cfSPaul Beesley }, 86240d553cfSPaul Beesley [1] = { 86340d553cfSPaul Beesley .type_desc = &soc_fw_config_hash, 86440d553cfSPaul Beesley .data = { 86540d553cfSPaul Beesley .ptr = (void *)soc_fw_config_hash_buf, 86640d553cfSPaul Beesley .len = (unsigned int)HASH_DER_LEN 86740d553cfSPaul Beesley } 86840d553cfSPaul Beesley } 86940d553cfSPaul Beesley } 87040d553cfSPaul Beesley }; 87140d553cfSPaul Beesley static const auth_img_desc_t bl31_image = { 87240d553cfSPaul Beesley .img_id = BL31_IMAGE_ID, 87340d553cfSPaul Beesley .img_type = IMG_RAW, 87440d553cfSPaul Beesley .parent = &soc_fw_content_cert, 87540d553cfSPaul Beesley .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { 87640d553cfSPaul Beesley [0] = { 87740d553cfSPaul Beesley .type = AUTH_METHOD_HASH, 87840d553cfSPaul Beesley .param.hash = { 87940d553cfSPaul Beesley .data = &raw_data, 88040d553cfSPaul Beesley .hash = &soc_fw_hash 88140d553cfSPaul Beesley } 88240d553cfSPaul Beesley } 88340d553cfSPaul Beesley } 88440d553cfSPaul Beesley }; 88540d553cfSPaul Beesley 88640d553cfSPaul BeesleyThe **Trusted Key certificate** is signed with the ROT private key and contains 88740d553cfSPaul Beesleythe Trusted World public key and the Non-Trusted World public key as x509v3 88840d553cfSPaul Beesleyextensions. This must be specified in the image descriptor using the 88940d553cfSPaul Beesley``img_auth_methods`` and ``authenticated_data`` arrays, respectively. 89040d553cfSPaul Beesley 89140d553cfSPaul BeesleyThe Trusted Key certificate is authenticated by checking its digital signature 89240d553cfSPaul Beesleyusing the ROTPK. Four parameters are required to check a signature: the public 89340d553cfSPaul Beesleykey, the algorithm, the signature and the data that has been signed. Therefore, 89440d553cfSPaul Beesleyfour parameter descriptors must be specified with the authentication method: 89540d553cfSPaul Beesley 89640d553cfSPaul Beesley- ``subject_pk``: parameter descriptor of type ``AUTH_PARAM_PUB_KEY``. This type 89740d553cfSPaul Beesley is used to extract a public key from the parent image. If the cookie is an 89840d553cfSPaul Beesley OID, the key is extracted from the corresponding x509v3 extension. If the 89940d553cfSPaul Beesley cookie is NULL, the subject public key is retrieved. In this case, because 90040d553cfSPaul Beesley the parent image is NULL, the public key is obtained from the platform 90140d553cfSPaul Beesley (this key will be the ROTPK). 90240d553cfSPaul Beesley- ``sig``: parameter descriptor of type ``AUTH_PARAM_SIG``. It is used to extract 90340d553cfSPaul Beesley the signature from the certificate. 90440d553cfSPaul Beesley- ``sig_alg``: parameter descriptor of type ``AUTH_PARAM_SIG``. It is used to 90540d553cfSPaul Beesley extract the signature algorithm from the certificate. 90640d553cfSPaul Beesley- ``raw_data``: parameter descriptor of type ``AUTH_PARAM_RAW_DATA``. It is used 90740d553cfSPaul Beesley to extract the data to be signed from the certificate. 90840d553cfSPaul Beesley 90940d553cfSPaul BeesleyOnce the signature has been checked and the certificate authenticated, the 91040d553cfSPaul BeesleyTrusted World public key needs to be extracted from the certificate. A new entry 91140d553cfSPaul Beesleyis created in the ``authenticated_data`` array for that purpose. In that entry, 91240d553cfSPaul Beesleythe corresponding parameter descriptor must be specified along with the buffer 91351d4e227SSandrine Bailleuxaddress to store the parameter value. In this case, the ``trusted_world_pk`` 91451d4e227SSandrine Bailleuxdescriptor is used to extract the public key from an x509v3 extension with OID 91540d553cfSPaul Beesley``TRUSTED_WORLD_PK_OID``. The BL31 key certificate will use this descriptor as 91640d553cfSPaul Beesleyparameter in the signature authentication method. The key is stored in the 91751d4e227SSandrine Bailleux``trusted_world_pk_buf`` buffer. 91840d553cfSPaul Beesley 91940d553cfSPaul BeesleyThe **BL31 Key certificate** is authenticated by checking its digital signature 92040d553cfSPaul Beesleyusing the Trusted World public key obtained previously from the Trusted Key 92140d553cfSPaul Beesleycertificate. In the image descriptor, we specify a single authentication method 92251d4e227SSandrine Bailleuxby signature whose public key is the ``trusted_world_pk``. Once this certificate 92351d4e227SSandrine Bailleuxhas been authenticated, we have to extract the BL31 public key, stored in the 92451d4e227SSandrine Bailleuxextension specified by ``soc_fw_content_pk``. This key will be copied to the 92551d4e227SSandrine Bailleux``content_pk_buf`` buffer. 92640d553cfSPaul Beesley 92740d553cfSPaul BeesleyThe **BL31 certificate** is authenticated by checking its digital signature 92840d553cfSPaul Beesleyusing the BL31 public key obtained previously from the BL31 Key certificate. 92951d4e227SSandrine BailleuxWe specify the authentication method using ``soc_fw_content_pk`` as public key. 93040d553cfSPaul BeesleyAfter authentication, we need to extract the BL31 hash, stored in the extension 93151d4e227SSandrine Bailleuxspecified by ``soc_fw_hash``. This hash will be copied to the 93251d4e227SSandrine Bailleux``soc_fw_hash_buf`` buffer. 93340d553cfSPaul Beesley 93440d553cfSPaul BeesleyThe **BL31 image** is authenticated by calculating its hash and matching it 93540d553cfSPaul Beesleywith the hash obtained from the BL31 certificate. The image descriptor contains 93640d553cfSPaul Beesleya single authentication method by hash. The parameters to the hash method are 93751d4e227SSandrine Bailleuxthe reference hash, ``soc_fw_hash``, and the data to be hashed. In this case, 93851d4e227SSandrine Bailleuxit is the whole image, so we specify ``raw_data``. 93940d553cfSPaul Beesley 94040d553cfSPaul BeesleyThe image parser library 94140d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~ 94240d553cfSPaul Beesley 94340d553cfSPaul BeesleyThe image parser module relies on libraries to check the image integrity and 94440d553cfSPaul Beesleyextract the authentication parameters. The number and type of parser libraries 94540d553cfSPaul Beesleydepend on the images used in the CoT. Raw images do not need a library, so 94640d553cfSPaul Beesleyonly an x509v3 library is required for the TBBR CoT. 94740d553cfSPaul Beesley 94840d553cfSPaul BeesleyArm platforms will use an x509v3 library based on mbed TLS. This library may be 94940d553cfSPaul Beesleyfound in ``drivers/auth/mbedtls/mbedtls_x509_parser.c``. It exports three 95040d553cfSPaul Beesleyfunctions: 95140d553cfSPaul Beesley 95240d553cfSPaul Beesley.. code:: c 95340d553cfSPaul Beesley 95440d553cfSPaul Beesley void init(void); 95540d553cfSPaul Beesley int check_integrity(void *img, unsigned int img_len); 95640d553cfSPaul Beesley int get_auth_param(const auth_param_type_desc_t *type_desc, 95740d553cfSPaul Beesley void *img, unsigned int img_len, 95840d553cfSPaul Beesley void **param, unsigned int *param_len); 95940d553cfSPaul Beesley 96040d553cfSPaul BeesleyThe library is registered in the framework using the macro 96140d553cfSPaul Beesley``REGISTER_IMG_PARSER_LIB()``. Each time the image parser module needs to access 96240d553cfSPaul Beesleyan image of type ``IMG_CERT``, it will call the corresponding function exported 96340d553cfSPaul Beesleyin this file. 96440d553cfSPaul Beesley 96540d553cfSPaul BeesleyThe build system must be updated to include the corresponding library and 96640d553cfSPaul Beesleymbed TLS sources. Arm platforms use the ``arm_common.mk`` file to pull the 96740d553cfSPaul Beesleysources. 96840d553cfSPaul Beesley 96940d553cfSPaul BeesleyThe cryptographic library 97040d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~ 97140d553cfSPaul Beesley 97240d553cfSPaul BeesleyThe cryptographic module relies on a library to perform the required operations, 97340d553cfSPaul Beesleyi.e. verify a hash or a digital signature. Arm platforms will use a library 97440d553cfSPaul Beesleybased on mbed TLS, which can be found in 97540d553cfSPaul Beesley``drivers/auth/mbedtls/mbedtls_crypto.c``. This library is registered in the 97640d553cfSPaul Beesleyauthentication framework using the macro ``REGISTER_CRYPTO_LIB()`` and exports 977f28057a2SManish V Badarkhebelow functions: 97840d553cfSPaul Beesley 97940d553cfSPaul Beesley.. code:: c 98040d553cfSPaul Beesley 98140d553cfSPaul Beesley void init(void); 98240d553cfSPaul Beesley int verify_signature(void *data_ptr, unsigned int data_len, 98340d553cfSPaul Beesley void *sig_ptr, unsigned int sig_len, 98440d553cfSPaul Beesley void *sig_alg, unsigned int sig_alg_len, 98540d553cfSPaul Beesley void *pk_ptr, unsigned int pk_len); 986f28057a2SManish V Badarkhe int crypto_mod_calc_hash(enum crypto_md_algo alg, void *data_ptr, 987f28057a2SManish V Badarkhe unsigned int data_len, 988f28057a2SManish V Badarkhe unsigned char output[CRYPTO_MD_MAX_SIZE]) 98940d553cfSPaul Beesley int verify_hash(void *data_ptr, unsigned int data_len, 99040d553cfSPaul Beesley void *digest_info_ptr, unsigned int digest_info_len); 991f97062a5SSumit Garg int auth_decrypt(enum crypto_dec_algo dec_algo, void *data_ptr, 992f97062a5SSumit Garg size_t len, const void *key, unsigned int key_len, 993f97062a5SSumit Garg unsigned int key_flags, const void *iv, 994f97062a5SSumit Garg unsigned int iv_len, const void *tag, 995f97062a5SSumit Garg unsigned int tag_len) 99640d553cfSPaul Beesley 997f29213d9SJustin ChadwellThe mbedTLS library algorithm support is configured by both the 998f29213d9SJustin Chadwell``TF_MBEDTLS_KEY_ALG`` and ``TF_MBEDTLS_KEY_SIZE`` variables. 999f29213d9SJustin Chadwell 1000f29213d9SJustin Chadwell- ``TF_MBEDTLS_KEY_ALG`` can take in 3 values: `rsa`, `ecdsa` or `rsa+ecdsa`. 1001f29213d9SJustin Chadwell This variable allows the Makefile to include the corresponding sources in 1002f29213d9SJustin Chadwell the build for the various algorithms. Setting the variable to `rsa+ecdsa` 1003f29213d9SJustin Chadwell enables support for both rsa and ecdsa algorithms in the mbedTLS library. 1004f29213d9SJustin Chadwell 1005f29213d9SJustin Chadwell- ``TF_MBEDTLS_KEY_SIZE`` sets the supported RSA key size for TFA. Valid values 1006f29213d9SJustin Chadwell include 1024, 2048, 3072 and 4096. 100740d553cfSPaul Beesley 1008f97062a5SSumit Garg- ``TF_MBEDTLS_USE_AES_GCM`` enables the authenticated decryption support based 1009f97062a5SSumit Garg on AES-GCM algorithm. Valid values are 0 and 1. 1010f97062a5SSumit Garg 1011e1c5026aSPaul Beesley.. note:: 1012e1c5026aSPaul Beesley If code size is a concern, the build option ``MBEDTLS_SHA256_SMALLER`` can 1013e1c5026aSPaul Beesley be defined in the platform Makefile. It will make mbed TLS use an 1014e1c5026aSPaul Beesley implementation of SHA-256 with smaller memory footprint (~1.5 KB less) but 1015e1c5026aSPaul Beesley slower (~30%). 101640d553cfSPaul Beesley 101740d553cfSPaul Beesley-------------- 101840d553cfSPaul Beesley 1019f28057a2SManish V Badarkhe*Copyright (c) 2017-2023, Arm Limited and Contributors. All rights reserved.* 102040d553cfSPaul Beesley 102140d553cfSPaul Beesley.. _TBBR-Client specification: https://developer.arm.com/docs/den0006/latest/trusted-board-boot-requirements-client-tbbr-client-armv8-a 1022