ST72F321BK Flash Memory Decrypt: Separating Ciphertext From Confusion
“Decrypt” is a word customers use to mean “make the file readable”, and those are not the same request. A ST72F321BK flash memory decrypt job can end with a plaintext image and no decryption having occurred at all, because most images that look encrypted are not. They are compressed, or they are tables, or they are pictures of a font, or they are damaged.
Distinguishing those five cases is the whole of the diagnostic work, and it is done by measurement rather than by inspection. The difference between ciphertext and a sine table is not visual. It is structural, and structure is measurable.
Decrypt is a conclusion, not a service
The useful way to frame the work is as a classification first and an operation second. An image region is examined, assigned to one of a small number of categories, and only then does anyone talk about what operation would make it readable.
| category | what it is | operation that makes it readable |
|---|---|---|
| compiled code | instructions and constants | disassembly |
| compressed resource | deflate or similar | decompression with the right dictionary |
| lookup table | deliberately regular data | interpretation with the right width and units |
| ciphertext | encrypted records | decryption, key required |
| damaged data | a failed write or a bad read | reconstruction, not decryption |
Four of those five are not decryption problems, and three of them are commonly reported as encryption problems by customers and by suppliers who did not measure.
Four things that look encrypted and are not
The first is a compressed resource. A firmware that stores a voice prompt, a graphics bitmap or a firmware update payload will contain a block of high-entropy bytes with a flat histogram. It looks exactly like ciphertext because compression and encryption both remove redundancy. The difference is that compressed data sits inside a container with a length field and usually a magic number, while encrypted code would have to cover the instruction stream.
The second is a lookup table. A sine table, a segment-code table for an LCD, or a conversion table has high byte diversity and no obvious pattern when viewed as bytes, and it decodes as nonsense as instructions. What gives it away is regularity at the right stride: read the same region as 16-bit words and the values climb and fall in a curve.
The third is a font or graphics bitmap. These have runs of identical bytes and abrupt transitions, and their entropy is intermediate — higher than code, lower than ciphertext. Their position, in a block with dimensions, is the giveaway.
The fourth is damage. A block that was interrupted during a write contains a mixture of erased bytes and new data, which reads as noise. Its entropy is high in a patchy way rather than uniformly, and it usually sits in exactly one block rather than across a region.
Measuring instead of guessing
Two measurements over a candidate region do most of the work: the byte-value histogram and the per-block entropy.
| measurement | code | table | compressed | ciphertext | damaged |
|---|---|---|---|---|---|
| histogram | peaked | clustered | flat | flat | patchy |
| entropy | moderate | moderate | near maximum | near maximum | uneven |
| structure at block boundaries | functions | fixed stride | container header | uniform | one block differs |
| repeat of 16-byte patterns | several | at stride | rare | none | none |
| aligned to a block boundary | no | no | usually | usually | yes |
The last row is the cheapest discriminator and the least used. Ciphertext is produced in records, and records are aligned to something — a block, a page, a record size. A region that starts at a block boundary and ends at the next block boundary, with uniform statistics throughout, is far more likely to be encrypted records than anything else in the list.
The case that is encrypted and does not matter
The most common real finding on this class of device is a parameter area encrypted with a key that the firmware itself uses. The key is in the code, the routine that applies it runs at startup, and the encryption serves to stop casual inspection of stored settings rather than to protect anything of value.
In that case the decryption is trivial once the code has been read, because the key is an immediate value or a table in the same image. There is no cryptanalysis, no key search, and no attack. The work is simply reading the code, finding the routine, and applying the inverse operation.
That configuration is worth naming clearly in a report, because customers often believe it is far stronger than it is. A key stored in the same memory as the ciphertext it protects is a lock with the key taped to it. It defeats casual inspection and nothing else.
Finding the boundary of the region
Before a region can be classified, its edges have to be found, and the customer is usually the last person who can help. They know that “the settings are encrypted” and not where the settings begin.
The boundary is found by scanning for a change in statistics rather than by asking. Walk the image in block-sized steps, compute the histogram for each step, and look for the point where the distribution changes character. A code region that suddenly becomes flat has a boundary within one block of that transition, and the boundary is almost always aligned to a block because the writer wrote in blocks.
| transition observed | likely boundary |
|---|---|
| peaked histogram becomes flat, aligned to a block | start of encrypted or compressed records |
| flat becomes peaked again | end of the records |
| patchy region inside otherwise regular data | a failed write, not a boundary |
| histogram changes but entropy does not | a table with different values, not encryption |
The last row is a frequent false positive. A code region followed by a table of 16-bit constants can change the byte histogram markedly without changing how redundant the data is, because the table is still structured. Entropy is the measure that does not move, and that is why both measurements are needed.
Where a key genuinely is out of reach
Three configurations put the key beyond the image.
The first is a key provisioned into a protected area of the device that is not part of the flash array — an area that cannot be read through any interface and does not appear in the recovered image.
The second is a key derived from a device-unique identifier and combined with a secret in the code. The code can be recovered, but the identifier differs per unit, so the key differs per unit and the decryption is bound to one device.
The third is a key held in a separate security device on the board, which the microcontroller asks at runtime. The firmware is readable and the records are not.
| key location | recoverable from the image | consequence |
|---|---|---|
| immediate value in code | yes | decryption is a mechanical step |
| table in code, indexed | yes | same, with a small amount of tracing |
| protected non-flash area | no | out of reach for this route |
| derived from a unique ID | partly | per-device key, cannot be reused across units |
| external security device | no | the firmware is readable; the data is not |
Reporting the finding
A decrypt ST72F321BK MCU flash program report that will survive scrutiny states the measurement, the category, and the consequence for the customer’s goal.
For a region that turns out to be a table, the report says so and gives the stride and the units, which is more useful than a decrypted file would have been. For a region that turns out to be ciphertext with a code-held key, the report gives the key and the record layout. For a region whose key is elsewhere, the report says exactly where the boundary is and what would be needed to cross it.
What the report must not do is use the word decryption for an operation that was reinterpretation. The difference matters to the next engineer, who will otherwise spend a day looking for a cipher that was never there.
The category boundaries overlap with two neighbouring questions: whether an instruction stream can be separated from data at all, covered in ST72F325J6 program code extraction, and how much of the original source can be reconstructed from what is recovered, covered in ST72F321BAR9T6 source code extraction. Where the customer’s belief in encryption stems from a read that returned nothing, the four-outcome model in ST72F32AK2 encrypted flash is the right starting frame.