Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 916 of 93612. IoT Connectivity and SecurityFree lesson

Securing Persistent Storage with Hardware Encryption

Implement disk or flash encryption using hardware-bound keys to prevent data theft from compromised or physically stolen storage media.

In this lesson, you will learn how to leverage hardware-bound keys to encrypt flash storage, ensuring that data remains unintelligible even if the physical storage medium is extracted or stolen.

The Problem: Data at Rest

In many IoT devices, firmware and sensitive data reside on external flash chips (like SPI NOR or NAND flash). An attacker with physical access can easily desolder these chips or use an in-circuit programmer to dump the raw bits. If the data is stored in plaintext, the device's confidentiality is entirely compromised. While we’ve previously discussed Hardware Root of Trust and Secure Boot, those protect the integrity of the execution path; now, we must protect the data payload itself.

Implementing Hardware-Bound Encryption

To prevent unauthorized access, we move the encryption process into the hardware layer. This is typically achieved using an inline encryption engine—a dedicated hardware block between the CPU/RAM and the storage controller.

The core mechanism involves using a Hardware Unique Key (HUK) or a device-specific key that never leaves the silicon. Because the key is bound to the hardware (via eFuses or a Secure Element), it cannot be extracted even by an attacker with logic analyzers on the board traces.

Conceptual Workflow

When the CPU writes data to flash, the engine performs the following:

  1. Fetch Key: The engine retrieves the hardware-bound key (often managed by the Hardware Security Module).
  2. Transform: Using a symmetric cipher (like AES-XTS, optimized for block-level storage), the engine encrypts the data block-by-block in real-time.
  3. Persist: Only the ciphertext is written to the flash.
// Conceptual Hardware Encryption Engine Configuration
void configure_storage_encryption(uint32_t key_slot) {
    // Enable the engine to use a hardware-bound key from a secure slot
    // This key is never accessible to software (no register read-back)
    engine_set_key_source(key_slot, KEY_FROM_TRNG_WRAPPED);
    
    // Set the AES-XTS mode, common for disk/flash encryption
    engine_set_algorithm(AES_XTS_256);
    
    // Enable transparent encryption for the flash memory map
    engine_enable_range(0x08000000, 0x08FFFFFF); 
}

By binding the encryption key to the hardware itself, the flash chip becomes useless if moved to another device, as the target hardware lacks the unique, non-exportable key required to decrypt the ciphertext.

Key Takeaway: Hardware-bound encryption prevents data theft by ensuring that flash contents remain encrypted using keys inaccessible to software, rendering physical storage media useless if removed from the device.