<!-- The Markdown twin of https://api.kleidos.dev/firmware/, converted from that page at build time. The page is the original; these are the same words, with the markup taken off. -->
Canonical: https://api.kleidos.dev/firmware/

**In development.** It changes without notice.

# Overview

Kleidos is firmware that turns an ESP32 board into a hardware password manager. It keeps the owner's logins, one-time-code secrets and saved Wi-Fi networks in an encrypted vault on the board, opens the vault with a secret entered on the board itself, and types a login into a computer or phone paired with it, as a Bluetooth keyboard. It sends keystrokes and never receives them.

The same source builds for nine boards: Core2 v1.3, CoreInk, CoreS3 SE, LILYGO T-Deck, M5Cardputer ADV, M5StickC Plus 1.1, M5StickC Plus2, M5StickC Plus SE and M5StickS3 ([The boards](https://api.kleidos.dev/firmware/boards_page)). The secret is a PIN or a passphrase, by board. Between uses a board sleeps or switches its supply off; which of the two depends on the board.

This is the reference of the firmware's own code, for people who want to read how it works or change it. It is not a library: nothing here is stable. It is written by Doxygen from the comments in the sources and holds no source code.

## Where to read

### How the parts fit together, and when each screen ends

- [Application States](https://api.kleidos.dev/firmware/group__states)

### What each board has

- [The boards](https://api.kleidos.dev/firmware/boards_page)

### How a login is stored and sealed

- [Vault Storage](https://api.kleidos.dev/firmware/group__vault)
- [Cryptography](https://api.kleidos.dev/firmware/group__crypto)

### How a secret is entered, and what a wrong one costs

- [Unlock Entry](https://api.kleidos.dev/firmware/group__ui__entry)
- [Security](https://api.kleidos.dev/firmware/group__security)

### What a factory reset and a vault wipe erase

- [Change of Owner & Resets](https://api.kleidos.dev/firmware/group__change__of__owner)

### Pairing with a computer or phone, and typing into it

- [BLE HID Keyboard](https://api.kleidos.dev/firmware/group__ble)

### One-time codes, and the clock they need

- [One-Time Codes](https://api.kleidos.dev/firmware/group__totp)
- [Clock & Time Zone](https://api.kleidos.dev/firmware/group__time)

### The Wi-Fi portal, and firmware updates

- [Wi-Fi Admin Portal](https://api.kleidos.dev/firmware/group__web)
- [Update Policy](https://api.kleidos.dev/firmware/group__ota)

### Sleep, wake and the CPU clock

- [Power, Sleep & System Control](https://api.kleidos.dev/firmware/group__platform__power)
- [Power, Battery & Parking](https://api.kleidos.dev/firmware/group__hal__power)

### Screens, settings, and buttons, keys and touch

- [User Interface](https://api.kleidos.dev/firmware/group__ui)
- [Settings Model](https://api.kleidos.dev/firmware/group__settings)
- [Input Sources & the Wake Rule](https://api.kleidos.dev/firmware/group__hal__input)

### What a board is made of, for adding one

- [Board Configurations](https://api.kleidos.dev/firmware/group__boards)

How all of this is tested, on a computer, on the boards and with a meter, is in [How it is tested](https://api.kleidos.dev/firmware/qa_and_bench).

## By module

The parts of the firmware as the topics divide it, each with what it covers. The [Topics](https://api.kleidos.dev/firmware/topics) page has the parts inside each.

### [Entry Point & State Dispatch](https://api.kleidos.dev/firmware/group__app__entry)

The start of the firmware: the boot, in order, and the loop that runs the active state.

### [Application States](https://api.kleidos.dev/firmware/group__states)

The states of the application, what moves it from one to the next, and the handler that runs each.

### [Vault Storage](https://api.kleidos.dev/firmware/group__vault)

The encrypted vault: how logins, one-time-code secrets and saved networks are stored, listed, changed, backed up and re-keyed.

### [Cryptography](https://api.kleidos.dev/firmware/group__crypto)

From a PIN or passphrase to the keys that seal the vault, the secret bound to the chip, the seal of a backup and the password generator.

### [Security](https://api.kleidos.dev/firmware/group__security)

The lockout after wrong secrets, which lasts through a sleep or a cut in power, the log of security events, and the rule for a new secret.

### [Change of Owner & Resets](https://api.kleidos.dev/firmware/group__change__of__owner)

What a factory reset, a vault wipe and a settings reset erase, one sequence for every way of asking for each.

### [One-Time Codes](https://api.kleidos.dev/firmware/group__totp)

Time-based one-time codes (RFC 6238): making one from the secret in the vault, and the gate that refuses when the clock cannot be trusted.

### [Clock & Time Zone](https://api.kleidos.dev/firmware/group__time)

The wall clock and how far it is trusted, what set it last, and the time zones with their daylight-saving rules.

### [BLE HID Keyboard](https://api.kleidos.dev/firmware/group__ble)

The board as a Bluetooth keyboard: advertising, pairing, the bonded hosts, and typing.

### [Wi-Fi Admin Portal](https://api.kleidos.dev/firmware/group__web)

The web pages the board serves to one browser over its own Wi-Fi: to edit the vault, back it up, change settings and install an update.

### [Network Services](https://api.kleidos.dev/firmware/group__net)

The time from the network, the Wi-Fi session that fetches it, the portal's network name, and the request for the portal after a restart.

### [Update Policy](https://api.kleidos.dev/firmware/group__ota)

What a boot decides after an update: to keep the new firmware, to refuse it, or to say that the board went back to the previous one.

### [User Interface](https://api.kleidos.dev/firmware/group__ui)

Everything the screen shows: drawing, components, the unlock entry (PIN or passphrase), popups and notices, brand logos and the on-screen keyboard.

### [Settings Model](https://api.kleidos.dev/firmware/group__settings)

The options a device has, once for every surface that shows them: their groups, their values and the words for each.

### [Internationalization](https://api.kleidos.dev/firmware/group__i18n)

The interface's text by name, in English, Spanish, French, German and Italian.

### [Brand Lookup & Logo Atlas](https://api.kleidos.dev/firmware/group__brands)

From the address or the name in a login to the service's logo.

### [Build Configuration](https://api.kleidos.dev/firmware/group__config)

What the board being built has, as constants.

### [Hardware Abstraction Layer](https://api.kleidos.dev/firmware/group__hal)

What the application calls instead of a chip: display, input, power and battery, motion, sound, SD card, clock and GPS.

### [Device Drivers](https://api.kleidos.dev/firmware/group__drivers)

One driver for each chip: panels, power chips, motion sensors, clock, touch, keyboards, trackball, audio and GPS.

### [Platform Abstraction](https://api.kleidos.dev/firmware/group__platform)

The facades over ESP-IDF and FreeRTOS that the firmware calls.

### [Utilities](https://api.kleidos.dev/firmware/group__util)

Text, lists and queues that never use the heap, a checksum, and a wipe the compiler cannot drop.

### [JSON Reader, Writer and Binder](https://api.kleidos.dev/firmware/group__json)

JSON read in pieces, written to a sink and bound to a record by a table, with no allocation.

### [Diagnostics](https://api.kleidos.dev/firmware/group__diag)

What a board reports of itself: the log's queue, memory and tasks, the time spent drawing, and an estimate of what it draws.

### [Serial Debug Console](https://api.kleidos.dev/firmware/group__debug)

The serial console of a debug build, which drives a board from a cable. No other image holds it.

### [QA Host Firmware](https://api.kleidos.dev/firmware/group__host__tools)

The firmware of a test host: a board that plays the computer, over Bluetooth or on the portal's Wi-Fi.

## Security properties

- Every record and file of the vault is encrypted with AES-256-CBC and authenticated with HMAC-SHA256, and the tag is checked before anything is decrypted. The keys come from a random vault key, which the secret unwraps through PBKDF2-SHA256 ([Cryptography](https://api.kleidos.dev/firmware/group__crypto), [Keys, Metadata & Rotation](https://api.kleidos.dev/firmware/group__vault__keyset)).
- A secret or a tag is compared in constant time, and key material is wiped with calls the compiler cannot drop ([Cryptography](https://api.kleidos.dev/firmware/group__crypto), [Utilities](https://api.kleidos.dev/firmware/group__util)).
- No login goes into a log line, a Bluetooth advertisement or an answer the portal gives without its session token ([Logging](https://api.kleidos.dev/firmware/group__platform__log), [Wi-Fi Admin Portal](https://api.kleidos.dev/firmware/group__web)).
- From the fourth wrong secret in a row the board waits 30 s between tries, from the seventh 300 s, and the tenth is a factory reset ([Security](https://api.kleidos.dev/firmware/group__security), [Change of Owner & Resets](https://api.kleidos.dev/firmware/group__change__of__owner)).
- Bluetooth is shut down before Wi-Fi starts and before the board sleeps ([BLE HID Keyboard](https://api.kleidos.dev/firmware/group__ble), [Application States](https://api.kleidos.dev/firmware/group__states)).
- A hardened build adds Secure Boot v2, flash encryption and a key bound to the chip, and burns the chip's fuses on its first boot, once and for good. An open build has none of the three and leaves the chip's debug port open ([Build Configuration](https://api.kleidos.dev/firmware/group__config), [Cryptography](https://api.kleidos.dev/firmware/group__crypto)).

The threats behind this list, and what each is answered with, are at [kleidos.dev/security](https://kleidos.dev/security/).

## Power

A figure is stated here only when a bench meter measured it, and only for the board it was measured on. There is one: the LILYGO T-Deck draws 3.925 ± 0.046 mA (95 %, k = 2) at 4.113 V in its production sleep. A board not measured states none. Every measurement, with how it was taken, is at [kleidos.dev/measurements](https://kleidos.dev/measurements/).

## Finding a name

| To find | Look in |
| --- | --- |
| A part of the firmware | [Topics](https://api.kleidos.dev/firmware/topics) |
| A class or a record | [Classes](https://api.kleidos.dev/firmware/annotated) |
| A member of a class | [Names](https://api.kleidos.dev/firmware/functions) |
| A namespace | [Namespaces](https://api.kleidos.dev/firmware/namespaces) |
| A function, a value or a type of a namespace | [Names in a namespace](https://api.kleidos.dev/firmware/namespacemembers) |
| A macro, or a name outside every namespace | [File-level names](https://api.kleidos.dev/firmware/globals) |

The search at the top of every page finds any of these by its name, and the lists above are plain pages that need no script ([Search](https://api.kleidos.dev/firmware/search)).

Private members, helpers local to one source and generated tables have no page, and neither does what is compiled only in a debug build ([Serial Debug Console](https://api.kleidos.dev/firmware/group__debug)) or into the test host ([QA Host Firmware](https://api.kleidos.dev/firmware/group__host__tools)). A topic lists the headers of its part, by their path in the sources.

## More

- [kleidos.dev](https://kleidos.dev/): what Kleidos is, for the people who use it.
- [kleidos.dev/architecture](https://kleidos.dev/architecture/): how it is built, in one page.
- [kleidos.dev/security](https://kleidos.dev/security/): what it defends against, and what it does not.
- [kleidos.dev/measurements](https://kleidos.dev/measurements/): what the boards draw, as measured.
