In development. It changes without notice.
Topic
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.
- See also
- Vault Storage, Record Log & Envelopes
Files | |
| file | src/ |
| Sparse label algebra for the record-owned custom list order. | |
| file | src/ |
| The credential record: one fixed size, encrypt-then-MAC, in the log. | |
| file | src/ |
| Favorite-first + manual-order sorting for the device credential lists. | |
| file | src/ |
| Single encrypted group-name table (groups.bin). | |
| file | src/ |
| The TOTP record: one entry of the record log, encrypt-then-MAC. | |
| file | src/ |
| Self-contained, encrypt-then-MAC WiFi/NTP config store (wifi.bin). | |
Typedefs | |
| using | kleidos:: |
| using | kleidos:: |
| Presence of every TOTP slot, one bit per slot. | |
| using | kleidos:: |
| One user-configured NTP server (a literal dotted-quad IPv4 string). | |
Enumerations | |
| enum class | kleidos:: |
| What a whole-table removal actually established. More about kleidos:: | |
Functions | |
| constexpr uint16_t | kleidos:: |
| The gap a seeded run leaves between consecutive ranks. | |
| constexpr uint16_t | kleidos:: |
The label of rank rank in a freshly seeded run (0-based). | |
| constexpr uint16_t | kleidos:: |
| The label a newly created record takes, given the highest one in use. | |
| constexpr bool | kleidos:: |
| The label strictly between two neighboring labels, if there is one. | |
| constexpr uint32_t | kleidos:: |
| constexpr bool | kleidos:: |
| ReorderPlanStats | kleidos:: |
| Turn a requested ranking into the record writes that realize it, as few as the stored labels allow. | |
| ReorderPlanStats | kleidos:: |
| Spread a ranking over the whole label space again, row by row. | |
| constexpr bool | kleidos:: |
| Read a slot's bit out of a CredentialSlotMask. | |
| bool | kleidos:: |
Strict ordering predicate: must a be listed above b? | |
| void | kleidos:: |
| Stable in-place sort of a loaded credential list. | |
| constexpr bool | kleidos:: |
True when mask marks slot id present. | |
Variables | |
| constexpr uint16_t | kleidos:: |
| Lowest label a record may carry. | |
| constexpr uint16_t | kleidos:: |
| Highest label a record may carry (:: | |
| constexpr uint16_t | kleidos:: |
| Gap between consecutive ranks of a seeded run on THIS build. | |
| constexpr uint16_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| Rank index meaning "no predecessor" inside the planner's link table. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| Maximum number of credential slots. | |
| constexpr uint16_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| The "no credential slot" sentinel of every board (never a valid slot id). | |
| constexpr size_t | kleidos:: |
| Max credential name length. | |
| constexpr size_t | kleidos:: |
| Max username length. | |
| constexpr size_t | kleidos:: |
| Max password length. | |
| constexpr size_t | kleidos:: |
| Max primary-URL length. | |
| constexpr size_t | kleidos:: |
| Max raw embedded-TOTP secret length, in bytes (mirrors kTotpMaxSecretLen). | |
| constexpr size_t | kleidos:: |
| Max embedded-TOTP account label length (mirrors kTotpAccountLen). | |
| constexpr uint16_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| CredentialRecord:: | |
| constexpr uint16_t | kleidos:: |
| CredentialRecord:: | |
| constexpr uint16_t | kleidos:: |
| CredentialRecord:: | |
| constexpr uint16_t | kleidos:: |
| CredentialRecord:: | |
| constexpr uint16_t | kleidos:: |
| CredentialRecord:: | |
| constexpr uint8_t | kleidos:: |
| CredentialRecord:: | |
| constexpr uint16_t | kleidos:: |
| CredentialRecord:: | |
| constexpr uint8_t | kleidos:: |
| Current credential-file format version. | |
| constexpr size_t | kleidos:: |
| Field offsets within a serialized credential record. | |
| constexpr size_t | kleidos:: |
| Size of the fixed-length header (everything before the ciphertext). | |
| constexpr size_t | kleidos:: |
| Smallest valid file: header + one AES block of ciphertext. | |
| constexpr uint8_t | kleidos:: |
| Record-schema version of the packed-binary credential plaintext. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Plaintext every credential encodes to, padded with zeros to exactly this. | |
| constexpr size_t | kleidos:: |
| Ciphertext size (AES-CBC adds one full PKCS#7 block to a block-aligned input). | |
| constexpr size_t | kleidos:: |
| Whole-envelope size — a constant, like everything else about a record. | |
| constexpr uint8_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Max group-name length (one wire row is 1 id + 1 prefix + 24 name = 26 B). | |
| constexpr const char * | kleidos:: |
| Canonical group-table file path, spelled by vault_paths.h. | |
| constexpr uint8_t | kleidos:: |
| Current group-file format version. | |
| constexpr size_t | kleidos:: |
| Size of the fixed-length header (mirrors the other vault files). | |
| constexpr size_t | kleidos:: |
| Smallest valid file: header + one AES block of ciphertext. | |
| constexpr uint8_t | kleidos:: |
| Record-schema version of the packed-binary group plaintext. | |
| constexpr size_t | kleidos:: |
| Worst-case packed-binary size of one row: id(1) + name (1 + 24) = 26 bytes. | |
| constexpr size_t | kleidos:: |
| Fixed plaintext header: plaintextVer(1) + rowCount(1). | |
| constexpr size_t | kleidos:: |
| Worst-case plaintext size (every group defined at the full name length). | |
| constexpr size_t | kleidos:: |
| Worst-case ciphertext size (one extra block for PKCS#7 padding). | |
| constexpr size_t | kleidos:: |
| Worst-case whole-file size. | |
| constexpr size_t | kleidos:: |
| Bytes of the "this id still has a label" bitmap (bit k = id k+1). | |
| constexpr uint8_t | kleidos:: |
| Maximum number of TOTP slots. | |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Max TOTP display-name length. | |
| constexpr size_t | kleidos:: |
| Max raw secret length, in bytes. | |
| constexpr size_t | kleidos:: |
| Max account-label length. | |
| constexpr uint8_t | kleidos:: |
| Current TOTP-envelope format version. | |
| constexpr size_t | kleidos:: |
| Field offsets within a serialized TOTP envelope. | |
| constexpr size_t | kleidos:: |
| Size of the fixed-length header (everything before the ciphertext). | |
| constexpr size_t | kleidos:: |
| Smallest valid file: header + one AES block of ciphertext. | |
| constexpr uint8_t | kleidos:: |
| Record-schema version of the packed-binary TOTP plaintext. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Worst-case ciphertext size (one extra block for PKCS#7 padding). | |
| constexpr size_t | kleidos:: |
| Worst-case whole-file size. | |
| constexpr uint8_t | kleidos:: |
| Maximum number of saved WiFi networks. | |
| constexpr size_t | kleidos:: |
| Max SSID length (802.11), in bytes. | |
| constexpr size_t | kleidos:: |
| Max WPA passphrase length, in bytes. | |
| constexpr size_t | kleidos:: |
| Minimum WPA passphrase length; a zero-length PSK means an open network. | |
| constexpr uint8_t | kleidos:: |
| Maximum user-configured NTP server entries (mirrors the default table size). | |
| constexpr size_t | kleidos:: |
| Max NTP-server text length: a literal dotted-quad IPv4 ("255.255.255.255"). | |
| constexpr const char * | kleidos:: |
| constexpr uint8_t | kleidos:: |
| Current WiFi-file format version (shared envelope version byte). | |
| constexpr size_t | kleidos:: |
| Field offsets within the serialized file (identical geometry to totp/index). | |
| constexpr size_t | kleidos:: |
| Size of the fixed-length header (everything before the ciphertext). | |
| constexpr size_t | kleidos:: |
| Smallest valid file: header + one AES block of ciphertext. | |
| constexpr uint8_t | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Worst-case ciphertext size (one extra block for PKCS#7 padding). | |
| constexpr size_t | kleidos:: |
| Worst-case whole-file size. | |
Typedef Documentation
CredentialSlotMask #
One presence bit per credential slot, so a whole-vault answer costs one directory read instead of one lookup per declared slot.
TotpSlotMask #
Presence of every TOTP slot, one bit per slot.
Fixed width: ceil(kMaxTotpSlots / 8), so it is 32 bytes at the widest slot space the u8 id space allows and a handful at every shipped capacity. Small enough to live on the vault worker's stack at any capacity, which is the property that lets the whole scan be a value rather than an allocation.
It is DERIVED, never stored: it is filled by a scan of the log at the moment of use and discarded with the walk that asked for it, so it cannot become a second source of truth that disagrees with the records.
Enumeration Type Documentation
GroupTableRemoval #
What a whole-table removal actually established.
Three-valued because the two ways a removal does not leave a file behind are different answers to the caller: "there was nothing to remove" is the ordinary fresh-device state, while "the removal did not take" means a table MAY still be on flash. A full-replace restore that folds them writes its labels on top of the previous ones and reports a replacement it did not make.
Function Documentation
credentialListedBefore() #
Strict ordering predicate: must a be listed above b?
Favorites come first; inside each group the order label ranks rows ascending. An unranked row's label is kleidos::
- Parameters
-
Name Direction Meaning a in Candidate for the higher list position. b in Entry compared against.
- Return values
-
Value Meaning true aprecedesb.false adoes not precedeb(equal ranks included).
credentialMaskHas() #
Read a slot's bit out of a CredentialSlotMask.
- Parameters
-
Name Direction Meaning mask in Mask filled by CredentialRepository::.scanPresentSlots id in Slot id in [0, kMaxCredentialSlots).
- Returns
- Whether the slot's bit is set.
orderAfter() #
The label a newly created record takes, given the highest one in use.
Appends after the last ranked row. Saturates at ::kOrderMax rather than wrapping: a create must stay one record write, so exhausting the tail is handled by the next reorder's renumber, not by relabelling inside a save.
- Parameters
-
Name Direction Meaning highWater in Highest label currently in use (::kOrderMin when none).
- Returns
- The new record's label.
orderMidpoint() #
The label strictly between two neighboring labels, if there is one.
The two-label form of what planReorder does with runs: the planner spreads a whole run evenly across its free labels at once, so this is the primitive stated on its own for a caller placing a single row.
- Parameters
-
Name Direction Meaning lower in Label of the row above the insertion point. upper in Label of the row below it. out out Receives the midpoint when one exists.
- Return values
-
Value Meaning true A free label exists and outholds it.false The two labels are adjacent (or inverted): renumber instead.
orderPlanFitsOneRequest() #
Whether one REQUEST may carry this plan out.
The whole plan runs inside a single blocking call on the vault worker, so its wall clock is what the caller waits for. A plan above the cap is refused with nothing written rather than started: a client that gives up half way leaves the device writing a ranking nobody is reading, and the same ranking is then re-posted onto a list that has moved under it.
- Parameters
-
Name Direction Meaning stats in What the plan costs.
- Return values
-
Value Meaning true The request path may carry this plan out. false The plan is wider than the cap and must be refused with nothing written.
orderPlanWorstCaseMs() #
Milliseconds a plan over rows rows that writes writes records is bounded by: the whole-list read that every plan makes BEFORE its first write, plus the write loop. Charging the writes alone is what leaves a client abandoning a device that is still working.
- Parameters
-
Name Direction Meaning rows in Rows the plan reads — every row the vault holds, whatever the ranking's length. writes in Records the plan writes.
- Returns
- The bound in milliseconds.
orderSeedLabel() #
The label of rank rank in a freshly seeded run (0-based).
- Parameters
-
Name Direction Meaning rank in 0-based position in the ranking.
- Returns
- (rank + 1) * kOrderStride, never ::
kCredOrderUnset.
orderStrideFor() #
The gap a seeded run leaves between consecutive ranks.
The largest power of two that keeps a full run of slots inside the lower half of the label space. Halving twice per capacity step is deliberate: the exponent is the number of repeated insertions at ONE fixed point that the midpoint rule absorbs before a renumber becomes necessary, and a power of two makes every midpoint exact.
- Parameters
-
Name Direction Meaning slots in Credential slot capacity of the build.
- Returns
- The stride, at least 1.
planReorder() #
Turn a requested ranking into the record writes that realize it, as few as the stored labels allow.
buffers.label arrives holding each rank's STORED label in requested rank order and leaves holding the label that rank must end up with; buffers.changed marks the ranks whose record has to be written.
The plan is computed in full before any of it is applied, so a rank whose label is revised twice here still costs ONE record write — the property that keeps a reorder inside the index's generation-lag repair window — and none at all when the second revision puts it back on the label it already carries.
- Parameters
-
Name Direction Meaning buffers in, out Working arrays; see ReorderBuffers. count in Ranks in the requested ranking (<= kMaxCredentialSlots).
- Returns
- What the plan cost; see ReorderPlanStats.
planReseed() #
Spread a ranking over the whole label space again, row by row.
planReorder writes as few records as the gaps allow, which is what a move wants and the opposite of what the maintenance action wants: posting the ranking the stored labels already realize keeps every row, writes nothing, and leaves the crowding that refused the move exactly where it was. This plans the LABELS instead — rank r takes orderSeedLabel(r), whatever it carried — so the gaps are back and ordinary moves cost one record again. A row already on its seed label costs no write.
- Parameters
-
Name Direction Meaning buffers in, out Working arrays; only labelandchangedare used.count in Ranks in the requested ranking (<= kMaxCredentialSlots).
- Returns
- What the plan cost; see ReorderPlanStats.
sortCredentialEntries() #
Stable in-place sort of a loaded credential list.
Insertion sort keyed by credentialListedBefore. Chosen over std:: because it allocates nothing (the library stable sort may reach for a temporary buffer) and the list is small and already almost sorted on reload, where insertion sort is near-linear.
- Parameters
-
Name Direction Meaning entries in, out Array filled by VaultStore:: loadIndex. count in Number of valid entries in entries.
totpMaskHas() #
True when mask marks slot id present.
- Parameters
-
Name Direction Meaning mask in Presence mask from TotpRepository:: scanPresentSlots. id in Slot id; anything outside [0, kMaxTotpSlots) reads absent.
- Returns
- Whether the slot's record was seen by the scan that filled
mask.
Variable Documentation
kCredFixedFieldBytes #
The fixed part's size, as an auditable sum of its fields. Every string is stored at its FULL capacity behind a length prefix, so the sum is what the encoder emits for every record — that is what makes the plaintext size a constant and the capacity exact.
kCredFlagAutoSubmit #
CredentialRecord::
kCredTotpBlockBytes #
Bytes the embedded-TOTP block always occupies in the fixed part: secretLen(1) + secret(64) + digits(1) + period(2) + algorithm(1)
- accountLen(1) + account(64)
. A zero secretLen means "no TOTP", so the block needs no presence byte of its own.
kFleetMaxCredentialSlots #
The most credentials a backup from any board can hold: the biggest boards' slots, or this build's own where a capacity-probe build raises it past them. A restore takes a bigger backup's first entries and counts the rest (backup::
kFleetMaxTotpSlots #
The most one-time codes a backup from any board can hold (see kFleetMaxCredentialSlots).
kInvalidTotpSlot #
The id no TOTP slot has on any board: slot ids stay uint8_t by design (capacity <= 255 on every board) and this one is kept free, so the cap stays below it. A backup naming it, or anything past it, names no slot anywhere.
kLargestBoardCredentialSlots #
Credential slots on the boards with the largest vault: the largest capacity any board declares, and a build check holds it there (which board has which: The boards).
kLargestBoardTotpSlots #
One-time-code slots on the boards with the largest vault: the largest one-time-code capacity any board declares, and a build check holds it there.
kMaxGroups #
Maximum number of groups. Ids are 1..kMaxGroups; 0 = "no group". The wire format is count-prefixed, so this capacity can change without migration.
kOrderBoundedPlanWorstCaseMs #
Worst case of the widest plan the REQUEST path may carry out, over a vault filled to this build's capacity, in milliseconds.
kOrderRenumberMaxRows #
Rows a bounded renumber may re-space in one operation, and the write cap the REQUEST path holds a whole plan to: 64 record writes and at most 64 segment rewrites.
The planner itself is not bounded by this — when no window up to this many rows has room, it falls through to re-seeding the whole ranking, and a left-to-right sweep can also spread a run of any length between two kept labels. Both are correct and both are unbounded in the vault's size, so a caller serving a request compares ReorderPlanStats::
kOrderRowReadWorstCaseMs #
Worst case of reading ONE row's stored label, in milliseconds.
Every plan reads the whole list before its first write, and that read is not flat: it is one index-segment decrypt per 32 rows while the segments are on flash, and one 4 KB record read and decrypt per credential when they are not — the state a restore's anchor leaves behind. The expensive form is the one a bound has to cover. No measurement of a bare record read exists on the current record, so it is charged at the widest figure that CONTAINS one: the ESP32 board's rotation step, 990 ms, which is a read and a decrypt plus an encrypt, an append and a commit. Loose, and loose in the safe direction — a client that waits too long costs a page a spinner, one that waits too little abandons a device mid-write.
kOrderWriteWorstCaseMs #
Worst case of one list-column record write, in milliseconds.
A column write is a read-modify-write of the record plus the index upsert. The bound is taken over every board rather than the fastest: a rotation step (read, decrypt, re-encrypt, append, commit — everything but the upsert) was measured at 988 ms per record on an ESP32-S3 board and 990 ms on an ESP32 one, and a create (encode, encrypt, append, commit AND upsert) at 316 ms and 420 ms. The upsert's own cost has not been measured apart, so it is charged at the whole create: 990 + 420, the slowest of each. Conservative by construction — the two figures share their append and their commit — which is the right direction for a bound a client's timeout is derived from. A capacity of 500 credentials runs on an ESP32 board too, so a bound taken from an ESP32-S3 alone would be one some board breaks. The figures are open builds'; a flash-encrypted vault has not been measured for this bound.
kTotpMaxPlaintextSize #
Worst-case packed-binary plaintext size, as an auditable sum of the per-field maxima. Layout (see record_
- algorithm(1) + account (1 + 64) = 1 + 33 + 1 + 64 + 1 + 2 + 1 + 65 = 168 bytes.
kWifiMaxPlaintextSize #
Worst-case packed-binary plaintext, as an auditable sum of per-field maxima: ver(1) + netCount(1) + kMaxWifiNetworks * ( (1 + 32) ssid + (1 + 63) psk )
- srvCount(1) + kMaxNtpServers * (1 + 15) = 2 + 8 * 97 + 1 + 4 * 16 = 843 bytes.
kWifiPath #
Canonical singleton path of the WiFi-network store, spelled by vault_paths.h.
kWifiPlaintextVer #
Record-schema version of the packed-binary plaintext (it carries the NTP server list; one version, no migration).