Posts Tagged ‘extract dsp cpld heximal content’
Extract DSP and CPLD Encrypted Software: Four Things Encrypted Can Mean
The word encrypted is used for at least four different situations in embedded systems, and they have almost nothing in common beyond the fact that a naive read does not produce readable output. Classifying which one applies is the first technical act in this kind of project, and getting it wrong means solving the wrong problem well.
The four are: a transport encryption applied to a bitstream that the device decrypts as it loads, a storage encryption applied by the application to its own data, a compression that makes data look random, and an obfuscation that rearranges or scrambles without any key at all. Each has a different signature in the extracted image, and each requires a different response.
The four situations
| Situation | Where the key is | What extraction yields |
|---|---|---|
| Transport encryption | In the receiving device, or derived | Ciphertext, plus the decrypting logic |
| Storage encryption | In the firmware that applies it | Plaintext firmware, ciphertext data |
| Compression | Nowhere; it is an algorithm | Compressed data, decompressible |
| Obfuscation | Nowhere, or a fixed constant | Scrambled data, reversible |
The second row is the most common on mixed boards and the most encouraging: the firmware is in the clear and only the data is encrypted, which means the key is in the same image as the ciphertext. That is not a weakness introduced by the designer; it is unavoidable, because the device must be able to decrypt its own data without user input.
Why the key always ends up on the device
Any system that boots unattended must be able to decrypt itself. There is no user to type a password and no network to fetch a key. So the key, or something from which it is derived, must be present in the device or in a companion device on the same board.
| Key location | Security implication |
|---|---|
| In the firmware image | Anyone who reads the firmware has the key |
| In a companion CPLD or EEPROM | Anyone who reads the companion has the key |
| Derived from a device serial | Key is per-device; a serial and an algorithm suffice |
| In a secure element | Genuinely out of reach without attacking the element |
The third row is the interesting design, and it is more common than people expect. A key derived from a serial number means each unit has a different key, which defeats copying an image from one unit to another, but does not defeat reading the algorithm and one serial. It raises the cost without changing the category.
The CPLD as a key carrier
On mixed boards, the CPLD frequently holds the thing that makes the DSP’s image work: a decrypting state machine, a key register loaded at boot, or the sequencing that unlocks a protected region.
| CPLD role | What it means for extraction |
|---|---|
| Holds the key in its own configuration | Key recovered with the fuse map |
| Implements the cipher in logic | Algorithm recovered as equations |
| Gates access to a protected memory | Protection is logical, and removing the CPLD removes it |
| Provides the clock or reset sequencing | Extraction order matters |
The third row describes a design that is weaker than it looks: if the protection consists of a CPLD refusing to assert a chip select, then the memory is readable by any means that accesses it directly, including a probe on the bus.
Telling them apart from the image
The classification is done from evidence, and the evidence is statistical and structural rather than secret.
| Observation | Points to |
|---|---|
| Entropy near maximum across the whole image | Compression or encryption |
| Entropy high in one region, low elsewhere | Storage encryption of a data blob |
| Repeated 16-byte blocks | Block cipher in ECB mode, or structured data |
| Bit-reversed or byte-swapped patterns | Obfuscation or endianness confusion |
| A routine with rotate and xor over a buffer | The cipher or checksum itself |
The third row is the giveaway for the weakest implementation: a block cipher in ECB mode leaves identical plaintext blocks as identical ciphertext blocks, and in firmware images there is almost always repetition.
What each case costs
The four cases are not equally expensive, and quoting without classification is how projects become unprofitable.
| Case | Typical work | Typical risk |
|---|---|---|
| Transport encryption | Read the receiving device, recover the key | Moderate |
| Storage encryption | Read firmware, identify routine, recover key | Low |
| Compression | Identify algorithm, decompress | Very low |
| Obfuscation | Identify transform, invert it | Very low |
| No encryption, just unreadable | Fix the extraction or the format | Very low |
The last row is worth keeping in mind, because a surprising share of “encrypted” reports turn out to be a misread: wrong endianness, an offset by one word, a file that contains a header the customer’s tool does not expect, or a device that returned a protection pattern.
A note on the CPLD half
If the CPLD is holding or implementing the protection, its own protection state matters. A flash-based device with a security bit is a different problem from an EEPROM device with read inhibit, and the two are treated in attacking CPLD encrypted code. What the CPLD’s configuration looks like once read is covered in reading Lattice CPLD embedded firmware. Where the DSP side holds the key, the segment layout work in reading DSP embedded source code is the prerequisite for finding it.
The container the extracted data arrives in is worth establishing early, because an encrypted blob and a compressed blob are distinguished more easily by their framing than by their content. Cracking DSP and CPLD files sets out the five containers and what each one records.
Services at this boundary
Work covers classification of the encryption situation, entropy and structure analysis, key location and recovery where the key is on the device, cipher routine documentation, and decryption of data regions. It does not cover breaking a cipher without its key, and it does not cover keys held exclusively in a separate secure element that is not supplied.
The first deliverable in every case is a classification with evidence. It costs little, and it prevents the far more expensive mistake of attacking a compression as if it were a cipher.