The Embedded New Testament

The "Holy Bible" for embedded engineers


Project maintained by theEmbeddedGeorge Hosted on GitHub Pages — Theme by mattgraham

TPM 2.0 Basics

Introduction to Trusted Platform Module

The Trusted Platform Module (TPM) 2.0 represents a critical hardware security component that provides a foundation of trust for embedded systems. Unlike software-based security solutions that can be compromised by malware or system attacks, TPM 2.0 operates as a separate, tamper-resistant hardware component that maintains security even when the main system is compromised. This hardware root of trust enables secure boot, secure storage, and remote attestation capabilities that are essential for modern embedded security requirements.

The fundamental architecture of TPM 2.0 consists of a dedicated microcontroller with its own processor, memory, and cryptographic engine. This isolation ensures that even sophisticated attacks against the main system cannot directly access TPM resources or compromise the security operations performed within the TPM. The TPM communicates with the main system through a standardized interface, typically SPI or I2C, and provides a comprehensive set of security services through well-defined command protocols.

TPM 2.0 Hardware Architecture

The physical implementation of TPM 2.0 involves several key hardware components that work together to provide secure operations. The TPM chip itself contains a dedicated microcontroller, typically based on ARM Cortex-M or similar architecture, with its own secure memory and cryptographic accelerators. This microcontroller operates independently of the main system processor, ensuring that security operations cannot be influenced by compromised system software.

The TPM’s memory architecture is designed with security as the primary concern. It contains several types of memory regions, each with specific security properties. The persistent memory stores long-term security data such as endorsement keys and platform configuration registers (PCRs). The volatile memory stores temporary data and working variables that are cleared when the TPM loses power. All memory access is controlled by the TPM’s internal security logic, preventing unauthorized access from external sources.

The cryptographic engine within the TPM provides hardware acceleration for various cryptographic operations. This includes support for symmetric encryption algorithms such as AES, asymmetric algorithms such as RSA and ECC, and hash functions such as SHA-256. The cryptographic engine operates with dedicated hardware that is resistant to timing attacks and other side-channel vulnerabilities that could compromise security.

TPM 2.0 Command Interface

The TPM 2.0 specification defines a comprehensive command set that enables the main system to interact with TPM security services. These commands are transmitted over the communication interface and processed by the TPM’s internal microcontroller. The command interface follows a request-response protocol where each command includes parameters that specify the operation to be performed and the data to be processed.

The basic command structure consists of a command header followed by command-specific parameters. The header includes information such as the command code, authorization type, and session information. The parameters vary depending on the specific command being executed. For example, a key creation command would include parameters specifying the key type, algorithm, and attributes, while a signing command would include the data to be signed and the key handle to use for signing.

Authorization is a critical aspect of TPM 2.0 command execution. Different commands require different levels of authorization, and the TPM enforces these requirements before executing any command. Authorization can be based on passwords, HMAC values, or policy-based mechanisms. The TPM validates the authorization before processing the command, ensuring that only authorized entities can perform sensitive operations.

Platform Configuration Registers (PCRs)

Platform Configuration Registers (PCRs) are one of the most important features of TPM 2.0, providing a mechanism for measuring and storing system integrity information. PCRs are special registers that can only be modified through specific TPM operations, making them ideal for storing cumulative measurements of system components. The TPM 2.0 specification defines 24 PCRs, each serving different measurement purposes.

PCRs operate using a specific mathematical operation called “extend,” which combines the current PCR value with new measurement data. The extend operation uses a cryptographic hash function to create a new PCR value that represents the cumulative measurement of all components measured so far. This cumulative approach means that any change to any measured component will result in different final PCR values, providing a reliable way to detect system modifications.

The measurement process begins during system boot when the TPM measures critical system components such as the bootloader, operating system kernel, and key applications. Each measurement is performed by calculating a cryptographic hash of the component and then extending the appropriate PCR with this hash value. The resulting PCR values provide a verifiable record of what software is running on the system.

Key Management and Storage

