ST72F32AK2 ‘Encrypted’ Flash: Testing an Assumption Before Acting on It
An enquiry that begins “the flash is encrypted, can you restore ST72F32AK2 encrypted flash heximal” carries an assumption that is wrong more often than it is right. The word encrypted is doing two jobs at once: it describes what the customer fears, and it presumes a mechanism the device very likely does not have. Acting on that presumption changes the plan, the price and the schedule, and it does so on the basis of a word rather than a measurement.
The measurement is cheap. This article is about running it before anything else happens, because a job that begins with a false assumption about encryption tends to end with a confident report that the wrong thing was recovered.
The word arrives before the evidence does
Customers rarely say “encrypted” because they have analysed the silicon. They say it because the device will not read, or because a previous supplier said so, or because a contract manufacturer told them the design was protected. Each of those origins points at a different technical reality, and none of them is a measurement.
The useful response is not to argue. It is to translate the word into a testable claim. “Encrypted” in this context normally means one of four things, and they have almost nothing in common beyond the vocabulary.
| what the customer means | technical condition | is the code ciphertext |
|---|---|---|
| the part will not read out | read-out protection enabled | no, plaintext behind a closed door |
| the data area looks like noise | application-level encryption of stored records | no, the code is plaintext |
| there is a security chip on the board | external device holding the keys | no, the code is plaintext |
| the vendor said so | unknown, possibly a sales term | unknown until measured |
Three of the four leave the instruction stream in plaintext. Only the fourth is open, and it is open precisely because it is not a technical statement.
Why an 8-bit part of this generation rarely has a cipher engine
A cipher engine costs silicon, and on an 8-bit microcontroller from this era the silicon budget was spent on peripherals that customers would pay for: timers, ADC channels, serial ports, more flash. A block cipher is a large amount of logic with no bearing on any of those, and it would need key storage that could not itself be protected by anything better than the read-out bit.
This is not an absolute rule, and it is worth checking rather than assuming. The check is documentary: does the datasheet list a cryptographic accelerator as a peripheral, with registers at fixed addresses? If it does, the engine exists and the key question is where the key lives. If it does not, then any encryption in the product was implemented in software, which places the key in the image you are trying to read.
| evidence | conclusion | next step |
|---|---|---|
| peripheral map lists a crypto block with key registers | hardware engine present | find the key source before planning the read |
| no crypto peripheral, but data region is high-entropy | software encryption of data | the key is in the code; recover the code first |
| no crypto peripheral, data region is low-entropy | no encryption at all | the enquiry is about protection, not encryption |
| a second IC on the board with its own supply | external security device | the code is readable; the key is not |
| the only evidence is the word “encrypted” | nothing established | measure |
Entropy, measured properly
The test that separates plaintext from ciphertext is a byte-histogram entropy calculation over the code region, and it is more subtle than the usual “does it look random” inspection.
Compiled 8-bit code is not uniform. It has favourite opcodes, frequent small constants, repeated prologue sequences, and long runs of similar bytes in constant tables. Its entropy per byte typically lands well below the maximum, and its byte histogram has visible peaks. Ciphertext has a flat histogram and entropy close to the maximum, because that is what a good cipher produces.
| measurement | compiled code | ciphertext | compressed data |
|---|---|---|---|
| byte entropy | clearly below maximum | near maximum | near maximum |
| byte histogram | visible peaks | flat | nearly flat |
| repeated 16-byte sequences | several | none | none |
| long runs of identical bytes | common in padding and tables | absent | absent |
| decodes as valid instructions | yes | almost never | no |
The fourth row is where compression and encryption look alike, and where a careless test gives the wrong answer. Compressed resources inside a firmware image are high-entropy and legitimate. The distinguishing feature is position: compressed resources sit in identifiable blocks with a header and a length, while encrypted code would have to cover the instruction stream itself, which would make the device unable to execute without decrypting on the fly. On a part with no cipher engine and no execute-in-place decryption, that is not possible.
When the code region passes and the data region fails
This is the most common real finding, and it is the one that produces the most useful report. The instruction stream is plaintext and entropy-typical; a region near the top or in a dedicated area is high-entropy and flat.
What that tells you is that the product encrypts its own stored records. The key is not hidden in silicon; it is in the code, used by a routine that runs at startup. Recovering the code recovers the key, and the records become readable without any cryptanalysis at all — which is why this configuration is far weaker than its authors usually believe.
| region | entropy | what it implies |
|---|---|---|
| application code | typical | plaintext, no action needed |
| constant tables | typical, with peaks | plaintext |
| parameter area | high, flat, block-aligned | encrypted records, key in code |
| whole map uniform and flat | maximum everywhere | would require on-the-fly decryption; verify the part has an engine |
The test that settles it in an hour
Take a readable device from the same production batch — an unprotected unit, a sample from the customer’s engineering stock, or the programming file from their archive. Compute the byte histogram and per-block entropy over the code region and over the parameter region separately.
If the code region is typical and the parameter region is flat, the model is software encryption of data, and the recovery is a code recovery. If both are typical, there is no encryption anywhere and the enquiry was about protection. If both are flat, stop and check whether the part actually has a cipher engine before planning anything, because that combination is unusual enough to be a misidentification.
An hour of measurement replaces a week of speculation, and it produces a sentence the customer can act on.
What to tell the customer
The report should state the measurement, not just the conclusion. “Byte entropy over the code region is 5.9 bits per byte with visible histogram peaks, consistent with compiled code” is a finding. “The firmware is not encrypted” is an opinion, and it invites a second opinion.
The report should also state what was not established. If the parameter area is encrypted and the key has not yet been extracted, say so. A partial finding that is honest is more useful than a complete-sounding one that is not, and on this kind of job the second supplier is always asked to confirm the first.
Where the service boundary sits
What is offered on this device is a set of distinguishable operations: a plaintext code recovery from an unprotected or physically accessed part, a key extraction from a recovered image where the key is software-held, and a decryption of stored records once the key is known. What is not offered is a cryptanalysis of a hardware engine on a part that does not have one.
Being precise about that boundary is the difference between a scope and a wish. The mechanics of the stored-data case are covered in ST72F321BK flash memory decrypt, and the tool-side limits — why software cannot vote on a protection bit that lives in silicon — are the subject of ST72F325R9 flash memory software readout. Where the conclusion is that the part is protected rather than encrypted, the three-read-outcomes analysis in ST72F32AK1 flash memory protection is the right next read.