Posts Tagged ‘mask rom ic firmware decrypt’
Encrypted Update Packages: The Key Sits in the Bootloader
An encrypted firmware update is a different thing from encrypted code, and the difference is not technical detail. Code encrypted at rest is decrypted by the fetch hardware and the key never moves. An update package is decrypted by software that is already on the device, and that software must hold the key in order to do its job.
One of these is designed to be irreversible. The other is designed to be reversible by the device, which means it is reversible by anyone who has the device.
What package encryption is for
The purpose of encrypting a distribution package is not to stop someone reading the firmware of the device they own. It is to stop three other things.
It stops a competitor from taking an update file and reading the code. It stops an attacker from building a modified image that the device would accept. And on some products it stops an unauthorised party from producing compatible hardware, because the update is the only thing that carries the proprietary parts.
| Threat | Mechanism that addresses it |
|---|---|
| Reading the code from a package | Encryption |
| Installing a modified image | Signature |
| Using the package on another product | Binding to a device identity |
| Extracting the key from a package | Key wrapping |
The second row is the one that matters most for product security, and note that it does not require encryption. A signed but unencrypted package cannot be modified, and anyone can read it. Many products choose encryption for commercial reasons and signature for security reasons, and they are separate decisions.
Three container structures
The structure of the package determines where the key is and how hard it is to get.
Signature only: the package contains the image in plaintext and a signature over it. There is nothing to decrypt. The work is to verify the signature or to bypass the verification, and the image is already readable.
Symmetric encryption plus signature: the image is encrypted with a key that the bootloader holds, and the ciphertext is signed. The key is in the bootloader, either as a constant or in a protected region, and finding it is a search of the bootloader rather than of the application.
| Structure | Image readable | Key location | Difficulty |
|---|---|---|---|
| Signature only | Yes | Not needed | None |
| Symmetric plus signature | No | Bootloader | Moderate |
| Hybrid: RSA-wrapped session key | No | Bootloader holds a private key | Moderate |
| Per-device key | No | Derived from device identity | High |
The third row is the common modern design and it is worth describing because it looks stronger than it is. Each package carries a random session key, encrypted with the device’s public key; the device decrypts the session key with its private key and then decrypts the image. The device’s private key is in the bootloader or in a protected area, and recovering it recovers every package that device would accept.
Why the bootloader is the target
The bootloader must decrypt, so it must hold or derive the key, and that fact is unavoidable for any design. The only variations are where the key is stored and how well that storage is protected.
| Storage | Extractable by | Effort |
|---|---|---|
| Constant in the bootloader code | Reading the bootloader | Low |
| In a separate flash page | Reading that page | Low |
| In OTP, read-protected | An attack on the protection | Moderate |
| Inside a secure element | Attacking the element | High |
| Derived from a PUF | Not extractable | Not possible |
The first two rows account for most real products. A key stored as a byte array in the bootloader is found by reading the bootloader and looking for a high-entropy constant; the search is the one described in credential hunting in firmware.
The fourth row is the case where the crypto operation happens inside a secure element that never releases the key, and only the plaintext comes out. That is a genuine improvement, and it moves the attack to the element, which is a different and usually harder target.
Reading the package without the key
There is a route that does not require the key, and it is worth knowing because it is often cheaper.
A device that accepts an update and then runs it can be made to reveal the decrypted image if the decryption happens before verification, or if the plaintext is briefly in memory. A debug session during an update, on a device whose debug port is available, captures the image as it is written to flash.
| Route | Requires | Yields |
|---|---|---|
| Extract the key | Read access to the bootloader | Every package |
| Capture during update | Debug access at update time | One package |
| Read the flash after update | Read access to the array | The installed image |
| Intercept the bus | Physical access | The package as received |
The third row is the simplest and is often overlooked. If the device has already installed an update, the plaintext is in its flash, and reading the flash gives the image without any decryption at all. The only situation where this fails is a device that keeps the image encrypted at rest, which is the case discussed in instruction-fetch decryption.
When the package is not encrypted at all
Before any key is sought, it is worth establishing that there is a key. A significant fraction of packages described as encrypted are compressed, and a compressed image looks like noise to a hex viewer.
The distinction is measurable. Compression produces high entropy with structure: a header that declares the uncompressed length, a stream with a repeating pattern at block boundaries, and a decompressor in the bootloader that a search for a known algorithm will find. Encryption produces high entropy without structure and without a declared length.
| Observation | Compression | Encryption |
|---|---|---|
| Header declares an output length | Usually | Rarely |
| Entropy uniform but block-aligned | Yes | No |
| A decompressor exists in the bootloader | Yes | No |
| Changing one byte breaks everything | No, varies | Yes |
| Tooling recognises the format | Often | No |
The fourth row is a cheap test. Flip a byte in the middle of a compressed stream and the tail of the output is usually corrupt while the head is fine. Flip a byte in an encrypted stream, in a mode with chaining, and everything after it is corrupt. The difference is visible in a single experiment.
The binding question
A package bound to a device identity is a package that only works on that device, and this changes the commercial picture.
If the binding is a check performed by the bootloader against the device’s identifier, capturing a package for device A does not give a package that device B will accept. If the binding is cryptographic — the package is encrypted to device A’s public key — then even a valid package is useless elsewhere, and the key for device A does not help with device B.
| Binding | Package usable on another device | What is needed |
|---|---|---|
| None | Yes | Nothing |
| Identifier checked in software | Yes, after patching the check | A patch |
| Encrypted to a per-device key | No | That device’s private key |
| Signed per device | No | The vendor’s signing key |
The second row is the one that appears most often in products that claim per-device binding, and it is defeated by a patch to the check rather than by any key recovery. That patch is the work in patching IC code.
What the service delivers
For a package decryption engagement we deliver the decrypted image, the container structure, the key location and how it was obtained, and a statement of whether the key is per-device or common across a product line. That last item determines whether the result generalises, and it is the first thing a customer asks.
| Finding | Implication |
|---|---|
| Key is a constant in the bootloader | Every package for this product is readable |
| Key is per-device | Only this device’s packages are readable |
| No encryption, signature only | The image was always readable |
| Key in a secure element | Not extractable; capture during update instead |
The work begins with the bootloader, which is a separate program in a separate region and is frequently left unprotected even when the application is not. Its layout and the reason it is a separate region are in extracting MCU firmware, and the verification it performs is the chain described in secure boot.
What we will not do is promise decryption of a package whose key is inside a secure element that does not export it. In that case the honest deliverable is a statement of the boundary and the alternative route, which is to capture the plaintext at the moment the device decrypts it.