1*54fd6939SJiyong ParkAuthentication Framework & Chain of Trust 2*54fd6939SJiyong Park========================================= 3*54fd6939SJiyong Park 4*54fd6939SJiyong ParkThe aim of this document is to describe the authentication framework 5*54fd6939SJiyong Parkimplemented in Trusted Firmware-A (TF-A). This framework fulfills the 6*54fd6939SJiyong Parkfollowing requirements: 7*54fd6939SJiyong Park 8*54fd6939SJiyong Park#. It should be possible for a platform port to specify the Chain of Trust in 9*54fd6939SJiyong Park terms of certificate hierarchy and the mechanisms used to verify a 10*54fd6939SJiyong Park particular image/certificate. 11*54fd6939SJiyong Park 12*54fd6939SJiyong Park#. The framework should distinguish between: 13*54fd6939SJiyong Park 14*54fd6939SJiyong Park - The mechanism used to encode and transport information, e.g. DER encoded 15*54fd6939SJiyong Park X.509v3 certificates to ferry Subject Public Keys, hashes and non-volatile 16*54fd6939SJiyong Park counters. 17*54fd6939SJiyong Park 18*54fd6939SJiyong Park - The mechanism used to verify the transported information i.e. the 19*54fd6939SJiyong Park cryptographic libraries. 20*54fd6939SJiyong Park 21*54fd6939SJiyong ParkThe framework has been designed following a modular approach illustrated in the 22*54fd6939SJiyong Parknext diagram: 23*54fd6939SJiyong Park 24*54fd6939SJiyong Park:: 25*54fd6939SJiyong Park 26*54fd6939SJiyong Park +---------------+---------------+------------+ 27*54fd6939SJiyong Park | Trusted | Trusted | Trusted | 28*54fd6939SJiyong Park | Firmware | Firmware | Firmware | 29*54fd6939SJiyong Park | Generic | IO Framework | Platform | 30*54fd6939SJiyong Park | Code i.e. | (IO) | Port | 31*54fd6939SJiyong Park | BL1/BL2 (GEN) | | (PP) | 32*54fd6939SJiyong Park +---------------+---------------+------------+ 33*54fd6939SJiyong Park ^ ^ ^ 34*54fd6939SJiyong Park | | | 35*54fd6939SJiyong Park v v v 36*54fd6939SJiyong Park +-----------+ +-----------+ +-----------+ 37*54fd6939SJiyong Park | | | | | Image | 38*54fd6939SJiyong Park | Crypto | | Auth | | Parser | 39*54fd6939SJiyong Park | Module |<->| Module |<->| Module | 40*54fd6939SJiyong Park | (CM) | | (AM) | | (IPM) | 41*54fd6939SJiyong Park | | | | | | 42*54fd6939SJiyong Park +-----------+ +-----------+ +-----------+ 43*54fd6939SJiyong Park ^ ^ 44*54fd6939SJiyong Park | | 45*54fd6939SJiyong Park v v 46*54fd6939SJiyong Park +----------------+ +-----------------+ 47*54fd6939SJiyong Park | Cryptographic | | Image Parser | 48*54fd6939SJiyong Park | Libraries (CL) | | Libraries (IPL) | 49*54fd6939SJiyong Park +----------------+ +-----------------+ 50*54fd6939SJiyong Park | | 51*54fd6939SJiyong Park | | 52*54fd6939SJiyong Park | | 53*54fd6939SJiyong Park v v 54*54fd6939SJiyong Park +-----------------+ 55*54fd6939SJiyong Park | Misc. Libs e.g. | 56*54fd6939SJiyong Park | ASN.1 decoder | 57*54fd6939SJiyong Park | | 58*54fd6939SJiyong Park +-----------------+ 59*54fd6939SJiyong Park 60*54fd6939SJiyong Park DIAGRAM 1. 61*54fd6939SJiyong Park 62*54fd6939SJiyong ParkThis document describes the inner details of the authentication framework and 63*54fd6939SJiyong Parkthe abstraction mechanisms available to specify a Chain of Trust. 64*54fd6939SJiyong Park 65*54fd6939SJiyong ParkFramework design 66*54fd6939SJiyong Park---------------- 67*54fd6939SJiyong Park 68*54fd6939SJiyong ParkThis section describes some aspects of the framework design and the rationale 69*54fd6939SJiyong Parkbehind them. These aspects are key to verify a Chain of Trust. 70*54fd6939SJiyong Park 71*54fd6939SJiyong ParkChain of Trust 72*54fd6939SJiyong Park~~~~~~~~~~~~~~ 73*54fd6939SJiyong Park 74*54fd6939SJiyong ParkA CoT is basically a sequence of authentication images which usually starts with 75*54fd6939SJiyong Parka root of trust and culminates in a single data image. The following diagram 76*54fd6939SJiyong Parkillustrates how this maps to a CoT for the BL31 image described in the 77*54fd6939SJiyong Park`TBBR-Client specification`_. 78*54fd6939SJiyong Park 79*54fd6939SJiyong Park:: 80*54fd6939SJiyong Park 81*54fd6939SJiyong Park +------------------+ +-------------------+ 82*54fd6939SJiyong Park | ROTPK/ROTPK Hash |------>| Trusted Key | 83*54fd6939SJiyong Park +------------------+ | Certificate | 84*54fd6939SJiyong Park | (Auth Image) | 85*54fd6939SJiyong Park /+-------------------+ 86*54fd6939SJiyong Park / | 87*54fd6939SJiyong Park / | 88*54fd6939SJiyong Park / | 89*54fd6939SJiyong Park / | 90*54fd6939SJiyong Park L v 91*54fd6939SJiyong Park +------------------+ +-------------------+ 92*54fd6939SJiyong Park | Trusted World |------>| BL31 Key | 93*54fd6939SJiyong Park | Public Key | | Certificate | 94*54fd6939SJiyong Park +------------------+ | (Auth Image) | 95*54fd6939SJiyong Park +-------------------+ 96*54fd6939SJiyong Park / | 97*54fd6939SJiyong Park / | 98*54fd6939SJiyong Park / | 99*54fd6939SJiyong Park / | 100*54fd6939SJiyong Park / v 101*54fd6939SJiyong Park +------------------+ L +-------------------+ 102*54fd6939SJiyong Park | BL31 Content |------>| BL31 Content | 103*54fd6939SJiyong Park | Certificate PK | | Certificate | 104*54fd6939SJiyong Park +------------------+ | (Auth Image) | 105*54fd6939SJiyong Park +-------------------+ 106*54fd6939SJiyong Park / | 107*54fd6939SJiyong Park / | 108*54fd6939SJiyong Park / | 109*54fd6939SJiyong Park / | 110*54fd6939SJiyong Park / v 111*54fd6939SJiyong Park +------------------+ L +-------------------+ 112*54fd6939SJiyong Park | BL31 Hash |------>| BL31 Image | 113*54fd6939SJiyong Park | | | (Data Image) | 114*54fd6939SJiyong Park +------------------+ | | 115*54fd6939SJiyong Park +-------------------+ 116*54fd6939SJiyong Park 117*54fd6939SJiyong Park DIAGRAM 2. 118*54fd6939SJiyong Park 119*54fd6939SJiyong ParkThe root of trust is usually a public key (ROTPK) that has been burnt in the 120*54fd6939SJiyong Parkplatform and cannot be modified. 121*54fd6939SJiyong Park 122*54fd6939SJiyong ParkImage types 123*54fd6939SJiyong Park~~~~~~~~~~~ 124*54fd6939SJiyong Park 125*54fd6939SJiyong ParkImages in a CoT are categorised as authentication and data images. An 126*54fd6939SJiyong Parkauthentication image contains information to authenticate a data image or 127*54fd6939SJiyong Parkanother authentication image. A data image is usually a boot loader binary, but 128*54fd6939SJiyong Parkit could be any other data that requires authentication. 129*54fd6939SJiyong Park 130*54fd6939SJiyong ParkComponent responsibilities 131*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~ 132*54fd6939SJiyong Park 133*54fd6939SJiyong ParkFor every image in a Chain of Trust, the following high level operations are 134*54fd6939SJiyong Parkperformed to verify it: 135*54fd6939SJiyong Park 136*54fd6939SJiyong Park#. Allocate memory for the image either statically or at runtime. 137*54fd6939SJiyong Park 138*54fd6939SJiyong Park#. Identify the image and load it in the allocated memory. 139*54fd6939SJiyong Park 140*54fd6939SJiyong Park#. Check the integrity of the image as per its type. 141*54fd6939SJiyong Park 142*54fd6939SJiyong Park#. Authenticate the image as per the cryptographic algorithms used. 143*54fd6939SJiyong Park 144*54fd6939SJiyong Park#. If the image is an authentication image, extract the information that will 145*54fd6939SJiyong Park be used to authenticate the next image in the CoT. 146*54fd6939SJiyong Park 147*54fd6939SJiyong ParkIn Diagram 1, each component is responsible for one or more of these operations. 148*54fd6939SJiyong ParkThe responsibilities are briefly described below. 149*54fd6939SJiyong Park 150*54fd6939SJiyong ParkTF-A Generic code and IO framework (GEN/IO) 151*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 152*54fd6939SJiyong Park 153*54fd6939SJiyong ParkThese components are responsible for initiating the authentication process for a 154*54fd6939SJiyong Parkparticular image in BL1 or BL2. For each BL image that requires authentication, 155*54fd6939SJiyong Parkthe Generic code asks recursively the Authentication module what is the parent 156*54fd6939SJiyong Parkimage until either an authenticated image or the ROT is reached. Then the 157*54fd6939SJiyong ParkGeneric code calls the IO framework to load the image and calls the 158*54fd6939SJiyong ParkAuthentication module to authenticate it, following the CoT from ROT to Image. 159*54fd6939SJiyong Park 160*54fd6939SJiyong ParkTF-A Platform Port (PP) 161*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^ 162*54fd6939SJiyong Park 163*54fd6939SJiyong ParkThe platform is responsible for: 164*54fd6939SJiyong Park 165*54fd6939SJiyong Park#. Specifying the CoT for each image that needs to be authenticated. Details of 166*54fd6939SJiyong Park how a CoT can be specified by the platform are explained later. The platform 167*54fd6939SJiyong Park also specifies the authentication methods and the parsing method used for 168*54fd6939SJiyong Park each image. 169*54fd6939SJiyong Park 170*54fd6939SJiyong Park#. Statically allocating memory for each parameter in each image which is 171*54fd6939SJiyong Park used for verifying the CoT, e.g. memory for public keys, hashes etc. 172*54fd6939SJiyong Park 173*54fd6939SJiyong Park#. Providing the ROTPK or a hash of it. 174*54fd6939SJiyong Park 175*54fd6939SJiyong Park#. Providing additional information to the IPM to enable it to identify and 176*54fd6939SJiyong Park extract authentication parameters contained in an image, e.g. if the 177*54fd6939SJiyong Park parameters are stored as X509v3 extensions, the corresponding OID must be 178*54fd6939SJiyong Park provided. 179*54fd6939SJiyong Park 180*54fd6939SJiyong Park#. Fulfill any other memory requirements of the IPM and the CM (not currently 181*54fd6939SJiyong Park described in this document). 182*54fd6939SJiyong Park 183*54fd6939SJiyong Park#. Export functions to verify an image which uses an authentication method that 184*54fd6939SJiyong Park cannot be interpreted by the CM, e.g. if an image has to be verified using a 185*54fd6939SJiyong Park NV counter, then the value of the counter to compare with can only be 186*54fd6939SJiyong Park provided by the platform. 187*54fd6939SJiyong Park 188*54fd6939SJiyong Park#. Export a custom IPM if a proprietary image format is being used (described 189*54fd6939SJiyong Park later). 190*54fd6939SJiyong Park 191*54fd6939SJiyong ParkAuthentication Module (AM) 192*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^ 193*54fd6939SJiyong Park 194*54fd6939SJiyong ParkIt is responsible for: 195*54fd6939SJiyong Park 196*54fd6939SJiyong Park#. Providing the necessary abstraction mechanisms to describe a CoT. Amongst 197*54fd6939SJiyong Park other things, the authentication and image parsing methods must be specified 198*54fd6939SJiyong Park by the PP in the CoT. 199*54fd6939SJiyong Park 200*54fd6939SJiyong Park#. Verifying the CoT passed by GEN by utilising functionality exported by the 201*54fd6939SJiyong Park PP, IPM and CM. 202*54fd6939SJiyong Park 203*54fd6939SJiyong Park#. Tracking which images have been verified. In case an image is a part of 204*54fd6939SJiyong Park multiple CoTs then it should be verified only once e.g. the Trusted World 205*54fd6939SJiyong Park Key Certificate in the TBBR-Client spec. contains information to verify 206*54fd6939SJiyong Park SCP_BL2, BL31, BL32 each of which have a separate CoT. (This 207*54fd6939SJiyong Park responsibility has not been described in this document but should be 208*54fd6939SJiyong Park trivial to implement). 209*54fd6939SJiyong Park 210*54fd6939SJiyong Park#. Reusing memory meant for a data image to verify authentication images e.g. 211*54fd6939SJiyong Park in the CoT described in Diagram 2, each certificate can be loaded and 212*54fd6939SJiyong Park verified in the memory reserved by the platform for the BL31 image. By the 213*54fd6939SJiyong Park time BL31 (the data image) is loaded, all information to authenticate it 214*54fd6939SJiyong Park will have been extracted from the parent image i.e. BL31 content 215*54fd6939SJiyong Park certificate. It is assumed that the size of an authentication image will 216*54fd6939SJiyong Park never exceed the size of a data image. It should be possible to verify this 217*54fd6939SJiyong Park at build time using asserts. 218*54fd6939SJiyong Park 219*54fd6939SJiyong ParkCryptographic Module (CM) 220*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^ 221*54fd6939SJiyong Park 222*54fd6939SJiyong ParkThe CM is responsible for providing an API to: 223*54fd6939SJiyong Park 224*54fd6939SJiyong Park#. Verify a digital signature. 225*54fd6939SJiyong Park#. Verify a hash. 226*54fd6939SJiyong Park 227*54fd6939SJiyong ParkThe CM does not include any cryptography related code, but it relies on an 228*54fd6939SJiyong Parkexternal library to perform the cryptographic operations. A Crypto-Library (CL) 229*54fd6939SJiyong Parklinking the CM and the external library must be implemented. The following 230*54fd6939SJiyong Parkfunctions must be provided by the CL: 231*54fd6939SJiyong Park 232*54fd6939SJiyong Park.. code:: c 233*54fd6939SJiyong Park 234*54fd6939SJiyong Park void (*init)(void); 235*54fd6939SJiyong Park int (*verify_signature)(void *data_ptr, unsigned int data_len, 236*54fd6939SJiyong Park void *sig_ptr, unsigned int sig_len, 237*54fd6939SJiyong Park void *sig_alg, unsigned int sig_alg_len, 238*54fd6939SJiyong Park void *pk_ptr, unsigned int pk_len); 239*54fd6939SJiyong Park int (*verify_hash)(void *data_ptr, unsigned int data_len, 240*54fd6939SJiyong Park void *digest_info_ptr, unsigned int digest_info_len); 241*54fd6939SJiyong Park 242*54fd6939SJiyong ParkThese functions are registered in the CM using the macro: 243*54fd6939SJiyong Park 244*54fd6939SJiyong Park.. code:: c 245*54fd6939SJiyong Park 246*54fd6939SJiyong Park REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash); 247*54fd6939SJiyong Park 248*54fd6939SJiyong Park``_name`` must be a string containing the name of the CL. This name is used for 249*54fd6939SJiyong Parkdebugging purposes. 250*54fd6939SJiyong Park 251*54fd6939SJiyong ParkImage Parser Module (IPM) 252*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^ 253*54fd6939SJiyong Park 254*54fd6939SJiyong ParkThe IPM is responsible for: 255*54fd6939SJiyong Park 256*54fd6939SJiyong Park#. Checking the integrity of each image loaded by the IO framework. 257*54fd6939SJiyong Park#. Extracting parameters used for authenticating an image based upon a 258*54fd6939SJiyong Park description provided by the platform in the CoT descriptor. 259*54fd6939SJiyong Park 260*54fd6939SJiyong ParkImages may have different formats (for example, authentication images could be 261*54fd6939SJiyong Parkx509v3 certificates, signed ELF files or any other platform specific format). 262*54fd6939SJiyong ParkThe IPM allows to register an Image Parser Library (IPL) for every image format 263*54fd6939SJiyong Parkused in the CoT. This library must implement the specific methods to parse the 264*54fd6939SJiyong Parkimage. The IPM obtains the image format from the CoT and calls the right IPL to 265*54fd6939SJiyong Parkcheck the image integrity and extract the authentication parameters. 266*54fd6939SJiyong Park 267*54fd6939SJiyong ParkSee Section "Describing the image parsing methods" for more details about the 268*54fd6939SJiyong Parkmechanism the IPM provides to define and register IPLs. 269*54fd6939SJiyong Park 270*54fd6939SJiyong ParkAuthentication methods 271*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~ 272*54fd6939SJiyong Park 273*54fd6939SJiyong ParkThe AM supports the following authentication methods: 274*54fd6939SJiyong Park 275*54fd6939SJiyong Park#. Hash 276*54fd6939SJiyong Park#. Digital signature 277*54fd6939SJiyong Park 278*54fd6939SJiyong ParkThe platform may specify these methods in the CoT in case it decides to define 279*54fd6939SJiyong Parka custom CoT instead of reusing a predefined one. 280*54fd6939SJiyong Park 281*54fd6939SJiyong ParkIf a data image uses multiple methods, then all the methods must be a part of 282*54fd6939SJiyong Parkthe same CoT. The number and type of parameters are method specific. These 283*54fd6939SJiyong Parkparameters should be obtained from the parent image using the IPM. 284*54fd6939SJiyong Park 285*54fd6939SJiyong Park#. Hash 286*54fd6939SJiyong Park 287*54fd6939SJiyong Park Parameters: 288*54fd6939SJiyong Park 289*54fd6939SJiyong Park #. A pointer to data to hash 290*54fd6939SJiyong Park #. Length of the data 291*54fd6939SJiyong Park #. A pointer to the hash 292*54fd6939SJiyong Park #. Length of the hash 293*54fd6939SJiyong Park 294*54fd6939SJiyong Park The hash will be represented by the DER encoding of the following ASN.1 295*54fd6939SJiyong Park type: 296*54fd6939SJiyong Park 297*54fd6939SJiyong Park :: 298*54fd6939SJiyong Park 299*54fd6939SJiyong Park DigestInfo ::= SEQUENCE { 300*54fd6939SJiyong Park digestAlgorithm DigestAlgorithmIdentifier, 301*54fd6939SJiyong Park digest Digest 302*54fd6939SJiyong Park } 303*54fd6939SJiyong Park 304*54fd6939SJiyong Park This ASN.1 structure makes it possible to remove any assumption about the 305*54fd6939SJiyong Park type of hash algorithm used as this information accompanies the hash. This 306*54fd6939SJiyong Park should allow the Cryptography Library (CL) to support multiple hash 307*54fd6939SJiyong Park algorithm implementations. 308*54fd6939SJiyong Park 309*54fd6939SJiyong Park#. Digital Signature 310*54fd6939SJiyong Park 311*54fd6939SJiyong Park Parameters: 312*54fd6939SJiyong Park 313*54fd6939SJiyong Park #. A pointer to data to sign 314*54fd6939SJiyong Park #. Length of the data 315*54fd6939SJiyong Park #. Public Key Algorithm 316*54fd6939SJiyong Park #. Public Key value 317*54fd6939SJiyong Park #. Digital Signature Algorithm 318*54fd6939SJiyong Park #. Digital Signature value 319*54fd6939SJiyong Park 320*54fd6939SJiyong Park The Public Key parameters will be represented by the DER encoding of the 321*54fd6939SJiyong Park following ASN.1 type: 322*54fd6939SJiyong Park 323*54fd6939SJiyong Park :: 324*54fd6939SJiyong Park 325*54fd6939SJiyong Park SubjectPublicKeyInfo ::= SEQUENCE { 326*54fd6939SJiyong Park algorithm AlgorithmIdentifier{PUBLIC-KEY,{PublicKeyAlgorithms}}, 327*54fd6939SJiyong Park subjectPublicKey BIT STRING } 328*54fd6939SJiyong Park 329*54fd6939SJiyong Park The Digital Signature Algorithm will be represented by the DER encoding of 330*54fd6939SJiyong Park the following ASN.1 types. 331*54fd6939SJiyong Park 332*54fd6939SJiyong Park :: 333*54fd6939SJiyong Park 334*54fd6939SJiyong Park AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE { 335*54fd6939SJiyong Park algorithm ALGORITHM.&id({IOSet}), 336*54fd6939SJiyong Park parameters ALGORITHM.&Type({IOSet}{@algorithm}) OPTIONAL 337*54fd6939SJiyong Park } 338*54fd6939SJiyong Park 339*54fd6939SJiyong Park The digital signature will be represented by: 340*54fd6939SJiyong Park 341*54fd6939SJiyong Park :: 342*54fd6939SJiyong Park 343*54fd6939SJiyong Park signature ::= BIT STRING 344*54fd6939SJiyong Park 345*54fd6939SJiyong ParkThe authentication framework will use the image descriptor to extract all the 346*54fd6939SJiyong Parkinformation related to authentication. 347*54fd6939SJiyong Park 348*54fd6939SJiyong ParkSpecifying a Chain of Trust 349*54fd6939SJiyong Park--------------------------- 350*54fd6939SJiyong Park 351*54fd6939SJiyong ParkA CoT can be described as a set of image descriptors linked together in a 352*54fd6939SJiyong Parkparticular order. The order dictates the sequence in which they must be 353*54fd6939SJiyong Parkverified. Each image has a set of properties which allow the AM to verify it. 354*54fd6939SJiyong ParkThese properties are described below. 355*54fd6939SJiyong Park 356*54fd6939SJiyong ParkThe PP is responsible for defining a single or multiple CoTs for a data image. 357*54fd6939SJiyong ParkUnless otherwise specified, the data structures described in the following 358*54fd6939SJiyong Parksections are populated by the PP statically. 359*54fd6939SJiyong Park 360*54fd6939SJiyong ParkDescribing the image parsing methods 361*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 362*54fd6939SJiyong Park 363*54fd6939SJiyong ParkThe parsing method refers to the format of a particular image. For example, an 364*54fd6939SJiyong Parkauthentication image that represents a certificate could be in the X.509v3 365*54fd6939SJiyong Parkformat. A data image that represents a boot loader stage could be in raw binary 366*54fd6939SJiyong Parkor ELF format. The IPM supports three parsing methods. An image has to use one 367*54fd6939SJiyong Parkof the three methods described below. An IPL is responsible for interpreting a 368*54fd6939SJiyong Parksingle parsing method. There has to be one IPL for every method used by the 369*54fd6939SJiyong Parkplatform. 370*54fd6939SJiyong Park 371*54fd6939SJiyong Park#. Raw format: This format is effectively a nop as an image using this method 372*54fd6939SJiyong Park is treated as being in raw binary format e.g. boot loader images used by 373*54fd6939SJiyong Park TF-A. This method should only be used by data images. 374*54fd6939SJiyong Park 375*54fd6939SJiyong Park#. X509V3 method: This method uses industry standards like X.509 to represent 376*54fd6939SJiyong Park PKI certificates (authentication images). It is expected that open source 377*54fd6939SJiyong Park libraries will be available which can be used to parse an image represented 378*54fd6939SJiyong Park by this method. Such libraries can be used to write the corresponding IPL 379*54fd6939SJiyong Park e.g. the X.509 parsing library code in mbed TLS. 380*54fd6939SJiyong Park 381*54fd6939SJiyong Park#. Platform defined method: This method caters for platform specific 382*54fd6939SJiyong Park proprietary standards to represent authentication or data images. For 383*54fd6939SJiyong Park example, The signature of a data image could be appended to the data image 384*54fd6939SJiyong Park raw binary. A header could be prepended to the combined blob to specify the 385*54fd6939SJiyong Park extents of each component. The platform will have to implement the 386*54fd6939SJiyong Park corresponding IPL to interpret such a format. 387*54fd6939SJiyong Park 388*54fd6939SJiyong ParkThe following enum can be used to define these three methods. 389*54fd6939SJiyong Park 390*54fd6939SJiyong Park.. code:: c 391*54fd6939SJiyong Park 392*54fd6939SJiyong Park typedef enum img_type_enum { 393*54fd6939SJiyong Park IMG_RAW, /* Binary image */ 394*54fd6939SJiyong Park IMG_PLAT, /* Platform specific format */ 395*54fd6939SJiyong Park IMG_CERT, /* X509v3 certificate */ 396*54fd6939SJiyong Park IMG_MAX_TYPES, 397*54fd6939SJiyong Park } img_type_t; 398*54fd6939SJiyong Park 399*54fd6939SJiyong ParkAn IPL must provide functions with the following prototypes: 400*54fd6939SJiyong Park 401*54fd6939SJiyong Park.. code:: c 402*54fd6939SJiyong Park 403*54fd6939SJiyong Park void init(void); 404*54fd6939SJiyong Park int check_integrity(void *img, unsigned int img_len); 405*54fd6939SJiyong Park int get_auth_param(const auth_param_type_desc_t *type_desc, 406*54fd6939SJiyong Park void *img, unsigned int img_len, 407*54fd6939SJiyong Park void **param, unsigned int *param_len); 408*54fd6939SJiyong Park 409*54fd6939SJiyong ParkAn IPL for each type must be registered using the following macro: 410*54fd6939SJiyong Park 411*54fd6939SJiyong Park.. code:: c 412*54fd6939SJiyong Park 413*54fd6939SJiyong Park REGISTER_IMG_PARSER_LIB(_type, _name, _init, _check_int, _get_param) 414*54fd6939SJiyong Park 415*54fd6939SJiyong Park- ``_type``: one of the types described above. 416*54fd6939SJiyong Park- ``_name``: a string containing the IPL name for debugging purposes. 417*54fd6939SJiyong Park- ``_init``: initialization function pointer. 418*54fd6939SJiyong Park- ``_check_int``: check image integrity function pointer. 419*54fd6939SJiyong Park- ``_get_param``: extract authentication parameter function pointer. 420*54fd6939SJiyong Park 421*54fd6939SJiyong ParkThe ``init()`` function will be used to initialize the IPL. 422*54fd6939SJiyong Park 423*54fd6939SJiyong ParkThe ``check_integrity()`` function is passed a pointer to the memory where the 424*54fd6939SJiyong Parkimage has been loaded by the IO framework and the image length. It should ensure 425*54fd6939SJiyong Parkthat the image is in the format corresponding to the parsing method and has not 426*54fd6939SJiyong Parkbeen tampered with. For example, RFC-2459 describes a validation sequence for an 427*54fd6939SJiyong ParkX.509 certificate. 428*54fd6939SJiyong Park 429*54fd6939SJiyong ParkThe ``get_auth_param()`` function is passed a parameter descriptor containing 430*54fd6939SJiyong Parkinformation about the parameter (``type_desc`` and ``cookie``) to identify and 431*54fd6939SJiyong Parkextract the data corresponding to that parameter from an image. This data will 432*54fd6939SJiyong Parkbe used to verify either the current or the next image in the CoT sequence. 433*54fd6939SJiyong Park 434*54fd6939SJiyong ParkEach image in the CoT will specify the parsing method it uses. This information 435*54fd6939SJiyong Parkwill be used by the IPM to find the right parser descriptor for the image. 436*54fd6939SJiyong Park 437*54fd6939SJiyong ParkDescribing the authentication method(s) 438*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 439*54fd6939SJiyong Park 440*54fd6939SJiyong ParkAs part of the CoT, each image has to specify one or more authentication methods 441*54fd6939SJiyong Parkwhich will be used to verify it. As described in the Section "Authentication 442*54fd6939SJiyong Parkmethods", there are three methods supported by the AM. 443*54fd6939SJiyong Park 444*54fd6939SJiyong Park.. code:: c 445*54fd6939SJiyong Park 446*54fd6939SJiyong Park typedef enum { 447*54fd6939SJiyong Park AUTH_METHOD_NONE, 448*54fd6939SJiyong Park AUTH_METHOD_HASH, 449*54fd6939SJiyong Park AUTH_METHOD_SIG, 450*54fd6939SJiyong Park AUTH_METHOD_NUM 451*54fd6939SJiyong Park } auth_method_type_t; 452*54fd6939SJiyong Park 453*54fd6939SJiyong ParkThe AM defines the type of each parameter used by an authentication method. It 454*54fd6939SJiyong Parkuses this information to: 455*54fd6939SJiyong Park 456*54fd6939SJiyong Park#. Specify to the ``get_auth_param()`` function exported by the IPM, which 457*54fd6939SJiyong Park parameter should be extracted from an image. 458*54fd6939SJiyong Park 459*54fd6939SJiyong Park#. Correctly marshall the parameters while calling the verification function 460*54fd6939SJiyong Park exported by the CM and PP. 461*54fd6939SJiyong Park 462*54fd6939SJiyong Park#. Extract authentication parameters from a parent image in order to verify a 463*54fd6939SJiyong Park child image e.g. to verify the certificate image, the public key has to be 464*54fd6939SJiyong Park obtained from the parent image. 465*54fd6939SJiyong Park 466*54fd6939SJiyong Park.. code:: c 467*54fd6939SJiyong Park 468*54fd6939SJiyong Park typedef enum { 469*54fd6939SJiyong Park AUTH_PARAM_NONE, 470*54fd6939SJiyong Park AUTH_PARAM_RAW_DATA, /* Raw image data */ 471*54fd6939SJiyong Park AUTH_PARAM_SIG, /* The image signature */ 472*54fd6939SJiyong Park AUTH_PARAM_SIG_ALG, /* The image signature algorithm */ 473*54fd6939SJiyong Park AUTH_PARAM_HASH, /* A hash (including the algorithm) */ 474*54fd6939SJiyong Park AUTH_PARAM_PUB_KEY, /* A public key */ 475*54fd6939SJiyong Park } auth_param_type_t; 476*54fd6939SJiyong Park 477*54fd6939SJiyong ParkThe AM defines the following structure to identify an authentication parameter 478*54fd6939SJiyong Parkrequired to verify an image. 479*54fd6939SJiyong Park 480*54fd6939SJiyong Park.. code:: c 481*54fd6939SJiyong Park 482*54fd6939SJiyong Park typedef struct auth_param_type_desc_s { 483*54fd6939SJiyong Park auth_param_type_t type; 484*54fd6939SJiyong Park void *cookie; 485*54fd6939SJiyong Park } auth_param_type_desc_t; 486*54fd6939SJiyong Park 487*54fd6939SJiyong Park``cookie`` is used by the platform to specify additional information to the IPM 488*54fd6939SJiyong Parkwhich enables it to uniquely identify the parameter that should be extracted 489*54fd6939SJiyong Parkfrom an image. For example, the hash of a BL3x image in its corresponding 490*54fd6939SJiyong Parkcontent certificate is stored in an X509v3 custom extension field. An extension 491*54fd6939SJiyong Parkfield can only be identified using an OID. In this case, the ``cookie`` could 492*54fd6939SJiyong Parkcontain the pointer to the OID defined by the platform for the hash extension 493*54fd6939SJiyong Parkfield while the ``type`` field could be set to ``AUTH_PARAM_HASH``. A value of 0 for 494*54fd6939SJiyong Parkthe ``cookie`` field means that it is not used. 495*54fd6939SJiyong Park 496*54fd6939SJiyong ParkFor each method, the AM defines a structure with the parameters required to 497*54fd6939SJiyong Parkverify the image. 498*54fd6939SJiyong Park 499*54fd6939SJiyong Park.. code:: c 500*54fd6939SJiyong Park 501*54fd6939SJiyong Park /* 502*54fd6939SJiyong Park * Parameters for authentication by hash matching 503*54fd6939SJiyong Park */ 504*54fd6939SJiyong Park typedef struct auth_method_param_hash_s { 505*54fd6939SJiyong Park auth_param_type_desc_t *data; /* Data to hash */ 506*54fd6939SJiyong Park auth_param_type_desc_t *hash; /* Hash to match with */ 507*54fd6939SJiyong Park } auth_method_param_hash_t; 508*54fd6939SJiyong Park 509*54fd6939SJiyong Park /* 510*54fd6939SJiyong Park * Parameters for authentication by signature 511*54fd6939SJiyong Park */ 512*54fd6939SJiyong Park typedef struct auth_method_param_sig_s { 513*54fd6939SJiyong Park auth_param_type_desc_t *pk; /* Public key */ 514*54fd6939SJiyong Park auth_param_type_desc_t *sig; /* Signature to check */ 515*54fd6939SJiyong Park auth_param_type_desc_t *alg; /* Signature algorithm */ 516*54fd6939SJiyong Park auth_param_type_desc_t *tbs; /* Data signed */ 517*54fd6939SJiyong Park } auth_method_param_sig_t; 518*54fd6939SJiyong Park 519*54fd6939SJiyong ParkThe AM defines the following structure to describe an authentication method for 520*54fd6939SJiyong Parkverifying an image 521*54fd6939SJiyong Park 522*54fd6939SJiyong Park.. code:: c 523*54fd6939SJiyong Park 524*54fd6939SJiyong Park /* 525*54fd6939SJiyong Park * Authentication method descriptor 526*54fd6939SJiyong Park */ 527*54fd6939SJiyong Park typedef struct auth_method_desc_s { 528*54fd6939SJiyong Park auth_method_type_t type; 529*54fd6939SJiyong Park union { 530*54fd6939SJiyong Park auth_method_param_hash_t hash; 531*54fd6939SJiyong Park auth_method_param_sig_t sig; 532*54fd6939SJiyong Park } param; 533*54fd6939SJiyong Park } auth_method_desc_t; 534*54fd6939SJiyong Park 535*54fd6939SJiyong ParkUsing the method type specified in the ``type`` field, the AM finds out what field 536*54fd6939SJiyong Parkneeds to access within the ``param`` union. 537*54fd6939SJiyong Park 538*54fd6939SJiyong ParkStoring Authentication parameters 539*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 540*54fd6939SJiyong Park 541*54fd6939SJiyong ParkA parameter described by ``auth_param_type_desc_t`` to verify an image could be 542*54fd6939SJiyong Parkobtained from either the image itself or its parent image. The memory allocated 543*54fd6939SJiyong Parkfor loading the parent image will be reused for loading the child image. Hence 544*54fd6939SJiyong Parkparameters which are obtained from the parent for verifying a child image need 545*54fd6939SJiyong Parkto have memory allocated for them separately where they can be stored. This 546*54fd6939SJiyong Parkmemory must be statically allocated by the platform port. 547*54fd6939SJiyong Park 548*54fd6939SJiyong ParkThe AM defines the following structure to store the data corresponding to an 549*54fd6939SJiyong Parkauthentication parameter. 550*54fd6939SJiyong Park 551*54fd6939SJiyong Park.. code:: c 552*54fd6939SJiyong Park 553*54fd6939SJiyong Park typedef struct auth_param_data_desc_s { 554*54fd6939SJiyong Park void *auth_param_ptr; 555*54fd6939SJiyong Park unsigned int auth_param_len; 556*54fd6939SJiyong Park } auth_param_data_desc_t; 557*54fd6939SJiyong Park 558*54fd6939SJiyong ParkThe ``auth_param_ptr`` field is initialized by the platform. The ``auth_param_len`` 559*54fd6939SJiyong Parkfield is used to specify the length of the data in the memory. 560*54fd6939SJiyong Park 561*54fd6939SJiyong ParkFor parameters that can be obtained from the child image itself, the IPM is 562*54fd6939SJiyong Parkresponsible for populating the ``auth_param_ptr`` and ``auth_param_len`` fields 563*54fd6939SJiyong Parkwhile executing the ``img_get_auth_param()`` function. 564*54fd6939SJiyong Park 565*54fd6939SJiyong ParkThe AM defines the following structure to enable an image to describe the 566*54fd6939SJiyong Parkparameters that should be extracted from it and used to verify the next image 567*54fd6939SJiyong Park(child) in a CoT. 568*54fd6939SJiyong Park 569*54fd6939SJiyong Park.. code:: c 570*54fd6939SJiyong Park 571*54fd6939SJiyong Park typedef struct auth_param_desc_s { 572*54fd6939SJiyong Park auth_param_type_desc_t type_desc; 573*54fd6939SJiyong Park auth_param_data_desc_t data; 574*54fd6939SJiyong Park } auth_param_desc_t; 575*54fd6939SJiyong Park 576*54fd6939SJiyong ParkDescribing an image in a CoT 577*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 578*54fd6939SJiyong Park 579*54fd6939SJiyong ParkAn image in a CoT is a consolidation of the following aspects of a CoT described 580*54fd6939SJiyong Parkabove. 581*54fd6939SJiyong Park 582*54fd6939SJiyong Park#. A unique identifier specified by the platform which allows the IO framework 583*54fd6939SJiyong Park to locate the image in a FIP and load it in the memory reserved for the data 584*54fd6939SJiyong Park image in the CoT. 585*54fd6939SJiyong Park 586*54fd6939SJiyong Park#. A parsing method which is used by the AM to find the appropriate IPM. 587*54fd6939SJiyong Park 588*54fd6939SJiyong Park#. Authentication methods and their parameters as described in the previous 589*54fd6939SJiyong Park section. These are used to verify the current image. 590*54fd6939SJiyong Park 591*54fd6939SJiyong Park#. Parameters which are used to verify the next image in the current CoT. These 592*54fd6939SJiyong Park parameters are specified only by authentication images and can be extracted 593*54fd6939SJiyong Park from the current image once it has been verified. 594*54fd6939SJiyong Park 595*54fd6939SJiyong ParkThe following data structure describes an image in a CoT. 596*54fd6939SJiyong Park 597*54fd6939SJiyong Park.. code:: c 598*54fd6939SJiyong Park 599*54fd6939SJiyong Park typedef struct auth_img_desc_s { 600*54fd6939SJiyong Park unsigned int img_id; 601*54fd6939SJiyong Park const struct auth_img_desc_s *parent; 602*54fd6939SJiyong Park img_type_t img_type; 603*54fd6939SJiyong Park const auth_method_desc_t *const img_auth_methods; 604*54fd6939SJiyong Park const auth_param_desc_t *const authenticated_data; 605*54fd6939SJiyong Park } auth_img_desc_t; 606*54fd6939SJiyong Park 607*54fd6939SJiyong ParkA CoT is defined as an array of pointers to ``auth_image_desc_t`` structures 608*54fd6939SJiyong Parklinked together by the ``parent`` field. Those nodes with no parent must be 609*54fd6939SJiyong Parkauthenticated using the ROTPK stored in the platform. 610*54fd6939SJiyong Park 611*54fd6939SJiyong ParkImplementation example 612*54fd6939SJiyong Park---------------------- 613*54fd6939SJiyong Park 614*54fd6939SJiyong ParkThis section is a detailed guide explaining a trusted boot implementation using 615*54fd6939SJiyong Parkthe authentication framework. This example corresponds to the Applicative 616*54fd6939SJiyong ParkFunctional Mode (AFM) as specified in the TBBR-Client document. It is 617*54fd6939SJiyong Parkrecommended to read this guide along with the source code. 618*54fd6939SJiyong Park 619*54fd6939SJiyong ParkThe TBBR CoT 620*54fd6939SJiyong Park~~~~~~~~~~~~ 621*54fd6939SJiyong Park 622*54fd6939SJiyong ParkCoT specific to BL1 and BL2 can be found in ``drivers/auth/tbbr/tbbr_cot_bl1.c`` 623*54fd6939SJiyong Parkand ``drivers/auth/tbbr/tbbr_cot_bl2.c`` respectively. The common CoT used across 624*54fd6939SJiyong ParkBL1 and BL2 can be found in ``drivers/auth/tbbr/tbbr_cot_common.c``. 625*54fd6939SJiyong ParkThis CoT consists of an array of pointers to image descriptors and it is 626*54fd6939SJiyong Parkregistered in the framework using the macro ``REGISTER_COT(cot_desc)``, where 627*54fd6939SJiyong Park``cot_desc`` must be the name of the array (passing a pointer or any other 628*54fd6939SJiyong Parktype of indirection will cause the registration process to fail). 629*54fd6939SJiyong Park 630*54fd6939SJiyong ParkThe number of images participating in the boot process depends on the CoT. 631*54fd6939SJiyong ParkThere is, however, a minimum set of images that are mandatory in TF-A and thus 632*54fd6939SJiyong Parkall CoTs must present: 633*54fd6939SJiyong Park 634*54fd6939SJiyong Park- ``BL2`` 635*54fd6939SJiyong Park- ``SCP_BL2`` (platform specific) 636*54fd6939SJiyong Park- ``BL31`` 637*54fd6939SJiyong Park- ``BL32`` (optional) 638*54fd6939SJiyong Park- ``BL33`` 639*54fd6939SJiyong Park 640*54fd6939SJiyong ParkThe TBBR specifies the additional certificates that must accompany these images 641*54fd6939SJiyong Parkfor a proper authentication. Details about the TBBR CoT may be found in the 642*54fd6939SJiyong Park:ref:`Trusted Board Boot` document. 643*54fd6939SJiyong Park 644*54fd6939SJiyong ParkFollowing the :ref:`Porting Guide`, a platform must provide unique 645*54fd6939SJiyong Parkidentifiers for all the images and certificates that will be loaded during the 646*54fd6939SJiyong Parkboot process. If a platform is using the TBBR as a reference for trusted boot, 647*54fd6939SJiyong Parkthese identifiers can be obtained from ``include/common/tbbr/tbbr_img_def.h``. 648*54fd6939SJiyong ParkArm platforms include this file in ``include/plat/arm/common/arm_def.h``. Other 649*54fd6939SJiyong Parkplatforms may also include this file or provide their own identifiers. 650*54fd6939SJiyong Park 651*54fd6939SJiyong Park**Important**: the authentication module uses these identifiers to index the 652*54fd6939SJiyong ParkCoT array, so the descriptors location in the array must match the identifiers. 653*54fd6939SJiyong Park 654*54fd6939SJiyong ParkEach image descriptor must specify: 655*54fd6939SJiyong Park 656*54fd6939SJiyong Park- ``img_id``: the corresponding image unique identifier defined by the platform. 657*54fd6939SJiyong Park- ``img_type``: the image parser module uses the image type to call the proper 658*54fd6939SJiyong Park parsing library to check the image integrity and extract the required 659*54fd6939SJiyong Park authentication parameters. Three types of images are currently supported: 660*54fd6939SJiyong Park 661*54fd6939SJiyong Park - ``IMG_RAW``: image is a raw binary. No parsing functions are available, 662*54fd6939SJiyong Park other than reading the whole image. 663*54fd6939SJiyong Park - ``IMG_PLAT``: image format is platform specific. The platform may use this 664*54fd6939SJiyong Park type for custom images not directly supported by the authentication 665*54fd6939SJiyong Park framework. 666*54fd6939SJiyong Park - ``IMG_CERT``: image is an x509v3 certificate. 667*54fd6939SJiyong Park 668*54fd6939SJiyong Park- ``parent``: pointer to the parent image descriptor. The parent will contain 669*54fd6939SJiyong Park the information required to authenticate the current image. If the parent 670*54fd6939SJiyong Park is NULL, the authentication parameters will be obtained from the platform 671*54fd6939SJiyong Park (i.e. the BL2 and Trusted Key certificates are signed with the ROT private 672*54fd6939SJiyong Park key, whose public part is stored in the platform). 673*54fd6939SJiyong Park- ``img_auth_methods``: this points to an array which defines the 674*54fd6939SJiyong Park authentication methods that must be checked to consider an image 675*54fd6939SJiyong Park authenticated. Each method consists of a type and a list of parameter 676*54fd6939SJiyong Park descriptors. A parameter descriptor consists of a type and a cookie which 677*54fd6939SJiyong Park will point to specific information required to extract that parameter from 678*54fd6939SJiyong Park the image (i.e. if the parameter is stored in an x509v3 extension, the 679*54fd6939SJiyong Park cookie will point to the extension OID). Depending on the method type, a 680*54fd6939SJiyong Park different number of parameters must be specified. This pointer should not be 681*54fd6939SJiyong Park NULL. 682*54fd6939SJiyong Park Supported methods are: 683*54fd6939SJiyong Park 684*54fd6939SJiyong Park - ``AUTH_METHOD_HASH``: the hash of the image must match the hash extracted 685*54fd6939SJiyong Park from the parent image. The following parameter descriptors must be 686*54fd6939SJiyong Park specified: 687*54fd6939SJiyong Park 688*54fd6939SJiyong Park - ``data``: data to be hashed (obtained from current image) 689*54fd6939SJiyong Park - ``hash``: reference hash (obtained from parent image) 690*54fd6939SJiyong Park 691*54fd6939SJiyong Park - ``AUTH_METHOD_SIG``: the image (usually a certificate) must be signed with 692*54fd6939SJiyong Park the private key whose public part is extracted from the parent image (or 693*54fd6939SJiyong Park the platform if the parent is NULL). The following parameter descriptors 694*54fd6939SJiyong Park must be specified: 695*54fd6939SJiyong Park 696*54fd6939SJiyong Park - ``pk``: the public key (obtained from parent image) 697*54fd6939SJiyong Park - ``sig``: the digital signature (obtained from current image) 698*54fd6939SJiyong Park - ``alg``: the signature algorithm used (obtained from current image) 699*54fd6939SJiyong Park - ``data``: the data to be signed (obtained from current image) 700*54fd6939SJiyong Park 701*54fd6939SJiyong Park- ``authenticated_data``: this array pointer indicates what authentication 702*54fd6939SJiyong Park parameters must be extracted from an image once it has been authenticated. 703*54fd6939SJiyong Park Each parameter consists of a parameter descriptor and the buffer 704*54fd6939SJiyong Park address/size to store the parameter. The CoT is responsible for allocating 705*54fd6939SJiyong Park the required memory to store the parameters. This pointer may be NULL. 706*54fd6939SJiyong Park 707*54fd6939SJiyong ParkIn the ``tbbr_cot*.c`` file, a set of buffers are allocated to store the parameters 708*54fd6939SJiyong Parkextracted from the certificates. In the case of the TBBR CoT, these parameters 709*54fd6939SJiyong Parkare hashes and public keys. In DER format, an RSA-4096 public key requires 550 710*54fd6939SJiyong Parkbytes, and a hash requires 51 bytes. Depending on the CoT and the authentication 711*54fd6939SJiyong Parkprocess, some of the buffers may be reused at different stages during the boot. 712*54fd6939SJiyong Park 713*54fd6939SJiyong ParkNext in that file, the parameter descriptors are defined. These descriptors will 714*54fd6939SJiyong Parkbe used to extract the parameter data from the corresponding image. 715*54fd6939SJiyong Park 716*54fd6939SJiyong ParkExample: the BL31 Chain of Trust 717*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 718*54fd6939SJiyong Park 719*54fd6939SJiyong ParkFour image descriptors form the BL31 Chain of Trust: 720*54fd6939SJiyong Park 721*54fd6939SJiyong Park.. code:: c 722*54fd6939SJiyong Park 723*54fd6939SJiyong Park static const auth_img_desc_t trusted_key_cert = { 724*54fd6939SJiyong Park .img_id = TRUSTED_KEY_CERT_ID, 725*54fd6939SJiyong Park .img_type = IMG_CERT, 726*54fd6939SJiyong Park .parent = NULL, 727*54fd6939SJiyong Park .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { 728*54fd6939SJiyong Park [0] = { 729*54fd6939SJiyong Park .type = AUTH_METHOD_SIG, 730*54fd6939SJiyong Park .param.sig = { 731*54fd6939SJiyong Park .pk = &subject_pk, 732*54fd6939SJiyong Park .sig = &sig, 733*54fd6939SJiyong Park .alg = &sig_alg, 734*54fd6939SJiyong Park .data = &raw_data 735*54fd6939SJiyong Park } 736*54fd6939SJiyong Park }, 737*54fd6939SJiyong Park [1] = { 738*54fd6939SJiyong Park .type = AUTH_METHOD_NV_CTR, 739*54fd6939SJiyong Park .param.nv_ctr = { 740*54fd6939SJiyong Park .cert_nv_ctr = &trusted_nv_ctr, 741*54fd6939SJiyong Park .plat_nv_ctr = &trusted_nv_ctr 742*54fd6939SJiyong Park } 743*54fd6939SJiyong Park } 744*54fd6939SJiyong Park }, 745*54fd6939SJiyong Park .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) { 746*54fd6939SJiyong Park [0] = { 747*54fd6939SJiyong Park .type_desc = &trusted_world_pk, 748*54fd6939SJiyong Park .data = { 749*54fd6939SJiyong Park .ptr = (void *)trusted_world_pk_buf, 750*54fd6939SJiyong Park .len = (unsigned int)PK_DER_LEN 751*54fd6939SJiyong Park } 752*54fd6939SJiyong Park }, 753*54fd6939SJiyong Park [1] = { 754*54fd6939SJiyong Park .type_desc = &non_trusted_world_pk, 755*54fd6939SJiyong Park .data = { 756*54fd6939SJiyong Park .ptr = (void *)non_trusted_world_pk_buf, 757*54fd6939SJiyong Park .len = (unsigned int)PK_DER_LEN 758*54fd6939SJiyong Park } 759*54fd6939SJiyong Park } 760*54fd6939SJiyong Park } 761*54fd6939SJiyong Park }; 762*54fd6939SJiyong Park static const auth_img_desc_t soc_fw_key_cert = { 763*54fd6939SJiyong Park .img_id = SOC_FW_KEY_CERT_ID, 764*54fd6939SJiyong Park .img_type = IMG_CERT, 765*54fd6939SJiyong Park .parent = &trusted_key_cert, 766*54fd6939SJiyong Park .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { 767*54fd6939SJiyong Park [0] = { 768*54fd6939SJiyong Park .type = AUTH_METHOD_SIG, 769*54fd6939SJiyong Park .param.sig = { 770*54fd6939SJiyong Park .pk = &trusted_world_pk, 771*54fd6939SJiyong Park .sig = &sig, 772*54fd6939SJiyong Park .alg = &sig_alg, 773*54fd6939SJiyong Park .data = &raw_data 774*54fd6939SJiyong Park } 775*54fd6939SJiyong Park }, 776*54fd6939SJiyong Park [1] = { 777*54fd6939SJiyong Park .type = AUTH_METHOD_NV_CTR, 778*54fd6939SJiyong Park .param.nv_ctr = { 779*54fd6939SJiyong Park .cert_nv_ctr = &trusted_nv_ctr, 780*54fd6939SJiyong Park .plat_nv_ctr = &trusted_nv_ctr 781*54fd6939SJiyong Park } 782*54fd6939SJiyong Park } 783*54fd6939SJiyong Park }, 784*54fd6939SJiyong Park .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) { 785*54fd6939SJiyong Park [0] = { 786*54fd6939SJiyong Park .type_desc = &soc_fw_content_pk, 787*54fd6939SJiyong Park .data = { 788*54fd6939SJiyong Park .ptr = (void *)content_pk_buf, 789*54fd6939SJiyong Park .len = (unsigned int)PK_DER_LEN 790*54fd6939SJiyong Park } 791*54fd6939SJiyong Park } 792*54fd6939SJiyong Park } 793*54fd6939SJiyong Park }; 794*54fd6939SJiyong Park static const auth_img_desc_t soc_fw_content_cert = { 795*54fd6939SJiyong Park .img_id = SOC_FW_CONTENT_CERT_ID, 796*54fd6939SJiyong Park .img_type = IMG_CERT, 797*54fd6939SJiyong Park .parent = &soc_fw_key_cert, 798*54fd6939SJiyong Park .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { 799*54fd6939SJiyong Park [0] = { 800*54fd6939SJiyong Park .type = AUTH_METHOD_SIG, 801*54fd6939SJiyong Park .param.sig = { 802*54fd6939SJiyong Park .pk = &soc_fw_content_pk, 803*54fd6939SJiyong Park .sig = &sig, 804*54fd6939SJiyong Park .alg = &sig_alg, 805*54fd6939SJiyong Park .data = &raw_data 806*54fd6939SJiyong Park } 807*54fd6939SJiyong Park }, 808*54fd6939SJiyong Park [1] = { 809*54fd6939SJiyong Park .type = AUTH_METHOD_NV_CTR, 810*54fd6939SJiyong Park .param.nv_ctr = { 811*54fd6939SJiyong Park .cert_nv_ctr = &trusted_nv_ctr, 812*54fd6939SJiyong Park .plat_nv_ctr = &trusted_nv_ctr 813*54fd6939SJiyong Park } 814*54fd6939SJiyong Park } 815*54fd6939SJiyong Park }, 816*54fd6939SJiyong Park .authenticated_data = (const auth_param_desc_t[COT_MAX_VERIFIED_PARAMS]) { 817*54fd6939SJiyong Park [0] = { 818*54fd6939SJiyong Park .type_desc = &soc_fw_hash, 819*54fd6939SJiyong Park .data = { 820*54fd6939SJiyong Park .ptr = (void *)soc_fw_hash_buf, 821*54fd6939SJiyong Park .len = (unsigned int)HASH_DER_LEN 822*54fd6939SJiyong Park } 823*54fd6939SJiyong Park }, 824*54fd6939SJiyong Park [1] = { 825*54fd6939SJiyong Park .type_desc = &soc_fw_config_hash, 826*54fd6939SJiyong Park .data = { 827*54fd6939SJiyong Park .ptr = (void *)soc_fw_config_hash_buf, 828*54fd6939SJiyong Park .len = (unsigned int)HASH_DER_LEN 829*54fd6939SJiyong Park } 830*54fd6939SJiyong Park } 831*54fd6939SJiyong Park } 832*54fd6939SJiyong Park }; 833*54fd6939SJiyong Park static const auth_img_desc_t bl31_image = { 834*54fd6939SJiyong Park .img_id = BL31_IMAGE_ID, 835*54fd6939SJiyong Park .img_type = IMG_RAW, 836*54fd6939SJiyong Park .parent = &soc_fw_content_cert, 837*54fd6939SJiyong Park .img_auth_methods = (const auth_method_desc_t[AUTH_METHOD_NUM]) { 838*54fd6939SJiyong Park [0] = { 839*54fd6939SJiyong Park .type = AUTH_METHOD_HASH, 840*54fd6939SJiyong Park .param.hash = { 841*54fd6939SJiyong Park .data = &raw_data, 842*54fd6939SJiyong Park .hash = &soc_fw_hash 843*54fd6939SJiyong Park } 844*54fd6939SJiyong Park } 845*54fd6939SJiyong Park } 846*54fd6939SJiyong Park }; 847*54fd6939SJiyong Park 848*54fd6939SJiyong ParkThe **Trusted Key certificate** is signed with the ROT private key and contains 849*54fd6939SJiyong Parkthe Trusted World public key and the Non-Trusted World public key as x509v3 850*54fd6939SJiyong Parkextensions. This must be specified in the image descriptor using the 851*54fd6939SJiyong Park``img_auth_methods`` and ``authenticated_data`` arrays, respectively. 852*54fd6939SJiyong Park 853*54fd6939SJiyong ParkThe Trusted Key certificate is authenticated by checking its digital signature 854*54fd6939SJiyong Parkusing the ROTPK. Four parameters are required to check a signature: the public 855*54fd6939SJiyong Parkkey, the algorithm, the signature and the data that has been signed. Therefore, 856*54fd6939SJiyong Parkfour parameter descriptors must be specified with the authentication method: 857*54fd6939SJiyong Park 858*54fd6939SJiyong Park- ``subject_pk``: parameter descriptor of type ``AUTH_PARAM_PUB_KEY``. This type 859*54fd6939SJiyong Park is used to extract a public key from the parent image. If the cookie is an 860*54fd6939SJiyong Park OID, the key is extracted from the corresponding x509v3 extension. If the 861*54fd6939SJiyong Park cookie is NULL, the subject public key is retrieved. In this case, because 862*54fd6939SJiyong Park the parent image is NULL, the public key is obtained from the platform 863*54fd6939SJiyong Park (this key will be the ROTPK). 864*54fd6939SJiyong Park- ``sig``: parameter descriptor of type ``AUTH_PARAM_SIG``. It is used to extract 865*54fd6939SJiyong Park the signature from the certificate. 866*54fd6939SJiyong Park- ``sig_alg``: parameter descriptor of type ``AUTH_PARAM_SIG``. It is used to 867*54fd6939SJiyong Park extract the signature algorithm from the certificate. 868*54fd6939SJiyong Park- ``raw_data``: parameter descriptor of type ``AUTH_PARAM_RAW_DATA``. It is used 869*54fd6939SJiyong Park to extract the data to be signed from the certificate. 870*54fd6939SJiyong Park 871*54fd6939SJiyong ParkOnce the signature has been checked and the certificate authenticated, the 872*54fd6939SJiyong ParkTrusted World public key needs to be extracted from the certificate. A new entry 873*54fd6939SJiyong Parkis created in the ``authenticated_data`` array for that purpose. In that entry, 874*54fd6939SJiyong Parkthe corresponding parameter descriptor must be specified along with the buffer 875*54fd6939SJiyong Parkaddress to store the parameter value. In this case, the ``trusted_world_pk`` 876*54fd6939SJiyong Parkdescriptor is used to extract the public key from an x509v3 extension with OID 877*54fd6939SJiyong Park``TRUSTED_WORLD_PK_OID``. The BL31 key certificate will use this descriptor as 878*54fd6939SJiyong Parkparameter in the signature authentication method. The key is stored in the 879*54fd6939SJiyong Park``trusted_world_pk_buf`` buffer. 880*54fd6939SJiyong Park 881*54fd6939SJiyong ParkThe **BL31 Key certificate** is authenticated by checking its digital signature 882*54fd6939SJiyong Parkusing the Trusted World public key obtained previously from the Trusted Key 883*54fd6939SJiyong Parkcertificate. In the image descriptor, we specify a single authentication method 884*54fd6939SJiyong Parkby signature whose public key is the ``trusted_world_pk``. Once this certificate 885*54fd6939SJiyong Parkhas been authenticated, we have to extract the BL31 public key, stored in the 886*54fd6939SJiyong Parkextension specified by ``soc_fw_content_pk``. This key will be copied to the 887*54fd6939SJiyong Park``content_pk_buf`` buffer. 888*54fd6939SJiyong Park 889*54fd6939SJiyong ParkThe **BL31 certificate** is authenticated by checking its digital signature 890*54fd6939SJiyong Parkusing the BL31 public key obtained previously from the BL31 Key certificate. 891*54fd6939SJiyong ParkWe specify the authentication method using ``soc_fw_content_pk`` as public key. 892*54fd6939SJiyong ParkAfter authentication, we need to extract the BL31 hash, stored in the extension 893*54fd6939SJiyong Parkspecified by ``soc_fw_hash``. This hash will be copied to the 894*54fd6939SJiyong Park``soc_fw_hash_buf`` buffer. 895*54fd6939SJiyong Park 896*54fd6939SJiyong ParkThe **BL31 image** is authenticated by calculating its hash and matching it 897*54fd6939SJiyong Parkwith the hash obtained from the BL31 certificate. The image descriptor contains 898*54fd6939SJiyong Parka single authentication method by hash. The parameters to the hash method are 899*54fd6939SJiyong Parkthe reference hash, ``soc_fw_hash``, and the data to be hashed. In this case, 900*54fd6939SJiyong Parkit is the whole image, so we specify ``raw_data``. 901*54fd6939SJiyong Park 902*54fd6939SJiyong ParkThe image parser library 903*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~ 904*54fd6939SJiyong Park 905*54fd6939SJiyong ParkThe image parser module relies on libraries to check the image integrity and 906*54fd6939SJiyong Parkextract the authentication parameters. The number and type of parser libraries 907*54fd6939SJiyong Parkdepend on the images used in the CoT. Raw images do not need a library, so 908*54fd6939SJiyong Parkonly an x509v3 library is required for the TBBR CoT. 909*54fd6939SJiyong Park 910*54fd6939SJiyong ParkArm platforms will use an x509v3 library based on mbed TLS. This library may be 911*54fd6939SJiyong Parkfound in ``drivers/auth/mbedtls/mbedtls_x509_parser.c``. It exports three 912*54fd6939SJiyong Parkfunctions: 913*54fd6939SJiyong Park 914*54fd6939SJiyong Park.. code:: c 915*54fd6939SJiyong Park 916*54fd6939SJiyong Park void init(void); 917*54fd6939SJiyong Park int check_integrity(void *img, unsigned int img_len); 918*54fd6939SJiyong Park int get_auth_param(const auth_param_type_desc_t *type_desc, 919*54fd6939SJiyong Park void *img, unsigned int img_len, 920*54fd6939SJiyong Park void **param, unsigned int *param_len); 921*54fd6939SJiyong Park 922*54fd6939SJiyong ParkThe library is registered in the framework using the macro 923*54fd6939SJiyong Park``REGISTER_IMG_PARSER_LIB()``. Each time the image parser module needs to access 924*54fd6939SJiyong Parkan image of type ``IMG_CERT``, it will call the corresponding function exported 925*54fd6939SJiyong Parkin this file. 926*54fd6939SJiyong Park 927*54fd6939SJiyong ParkThe build system must be updated to include the corresponding library and 928*54fd6939SJiyong Parkmbed TLS sources. Arm platforms use the ``arm_common.mk`` file to pull the 929*54fd6939SJiyong Parksources. 930*54fd6939SJiyong Park 931*54fd6939SJiyong ParkThe cryptographic library 932*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~ 933*54fd6939SJiyong Park 934*54fd6939SJiyong ParkThe cryptographic module relies on a library to perform the required operations, 935*54fd6939SJiyong Parki.e. verify a hash or a digital signature. Arm platforms will use a library 936*54fd6939SJiyong Parkbased on mbed TLS, which can be found in 937*54fd6939SJiyong Park``drivers/auth/mbedtls/mbedtls_crypto.c``. This library is registered in the 938*54fd6939SJiyong Parkauthentication framework using the macro ``REGISTER_CRYPTO_LIB()`` and exports 939*54fd6939SJiyong Parkfour functions: 940*54fd6939SJiyong Park 941*54fd6939SJiyong Park.. code:: c 942*54fd6939SJiyong Park 943*54fd6939SJiyong Park void init(void); 944*54fd6939SJiyong Park int verify_signature(void *data_ptr, unsigned int data_len, 945*54fd6939SJiyong Park void *sig_ptr, unsigned int sig_len, 946*54fd6939SJiyong Park void *sig_alg, unsigned int sig_alg_len, 947*54fd6939SJiyong Park void *pk_ptr, unsigned int pk_len); 948*54fd6939SJiyong Park int verify_hash(void *data_ptr, unsigned int data_len, 949*54fd6939SJiyong Park void *digest_info_ptr, unsigned int digest_info_len); 950*54fd6939SJiyong Park int auth_decrypt(enum crypto_dec_algo dec_algo, void *data_ptr, 951*54fd6939SJiyong Park size_t len, const void *key, unsigned int key_len, 952*54fd6939SJiyong Park unsigned int key_flags, const void *iv, 953*54fd6939SJiyong Park unsigned int iv_len, const void *tag, 954*54fd6939SJiyong Park unsigned int tag_len) 955*54fd6939SJiyong Park 956*54fd6939SJiyong ParkThe mbedTLS library algorithm support is configured by both the 957*54fd6939SJiyong Park``TF_MBEDTLS_KEY_ALG`` and ``TF_MBEDTLS_KEY_SIZE`` variables. 958*54fd6939SJiyong Park 959*54fd6939SJiyong Park- ``TF_MBEDTLS_KEY_ALG`` can take in 3 values: `rsa`, `ecdsa` or `rsa+ecdsa`. 960*54fd6939SJiyong Park This variable allows the Makefile to include the corresponding sources in 961*54fd6939SJiyong Park the build for the various algorithms. Setting the variable to `rsa+ecdsa` 962*54fd6939SJiyong Park enables support for both rsa and ecdsa algorithms in the mbedTLS library. 963*54fd6939SJiyong Park 964*54fd6939SJiyong Park- ``TF_MBEDTLS_KEY_SIZE`` sets the supported RSA key size for TFA. Valid values 965*54fd6939SJiyong Park include 1024, 2048, 3072 and 4096. 966*54fd6939SJiyong Park 967*54fd6939SJiyong Park- ``TF_MBEDTLS_USE_AES_GCM`` enables the authenticated decryption support based 968*54fd6939SJiyong Park on AES-GCM algorithm. Valid values are 0 and 1. 969*54fd6939SJiyong Park 970*54fd6939SJiyong Park.. note:: 971*54fd6939SJiyong Park If code size is a concern, the build option ``MBEDTLS_SHA256_SMALLER`` can 972*54fd6939SJiyong Park be defined in the platform Makefile. It will make mbed TLS use an 973*54fd6939SJiyong Park implementation of SHA-256 with smaller memory footprint (~1.5 KB less) but 974*54fd6939SJiyong Park slower (~30%). 975*54fd6939SJiyong Park 976*54fd6939SJiyong Park-------------- 977*54fd6939SJiyong Park 978*54fd6939SJiyong Park*Copyright (c) 2017-2020, Arm Limited and Contributors. All rights reserved.* 979*54fd6939SJiyong Park 980*54fd6939SJiyong Park.. _TBBR-Client specification: https://developer.arm.com/docs/den0006/latest/trusted-board-boot-requirements-client-tbbr-client-armv8-a 981