TPM 2.0 provides sophisticated key management capabilities that enable secure storage and use of cryptographic keys. The TPM can generate keys internally, import external keys, and manage key hierarchies that provide different levels of security for different types of operations. All keys stored within the TPM are protected by the TPM’s internal security mechanisms, ensuring that they cannot be extracted or compromised by external attacks.

The key hierarchy in TPM 2.0 is organized around several key types, each serving different purposes. The Storage Root Key (SRK) serves as the foundation of the key hierarchy and is typically embedded in the TPM during manufacturing. This key cannot be changed and provides the cryptographic foundation for all other keys in the system. Below the SRK, the TPM can create various types of keys including storage keys, signing keys, and attestation keys.

Key creation within the TPM involves several steps. First, the TPM generates random data using its internal random number generator. This random data is used to create the key material according to the specified algorithm and key size. The TPM then assigns attributes to the key that determine how it can be used and what operations it can perform. Finally, the key is stored in the TPM’s secure memory and a handle is returned to the main system for future reference.

Secure Boot Implementation

TPM 2.0 plays a crucial role in secure boot implementations by providing hardware-based verification of system integrity. During the secure boot process, the TPM measures each component of the boot chain and stores these measurements in PCRs. The boot process can only continue if the measurements match expected values, ensuring that only trusted software can execute.

The secure boot implementation begins with the TPM measuring the initial bootloader. This measurement is performed by calculating a hash of the bootloader code and extending PCR 0 with this value. The bootloader then measures the next component in the boot chain, typically the operating system kernel, and extends the appropriate PCR. This process continues through the entire boot chain, with each component being measured before execution.

The verification of boot measurements involves comparing current PCR values with expected values that represent a trusted system state. These expected values can be stored in the TPM or verified against a trusted reference. If the measurements match, the system is considered trustworthy and boot can continue. If the measurements don’t match, the system may enter a secure failure mode or refuse to boot entirely.

Remote Attestation

Remote attestation is a powerful TPM 2.0 feature that enables a system to prove its integrity to a remote party. This capability is essential for establishing trust in distributed systems, cloud computing environments, and IoT networks where devices need to prove their trustworthiness to other systems or services.

The attestation process begins with the TPM creating a signed statement about the current system state. This statement includes the current values of all PCRs, which represent the measurements of system components. The TPM signs this statement using an attestation key, which is a special key that can only be used for attestation purposes. This signature provides cryptographic proof that the statement was created by a genuine TPM and hasn’t been tampered with.

The remote party receiving the attestation data can verify the signature using the TPM’s public key and then examine the PCR values to determine whether the system is running trusted software. The verification process involves checking that the signature is valid and that the PCR values match expected values for a trusted system configuration. This enables the remote party to make trust decisions based on the attested system state.

Secure Storage and Data Protection

TPM 2.0 provides secure storage capabilities that enable sensitive data to be protected even when the main system is compromised. The TPM can encrypt data using keys that are stored within the TPM itself, ensuring that the data cannot be decrypted without access to the TPM. This secure storage capability is essential for protecting encryption keys, user credentials, and other sensitive information.

The secure storage process involves several steps. First, the TPM generates or uses an existing storage key to encrypt the data. The encrypted data is then stored in external memory or storage, while the storage key remains protected within the TPM. When the data needs to be accessed, the TPM uses the storage key to decrypt it, ensuring that the decryption process occurs within the secure boundary of the TPM.

One of the most powerful features of TPM 2.0 secure storage is sealed storage, which allows data to be encrypted in such a way that it can only be decrypted when the system is in a specific state. This is achieved by including PCR values in the encryption process, so that the data can only be decrypted when the PCRs contain the expected values. This feature is particularly useful for protecting encryption keys that should only be available when the system is running trusted software.

TPM 2.0 Integration in Embedded Systems

Integrating TPM 2.0 into embedded systems requires careful consideration of both hardware and software requirements. From a hardware perspective, the TPM needs to be connected to the main processor through a secure communication channel, typically using SPI or I2C interfaces. The physical security of the TPM is also important, as physical access to the TPM chip could potentially compromise the entire security system.

