PostHeaderIcon Break IC PIC12F635 Program: Where the Key Lives When There Is a Key

Remote controls, access tokens and rolling-code systems built on this family have one thing in common that most small microcontrollers do not: a secret. The device carries a hardware block that implements a proprietary hopping code algorithm, and the algorithm is only useful in combination with a key.

That key is content. It is stored in the device, it is read along with everything else when the device is read, and it is the part of the recovery that requires an actual decision rather than a procedure.

What the block does and what it needs

The algorithm takes a counter, a set of discrimination bits and a key, and produces a transmission that the receiver can verify and whose counter the receiver can track. Replay is prevented by the counter, and forgery is prevented by the key.

Element Where it lives Consequence of copying it
algorithm hardware block, not in the array not copied, identical on every device
key device memory, write-protected separately two devices become interchangeable to the receiver
counter device memory, updated on each use a copy inherits the donor’s counter position
discrimination bits device memory or code the copy identifies itself as the same unit

The second row is the one that matters. Copying the key produces a device that a receiver will accept. In a repair, that is exactly the desired outcome. In a duplication, it is the outcome being prevented, and the difference between the two is a conversation, not a technical step.

Where the key actually sits

On this family the key is held in the device’s data memory rather than in the program array, and it is write-protected by a mechanism separate from code protection. That separation is deliberate: it lets the production line install a key and then lock it, so that the key cannot be extracted by anything that merely has programming access.

The practical consequences for a recovery are three.

Reading the program array does not read the key. A job that returns the code has returned the part of the device that says how the product behaves, and none of the part that makes it acceptable to a receiver.

Reading the data memory may or may not return the key, depending on the protection state. Where the key is protected and the code is not, the image is complete as code and worthless as a duplicate.

The write protection is one-way on some parts. Installing a key and then protecting it is a final step; a device whose key has been protected cannot be re-keyed through the interface, which matters when a replacement is being prepared.

The counter and the failure it causes

The counter is updated every time the device transmits, and it is stored persistently. A copy inherits whatever value the donor had at the moment of the read.

On a receiver that tracks the counter and accepts only values ahead of the last one it saw, a copy with an old counter is rejected — silently, as a bad code rather than as an error. That produces a symptom that looks like a failed copy: the replacement device transmits, the receiver ignores it, and nothing indicates why.

The fix is to understand the receiver’s window. Some accept a small backward window for lost transmissions; some accept any counter value on a re-learn; some are strict. Knowing which applies decides whether a copied counter is usable or whether the device must be re-keyed and re-learned.

What code protection means when there is also a key

Two protections, often confused.

Code protection stops the interface returning the program array. It says nothing about the key. Key protection stops the interface returning the key, and says nothing about the code.

A device can therefore be in any of four states, and the state determines what the job can produce:

Code Key What a recovery can deliver
open open the program, the key, the counter — a complete duplicate
open protected the program and the product’s logic, but not a duplicate
protected open the key alone, which is sometimes the more valuable half
protected protected behaviour only

The third row is the one customers rarely expect and occasionally need. A receiver-side or a re-keying job may require only the key, and a device whose code is locked may still yield it.

The decision that has to be made explicitly

Duplicating a keyed device is not a technical question. A device that has been copied at this level can impersonate the original to any receiver that trusts the key, forever, and no countermeasure exists on the receiver side short of a re-key.

That means the scope of the work has to be established in writing before it begins: whether the deliverable is an understanding of the product, a repair of one unit, or a duplicate. The first two have ordinary engineering answers. The third has a different kind of answer, and it should be given to the person who owns the system rather than to whoever holds the device.

Being clear about this is not obstruction. It is the same discipline as asking whether a device is safety-critical before advising on a modification.

Reading order

  1. Read the identifier and the protection state of both the code and the key. This determines what is achievable before any work is spent.
  2. Read the program array if permitted, and interpret it for the transmission logic, the counter update path and the discrimination bits.
  3. Read the data memory if permitted, and look for a block of high-entropy bytes — a key looks like nothing in particular, which is itself a signature.
  4. Record the counter value, since it is part of the device’s state and not part of its design.
  5. Note which of the four protection states applied, in the delivery.

Step four is small and often overlooked. A customer who later reports that a replacement is rejected is usually reporting a counter problem, and having the donor’s value recorded makes the diagnosis immediate.

The delivery

  • the program image, with the transmission and counter logic identified
  • the counter value as a device state, not as code
  • the data memory image, or an explicit statement that the key was protected
  • the protection state of both regions
  • a statement of what the deliverable enables and what it does not

The last item is what keeps the work honest. A file that contains a key enables duplication whether or not that was the intent, and saying so is part of delivering it.

For the file-format side of handing over an image this small, PIC12F609 heximal recovery covers the conventions that prevent a correct extraction from being misread. Where the data memory is small and unprotected and the whole question becomes one of interpreting sixteen bytes, PIC12CE518 binary recovery is the closer case. And for a larger device where an encrypted store rather than a keyed transmission is the subject, PIC16F76 EEPROM recovery treats the encryption from the data side.

The general principle

When a device contains a secret, the recovery has two halves with different characters. One half is engineering: read the array, interpret the code, describe the behaviour. The other half is a decision about a credential, and credentials do not become less sensitive by having been extracted. Keeping the two halves separate — in the work, in the delivery, and in the conversation — is what makes this kind of job defensible.

Comments are closed.