1# Open Profile for DICE 2 3v2.4 4 5[TOC] 6 7## Background 8 9The Trusted Computing Group (TCG) specifies 10[Hardware Requirements for a Device Identifier Composition Engine](https://trustedcomputinggroup.org/wp-content/uploads/Hardware-Requirements-for-Device-Identifier-Composition-Engine-r78_For-Publication.pdf) 11(DICE) which provides the context for this document. We'll call this TCG 12document the *TCG DICE specification*. Concepts like a Unique Device Secret 13(UDS) and a Compound Device Identifier (CDI) are used as defined in the TCG DICE 14specification. 15 16#### A Note on Nomenclature 17 18This document uses the term *hardware* to refer to anything that is immutable by 19design after manufacturing. Code in mask ROM, for example, is *hardware*. The 20terms *firmware*, *software* and *program* are all interchangeable; they all 21refer to mutable code. Often we say *firmware* for code that runs early in boot, 22and *program* for a particular unit of code, but it's really all *software*. 23 24#### DICE Primer 25 26For those not familiar with DICE, here is a quick primer on the concepts: 27 28* **UDS** - Unique Device Secret. This is a per-device hardware-level secret 29 accessible to the DICE but not accessible after the DICE runs. This is one 30 of the DICE inputs. Note that when [layering](#layering-details) DICE 31 computations the UDS is only used for the first computation when 32 transitioning from hardware to software. Mutable software must never have 33 access to the hardware UDS. 34* **CDI** - Compound Device Identifier. This value represents the 35 hardware/software combination measured by the DICE. This is the DICE output 36 and is passed to the software which has been measured. This is a secret. 37* **DICE** - Device Identifier Composition Engine. This is a process which 38 mixes the UDS with software hashes and other inputs to produce a CDI and 39 locks down further access to the UDS. This computation occurs at the point 40 of transition from hardware (e.g. ROM) to software (e.g. first bootloader), 41 but we can perform the same computation at the point of transition from one 42 program to another in general to extend CDIs throughout a system. 43 44DICE can be implemented with a simple HMAC with the UDS as the key, attributes 45of the target code or system as the input, and the output is the CDI. However, 46for a particular implementation there are questions that need to be addressed 47such as "what is in the input, exactly?", and "how should we use the CDI once we 48have it?". That's where this profile comes in, it fills in many of these 49details. 50 51## Overview 52 53This document specifies a DICE profile suitable for use in a variety of products 54and platforms. The [TCG DICE specification](#background) intentionally allows 55for flexibility in implementation; this document specifies many of these 56implementation details. This document also fills in various details the TCG DICE 57specification considers out of scope. In particular, this document specifies: 58 59* Cryptographic mechanisms 60* UDS size and provisioning 61* DICE input details, including how DICE interacts with verified boot 62* Additional requirements, including asymmetric key derivation and 63 certification 64 65#### Goals 66 67The main goals of this document are: 68 69* Make it **easier to implement** DICE well, with quality and confidence. 70* **Consistency for DICE implementers**, whether in hardware, firmware, or 71 software. 72* **Consistency for attestation verifiers**. There will always be some details 73 in the certificate extensions that are specific to the target system, but 74 those differences can be minimized by adopting some conventions when 75 generating the certificates. 76 77#### Non-Goals 78 79This document is not intended to: 80 81* Be a formal standard 82* Limit the use of DICE-style mechanisms not described here 83 84## Architecture Diagram 85 86This architecture diagram shows the first DICE transition from hardware to 87software, and uses the UDS in the derivation of both the Attestation CDI and 88Sealing CDI. Subsequent DICE transitions would use the current CDI values in 89place of the UDS to compute the subsequent CDI values. See 90[Layering Details](#layering-details). See the [Cryptography](#cryptography) 91section for details on the primitives referenced in the diagram. 92 93![Architecture Diagram](../images/architecture.png) 94 95## Use Cases 96 97This design is motivated by two use cases: **attestation** and **sealing**. 98*Attestation* allows a computing device or program to provide verifiable 99evidence of its identity and operating state, including hardware identity, 100software image, security-relevant configuration, operating environment, etc. 101*Sealing* allows a computing device or program to encrypt data in such a way 102that it can only be decrypted by the same device or program operating in the 103same state as at the time of encryption. 104 105With this design, sealing only works well in combination with some kind of 106verified boot system. For a more sophisticated example of sealing key 107generation, see 108[Appendix C: Versioned Sealing Keys](#appendix-c-versioned-sealing-keys). 109 110# Profile Design 111 112## Input Values 113 114For attestation, DICE inputs should represent all security-relevant properties 115of the target program. The target program is the program to which control will 116be passed, along with DICE outputs, after the DICE computations are complete. 117This profile defines the following types of input, each of which is represented 118by a fixed length value: 119 1201. **Code (64 bytes)** - This input is computed by hashing the target code. 121 This is the traditional input described most clearly in the 122 [TCG DICE specification](#background). If a software image is too large to 123 load and hash entirely, then a descriptor of the code (like the root hash of 124 a hash tree) may be used instead. Note that this approach requires 125 additional ongoing enforcement to verify pages as they are loaded. A 126 canonical example of this is 127 [dm-verity](https://source.android.com/security/verifiedboot/dm-verity). 1282. **Configuration Data (64 bytes)** - This input is a catch-all for any 129 security-relevant configuration or environment properties that characterize 130 the integrity of the system and can be used by an external party to validate 131 its identity and/or its operating state. This may capture verified boot 132 authority selection, device mode, boot location, chip status information, 133 instance identifiers, etc. This value may or may not be a hash of the actual 134 configuration data. When it is a hash, the original data must also be 135 included in certificates. It's ok for this input to be *not stable*, it may 136 change from one boot to the next. 1373. **Authority Data (64 bytes)** - This input is computed by hashing a 138 representation of the verified boot trusted authority. For example, this may 139 be a public key, a hash of a public key, or a hash of a descriptor 140 containing a set of public keys. For many SoCs, this representation of the 141 trusted authority is programmed into one-time-programmable (OTP) memory. If 142 a code authorization mechanism is disabled or not supported, this input 143 should be 64 zero bytes. If multiple public keys are supported with runtime 144 selection, this input value must represent all of them. (This is so the 145 value remains stable across a key change, the actual key that was used 146 during boot should be included in the configuration data input value). The 147 authority input value is designed to be stable, it is very unlikely to 148 change during a device lifecycle. 1494. **Mode Decision (1 byte)** - This input value is a single-byte mode value. 150 Valid mode values are: **0**: Not Configured, **1**: Normal, **2**: Debug, 151 **3**: Recovery. The mode is determined at runtime based on the other 152 inputs, and only the other inputs. This input is designed to capture a 153 configuration signal in a stable way, and to reflect important decisions a 154 device makes at runtime. In the sealing use case, this enables data to be 155 sealed separately under each mode. See 156 [Mode Value Details](#mode-value-details). 1575. **Hidden Inputs (64 bytes)** - This optional input value is *hidden* in the 158 sense that it does not appear in any certificate. It is used for both 159 attestation and sealing CDI derivation so it is expected to be stable; it 160 should not change under normal operation except when that change is an 161 intentional part of the device lifecycle. If not used, this value should be 162 all zero bytes. While this value can be anything, intended use cases 163 include: 164 165 * Mixing in an additional secret which may be changed as part of the 166 device lifecycle, for example ownership transfer 167 * Mixing in a rotation nonce or counter to control the rotation of 168 attestation keys and sealing keys 169 * Mixing in stable instance IDs or other internal IDs which may provide 170 differentiation for sealing CDIs 171 * Mixing in stable configuration inputs which appear in Configuration Data 172 but also should be used in the sealing CDI derivation 173 174## CDI Values 175 176The [TCG DICE specification](#background) refers to a single CDI, but this 177profile defines multiple CDIs with different characteristics which can be used 178for different use cases: 179 1801. **Attestation CDI** - This CDI is derived from the combination of all input 181 values and will change across software updates or configuration changes. 182 This CDI is appropriate for attestation and is *mandatory* for 183 implementations of this profile. 1842. **Sealing CDI** - This CDI is derived from only the authority data, mode 185 decision, and hidden inputs because these are stable. It will reflect this 186 stability and will remain the same across software updates and some 187 configuration changes. This CDI is appropriate for sealing and is *optional* 188 for implementations of this profile. 189 190### CDI Certificates 191 192This profile requires the generation of a CDI certificate as part of the DICE 193flow. The subject key pair is derived from the Attestation CDI value for the 194target code. The authority key pair which signs the certificate is derived from 195the UDS or, after the initial hardware to software transition, from the 196Attestation CDI value for the current code (see 197[Layering Details](#layering-details)). The DICE flow outputs the CDI values and 198the generated certificate; the private key associated with the certificate may 199be optionally passed along with the CDI values to avoid the need for 200re-derivation by the target code. The UDS-derived public key is certified by an 201external authority during manufacturing to complete the certificate chain. See 202[Certificate Details](#certificate-details). 203 204As an example, if the CDI private key were used to sign a leaf certificate for 205an attestation key, the certificate chain may look like this: 206 207![Single Layer Certificate Chain Diagram](../images/single-layer-cert-chain.png) 208 209## High-level DICE Flow 210 211The [TCG DICE specification](#background) outlines a four stage flow: measure, 212compute CDI, lock UDS, and transfer control. This profile expands on this to 213include operations for CDI certification. The expanded flow has the following 214steps: 215 2161. Measure CDI input values and compute CDI values 2172. Derive an asymmetric key pair from the UDS 2183. Lock UDS 2194. Derive an asymmetric key pair from the Attestation CDI 2205. Generate a CDI certificate 2216. Destroy the UDS-derived private key from step (2) 2227. Transfer control to the target code, passing on the certificate and all CDI 223 values 224 225## Cryptography 226 227This profile requires three cryptographic primitives: a hash function, a key 228derivation function, and an asymmetric digital signature. The recommended 229defaults are [SHA-512](https://en.wikipedia.org/wiki/SHA-2), 230[HKDF](https://en.wikipedia.org/wiki/HKDF) (using SHA-512) and 231[Ed25519](https://en.wikipedia.org/wiki/EdDSA#Ed25519). Since Ed25519 uses 232SHA-512 under the hood, using this combination means implementing only one hash 233function. See below for the full list of 234[acceptable algorithms](#acceptable-cryptographic-algorithms). 235 236The following pseudocode operations are used throughout this document: 237 238```py 239# A hash function. The input can be any length. 240hash = H(input) 241 242# Random salt values used as the 'salt' KDF argument (hex encoded). 243ASYM_SALT = 63B6A04D2C077FC10F639F21DA793844356CC2B0B441B3A77124035C03F8E1BE 244 6035D31F282821A7450A02222AB1B3CFF1679B05AB1CA5D1AFFB789CCD2B0B3B 245ID_SALT = DBDBAEBC8020DA9FF0DD5A24C83AA5A54286DFC263031E329B4DA148430659FE 246 62CDB5B7E1E00FC680306711EB444AF77209359496FCFF1DB9520BA51C7B29EA 247 248# A KDF operation with the given desired output length, input key material, 249# salt, and info. 250output = KDF(length, ikm, salt, info) 251 252# An asymmetric key pair derivation, either Ed25519 or ECDSA. 253# * The private key is derived using KDF(32, input, ASYM_SALT, "Key Pair"). 254# * The public key is derived from the private key (per the chosen algorithm). 255private_key, public_key = ASYM_KDF(input) 256``` 257 258### Computing CDI Values 259 260Each CDI value is 32 bytes in length and is computed using a KDF operation with 261the UDS or previous CDI value as the input key material argument and the 262relevant input measurement as the salt argument. The KDF info argument differs 263for each type of CDI. 264 265#### Attestation CDI 266 267The Attestation CDI input measurement is derived from the combination of all 268input values. The [input values](#input-values) are hashed in this order: code, 269config, authority, mode, hidden. 270 271```py 272CDI_Attest = KDF(32, UDS, H(code + config + authority + mode + hidden), 273 "CDI_Attest") 274``` 275 276#### Sealing CDI 277 278The Sealing CDI input measurement is similar but is derived from only the stable 279inputs. The [input values](#input-values) are hashed in this order: authority, 280mode, hidden. 281 282```py 283CDI_Seal = KDF(32, UDS, H(authority + mode + hidden), "CDI_Seal") 284``` 285 286### Deriving Asymmetric Key Pairs 287 288There are two key pair derivations; one to derive from the UDS, and the other to 289derive from the Attestation CDI. When deriving from the UDS, the KDF input is 290simply the UDS. 291 292```py 293UDS_Private, UDS_Public = ASYM_KDF(UDS) 294``` 295 296When deriving from Attestation CDI, the KDF input is simply the 297[CDI\_Attest](#attestation-cdi) value. 298 299```py 300CDI_Private, CDI_Public = ASYM_KDF(CDI_Attest) 301``` 302 303Note: It is important that these two derivations remain consistent except for 304the input key material; this is what makes [layering](#layering-details) 305possible. 306 307### Deriving Identifiers 308 309There are a few cases where the DICE needs to generate an identifier for use in 310certificates. To ensure these identifiers are deterministic and require no 311additional DICE inputs, the identifiers are derived from the associated public 312key. The identifiers are 20 octets so they fit in the RFC 5280 serialNumber 313field constraints and the X520SerialNumber type when hex encoded. The big-endian 314high-order bit is cleared so the ASN.1 integer representation is always positive 315without padding. 316 317```py 318UDS_ID = KDF(20, UDS_Public, ID_SALT, "ID") 319CDI_ID = KDF(20, CDI_Public, ID_SALT, "ID") 320``` 321 322Note: Like the public key derivations, it is important that the ID derivations 323remain consistent except for the input key material. This is because these are 324used in certificate issuer and subject fields and need to match when 325[layering](#layering-details). 326 327### Acceptable Cryptographic Algorithms 328 329#### Hash Algorithms 330 331Acceptable hash algorithms are: 332 333* SHA-256, SHA-384, SHA-512 334* SHA3-256, SHA3-384, SHA3-512 335 336#### Key Derivation Functions 337 338##### HKDF 339 340[HKDF](https://en.wikipedia.org/wiki/HKDF) can be used with any acceptable hash 341algorithm. The KDF inputs map exactly to HKDF parameters, by design. This is the 342recommended default. 343 344Per the HKDF 345[specification](https://datatracker.ietf.org/doc/html/rfc5869#section-3.3) the 346extract step can be skipped in some cases, and since all KDFs used in this 347specification use cryptographically strong ikm values, doing so is acceptable 348here. 349 350##### DRBG 351 352A 353[DRBG](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf) 354can be used to implement the KDF operation. Depending on the DRBG implementation 355this may require UDS and CDI values larger than 256 bits to provide both *nonce* 356and *entropy* inputs when instantiating the DRBG. The DRBG should be 357instantiated with a security strength of 256 bits. The sequence of DRBG 358functions {instantiate, generate, uninstantiate}, are used as a KDF operation. 359The mapping of inputs is as shown in the following table. 360 361HKDF Input | Corresponding DRBG Input 362---------- | ------------------------------------ 363ikm | Instantiate: Entropy Input and Nonce 364salt | Generate: Additional Input 365info | Instantiate: Personalization String 366 367##### OpenTitan Key Manager 368 369The 370[OpenTitan Key Manager](https://docs.opentitan.org/hw/ip/keymgr/doc/index.html) 371can be used as a KDF. See the OpenTitan documentation for details. 372 373##### SP800-108 374 375The KDFs described in NIST's 376[SP800-108](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-108.pdf) 377can be used. 378 379#### Digital Signatures 380 381##### Ed25519 382 383[Ed25519](https://en.wikipedia.org/wiki/EdDSA#Ed25519) is the recommended 384default. 385 386When deriving Ed25519 key pairs, using the output of ASYM_KDF directly as the 387private key is acceptable. 388 389##### ECDSA 390 391[ECDSA](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm) 392can be used instead of Ed25519. When signing the CDI certificate, the random *k* 393required by ECDSA may be generated deterministically per 394[RFC6979](https://tools.ietf.org/html/rfc6979). One weakness of Ed25519 is that 395implementations may be susceptible to error injection 396([example](https://www.romailler.ch/ddl/10.1109_FDTC.2017.12_eddsa.pdf)). 397Another disadvantage of Ed25519 is that it is not [currently] FIPS 140-2 398certifiable. In any case, either algorithm is acceptable for this profile. 399 400The following [NIST](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf) 401curves are acceptable for use with ECDSA: 402 403* P-256 404* P-384 405 406When deriving ECDSA key pairs the output of ASYM_KDF cannot be used directly. 407Following the process described in 408[RFC 6979](https://datatracker.ietf.org/doc/html/rfc6979#section-3.3) is 409recommended. In this process the seed, in this case the output of ASYM_KDF, is 410used to seed an HMAC_DRBG instance and then the private key is generated from 411the DRBG. See the RFC for details. 412 413## Layering Details 414 415This DICE profile is designed to be layered. That is, software that receives CDI 416values can in turn execute a DICE flow using those CDI values in place of the 417UDS value. The certificate generated by the next DICE layer can chain to the 418certificate generated by the previous DICE layer because the asymmetric key 419derivation is consistent across layers for authority and subject keys. 420 421### Computing Layered CDI Values 422 423When computing CDI values, the previous Attestation CDI or Sealing CDI is used 424as the input key material instead of the hardware UDS: 425 426```py 427CDI_Attest[n+1] = KDF(32, CDI_Attest[n], H(code + config + authority + mode + hidden), "CDI_Attest") 428CDI_Seal[n+1] = KDF(32, CDI_Seal[n], H(authority + mode + hidden), "CDI_Seal") 429``` 430 431### Protecting Layered CDI Values 432 433Just like the UDS is locked in the DICE [flow](#high-level-dice-flow), previous 434layer CDIs must be destroyed, locked, or otherwise protected before control is 435passed to the next layer. Layer[n+1] must never obtain access to CDI[n] values 436and must not be able to use CDI[n] in any computation. For example, a layer[n] 437program cannot offer a service that uses CDI[n] to layer[n+1] programs. In some 438cases a layer[n] program will stay active and spawn multiple programs (for 439example, a kernel, TEE, or hypervisor). In these cases the CDI[n] values must be 440protected from all layer[n+1] programs for the duration they are in operation, 441and must be destroyed when no longer needed. 442 443### Generating Layered Certificates 444 445When generating certificates, the authority is the previous CDI key pair and the 446certificates chain together. So the certificate chain may look like this: 447 448![Multi Layer Certificate Chain Diagram](../images/multi-layer-cert-chain.png) 449 450## UDS Details 451 452### Requirements 453 454In addition to the requirements described in the 455[TCG DICE specification](#background), this profile requires the following: 456 457* The UDS is at least 256 bits in size and is full-entropy. This means the UDS 458 value has been conditioned from at least 512 bits of entropy. 459* If a UDS has not been provisioned, a value of all zero bytes is used. This 460 convention enables provisioning testability since running a DICE on an 461 unprovisioned UDS will yield predictable outputs. 462* UDS values and certificates must use one of the provisioning schemes 463 described in this section. The provisioning process is expected to occur 464 very seldom, likely once per device during manufacture. Hardware may or may 465 not support re-provisioning of the UDS. 466 467### Provisioning Scheme 1: Pre-generation 468 469In this scheme, the UDS and an associated certificate are pre-generated and 470injected during a manufacturing process in a controlled environment appropriate 471for the implementation or product. The pre-generation infrastructure does not 472retain UDS values after provisioning. This approach is designed to balance the 473risks and costs associated with provisioning between security and scale. 474Rationale is not described here in detail, but the primary benefits are: 475 476* No in-factory CAs (which make revocation as difficult as pre-generation) 477* On-device certificates (which enable offline use cases) 478 479Note: If the UDS is integrated with an SoC at the time of SoC manufacture, the 480issuer may be the SoC vendor. If the UDS is integrated at the time of device 481manufacture, the issuer may be the OEM. 482 483#### Provisioning Flow 484 4851. [Pre-generation] Generate a random UDS 4862. [Pre-generation] Derive UDS\_Public and generate an associated certificate 487 which has a subject matching the expected issuer field generated for CDI 488 certificates (see [X.509 UDS Certificates](#x_509-uds-certificates)). 4893. [Manufacturing] Program the UDS to the hardware (and destroy the source 490 copy) 4914. [Manufacturing] Test the DICE to ensure: 492 1. The UDS certificate correctly chains to the CDI certificate 493 2. The CDI values cannot be reproduced using a zero UDS 4945. [Manufacturing] Write the certificate to device storage 495 496### Provisioning Scheme 2: Factory CA 497 498In some cases, it may be feasible and preferable to install a CA for UDS 499provisioning during an SoC or device manufacturing stage. In this scheme, the 500UDS is derived on-chip from internal and external entropy, at least 256 bits 501each. Internal entropy may be generated using a 502[PUF](https://en.wikipedia.org/wiki/Physical_unclonable_function), or generated 503once using an internal hardware TRNG and stored, for example, in OTP memory. 504External entropy is injected once during manufacturing and stored, for example, 505in OTP memory. The UDS is derived at runtime on every boot from the combined 506entropy. The UDS derivation (i.e. conditioning) from internal and external 507entropy uses a KDF: 508 509```py 510UDS = KDF(32, internal_entropy, external_entropy, "UDS") 511``` 512 513With this provisioning scheme, the device must output UDS\_Public so 514provisioning software can read the public key and issue a certificate. 515 516#### Provisioning Flow 517 518All steps occur during manufacturing. 519 5201. Generate and inject external entropy; do not retain or inject to multiple 521 devices 5222. Run the DICE flow and read the UDS\_Public key 5233. Issue a certificate for UDS\_Public 5244. Test the DICE to ensure: 525 1. The UDS certificate correctly chains to the CDI certificate 526 2. The CDI values cannot be reproduced using a zero UDS 5275. Write the certificate to device storage 528 529### Provisioning Scheme 3: On-Demand Certification 530 531In some cases, the certificate may not need to be stored on the device or the 532device may not be capable of storing a certificate. In this scheme the UDS is 533derived in the same way as 534[Provisioning Scheme 2](#provisioning-scheme-2-factory-ca), and the UDS\_Public 535key must similarly be output by the device. A SHA-512 hash of the UDS\_Public 536key is retained in a secure database by the manufacturer. 537 538The manufacturer then operates or coordinates with an online CA to provide 539on-demand certification of UDS public keys. Acceptable approaches include but 540are not limited to: 541 542* Manufacturer provides the list of UDS public key hashes to the CA. This has 543 the downside of revealing the total number of devices. 544* Manufacturer operates a simple web service on a dedicated domain over HTTPS 545 which takes as input the hash of a UDS public key and provides as output a 546 boolean indicating whether or not the hash is valid and should be certified. 547 548The CA issues certificates for any valid UDS public key without requiring 549proof-of-possession from the caller, only requiring a signal of approval from 550the manufacturer. This allows a certificate chain to be requested by a CDI 551certificate verifier that received an incomplete chain from a device. The UDS 552certificate may be cached indefinitely by the device or by a verifier. 553 554#### Provisioning Flow 555 5561. [Manufacturing] Generate and inject external entropy; do not retain or 557 inject to multiple devices 5582. [Manufacturing] Run the DICE flow and read the UDS\_Public key 5593. [Manufacturing] Retain H(UDS\_Public) in a secure database 5604. [On-Demand] Send UDS\_Public from the device to the CA (no 561 proof-of-possession necessary) 5625. [CA] Check that H(UDS\_Public) is approved by the manufacturer 5636. [CA] Issue a certificate for UDS\_Public 564 565## Mode Value Details 566 567The following table describes the semantics of each mode. 568 569Mode | Value | Description 570-------------- | ----- | ----------- 571Not Configured | 0 | This mode indicates that at least one security mechanism has not been configured. This mode also acts as a catch-all for configurations which do not fit the other modes. Invalid mode values -- values not defined here -- should be treated like this mode. 572Normal | 1 | This mode indicates the device is operating normally under secure configuration. This may mean, for example: Verified boot is enabled, verified boot authorities used for development or debug have been disabled, debug ports or other debug facilities have been disabled, and the device booted software from the normal primary source, for example, eMMC, not USB, network, or removable storage. 573Debug | 2 | This mode indicates at least one criteria for Normal mode is not met and the device is not in a secure state. 574Recovery | 3 | This mode indicates a recovery or maintenance mode of some kind. This may mean software is being loaded from an alternate source, or the device is configured to trigger recovery logic instead of a normal boot flow. 575 576## Configuration Input Value Details (Optional) 577 578The format and meaning of the 64-byte configuration input value is 579implementation dependent and may be a hash of more configuration data. 580Implementers may choose to use the following convention for the configuration 581input which covers a set of common security-relevant configuration. 582 583Field | Byte/Bits (MSB=0) | Description 584------------------------------- | ----------------- | ----------- 585Verified Boot Enabled | 0/0 | This bit indicates whether a verified boot feature is enabled. The bit is set if enabled, clear if disabled or not supported. 586Verified Boot Authority Enabled | 0/1-7 | These bits indicate which of the verified boot authorities available are enabled. The bit is set if the authority is enabled, clear if disabled. If a verified boot system is disabled or not supported, all bits are clear. The mapping of these bits to particular authorities is implementation dependent. 587Debug Ports Enabled | 1 | The bits of this byte each indicate that a debug port or feature is enabled. A bit is set if the port or feature is enabled, clear if disabled. The mapping of these bits to particular ports or features is implementation dependent. 588Boot Source | 2 | This value indicates the boot source; that is, where the target software was loaded from. The mapping of this value to particular boot sources is implementation dependent but by convention 0 is used for the default boot source. 589Version | 3-4 | This value encodes target software version information. The format and interpretation of this value is implementation dependent. 590Reserved | 5-31 | These are reserved for future versions of this profile. 591Implementation Specific | 32-63 | An implementation can use these bytes to represent any other security-relevant configuration. 592 593## Certificate Details 594 595This profile allows for two certificate options: standard X.509, or CBOR. The 596certificate type does not need to be consistent for all certificates in a 597certificate chain. Any certificate in the chain may be any type. Attestation 598infrastructure may place additional constraints on certificate type, but this 599profile does not. 600 601Regardless of type, UDS and CDI certificates are always semantically *CA 602certificates* to enable use cases for certifying subsequent DICE 603[layers](#layering-details) or certifying attestation keys of some kind; the 604UDS\_Private and CDI\_Private keys are not intended to be used for any purpose 605other than signing certificates. In particular, this means CDI\_Private should 606not participate directly in attestation protocols, but should rather certify an 607attestation key. If a target software component does not launch additional 608software, the *pathLenConstraint* field can be set to zero so certification of a 609subsequent CDI\_Public is not possible. 610 611When UDS and CDI certificates are standard X.509 certificates, they follow the 612profile specified in [RFC 5280](https://tools.ietf.org/html/rfc5280). When they 613are CBOR, they follow the IETF 614[CBOR Web Token](https://tools.ietf.org/html/rfc8392) (CWT) specification, and 615the [CBOR Object Signing and Encryption](https://tools.ietf.org/html/rfc8152) 616(COSE) specification. 617 618### X.509 UDS Certificates 619 620X.509 UDS certificates generally follow 621[RFC 5280](https://datatracker.ietf.org/doc/html/rfc5280). The following table 622describes all standard fields of a UDS certificate's tbsCertificate field that 623this profile requires. Fields omitted are implementation dependent, but must not 624break the ability to chain to a CDI Certificate. 625 626Field | Description 627-------------------- | ----------- 628version | v3 629subject | "SERIALNUMBER=\<UDS\_ID\>" where UDS\_ID is hex encoded lower case 630subjectPublicKeyInfo | When using Ed25519, the info per [RFC 8410](https://tools.ietf.org/html/rfc8410) and [RFC 8032](https://tools.ietf.org/html/rfc8032) 631extensions | The standard extensions described below are included. 632 633##### UDS Standard Extensions 634 635Extension | Critical | Description 636-------------------- | ------------ | ----------- 637subjectKeyIdentifier | non-critical | Set to UDS\_ID 638keyUsage | critical | Contains only keyCertSign 639basicConstraints | critical | The cA field is set to TRUE. The pathLenConstraint field is normally not included, but may be included and set to zero if it is known that no additional DICE [layers](#layering-details) exist. 640 641### X.509 CDI Certificates 642 643X.509 CDI certificates generally follow 644[RFC 5280](https://datatracker.ietf.org/doc/html/rfc5280). All standard fields 645of a CDI certificate and the tbsCertificate field are described in the following 646table. Notably, this certificate can be generated deterministically given a 647CDI\_Public key and the DICE input value details. 648 649Field | Description 650-------------------- | ----------- 651signatureAlgorithm | When using Ed25519, id-Ed25519 per [RFC 8410](https://tools.ietf.org/html/rfc8410) 652signatureValue | When using Ed25519, 64 byte Ed25519 signature per [RFC 8032](https://tools.ietf.org/html/rfc8032), using UDS\_Private or the current CDI\_Private as the signing key 653version | v3 654serialNumber | CDI\_ID in ASN.1 INTEGER form 655signature | When using Ed25519, id-Ed25519 per [RFC 8410](https://tools.ietf.org/html/rfc8410) 656issuer | "SERIALNUMBER=\<UDS\_ID\>" where UDS\_ID is hex encoded lower case. When layering, UDS\_ID becomes CDI\_ID of the current layer. 657validity | The DICE is not expected to have a reliable source of time when generating a certificate. The validity values are populated as follows: *notBefore* can be any time known to be in the past; in the absence of a better value, "180322235959Z" can be used which is the date of publication of the [TCG DICE specification](#background), and *notAfter* is set to the standard value used to indicate no well-known expiry date, "99991231235959Z". 658subject | "SERIALNUMBER=\<CDI\_ID\>" where CDI\_ID is hex encoded lower case. When layering this is the CDI\_ID of the next layer. 659subjectPublicKeyInfo | When using Ed25519, the info per [RFC 8410](https://tools.ietf.org/html/rfc8410) and [RFC 8032](https://tools.ietf.org/html/rfc8032) 660issuerUniqueID | Omitted 661subjectUniqueID | Omitted 662extensions | Standard extensions are included as well as a custom extension which holds information about the measurements used to derive CDI values. Both are described below. 663 664##### CDI Standard Extensions 665 666Extension | Critical | Description 667---------------------- | ------------ | ----------- 668authorityKeyIdentifier | non-critical | Contains only keyIdentifier set to UDS\_ID 669subjectKeyIdentifier | non-critical | Set to CDI\_ID 670keyUsage | critical | Contains only keyCertSign 671basicConstraints | critical | The cA field is set to TRUE. The pathLenConstraint field is normally not included, but may be included and set to zero if it is known that no additional DICE [layers](#layering-details) exist. 672 673##### CDI Custom Extension Fields 674 675Field | Value 676--------- | ----- 677extnID | 1.3.6.1.4.1.11129.2.1.24 (The 1.3.6.1.4.1 is the [enterprise number](https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers), the 11129.2.1 is google.googleSecurity.certificateExtensions, and 24 is diceAttestationData assigned for this profile). 678critical | TRUE 679extnValue | A [OpenDiceInput](#custom-extension-format) sequence 680 681#### Custom Extension Format 682 683The custom extension follows this ASN.1 format: 684 685``` 686Mode ::= INTEGER (0..3) 687OpenDiceInput ::= SEQUENCE { 688 codeHash [0] EXPLICIT OCTET STRING OPTIONAL, 689 codeDescriptor [1] EXPLICIT OCTET STRING OPTIONAL, 690 configurationHash [2] EXPLICIT OCTET STRING OPTIONAL, 691 configurationDescriptor [3] EXPLICIT OCTET STRING OPTIONAL, 692 authorityHash [4] EXPLICIT OCTET STRING OPTIONAL, 693 authorityDescriptor [5] EXPLICIT OCTET STRING OPTIONAL, 694 mode [6] EXPLICIT Mode OPTIONAL, 695} 696``` 697 698All fields are explicitly tagged and optional to allow for flexibility and 699extensibility in the format itself. The actual semantics are as follows: 700 701* **codeHash** - Required. This is the exact 64-byte code input value used to 702 compute CDI values. 703* **codeDescriptor** - Optional. This field contains additional information 704 about the code input value. The format of this field is 705 implementation-specific. If this field is included then all the information 706 here must have been used to compute codeHash; i.e. a change in this value 707 implies a change in codeHash. 708* **configurationHash** - Optional. If the configuration input is a hash, this 709 field contains that hash. If the configuration is not a hash, this field is 710 omitted. If present, this value is the exact configuration input used to 711 compute CDI values, and also matches H(configurationDescriptor). 712* **configurationDescriptor** - Required. If the configuration input is a hash 713 this field contains the original configuration data that was hashed. If it 714 is not a hash, this field contains the exact 64-byte configuration input 715 value used to compute CDI values. 716* **authorityHash** - Required. This is the exact 64-byte authority input 717 value used to compute CDI values. 718* **authorityDescriptor** - Optional. This field contains additional 719 information about the authority input value. The format of this field is 720 implementation-specific. If this field is included then all the information 721 here must have been used to compute authorityHash; i.e. a change in this 722 value implies a change in authorityHash. 723* **mode** - Required. This is the mode input value. 724 725### CBOR UDS Certificates 726 727A CBOR UDS certificate is a standard signed CWT. The following table lists all 728field constraints required by this profile in addition to the standard. The 729certificate is *untagged*, and it must be a *COSE\_Sign1* message. 730 731Field | Description 732----- | ----------- 733iss | Required: The value is implementation dependent. 734sub | Required: The value must be "\<UDS\_ID\>" where UDS\_ID is hex encoded lower case. 735 736#### Additional Fields 737 738The following table lists additional entries in the CWT. Note these have the 739same labels and semantics as the corresponding fields in 740[CBOR CDI certificates](#cbor-cdi-certificates). 741 742Field | CBOR Label 743---------------- | ---------- 744subjectPublicKey | -4670552 745keyUsage | -4670553 746 747The *subjectPublicKey* field contains the public key associated with the subject 748in the form of a COSE\_Key structure encoded to a CBOR byte string. 749 750The *keyUsage* field contains a CBOR byte string the bits of which correspond to 751the [X.509 KeyUsage bits](https://tools.ietf.org/html/rfc5280#section-4.2.1.3) 752in little-endian byte order (i.e. bit 0 is the low-order bit of the first byte). 753For UDS certificates this should have only the keyCertSign bit set. 754 755### CBOR CDI Certificates 756 757A CBOR CDI certificate is a standard signed CWT with additional fields. The 758certificate is *untagged*, and it must be a *COSE\_Sign1* message. The following 759table lists all constraints on standard fields required by this profile. 760 761Field | Description 762----- | ----------- 763iss | Required: The value must be "\<UDS\_ID\>" where UDS\_ID is hex encoded lower case. When layering, UDS\_ID becomes CDI\_ID of the current layer. 764sub | Required: The value must be "\<CDI\_ID\>" where CDI\_ID is hex encoded lower case. When layering this is the CDI\_ID of the next layer. 765exp | Omitted when a reliable time source is not available 766nbf | Omitted when a reliable time source is not available 767iat | Omitted when a reliable time source is not available 768 769#### Additional Fields 770 771The following table lists additional entries in the CWT. By convention, the 772private fields in the map are labeled using negative integers starting at 773-4670545. 774 775Field | CBOR Label 776----------------------- | ---------- 777codeHash | -4670545 778codeDescriptor | -4670546 779configurationHash | -4670547 780configurationDescriptor | -4670548 781authorityHash | -4670549 782authorityDescriptor | -4670550 783mode | -4670551 784subjectPublicKey | -4670552 785keyUsage | -4670553 786 787The *subjectPublicKey* field contains the public key associated with the subject 788in the form of a COSE\_Key structure encoded to a CBOR byte string. 789 790The *keyUsage* field contains a CBOR byte string the bits of which correspond to 791the [X.509 KeyUsage bits](https://tools.ietf.org/html/rfc5280#section-4.2.1.3) 792in little-endian byte order (i.e. bit 0 is the low-order bit of the first byte). 793For CDI certificates this should have only the keyCertSign bit set. 794 795All other fields have identical semantics to their counterparts in the 796[X.509 custom extension](#custom-extension-format). The encoding for each is a 797CBOR byte string including *mode* which is a CBOR byte string holding a single 798byte (the advantage to using a byte string here is a consistent encoding size 799regardless of the value of mode). 800 801# Appendix A: Implementing on Existing Hardware 802 803This profile requires hardware changes to implement fully. However, there is 804still value in implementing it in software on top of existing hardware. 805Depending on the existing hardware capabilities, the security of the DICE root 806may be equivalent to a full hardware implementation. 807 808## Implementing with Standard DICE Support 809 810If hardware supports a standard DICE mechanism but does not support this profile 811directly, this profile can be implemented in firmware and can use the firmware 812CDI from the standard DICE as a UDS. The provisioned certificate would then 813cover both the hardware and the firmware implementing this profile. 814 815However, this only works if the firmware that implements this profile is 816unmodified during normal operation. It becomes a *ROM extension* in the sense 817that if it is modified, the firmware CDI changes, and the certificate chain 818provisioned for the device is no longer valid. In an ARM Trusted Firmware 819architecture, it would likely be BL2 firmware that implements this profile. 820 821If the firmware implementing this profile is the first firmware to run on the 822system, this approach has equivalent security to a full hardware implementation. 823 824## Implementing with Lockable Persistent Storage 825 826If hardware supports a lockable persistent storage mechanism early in boot, this 827profile can be implemented in firmware and can use a secret stored using this 828mechanism as a UDS. This firmware should run as early in boot as possible. The 829storage could be lockable OTP memory, lockable NVRAM, a one-time derivation, or 830similar. Security chips like a TPM or SE often have an appropriate capability. 831 832However, this only works along with a robust verified boot system to verify the 833firmware that implements this profile and any other firmware that runs before 834it. It also has the downside that changes to the firmware, or any other firmware 835that runs before it, are not reflected in the CDIs. 836 837The security of this approach is not equivalent to a full hardware 838implementation, but may still be acceptable for many applications. If the 839firmware implementing this profile is the first firmware to run on the system, 840this approach has equivalent security to a full hardware implementation which 841employs a hardware modification mechanism like an FPGA or microcode. 842 843This approach can also be used later in boot, for example in a TEE. However, the 844more code that runs without being covered by a DICE flow, the lower the security 845of the implementation. 846 847## Other Hardware Implementations 848 849With a robust verified boot system, there are many other possible 850implementations as long as (1) A UDS can be made available by some means early 851in boot, and (2) that UDS can be made subsequently unavailable until the next 852boot. These implementations meet the requirements of the TCG DICE specification 853as an *updatable DICE* per section 6.2. 854 855# Appendix B: Hardware Implementation Checklist 856 857The following is a list of capabilities that a full hardware implementation must 858have. This is intended for the convenience of hardware designers, and is not 859intended to add any additional requirements or constraints. 860 8611. Provide a UDS capability as required by this profile and the TCG DICE 862 specification. Usually this *cannot* be implemented in mask ROM but requires 863 additional hardware capabilities. See [UDS Details](#uds-details). 8641. Reserve on the order of 8KB of mask ROM for DICE, not including crypto 865 primitives. The rest of this list can usually be implemented entirely in 866 ROM. 8671. Choose crypto primitives and provide implementations, ideally with hardware 868 acceleration. See [Cryptography](#cryptography). 8691. Provide a code input. At this level a simple code hash is recommended, 870 without an additional descriptor. Often the verified boot system already has 871 a code hash it verifies, and using the same hash as input to DICE is 872 recommended. See [Input Values](#input-values). 8731. Provide a configuration input. At this level, using the 64-bit value 874 described in this profile is recommended. See [Input Values](#input-values) 875 and 876 [Configuration Input Value Details](#configuration-input-value-details-optional). 8771. Provide a verified boot authority input. This should be very simple and 878 stable, often copied directly out of OTP memory. At this level a simple hash 879 is recommended, without an additional descriptor. See 880 [Input Values](#input-values). 8811. Provide a mode input. Determining the mode is a runtime decision so a bit of 882 logic will have to be coded. The 64-bit configuration value should have all 883 the information necessary to make this decision. See 884 [Input Values](#input-values) and [Mode Value Details](#mode-value-details). 8851. Provide a hidden input value if necessary. At this level it is not 886 recommended. 8871. Implement the [DICE flow](#high-level-dice-flow) and certificate generation; 888 reference code is available. If recommendations in this list are followed 889 for simple inputs, the certificate will be a constant size and layout and a 890 template can be used (avoiding the need for X.509 or CBOR code). See 891 [Certificate Details](#certificate-details). 8921. Make DICE outputs available to firmware (CDIs and certificate). 8931. Depending on which provisioning model is used, make the UDS-derived public 894 key available. 895 896# Appendix C: Versioned Sealing Keys 897 898A versioned sealing key is a key that is derived from a secret seed and one or 899more software versions. The versions cannot be higher than the current software 900version. In other words, a versioned sealing key can be derived for the current 901software version and each previous version, but not for future versions. These 902keys can be used to seal data in a rollback-protected way, that is, in a way 903that current and future software can unseal but older software cannot. Each time 904software is upgraded, the data can be re-sealed to be bound to the latest 905version. 906 907The Sealing CDIs derived by using DICE in layers as described in this profile 908are not versioned; rather they are stable across versions. To achieve versioned 909sealing keys, an additional hardware mechanism is required: a versioned KDF 910(V-KDF). There are many possible implementations but in general it must be 911possible to seed the V-KDF with one or more secrets that it will not expose, and 912one or more maximum versions that it will not allow to be subsequently modified. 913After seeding, the V-KDF accepts version info as input (likely along with other 914inputs), and the output is a key that may be used as a versioned sealing key. 915 916Given such a V-KDF, versioned keys can be derived from a Sealing CDI by adding a 917few steps to precede the [DICE flow](#high-level-dice-flow): 918 919* Derive a V-KDF seed from the current sealing CDI (or UDS if this is the 920 initial DICE instance) and the same inputs used for deriving the next layer 921 sealing CDI. The derivation differs from the sealing CDI derivation only by 922 the info string: 923 924```py 925VKDF_SEED = KDF(32, CDI_Seal_or_UDS, H(authority + mode + hidden), "VKDF_SEED") 926``` 927 928* Seed the V-KDF with the output of (1) and the version of the target code 929 (the code to which control will be transferred at the end of the DICE flow) 930* Destroy any copy of the V-KDF seed, so it's only available to the V-KDF 931* Run the DICE flow as usual 932 933Note that the V-KDF seed is derived from the *current* sealing CDI; this value 934is *not* passed to target code but is locked / destroyed as part of the DICE 935flow. As a result the target code can only generate versioned keys as seeded by 936the previous layer. 937 938When multiple layers are involved, the V-KDF should use the seed inputs 939cumulatively: 940 941* The seed value should be mixed into the current state, it should not reset 942 the state. 943* The max version value should be retained in addition to the existing max 944 version values. The version info supplied as KDF input must then contain one 945 version for each maximum version configured. The number of layers supported 946 may be limited by the V-KDF hardware; support for at least 8 maximum 947 versions is recommended. 948