The software integration involves implementing the TPM 2.0 command interface and managing the various TPM resources such as keys, PCRs, and storage areas. This typically requires a TPM software stack that handles the low-level communication with the TPM and provides higher-level APIs for security operations. The software stack must be carefully designed to handle TPM errors, manage TPM resources efficiently, and provide appropriate security controls.

The integration process typically begins with TPM initialization, which involves establishing the initial key hierarchy and configuring the PCRs for the specific system requirements. This initialization process is critical because it establishes the foundation for all subsequent security operations. Once initialized, the TPM can be used for various security functions such as secure boot, secure storage, and remote attestation.

Practical Implementation Considerations

When implementing TPM 2.0 in embedded systems, several practical considerations must be addressed. First, the TPM requires a reliable source of entropy for cryptographic operations. This entropy is used for generating random numbers and creating cryptographic keys. In embedded systems, this entropy can be provided by hardware random number generators or by collecting entropy from various system sources such as timing variations and sensor noise.

Power management is another important consideration in TPM 2.0 implementation. TPM chips typically have specific power requirements and may need to maintain certain state information even during low-power modes. This is particularly important for embedded systems that may spend significant time in sleep or standby modes. The TPM must be able to wake up quickly when needed and maintain its security state across power transitions.

Memory management is also a critical consideration in TPM 2.0 implementation. The TPM has limited internal memory, and most data must be stored externally. This external storage must be managed carefully to ensure that sensitive data is properly protected and that the TPM can access the data it needs when performing operations. The memory management system must also handle TPM memory exhaustion gracefully and provide appropriate error handling.

Security Best Practices and Common Pitfalls

Implementing TPM 2.0 securely requires adherence to several best practices and awareness of common pitfalls. One of the most important best practices is to use the TPM’s built-in security features rather than trying to implement security in software. The TPM is specifically designed to provide secure cryptographic operations, and attempting to duplicate this functionality in software can introduce vulnerabilities.

Another important best practice is to properly manage the TPM’s authorization mechanisms. TPM 2.0 supports multiple types of authorization, including password-based, HMAC-based, and policy-based authorization. The choice of authorization method should be based on the specific security requirements of the system, and the authorization credentials should be managed securely. Weak authorization mechanisms can significantly reduce the security benefits provided by the TPM.

Common pitfalls in TPM 2.0 implementation include improper key management, insufficient entropy for cryptographic operations, and failure to properly validate attestation data. These pitfalls can significantly reduce the security benefits provided by the TPM and potentially introduce new vulnerabilities. Key management is particularly important because the security of the entire system depends on the proper protection of cryptographic keys.

Performance and Resource Considerations

The performance characteristics of TPM 2.0 operations are important considerations in embedded system design. TPM operations can take significant time, particularly for complex cryptographic operations such as key generation and signing. The system design must account for these timing requirements and ensure that TPM operations don’t interfere with critical real-time functions.

Resource usage is another important consideration. TPM 2.0 operations consume system resources including memory, processing time, and communication bandwidth. The system must be designed to handle these resource requirements efficiently, particularly in resource-constrained embedded systems. This may involve implementing efficient TPM command batching, optimizing memory usage for TPM operations, and managing communication overhead.

The trade-offs between security and performance must be carefully considered during system design. Higher security levels typically require more TPM operations and consume more resources, while lower security levels may provide insufficient protection for the application requirements. The optimal balance depends on the specific security requirements and performance constraints of the target system.

Conclusion

TPM 2.0 provides a powerful foundation for embedded system security, offering hardware-based protection that cannot be easily compromised by software attacks. The comprehensive security features including secure boot, secure storage, and remote attestation make TPM 2.0 an essential component for any embedded system that requires high levels of security.

The successful implementation of TPM 2.0 requires careful attention to both hardware and software integration, as well as adherence to security best practices. However, the security benefits provided by TPM 2.0 far outweigh the implementation challenges, making it a worthwhile investment for systems that require robust security.

As embedded systems become more interconnected and face new security challenges, the role of TPM 2.0 in providing hardware-based security will become increasingly important. The TPM’s ability to provide a trusted foundation for security operations makes it an essential component of modern embedded systems, and its continued evolution will help address the security challenges of the future.