Posts Tagged ‘decrypt locked chip software’
PIC12F508 Firmware: A Bit Shift Is Not Encryption
The word decrypt arrives in enquiries far more often than encryption exists in hardware. On a part like the PIC12F508 there is no cryptographic engine, no key storage and no encrypted bus. What there is, is an internal oscillator that the programmer has to synchronise with, and when that synchronisation drifts the resulting dump looks scrambled in a way that invites a cryptographic explanation.

What a shifted dump looks like
The characteristic sign is that the file is nearly right. Long stretches decode into plausible instructions, then a word appears that belongs somewhere else, and the same displacement repeats at a regular interval. Bits are not randomised, they are displaced. A real encryption produces a uniform distribution with no structure at all, which is a very different picture, and telling the two apart takes about a minute with a disassembler.
Where the drift comes from
The programming interface clocks data at a rate it controls, and the device has to sample it with an oscillator it generates internally. That oscillator is trimmed at final test and has a spread, and at low supply voltage the frequency falls further. If the programmer assumes a nominal rate and the part is running slow, samples land near the edge of the valid window and occasionally on the wrong side of it. Every such sample shifts the following bits, and the shift propagates until the next framing boundary resets it.
Three signatures, three causes
| Signature | Cause | Fix |
|---|---|---|
| Uniform displacement, no errors | Clock too fast | Slow the interface |
| Occasional errors, temperature linked | Marginal cells | Read at nominal supply, repeat |
| Errors clustered at a fixed period | Framing assumption wrong | Correct the frame length |
| Nothing but zeros | Protection set | Physical route |
The second row is what makes this part interesting: the same symptom can come from the clock or from the cells, and the only way to separate them is to change one variable at a time. A read taken at five volts with a slow clock that still errs is a cell problem; one that cleans up is a timing problem.
Fixing it rather than decrypting it
Read at the nominal supply, not at the low end of the range the product uses. Reduce the interface clock until the read is stable, then reduce it once more for margin. Read the array twice and compare, then compare the result against a known-good part of the same family if one exists. None of that is decryption and all of it is what actually recovers the file. The same discipline recovers images from marginal cells on the low-voltage variant, as described in PIC12LC508.
What a real cipher would look like
It is worth knowing what the alternative looks like, because it is occasionally real. An encrypted image has no structure at all: every word looks like every other word statistically, adjacent words share nothing, and no long run decodes into a plausible instruction sequence. Diffuse, uniform, and unhelpful. A file with a recognisable instruction stream and a repeating displacement is the opposite of that description, which is why the first test is always a disassembly rather than a statistical one.
Why nobody calls it timing
Because the customer did not perform the read; a programmer did, and it reported success. A tool that returns a file and a checksum has asserted that it did the job, so the natural next hypothesis is that the file is encrypted rather than that the tool lied. That is a reasonable inference from the information available, and correcting it early is worth more than any amount of explaining afterwards. The two answers that a dump can carry are set out in PIC12C509 code, and zero-versus-blank is the first distinction to make.
When the array really is protected
Then the answer is not decryption but access, and the route is the physical one. It is worth saying plainly that a protected part produces zeros rather than ciphertext, so an enquiry about encryption on a part that has no cipher is nearly always one of two things: a timing fault, or a customer who has been told by someone else that the file is encrypted. Both are resolved by reading the array properly, which is the process described in reading MCU code. Where the protection is real and the contents are needed bit-exact, the options narrow to the ones in attacking an MCU.