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