Expand description
Host-side cryptography for the ATECC’s encrypted write flow.
The chip can write a 32-byte slot only after the host has set up a
shared “session key” in TempKey via Nonce + GenDig. The host must
then encrypt the new value and produce a MAC that the chip can verify.
The full sequence is:
- Host generates a random 32-byte input and sends it as
Nonce(passthrough). The chip’sTempKeyis now equal to that input. - Host issues
GenDig(zone=Data, key_id=io_slot). The chip updatesTempKeytoSHA-256(io_key || opcode || param1 || param2 || sn[8] || sn[0..2] || zeros(25) || TempKey_prev). - The host can recompute the same
TempKeybecause it knows theio_key(passed in at provisioning) and all the other inputs. - To write
plaintext(32 bytes) intotarget_slot, the host sendsWritewithdata = ciphertext || macwhere:ciphertext[i] = plaintext[i] XOR TempKey[i]mac = SHA-256(io_key || opcode_write || param1 || param2 || sn[8] || sn[0..2] || zeros(25) || TempKey || plaintext)
The chip recomputes the MAC, validates it, decrypts, and stores.
This module exposes the pure host-side helpers. The orchestration
against the live chip lives in crate::service::CryptoService.
Constants§
- CHIP_
SERIAL_ 🔒LEN - Length of an ATECC chip serial number in bytes (as read from the config zone).
- OP_
GENDIG 🔒 - ATECC opcode for
GenDig. - OP_
WRITE 🔒 - ATECC opcode for
Write. - SLOT_
VALUE_ 🔒LEN - Length of a slot value (32 bytes).
- ZONE_
DATA 🔒 - Zone byte encoding
Datain theGenDigand Write commands.
Functions§
- build_
encrypted_ 🔒write_ payload - Assemble the 64-byte payload (
ciphertext || mac) that the driver expects in [atecc608b::AteccChannel::write_32_encrypted]. - derive_
session_ 🔒key - Compute the
TempKeyvalue that the chip ends up with after aNonce(passthrough, nonce_input)followed byGenDig(zone=Data, key_id=io_slot). - encrypt_
payload 🔒 - XOR-encrypt a 32-byte plaintext with the session key.
- write_
mac 🔒 - Compute the MAC that the chip expects to find appended to the ciphertext in an encrypted write.