Secure Elements
Keep a device’s private key in dedicated hardware, where it can be used but never read out. Without one, a key in a microcontroller’s flash can be copied by anyone with physical access, unless flash encryption is on.
This guide uses the Embedded C SDK, with an ATECC608 as the secure element.
1. How it works
Section titled “1. How it works”For token login, the SDK signs through a small interface, so the key can live anywhere. Your code signs a SHA-256 digest with whatever hardware you have, and the SDK does the rest.
static espoirnet_err_t signInChip(void *, const uint8_t hash[32], uint8_t sig[64]) { return ECCX08.ecSign(0, hash, sig) ? ESPOIRNET_OK : ESPOIRNET_ERR_CRYPTO;}
espoirnet_signer_t signer = { nullptr, signInChip };device.beginWithSigner(cfg, signer);To use other hardware, write your own version of that function:
- Input and output: you receive the digest (32 bytes) and write the raw signature (64 bytes, r then s, big-endian, not DER). The key must be P-256.
- Result: return
ESPOIRNET_OK, orESPOIRNET_ERR_CRYPTOon failure. A failure abandons that login attempt, and the SDK retries with a delay. - Timing: it’s called once per login, inside
poll(), so keep it well under a second. An ATECC608A takes about 140 ms. - Registering the key:
espoirnet_p256_public_key_pem()turns a raw public key (X then Y) into the text the console accepts.
2. Wire up an ATECC608
Section titled “2. Wire up an ATECC608”The SDK’s two ATECC608 examples need the ArduinoECCX08 library (1.4.1), from the Arduino Library Manager or in PlatformIO as arduino-libraries/[email protected]. Your other sketches don’t need it.
Use a blank chip, such as the ATECC608A-SSHDA-B or ATECC608B-SSHDA-B, not one sold pre-provisioned (-TNGTLS, -TFLXTLS).
| ATECC608 (SOIC-8) | ESP32 |
|---|---|
| Pin 8, VCC | 3V3 |
| Pin 4, GND | GND |
| Pin 5, SDA | GPIO 21, with a 4.7 kΩ pull-up to 3V3 |
| Pin 6, SCL | GPIO 22, with a 4.7 kΩ pull-up to 3V3 |
Pins 1, 2, 3 and 7 aren’t connected. Fit a 0.1 µF capacitor between VCC and GND, close to the chip.
3. Set up the chip
Section titled “3. Set up the chip”Flash the SecureElementProvisioning example and open the serial monitor at 115200 baud, with newline line endings.
-
schecks the chip: its serial number, and whether it’s locked. -
lwrites the configuration and locks the chip. It checks the written configuration before locking. -
kgenerates the key inside the chip. You have to typeyes, because this replaces any existing key. -
pprints the public key. Add it to the device in the console, as with any other key (see Device Provisioning).
4. Use it in your application
Section titled “4. Use it in your application”Start from the SecureElement example, which is the Telemetry example with login signed inside the chip. Everything else about the SDK works as usual: readings, state reports, commands, and revoking the key from the console.
5. Limits
Section titled “5. Limits”- Token login only. Certificate login still reads its key from flash on ESP32, because the TLS layer in the Arduino core can’t sign through an external chip.
- The link between the ESP32 and the chip isn’t paired or encrypted in this setup. The key can’t be read out, but someone with physical access to the board could ask the chip to sign. Protect your firmware with secure boot too.
Next steps
Section titled “Next steps”- Embedded C SDK — the rest of the SDK.
- Device Provisioning — rotating and revoking keys.

