Why a secure element?
The SAMD21 MCU alone cannot provide:- True random numbers — MCUs generate pseudo-random numbers from software seeds; quality is hard to verify.
- Tamper-resistant monotonic counters — software counters can be reset by erasing EEPROM or reflashing firmware.
- Device-unique identity — a chip serial baked into the die at manufacture provides an unforgeable hardware salt.
Hardware connection
| Signal | SAMD21 pin | ATECC608A pin |
|---|---|---|
| SDA | PA08 | SDA |
| SCL | PA09 | SCL |
| GND | GND | GND |
| VCC | 3.3 V | VCC |
0x60Bus speed: 100 kHz (set at startup and matched by the bootloader)
SKU note — MAHDA-T
TheMAHDA-T variant ships with:
- Hardware AES command disabled (cannot perform on-chip AES ECB/CBC).
- Standard TRNG, Counter, CheckMac, and ReadSerial commands enabled.
- Factory-default slot configuration (all slots unlocked, readable, and writable until provisioning locks them).
Slot map
Established at provisioning and locked permanently:| Slot | Size | Purpose | Write policy |
|---|---|---|---|
| 9 | 32 B | PIN key: SHA-256(pinArray[16] ∥ chip_serial[9]) | Clear 32-byte write allowed (IsSecret=0, WriteConfig=Always) |
| 8 | 16 B | Reserved for AES key (provisioning path) | — |
| Counter 0 | 4 B mono | PIN attempt counter | Increment-only, read-allowed |
Slot 9 security note: BecauseMAHDA-Trejects clear writes to IsSecret slots (slots 0–7), the PIN key is stored in slot 9 which keepsIsSecret=0. This means the 32-byte PIN hash is readable over I²C by anyone with physical access. An adversary could read the hash and attempt offline SHA-256(PIN∥serial) dictionary attacks. Short PINs (< 6 digits) are particularly vulnerable to this approach.
Commands used
RANDOM (opcode 0x1B)
- Mode
0x00: refreshes the internal DRBG seed from hardware entropy before generating 32 random bytes. - Used to generate the AES master key (16 B) and the IV (16 B) at provisioning, and to regenerate the IV on demand.
INFO (opcode 0x30)
- Mode
0x00: returns 4-byte revision word. - Used as a liveness check (
ping()) to detect an unprovisioned or missing chip at boot.
READ (opcode 0x02)
- 32-byte block read from Config Zone.
- Used by
readSerial()to extract the 9-byte chip serial (bytes 0–3 and 8–12 of Config Zone block 0). - Used by
readConfigBlock()(provisioning only) andreadLockStatus().
COUNTER (opcode 0x24)
- Mode
0x00(read): returns current Counter0 value. - Mode
0x01(increment): atomically increments Counter0 and returns the new value. - Called before every PIN verification attempt. The counter is hardware monotonic — no software path can decrement it.
WRITE (opcode 0x12)
- 32-byte clear write to data zone (slot 9).
- Used by
writeSlot32(ATECC_SLOT_PIN, derived_key)during PIN setup and PIN change.
CHECKMAC (opcode 0x28) — defined but not used in primary verify path
- Computes
SHA-256(slot_key ∥ ClientChallenge ∥ OtherData)inside the chip and compares it to a host-computed response. - Implemented in
checkMacAgainstPin()for future use. CurrentverifySignature()uses a direct EEPROM hash comparison instead.
LOCK (opcode 0x17) — provisioning only
- Irreversibly locks the Config Zone and/or Data+OTP Zone.
- Called by the provisioning kit after all slots and config words are written.
Wake / sleep protocol
The ATECC608A uses a non-standard I²C wake sequence:- Drive SDA low for > 60 µs. Achieved by addressing
0x00at 100 kHz (ignored NACK expected). - Wait ≥ 1.5 ms (t_WHI).
- Read 4-byte wake response: expect
[0x04, 0x11, CRC_lo, CRC_hi]. - Validate CRC-16 (poly
0x8005, init0x0000, no reflection) over first 2 bytes.
wake() → execute() → sleep(). The chip returns to low-power sleep after every operation.
PIN key derivation
pin_bytesare the raw digit values frompinArray[16](each byte = 0–9 from touch input).serialis the 9-byte device-unique identifier (irreversible, factory-programmed).- The same formula is used by the provisioning kit when writing slot 9, ensuring the app and chip agree.
serial is unique per chip, the same PIN on two different ZeroKeyUSB devices produces completely different 32-byte keys.
Counter0 — hard PIN limit
Counter0 is initialised at provisioning to its current factory valuecur_counter. The threshold stored in EEPROM at 0x0020 is set to cur_counter + 50.
Each PIN attempt — right or wrong — calls counterIncrement(). On a correct PIN the threshold is reset to new_counter + 50. On wrong PINs the threshold stays fixed, so after 50 consecutive wrong attempts without a correct one, new_counter ≥ threshold and the firmware wipes all credential slots (eraseAll()).
The counter’s maximum value is 2^20 - 1 (≈ 1 048 575) per the ATECC608A datasheet. This is enough for decades of normal use.
CRC protocol
All ATECC608A command packets use a custom CRC-16:- Polynomial:
0x8005 - Initial value:
0x0000 - No input/output reflection
- No final XOR
count through the last data byte, excluding the CRC bytes themselves. Response CRC covers from byte 0 (count) through the last data byte.
Lock status
readLockStatus() reads Config Zone block 2 (bytes 64–95):
- Byte 86 (
LockValue):0x55= Data+OTP zone unlocked; any other value = locked. - Byte 87 (
LockConfig):0x55= Config zone unlocked; any other value = locked.
lockConfig() then lockData() as the final step.