In development. It changes without notice.
Topic
Vault Storage
The encrypted vault: how logins, one-time-code secrets and saved networks are stored, listed, changed, backed up and re-keyed.
VaultStore is the facade every caller uses. It sends each call to the vault worker, a task on core 0 that does all the reading, writing and deriving, and it owns the life of the session's key and the recovery after a cut in power. The parts behind it are subtopics: Record Log & Envelopes the log the records live in, Keys, Metadata & Rotation the keys, the metadata and the rotation, Record Repositories the stores of each kind of record, and Backup, Import & Export backups, imports and exports.
On flash (a LittleFS partition that an update does not touch):
| File | Holds |
|---|---|
| /vault/meta.bin | The metadata: the salt, the work factor, the verifier, the wrapped vault key, the state of a rotation, and a generation counter for each slot. |
| /vault/r/rc_NN.bin | A segment of the record log: the logins of a fixed range of slots. |
| /vault/r/rt_NN.bin | The same for one-time-code secrets. |
| /vault/i/idx_NN.bin | An encrypted segment of the list's index. |
| /vault/groups.bin | The names of the groups. |
| /vault/wifi.bin | The saved networks. |
| /vault/mut_stage.bin and .mark | A record being changed, and the mark that says so. Present only meanwhile. |
| /vault/import_new/ and import.commit | An import from a card being built, and the mark that says it is complete. Present only meanwhile. |
A record is packed binary: each field carries its length, and the decoder checks every bound and refuses what does not fit. Each record and each file carries its own HMAC tag, checked before anything is decrypted. The tag also covers what the record is, its slot and that slot's generation, so a file that was moved, swapped for another kind or put back from an older copy is refused.
Opening and listing. The secret's key checks the verifier and unwraps the vault key out of the metadata; the vault key then checks the metadata's own tag and reads the list from the index segments, without opening a record. A record is decrypted only when it is shown, edited or sent. The key path is drawn in Cryptography. The vault key is wiped when the session locks and before any sleep.
A mount that fails formats nothing. The partition is formatted only when every sector of it reads blank, or when a person or a wipe asked for it.
Topics | |
| Record Log & Envelopes | |
| The log the records are appended to, the binary form of a record, and the sealed envelope around it. | |
| Keys, Metadata & Rotation | |
| The vault's keys, the authenticated metadata that holds them wrapped, what a typed secret becomes before it is derived, and the key rotation. | |
| Record Repositories | |
| The store of each kind of record: logins, one-time-code secrets and saved networks, with the names of the groups and the order of the lists. | |
| Backup, Import & Export | |
| The sealed backup the portal and the SD card share, the import of other managers' CSV files, and the SD card's flows. | |
Files | |
| file | src/ |
| The bytes a factory reset leaves in the blank vault partition until NVS is erased too. | |
| file | src/ |
| Whether a refused vault mount follows a format that failed, across boots. | |
| file | src/ |
| The secret epoch's NVS counter: what refuses a meta.bin that a rollback brought back. | |
| file | src/ |
| Creates the vault's directory tree, and recognizes a tree this build cannot read. | |
| file | src/ |
| The single owner of every vault file path, directory and basename. | |
| file | src/ |
| The session state and the helpers the other sources share: the format-failure record, the meta I/O, the session keys and the crash-safe mutation (part of vault_store.h). | |
| file | src/ |
| The one way the rest of the firmware reaches the encrypted vault. | |
| file | src/ |
| VaultStore's credentials: the record adapters, save, load, delete and the last-used slot (part of vault_store.h). | |
| file | src/ |
| VaultStore's other entries: the one-time codes, the saved Wi-Fi networks and the NTP servers (part of vault_store.h). | |
| file | src/ |
| VaultStore's groups: the encrypted label table and the member sweeps (part of vault_store.h). | |
| file | src/ |
| VaultStore's index cache: the listing walks, the rebuild and the batch guard (part of vault_store.h). | |
| file | src/ |
| What the sources of VaultStore share: the session state, the meta I/O, the session keys and the crash-safe mutation. | |
| file | src/ |
| VaultStore's lifecycle: the mount, the boot's verdicts, provisioning, the unlock and the lock (part of vault_store.h). | |
| file | src/ |
| VaultStore's list columns: favorites and the custom list order (part of vault_store.h). | |
| file | src/ |
| VaultStore's secret change and the in-place key rotation (part of vault_store.h). | |
| file | src/ |
| VaultStore's backup boundary: the JSON import and the streamed restore (part of vault_store.h). | |
| file | src/ |
| Value types of the VaultStore facade API: the record structs, the capacity caps, and the unlock and wipe verdicts. | |
| file | src/ |
| VaultStore's wipes: the crypto-erase and sweep fallbacks, wipeAll and emptyKeepingSecret (part of vault_store.h). | |
| file | src/ |
| Single-owner vault / LittleFS worker task pinned to Core 0 (PRO_CPU). | |
| file | src/ |
| One NVS byte that says a wipe was asked and has not finished. | |
Namespaces | |
| namespace | kleidos:: |
| The vault: its records and their encryption, the record log and index, backups, import and the worker that runs them. | |
| namespace | kleidos:: |
| The JSON backup of the vault: the export, and the streamed restore of a backup document. | |
Classes | |
| struct | kleidos:: |
| What a factory reset hands to the boot that finishes it. More about kleidos:: | |
| struct | kleidos:: |
| read's answer. More about kleidos:: | |
| struct | kleidos:: |
| What a mount leaves of the failed-format record, and what the vault reports. More about kleidos:: | |
| struct | kleidos:: |
| The counter as read. More about kleidos:: | |
| class | kleidos:: |
| Creating and recognizing the vault's on-flash directory tree. More about kleidos:: | |
| class | kleidos:: |
| Static facade for encrypted credential, TOTP, and meta storage on LittleFS. More about kleidos:: | |
| class | kleidos:: |
| Defers the list-index rewrite across a bulk credential operation. More about kleidos:: | |
| struct | kleidos:: |
| What a ranking's plan cost — reported whether it was applied or refused, so a refusal can say what the maintenance action would do. More about kleidos:: | |
| struct | kleidos:: |
| Called as an ordering plan is read and written. More about kleidos:: | |
| struct | kleidos:: |
| Decrypted credential held only in RAM. More about kleidos:: | |
| struct | kleidos:: |
| Credential list entry: slot, name, favorite and order, read without opening the record. More about kleidos:: | |
| struct | kleidos:: |
| Decrypted TOTP entry held only in RAM. More about kleidos:: | |
| struct | kleidos:: |
| Secret-free listing view of a stored TOTP entry. More about kleidos:: | |
| struct | kleidos:: |
| One group id → display-name mapping surfaced by VaultStore:: | |
| struct | kleidos:: |
| What a group sweep did, whichever answer it went on to give. More about kleidos:: | |
| struct | kleidos:: |
| Everything about a credential the login subset does not carry. More about kleidos:: | |
| struct | kleidos:: |
| What a credential's detail screen renders, and nothing more. More about kleidos:: | |
| struct | kleidos:: |
| The unlock surface a vault's meta records: the PIN length and the kind of secret, as the raw persisted bytes. More about kleidos:: | |
| struct | kleidos:: |
| What a restore found in a backup and what of it this device took: the numbers every surface tells the owner when they differ. More about kleidos:: | |
Typedefs | |
| using | kleidos:: |
| The tag's bytes. | |
| using | kleidos:: |
| using | kleidos:: |
| One superseded password and when it was replaced (panel-only audit surface). | |
Functions | |
| TagBytes | kleidos:: |
Encode tag. | |
| std:: | kleidos:: |
Decode bytes as a tag. | |
| ReadResult | kleidos:: |
| Read offset 0 of the vault partition and decode it. | |
| bool | kleidos:: |
| Whether a factory reset is pending, failing closed. | |
| bool | kleidos:: |
Write tag over the (blank) first bytes of the vault partition, and read it back. | |
| bool | kleidos:: |
| Erase the tag's sector, and read the whole sector back erased. | |
| constexpr FormatFailureVerdict | kleidos:: |
The record and the report after a mount that ended in outcome. | |
| constexpr Verdict | kleidos:: |
| Judge a record's epoch against the counter. | |
| constexpr bool | kleidos:: |
| Whether a verdict refuses the record. | |
| constexpr uint32_t | kleidos:: |
| The epoch a new KEK half takes: one above the record it replaces and the counter. | |
| Counter | kleidos:: |
| Read the counter. | |
| bool | kleidos:: |
Raise the counter to epoch, never lowering it, and read it back. | |
| constexpr bool | kleidos:: |
| Are two NUL-terminated literals identical, at compile time? | |
| template<size_ | |
| void | kleidos:: |
Build the canonical credential basename for slot. | |
| template<size_ | |
| void | kleidos:: |
Build the canonical one-time-code basename for slot. | |
| template<size_ | |
| void | kleidos:: |
Build the canonical list-index segment basename for segment. | |
| template<size_ | |
| void | kleidos:: |
Join <dir>/<name> into out. | |
| template<size_ | |
| void | kleidos:: |
Build the canonical path of the credential in slot. | |
| template<size_ | |
| void | kleidos:: |
Build the canonical path of the one-time code in slot. | |
| template<size_ | |
| void | kleidos:: |
Build the basename of record-log segment segment. | |
| template<size_ | |
| void | kleidos:: |
Build the canonical path of record-log segment segment. | |
| template<size_ | |
| void | kleidos:: |
Build the compaction-twin path of record-log segment segment. | |
| template<size_ | |
| void | kleidos:: |
Build the canonical path of list-index segment segment. | |
| template<size_ | |
| void | kleidos:: |
Build the staging-twin path of list-index segment segment. | |
| template<size_ | |
| void | kleidos:: |
Build the SD-import staging path of basename. | |
| const char * | kleidos:: |
| Directory a canonical basename belongs in. | |
| template<size_ | |
| void | kleidos:: |
Build the canonical path a staged basename is promoted onto. | |
| void | kleidos:: |
| Native-test hook: inject the trusted-epoch source used for timestamps. | |
| void | kleidos:: |
| Native-test hook: forget the failed-format record this boot has read and the manual-recovery verdict, as a restart does. | |
| constexpr bool | kleidos:: |
| Whether a verdict is evidence of a wrong guess at the secret. | |
| constexpr bool | kleidos:: |
| Whether a verdict entitles a surface to tell the owner the vault is gone. | |
| constexpr bool | kleidos:: |
| Whether the secret was proven by the vault-only wipe. | |
| bool | kleidos:: |
| Bring up the worker task. Safe to call multiple times: subsequent invocations are no-ops while the task is already running. The worker owns no shared state at construction; the queue and task handle are the only static resources. | |
| void | kleidos:: |
| Stop the worker. Drains the queue first (with a bounded timeout), then signals the task to exit and joins it. Must be called before LittleFS unmount in the deep-sleep teardown sequence. | |
| bool | kleidos:: |
| True between begin() returning true and shutdown() returning. Used by the public VaultStore shim to decide whether to dispatch or run inline. | |
| rtos:: | kleidos:: |
| Returns the worker task handle, or nullptr when the task is not running. Exposed so the dispatcher can detect re-entrant calls from the worker itself and skip the queue. | |
| uint32_t | kleidos:: |
| Number of requests currently queued. A queue-depth probe for diagnostics surfaces (e.g. the serial debug console). | |
| bool | kleidos:: |
| True when (a) the worker is not running yet, or (b) the calling task IS the worker. In either case, public VaultStore shims must run their body inline rather than dispatching — otherwise the worker would deadlock on self-dispatch, and pre-begin() boot code would block forever. | |
| template<typename Fn> | |
| bool | kleidos:: |
| Run fn() on the vault worker thread and return its result. Fn must be callable as bool fn(). Capturing lambdas are allowed: the worker invokes them through a captureless trampoline, so all state in the closure stays on the caller's stack. | |
Variables | |
| constexpr size_t | kleidos:: |
| Bytes the tag takes at offset 0 of the vault partition. | |
| constexpr uint8_t | kleidos:: |
| The tag's layout version. | |
| constexpr std::array< uint8_t, 16 > | kleidos:: |
| The tag's magic, NUL included. | |
| constexpr size_t | kleidos:: |
| Where the version byte sits. | |
| constexpr size_t | kleidos:: |
| Where the carried freshness floor sits. | |
| constexpr size_t | kleidos:: |
| Where the CRC sits; it covers every byte before it. | |
| constexpr const char * | kleidos:: |
| NVS namespace of the counter, apart from every preference. | |
| constexpr const char * | kleidos:: |
| NVS key of the counter. | |
| constexpr size_t | kleidos:: |
| Capacity of a canonical-path buffer, excluding the NUL. | |
| constexpr size_t | kleidos:: |
| Capacity of a staged-path buffer, excluding the NUL. | |
| constexpr size_t | kleidos:: |
| Capacity of a basename buffer, excluding the NUL. | |
| constexpr const char * | kleidos:: |
| Root directory of the encrypted vault on LittleFS. | |
| constexpr const char * | kleidos:: |
| Directory of an older layout's credential files (cred_NN.bin), read only to detect that layout. | |
| constexpr const char * | kleidos:: |
| Directory of an older layout's one-time-code files (totp_NN.bin), read only to detect that layout, as :: | |
| constexpr const char * | kleidos:: |
| Directory holding every idx_NN.bin list-index segment. | |
| constexpr const char * | kleidos:: |
| Directory holding every record-log segment: rc_NN.bin for a fixed range of credential slots, rt_NN.bin for TOTP slots. | |
| constexpr const char * | kleidos:: |
| Staging tree the SD import copies an incoming vault into. | |
| constexpr std::array< const char *, 5 > | kleidos:: |
| Every directory the canonical vault occupies, root first. | |
| constexpr const char * | kleidos:: |
| Path separator, so a joined path never spells one inline. | |
| constexpr const char * | kleidos:: |
| Basename of the vault metadata record — the root of trust. | |
| constexpr const char * | kleidos:: |
| Basename of the singleton group-label table. | |
| constexpr const char * | kleidos:: |
| Basename of the singleton saved-network store. | |
| constexpr const char * | kleidos:: |
| Basename of the per-mutation record staging file. | |
| constexpr const char * | kleidos:: |
| Basename of the per-mutation staging marker sidecar. | |
| constexpr const char * | kleidos:: |
| Basename of the SD-import commit marker. | |
| constexpr const char * | kleidos:: |
| Leading run of every credential basename. | |
| constexpr const char * | kleidos:: |
| Leading run of every one-time-code basename. | |
| constexpr const char * | kleidos:: |
| Leading run of every list-index segment basename. | |
| constexpr const char * | kleidos:: |
| Leading run of a credential-log segment basename. | |
| constexpr const char * | kleidos:: |
| Leading run of a TOTP-log segment basename. | |
| constexpr const char * | kleidos:: |
| Trailing run of every record basename. | |
| constexpr const char * | kleidos:: |
| Suffix of a file staged for an atomic rename onto its final name. | |
| constexpr const char * | kleidos:: |
| printf spelling of a slot id inside a basename. | |
| constexpr const char * | kleidos:: |
| printf template of a credential basename. | |
| constexpr const char * | kleidos:: |
| printf template of a one-time-code basename. | |
| constexpr const char * | kleidos:: |
| printf template of a list-index segment basename. | |
| constexpr const char * | kleidos:: |
| printf template of a credential-log segment basename. | |
| constexpr const char * | kleidos:: |
| printf template of a TOTP-log segment basename. | |
| constexpr const char * | kleidos:: |
| Canonical vault metadata path. | |
| constexpr const char * | kleidos:: |
| Path the metadata is written to before its atomic rename into place. | |
| constexpr const char * | kleidos:: |
| Canonical group-label table path. | |
| constexpr const char * | kleidos:: |
| Path the group-label table is written to before its atomic rename. | |
| constexpr const char * | kleidos:: |
| Canonical saved-network store path. | |
| constexpr const char * | kleidos:: |
| Path the saved-network store is written to before its atomic rename. | |
| constexpr const char * | kleidos:: |
| Per-mutation record staging path. | |
| constexpr const char * | kleidos:: |
| Per-mutation staging marker path. | |
| constexpr const char * | kleidos:: |
| SD-import commit marker: present means roll FORWARD. | |
| constexpr const char * | kleidos:: |
| Temp name the import commit marker is written to before its rename. | |
| constexpr const char * | kleidos:: |
| Staged metadata path inside the SD-import staging tree. | |
Typedef Documentation
CustomField #
One typed custom field, as the pool stores it. The canonical type, not a mirror: there is one definition and the facade re-exports it.
Enumeration Type Documentation
EmptyOutcome #
Verdict of VaultStore::
Only WrongSecret weighed a secret and was wrong; only Emptied kept it.
GroupSweepStage #
Which step of a group sweep answered, so a caller can say what is still true instead of attributing every failure to the sweep.
ImportStatus #
Outcome of a whole-vault restore.
A restore fails in ways that mean opposite things to the vault owner, and a caller that collapses them into one boolean tells the user the wrong one. ImportStatus keeps them apart at the only boundary where they are still distinguishable:
- ImportStatus::
Rejected — every refusal fires BEFORE the first write, so the vault is byte-for-byte what it was. Nothing to recover from. - ImportStatus::
DoesNotFit — the document's counts member says the backup holds more credentials or TOTP entries than this device has slots. Refused before the first write, like Rejected, but a different answer: the file is a good backup, of a bigger device. It is the question, not the end: the counts are in the restore's RestoreTally, and the owner who goes on restores again with OverCapacity:: FillInOrder. - ImportStatus::
ContentRefused — the document reached the restore and what it carries is not a backup this firmware reads: a version it does not know, a meta record no board writes, a malformed element. Refused before the first write, like Rejected, and a different answer for the reason DoesNotFit is one: a sealed backup can only reach this far once its envelope opened, so the passphrase was right, and a prompt that asks for it again reports a correct secret as a wrong one. Rejected keeps the refusals that say nothing about the document: an envelope that did not open, a document that never arrived whole, a vault that was locked or busy.
The two remaining answers both mean the vault was already being replaced and now holds a strict SUBSET of the backup: the previous contents are gone and the records that did not land are missing (visibly missing — never a pre-restore record masquerading as restored). The owner must be told the vault changed and that the backup file is still the good copy. What separates them is WHO failed, which is what decides whether restoring the same file again can do any better:
- ImportStatus::
PartialWriteFailed — this device could not write what the document legitimately carried: a record or a group label that did not commit, a stale table that would not drop, or a document that stopped arriving part-way. The file is fine; restoring it again on a device with room can complete it. - ImportStatus::
PartialEntriesRefused — every write this device attempted landed, and what is missing are entries the document carries that fall outside the record grammar this device accepts: a one-time code whose secret, digit count or period this build does not read, a slot id that names no slot on any board (a record that sat beyond THIS board's slots on a bigger one is written to a free slot here), or a group id no label in the same document answers for. Nothing failed here, and restoring the same file again drops the same entries and reaches the same verdict, forever. - ImportStatus::
PartialLeftOut — every write landed and the backup held more credentials or one-time codes than this device stores: the owner chose to go on (OverCapacity:: FillInOrder), so the backup's entries were written in the backup's own order until each kind of slot was full, and the rest were left out. How many is in the restore's RestoreTally, which the owner is told: a loss the owner agreed to, never a silent one.
A restore that hits more than one answers the first of PartialWriteFailed, PartialEntriesRefused, PartialLeftOut: a device that failed to write is the most urgent fact, and it is the one for which a retry is worth the owner's time. The tally counts the entries left out whichever is answered.
| Enumerator | |
|---|---|
| Ok | Envelope accepted and every record it carries is on flash. |
| Rejected | Refused before the first write; the vault is untouched. |
| PartialWriteFailed | Accepted, then a write this device attempted did not land (or the document stopped arriving); the vault is now a subset. |
| DoesNotFit | The backup's counts exceed this device's slots; untouched. |
| PartialEntriesRefused | Accepted and every write landed, but entries outside this device's record grammar were dropped; the vault is now a subset. |
| ContentRefused | The document arrived and this firmware does not read what it carries; refused before the first write, the vault is untouched. Reached through a sealed backup only once its envelope opened: never a wrong passphrase. |
| PartialLeftOut | Accepted and every write landed; the backup held more than this device stores, and the entries past its capacity were left out, in the backup's order, because the owner chose to go on (RestoreTally). |
LayoutVerdict #
What a look at the vault root says about the layout the vault was written in.
ListColumnResult #
How a list-column write (the star, the ranking) ended.
A caller acting on a plain false has one response for every refusal, and the responses are opposite: a request the vault cannot apply to itself asks the caller to look at the vault again, while a vault that could not carry out a request it accepted asks for the same request once more. A remote caller cannot look at the vault at all, so the distinction has to reach it: the portal posts a ranking built from a list that a delete on the device may have moved under it, and answering that with a server error hides the one thing the user can act on.
Damaged is a fourth answer: the vault holds the row and the stored bytes were read and refused. Asking again reaches the same bytes, so it is neither a retry nor a re-read — it is the one refusal the owner has to hear about, because only re-saving that credential (which replaces the damaged bytes) or deleting it clears it.
Exhausted is a fifth: the request is valid and the vault could carry it out, but not inside the write cap a request path holds itself to. Nothing is written, and the answer carries what the plan would have cost so the caller can offer it as a maintenance action instead of hanging on it.
ListColumnWrite #
Whether a save writes one of the record's list columns or leaves it alone.
A save carries the WHOLE record, so an absent field cannot be distinguished from a cleared one by value. The device edit screens and the debug console never touch the star or the ranking, so the default has to be Keep: a two-state bool favorite would let every one of those saves clear a star.
OrderWriteBudget #
What a ranking asks the vault to do with the labels.
| Enumerator | |
|---|---|
| Bounded | Realize the ranking with the FEWEST record writes, and at most kleidos:: |
| Reseed | Re-space the ranking: every row onto the evenly spaced label of its position, however few writes the ranking itself would have needed, and with no cap on how many records that is. The maintenance action, run by a caller that has stated the time bound and waits for it. Lifting the cap alone would not do it — the plan that realizes an order the stored labels already carry is the empty plan, so the crowding that refused the move would survive the action offered to clear it. |
OverCapacity #
What a restore does with a backup that holds more than this device stores.
A backup is written by any board and restored on any other, and a board's only limit on what it takes is its own capacity: nothing else of the backup — its work factor, its meta, its slot ids — may stop an import. So a backup bigger than this device is never refused for good: the first answer (OverCapacity::
| Enumerator | |
|---|---|
| Refuse | Write nothing and answer ImportStatus:: |
| FillInOrder | The owner chose to go on: write the backup's entries in its own order until each kind of slot is full, leave the rest out and count them. |
PoolValue #
Which pool value VaultStore:: fetches.
Reading [1/2] #
What read found at offset 0 of the vault partition.
Reading [2/2] #
SlotWrite #
What a caller means by writing to a slot it named.
A save opens its destination truncating, so writing to an occupied slot replaces what is there. That is correct when the caller is editing a record it just read, and it is the loss of a live credential when the caller took the slot from VaultStore::
The whole chain that produces a "free" slot is one predicate deep: a directory listing that could stop part-way, a mask bit, an id. Declaring SlotWrite::
UnlockOutcome #
What an unlock attempt established about the secret it was given.
VaultStore::BruteForceGuard:: — which erases the whole vault at ten consecutive failures. A vault that could not be mounted, a meta.bin that could not be read, an allocation that failed inside the sub-key derivation and a MAC that did not verify are not guesses at the secret: counting them destroys the vault of an owner who typed the correct secret every time. The authority to destroy is a byte in NVS that outlives the boot the predicate ran in, so nothing downstream can recover a distinction thrown away here.
Only UnlockOutcome:: is evidence about the secret. Route every verdict through countsAsFailedAttempt rather than counting every outcome but UnlockOutcome::, which counts all eight.
| Enumerator | |
|---|---|
| Unlocked | The secret was checked and matched; |
| WrongSecret | The secret was checked and did not match. THE ONLY countable failure. |
| LegacyLayout | An older layout (flat, or one file per record): no secret opens this vault, so none was tried. |
| MetaUnreadable | meta.bin absent, wrong size, short read, or malformed. |
| TamperDetected | The secret matched but meta.bin failed its MAC — fail closed, do not count. |
| NotChecked | A step could not run (unmounted vault, backend, allocation, binding). |
| BadArgument | Caller passed no secret or no output buffer — a bug, never an attempt. |
| KeyfileUnavailable | The record declares a key-file second factor the card did not give up, so the derivation input could not be assembled and NOTHING was derived. An unseated card is not a wrong secret; surfaces should say "seat the key file", never "wrong secret". |
| RolledBack | The record's secret epoch is below the NVS counter, or no counter stands beside it: meta.bin is one a rollback brought back (an undone LittleFS commit, a written-back partition), refused before any secret is weighed. Not an attempt, so never counted ( |
Verdict #
What a record's epoch is, against the counter.
WipeOutcome #
What a vault wipe established about the state it left behind.
VaultStore::
The three verdicts are decided by different evidence. Erased means the whole-partition erase landed, which is the only step that removes bytes from flash on a copy-on-write filesystem. LogicalOnly means it did not, but every traversal that had to empty a directory finished and reported it empty. The residue that leaves is precise and worth stating exactly: the unlinks are logical, so LittleFS keeps the old blocks until they are reused — the record ciphertext, the KDF salt and the secret verifier are all still in freed blocks. On the open builds they are recoverable from a raw flash dump. On the hardened build, whose table flags the vault for Flash Encryption, the dump holds them as ciphertext under the chip's key and the KEK is bound to the chip, so the residue cannot open away from it. Incomplete means neither: a directory could not be listed or would not empty, so named files may still be sitting there under their own names.
Function Documentation
begin() #
Bring up the worker task. Safe to call multiple times: subsequent invocations are no-ops while the task is already running. The worker owns no shared state at construction; the queue and task handle are the only static resources.
- Parameters
-
Name Meaning core Target core. Defaults to PRO_CPU, the services core. priority Application priority. Defaults to 3: above the services at 2 (the debug logger, name store, speaker, NTP sync) and below the TOTP worker and the BLE stack task (4). The unlock's crypto runs on this worker itself.
- Return values
-
Value Meaning true Worker spawned (or already running; idempotent). false Queue or task could not be created (typically OOM).
canonicalPathFor() #
Build the canonical path a staged basename is promoted onto.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path. basename in Canonical basename.
clear() #
Erase the tag's sector, and read the whole sector back erased.
- Return values
-
Value Meaning true The first sector was erased and every byte of it reads 0xFF. false The erase failed, or a byte did not read back erased.
countsAsFailedAttempt() #
Whether a verdict is evidence of a wrong guess at the secret.
The single definition of what may escalate the brute-force counter. Every other verdict describes something that happened to the device, not something the user typed: the derivation either never ran or ran and matched, so the attempt taught an attacker nothing and must cost nothing.
- Parameters
-
Name Direction Meaning outcome in The verdict from VaultStore:: unlockVault.
- Return values
-
Value Meaning true UnlockOutcome::— count it.WrongSecret false Everything else — leave the counter where it was.
credentialBasename() #
Build the canonical credential basename for slot.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives cred_NN.bin. slot in Credential slot id.
credentialPath() #
Build the canonical path of the credential in slot.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path. slot in Credential slot id.
decode() #
Decode bytes as a tag.
- Parameters
-
Name Direction Meaning bytes in 32 bytes read raw from offset 0 of the vault partition.
- Returns
- The tag, or nothing when the magic, the version, a reserved byte or the CRC does not match: erased flash, a file system or a half-written tag.
directoryFor() #
Directory a canonical basename belongs in.
The promote step of an import copies a staged file onto its canonical path, and it knows only the basename. Classification is by stem alone — no capacity, no record geometry — so this stays the one place that answers "where does a file with this name live", for the writer and the promoter alike.
- Parameters
-
Name Meaning basename Canonical basename (no directory component).
- Returns
- The directory the file belongs in; ::kVaultDir for the singletons and for anything the record stems do not match.
emptyProvedSecret() #
Whether the secret was proven by the vault-only wipe.
- Parameters
-
Name Direction Meaning outcome in Its verdict.
- Returns
- true for every verdict that went past the authentication.
encode() #
Encode tag.
- Parameters
-
Name Direction Meaning tag in What to carry.
- Returns
- Its 32 bytes.
execute() #
Run fn() on the vault worker thread and return its result. Fn must be callable as bool fn(). Capturing lambdas are allowed: the worker invokes them through a captureless trampoline, so all state in the closure stays on the caller's stack.
Fast paths:
- Worker not running yet → run inline on caller's thread.
- Caller already on worker → run inline (re-entrancy).
A host build has no FreeRTOS worker and always runs fn inline.
- Template Parameters
-
Name Meaning Fn Callable as bool fn(); capturing lambdas are allowed.
- Parameters
-
Name Direction Meaning fn in Work to run on the worker.
- Returns
- What
fnreturned, or false when the completion semaphore could not be created or the dispatch failed andfndid not run.
forgetFormatFailureRecordForTest() #
Native-test hook: forget the failed-format record this boot has read and the manual-recovery verdict, as a restart does.
On device the facade reads the record from NVS once a boot and keeps it in RAM (VaultStore::
formatFailureAfter() #
The record and the report after a mount that ended in outcome.
- Parameters
-
Name Direction Meaning outcome in How the mount ended. recorded in The record as the mount found it.
- Returns
- The record to keep, and whether the refusal is a failed format.
importStagePath() #
Build the SD-import staging path of basename.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path. basename in Canonical basename to stage.
indexSegmentBasename() #
Build the canonical list-index segment basename for segment.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives idx_NN.bin. segment in Index segment number.
indexSegmentPath() #
Build the canonical path of list-index segment segment.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path. segment in Index segment number.
indexSegmentTempPath() #
Build the staging-twin path of list-index segment segment.
A segment is written here and moved onto its canonical path with an atomic rename, so a reset during a write leaves the previous segment rather than a hole.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path. segment in Index segment number.
isRunning() #
True between begin() returning true and shutdown() returning. Used by the public VaultStore shim to decide whether to dispatch or run inline.
- Return values
-
Value Meaning true The worker is running. false It was never started, or has been shut down.
join() #
Join <dir>/<name> into out.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the joined path. dir in Directory, without a trailing separator. name in Basename.
judge() #
Judge a record's epoch against the counter.
- Parameters
-
Name Direction Meaning recordEpoch in The epoch the record carries. counter in The counter as read.
- Returns
- The verdict.
literalEquals() #
Are two NUL-terminated literals identical, at compile time?
- Parameters
-
Name Meaning a First literal. b Second literal.
- Return values
-
Value Meaning true Same characters and same length. false They differ.
next() #
The epoch a new KEK half takes: one above the record it replaces and the counter.
It saturates at the top of the range, which no owner reaches (one per change of secret or vault key); an absent or unreadable counter counts as 0, the caller having refused an unreadable one before it gets here.
- Parameters
-
Name Direction Meaning recordEpoch in The epoch of the record being replaced (0 when there is none). counter in The counter as read.
- Returns
- The new epoch.
onWorker() #
True when (a) the worker is not running yet, or (b) the calling task IS the worker. In either case, public VaultStore shims must run their body inline rather than dispatching — otherwise the worker would deadlock on self-dispatch, and pre-begin() boot code would block forever.
Public VaultStore methods use this as a one-line guard:
bool VaultStore::saveCredential(args) {
if (!kleidos::vault::onWorker()) {
return kleidos::vault::execute(
[&](){ return saveCredential(args); });
}
// ... original body ...
}
- Return values
-
Value Meaning true Run the body inline (always, on a host build: no worker thread exists there). false Dispatch it to the worker.
pendingOrUnknown() #
Whether a factory reset is pending, failing closed.
- Return values
-
Value Meaning true A tag is present, or the read failed: no vault may be minted. false No tag.
pendingRequests() #
Number of requests currently queued. A queue-depth probe for diagnostics surfaces (e.g. the serial debug console).
- Returns
- Number of pending dispatch requests.
raiseTo() #
Raise the counter to epoch, never lowering it, and read it back.
A counter already at or above epoch is left as it is. The value is read back after the write, so true means NVS holds at least epoch.
- Parameters
-
Name Direction Meaning epoch in The epoch the record on flash now carries.
- Return values
-
Value Meaning true The counter reads epochor more.false It could not be read or written; the caller decides what that costs.
read() [1/2] #
Read offset 0 of the vault partition and decode it.
- Returns
- What was there.
read() [2/2] #
Read the counter.
- Returns
- What is stored, or why nothing could be said.
recordLogBasename() #
Build the basename of record-log segment segment.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives rc_NN.bin or rt_NN.bin. totp in Whether the segment holds TOTP slots. segment in Log segment number within its class.
recordLogPath() #
Build the canonical path of record-log segment segment.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path. totp in Whether the segment holds TOTP slots. segment in Log segment number within its class.
recordLogTempPath() #
Build the compaction-twin path of record-log segment segment.
The live entries are copied here and the file is renamed over the segment in one step, so an interruption leaves either the segment intact (the rename has not happened) or the copy complete (it has).
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path with ::kTempSuffix appended. totp in Whether the segment holds TOTP slots. segment in Log segment number within its class.
refuses() #
Whether a verdict refuses the record.
- Parameters
-
Name Direction Meaning verdict in What judge said.
- Return values
-
Value Meaning true RolledBackorNoCounter:the record may not open.false Every other verdict.
setTestTrustedEpochProvider() #
Native-test hook: inject the trusted-epoch source used for timestamps.
On device, VaultStore::ctime / mtime from the trust-gated wall clock (see time/platform/ test-provider pattern. A null provider (the default) reads as epoch 0, i.e. "clock not trusted".
- Parameters
-
Name Direction Meaning provider in Function returning the current Unix epoch seconds, or null to restore the untrusted-clock default.
taskHandle() #
Returns the worker task handle, or nullptr when the task is not running. Exposed so the dispatcher can detect re-entrant calls from the worker itself and skip the queue.
- Returns
- The worker task handle, or nullptr when not running.
totpBasename() #
Build the canonical one-time-code basename for slot.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives totp_NN.bin. slot in One-time-code slot id.
totpPath() #
Build the canonical path of the one-time code in slot.
- Template Parameters
-
Name Meaning Capacity Capacity of out.
- Parameters
-
Name Direction Meaning out out Receives the path. slot in One-time-code slot id.
vaultIsGone() #
Whether a verdict entitles a surface to tell the owner the vault is gone.
The single definition of what "wiped" means to a toast, a countdown screen, a console line or an audit trail. WipeOutcome:: counts: every file the vault is reachable through is unlinked and the device reboots into onboarding. WipeOutcome:: and WipeOutcome:: do not — under those, records are still on the filesystem under their own names.
- Parameters
-
Name Direction Meaning outcome in The verdict from VaultStore:: wipeAll.
- Return values
-
Value Meaning true Say the vault was wiped. false Say it was not; do not record a completed wipe.
write() #
Write tag over the (blank) first bytes of the vault partition, and read it back.
The caller has proven the partition blank first: NOR flash only clears bits, so a tag written over anything else does not read back.
- Parameters
-
Name Direction Meaning tag in What to carry.
- Return values
-
Value Meaning true The tag reads back as written. false The write failed or did not read back.
Variable Documentation
kBasenameCapacity #
Capacity of a basename buffer, excluding the NUL.
The longest basename is "mut_
kCanonicalPathCapacity #
Capacity of a canonical-path buffer, excluding the NUL.
The longest canonical path is the index staging twin, "/vault/i/idx_999.bin.tmp" (24 characters). The margin absorbs a deeper per-class directory without a sweep of every buffer declaration.
kCredentialDir #
Directory of an older layout's credential files (cred_NN.bin), read only to detect that layout.
This firmware creates it empty with the others and writes no file in it. VaultLayout::
kRecordDir #
Directory holding every record-log segment: rc_NN.bin for a fixed range of credential slots, rt_NN.bin for TOTP slots.
The records live one directory down from ::kVaultDir, and share a file per slot range rather than one file each, because a LittleFS name lookup and a directory listing both cost in proportion to what the directory holds (on an ESP32, a listing grows by about 4 ms a file); and they share SEVERAL files rather than one, because a compaction copies the file it rewrites and the peak that copy adds is what bounds a board's capacity. One segment is the unit of that copy.
kSlotDigits #
printf spelling of a slot id inside a basename.
A MINIMUM width, so a slot spells two digits below 100 and three from 100 on. The grammar is canonical — digits to slot is injective — because a zero-padded three-digit twin would let one slot be spelled two ways and a promote would then write a file nothing ever opens.
kStagedPathCapacity #
Capacity of a staged-path buffer, excluding the NUL.
The longest staged path is "/vault/import_new/cred_999.bin" (30 characters).
kVaultDirectories #
Every directory the canonical vault occupies, root first.
One list, so that everything which has to touch the WHOLE tree walks the same set: creating the layout before the first record is written, sweeping it on a wipe, and the SD export's traversal. A class directory added here reaches all three without a second enumeration to keep in step.