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