In development. It changes without notice.
Topic
Record Log & Envelopes
The log the records are appended to, the binary form of a record, and the sealed envelope around it.
Records are entries of an append-only log cut into fixed segments: a write appends, and a read finds the live entry of a slot through the log's own index. Each entry is an envelope of a version byte, the IV, the HMAC tag and the ciphertext. The list index, the pool of a login's optional fields, and the reserved buffers the record path works in are here too, so that saving a record allocates nothing it could be refused.
Files | |
| file | src/ |
| The credential record's flexible pool: everything optional, as TLV. | |
| file | src/ |
| In-house packed binary codec for the vault at-rest plaintext records. | |
| file | src/ |
| The append-only record log: a few segment files hold every credential and TOTP entry. | |
| file | src/ |
| The credential path's three large buffers, reserved rather than allocated. | |
| file | src/ |
| Where a slot's live record is: the log plus a slot table in RAM. | |
| file | src/ |
| The one bounded-unit segmentation: slot partition, feed boundary, trace. | |
| file | src/ |
| Canonical grammar for vault file basenames (cred_NN.bin, wifi.bin, …). | |
| file | src/ |
| Shared encrypt-then-MAC envelope contract for the vault records. | |
| file | src/ |
| Slot-keyed encrypted list index (idx_NN.bin) for O(1) vault listing. | |
Classes | |
| struct | kleidos:: |
| One typed custom field of a credential. More about kleidos:: | |
| struct | kleidos:: |
| One superseded password and when it stopped being current. More about kleidos:: | |
| class | kleidos:: |
| The bounded TLV region of a credential record. More about kleidos:: | |
| class | kleidos:: |
| Append-only cursor that packs fields into a fixed stack buffer. More about kleidos:: | |
| class | kleidos:: |
| Forward-only cursor that decodes fields with a single guard. More about kleidos:: | |
| struct | kleidos:: |
| One entry's header, plus where it sits. More about kleidos:: | |
| class | kleidos:: |
| The record log's operations. Stateless: every call opens the file. More about kleidos:: | |
| class | kleidos:: |
| One reserved byte buffer, lent out for the duration of a scope. More about kleidos:: | |
| class | kleidos:: |
| One reserved, decrypted CredentialRecord, lent out for a scope. More about kleidos:: | |
| class | kleidos:: |
| The record store's operations. All static; the vault worker owns it. More about kleidos:: | |
| class | kleidos:: |
| Drives a sequence of bounded units and owns what happens between them. More about kleidos:: | |
| struct | kleidos:: |
| One slotted record family: the stem its basenames start with, the kind that stem classifies as, and the build's capacity for that family. More about kleidos:: | |
| struct | kleidos:: |
| Identity fields bound into the authenticated context prefix of a record. More about kleidos:: | |
| struct | kleidos:: |
| One cached list row: enough to render a list item without decrypting the full credential. More about kleidos:: | |
| struct | kleidos:: |
| The facts a segment read needs about a live rotation. More about kleidos:: | |
| class | kleidos:: |
| The encrypted vault list cache, with rebuild-on-miss semantics. More about kleidos:: | |
Typedefs | |
| using | kleidos:: |
| using | kleidos:: |
| using | kleidos:: |
| using | kleidos:: |
Per-row sink invoked by kleidos::. | |
Functions | |
| size_t | kleidos:: |
The widest payload an entry of type may carry: the widest envelope THAT CLASS is stored as. | |
| void | kleidos:: |
Write into out the header bytes an append of these fields writes, checksum included. | |
| constexpr uint16_t | kleidos:: |
Segment that owns slot within its class. | |
| constexpr uint16_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
Number of units that cover a slot space of slotCapacity. | |
| constexpr uint16_t | kleidos:: |
Unit that owns slot slotId. | |
| constexpr uint32_t | kleidos:: |
First slot owned by unit segment. | |
| constexpr uint32_t | kleidos:: |
One past the last slot owned by unit segment. | |
| bool | kleidos:: |
| Parse the canonical decimal slot span of a record basename. | |
| StagedKind | kleidos:: |
Classify a vault file basename; fills slotOut for Cred/Totp. | |
| size_t | kleidos:: |
| Write the authenticated context prefix that precedes the IV in the MAC. | |
| bool | kleidos:: |
| Compute the bound EtM tag HMAC(macKey, ctx || iv || cipher). | |
| template<size_ | |
| bool | kleidos:: |
| Bound-checked wrapper kept for the record modules' call shape. | |
| template<size_ | |
| bool | kleidos:: |
Verify an envelope held in memory — the record-log form of a file's verify-before-decrypt: version, block alignment, and the tag under context, compared in constant time. | |
| constexpr uint16_t | kleidos:: |
Segment that caches credential slot id. | |
| constexpr uint16_t | kleidos:: |
First credential slot cached by segment segment. | |
| constexpr uint16_t | kleidos:: |
One past the last credential slot cached by segment segment. | |
| void | kleidos:: |
Derive a record's list domain: the index's domain column for url. | |
Variables | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Bytes the pool may hold, entry headers included. | |
| constexpr size_t | kleidos:: |
| Bytes one pool entry costs beyond its value: [type u8][len u16]. | |
| constexpr size_t | kleidos:: |
| Max notes length. | |
| constexpr size_t | kleidos:: |
| Max recovery-codes block. | |
| constexpr size_t | kleidos:: |
| Max length of one extra URL. | |
| constexpr size_t | kleidos:: |
| Max SSO provider name. | |
| constexpr size_t | kleidos:: |
| Max custom-field label. | |
| constexpr size_t | kleidos:: |
| Max custom-field value. | |
| constexpr size_t | kleidos:: |
| Max historical password. | |
| constexpr size_t | kleidos:: |
| Custom fields per record. | |
| constexpr size_t | kleidos:: |
| Extra URLs per record. | |
| constexpr size_t | kleidos:: |
| History entries per record. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Value bytes of a history entry before its password: [changedAt u32]. | |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| Type-byte flag marking a tombstone: the slot was deleted; no payload. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| "No entry": the value a slot's offset holds when the log has none for it. | |
| constexpr uint16_t | kleidos:: |
| Credential slots this build declares. | |
| constexpr uint16_t | kleidos:: |
| TOTP slots this build declares. | |
| constexpr uint16_t | kleidos:: |
| Segment files covering the credential slot space. | |
| constexpr uint16_t | kleidos:: |
| Segment files covering the TOTP slot space. | |
| constexpr uint16_t | kleidos:: |
| Segments of both classes together — what a whole-log walk visits. | |
| constexpr size_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| Slots covered by ONE bounded unit. | |
| constexpr std::array< SlottedFamily, 5 > | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| Fixed slot id bound for the singleton WiFi-network file (it has no real slot). | |
| constexpr uint32_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
| Fixed slot id bound for the singleton group-name file (it has no real slot). | |
| constexpr uint32_t | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Byte layout of an envelope in memory: [ver 1][iv 16][hmacTag 32][cipher]. | |
| constexpr size_t | kleidos:: |
| Display-name length cached in the index (bounded to keep the file compact). | |
| constexpr size_t | kleidos:: |
| Username length cached in the index (bounded to keep the file compact). | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| Current index-file format version. | |
| constexpr size_t | kleidos:: |
| Field offsets within a serialized segment file (mirror the 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 uint16_t | kleidos:: |
| Credential slots cached by ONE segment file. | |
| constexpr uint16_t | kleidos:: |
| Number of segment files that cover the whole slot space. | |
| constexpr uint8_t | kleidos:: |
| Record-schema version of the packed-binary segment plaintext. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Fixed segment plaintext header: plaintextVer(1) + segIndex(2 LE) + rowCount(2 LE). | |
| constexpr size_t | kleidos:: |
| Worst-case segment plaintext: every row of the segment at full field lengths. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Worst-case whole-file size of one segment (< the 4 KB LittleFS block). | |
| constexpr size_t | kleidos:: |
Typedef Documentation
EnvelopeScratch #
The [ver][iv][tag][cipher] bytes of one credential record, on their way to or from the log.
IndexRowVisitor #
Per-row sink invoked by kleidos::.
A plain function pointer plus an opaque cookie, not a std::function: the sink is called from the vault worker with no allocation of its own (see sonar-project.properties, rule S5205/S5008).
- Parameters
-
Name Direction Meaning row in The decoded row, valid only for the duration of the call. user in The cookie handed to forEach.
- Return values
-
Value Meaning true Continue with the next row. false Stop the walk; the remaining rows are not delivered.
- Warning
- SECURITY:
rowcarries a name, a username and an origin domain. The walk wipes the whole working set when it returns, so a sink that copies any of those out owns wiping its copy.
Mirror of the sink alias defined in vault_index.h, so VaultStore::
PlaintextScratch #
One credential record's plaintext — the encoder's output and the decrypt's destination, which is a padding block wider — and, while a restore reads a record or the backup's meta string, the text it unescapes them into.
UnitTick #
Paint slot handed to the caller between two bounded units: a plain function pointer, or nullptr for none. No caller passes one: a screen that shows the wait paints from inside each unit's wait on the vault worker (wait_pump.h), so nothing paints between the units.
Enumeration Type Documentation
CredFieldKind #
What kind of value a custom field carries.
Mirrors the typed sections a 1Password export distinguishes, so an import keeps the distinction and the panel can render a date as a date. The device types Text, Concealed and Email; it shows the rest.
CredPoolType #
What one pool entry holds.
The numeric values are the wire format: they are read from records already on flash, so an existing one is never renumbered and a retired one is never reused. An unknown type decodes as an opaque entry — it is kept on re-encode, so a record written by a newer firmware survives a round trip through an older one.
| Enumerator | |
|---|---|
| Notes | Free text. At most one. |
| CustomField | Typed label + value (see CredCustomField). |
| RecoveryCodes | Multi-line backup codes, always hidden. At most one. |
| ExtraUrl | An additional URL beyond the record's primary one. |
| SsoProvider | "Sign in with …" provider name. At most one. |
| PasswordHistory | A superseded password and when it was replaced. |
EnvelopeRead #
Why a stored envelope could not be produced.
The distinction that matters to a caller rebuilding a cache from the log: a slot that holds nothing is a row that must not be listed, while a log that could not be read is a row whose fate is simply unknown right now.
EnvelopeRecordType #
Per-record type discriminator bound into the authenticated tag.
Distinct values give cross-type substitution a different recomputed tag, so a file of one type can never verify when loaded as another type.
LoadVerdict #
Whether a stored artifact was proven to be a record this key set authenticates, proven not to be, or neither — the third value is what a caller acting on the answer must not fold into the second.
Two-valued was the defect: a MAC that did not match, a file that was not there, and a heap or backend failure all collapsed into one false, and the singleton loaders read that as "the store is empty". The next mutator then read-modify-wrote that emptiness over a perfectly good record. Absence really is an empty store; a failure to check is not, and must reach the caller as its own answer.
The three spellings are the ones already used for staged records, kept deliberately identical so the vault has one vocabulary for "authenticated / provably not / could not tell" rather than three.
LogEntryType #
Which record class an entry belongs to. A tombstone carries the class of the slot it deletes (credential slot 5 and TOTP slot 5 are different slots).
LogFind #
How a lookup by (slot, generation) ended.
"The log holds no such entry" and "the log could not be read" are the same false to a two-valued answer, and every caller of this lookup acts on the first by writing: a rebuild omits the row, a reconcile tombstones the slot. A scan that failed is no evidence for either, so it is a value of its own.
LogScanEnd #
How a scan ended.
TornTail and Damaged both mean the walk stopped before the file's end and everything in front of that point was delivered. They differ in whether the bytes at the stopping point are a header THIS FIRMWARE WROTE, which is what says whether the rest of the file may be thrown away.
The whole decision rests on the header's own checksum, and on nothing else: a header that verifies and declares a payload the file ends inside of is one interrupted append, so a rewrite drops that entry and keeps every other. Any other stopping point is damage of unknown extent, contained where it lies. No property of the bytes BEHIND the stopping point takes part — a run of intact entries is exactly what a mid-file bit flip leaves behind it, and every measure of that run (its width above all) reads the same on an interrupted append as on damage, because an entry of a class is not one width: a credential segment holds 11-byte tombstones beside 4 KB records.
RecordLoad #
Why a stored record could not be produced.
A cache rebuilt from the records has to tell "this slot holds nothing" from "this slot could not be read just now": the first is a row that must not be listed, the second is a row whose omission would publish a live credential as gone. RecordLoad::
RotateOutcome #
What re-encrypting a single-record store under a new key established.
The four answers are the four states a rotation step can actually be in, and collapsing any two of them costs something: Unreadable is a permanent loss the owner must be told about, while Failed is a retry — and AlreadyThere is the resume case, where a previous attempt's promote landed and re-doing the work would fail a proof on a file that no longer exists and retry for ever.
StagedKind #
Classification of a staged / canonical vault file by its basename.
Function Documentation
classifyStagedName() #
Classify a vault file basename; fills slotOut for Cred/Totp.
The singleton names (meta.bin, groups.bin, wifi.bin) match whole-string and exactly, so no near-miss spelling — a .tmp sidecar, a marker, a staging directory — can be mistaken for one of them.
Slot ids at or past the build-time capacity classify as ::
- Parameters
-
Name Direction Meaning name in NUL-terminated basename (no directory component). slotOut out Receives the slot id for :: StagedKind:: Cred / ::Totp, or the segment number for :: StagedKind:: IndexSegment and :: StagedKind:: RecordLog.
- Returns
- The basename's classification.
computeEnvelopeTag() #
Bound-checked wrapper kept for the record modules' call shape.
- Template Parameters
-
Name Meaning MaxCipher Compile-time upper bound on cipherLen(schema sanity; no buffer of this size exists anywhere). Shared by every record module and the re-key path so all sites are bit-identical. The authenticated message is the context prefix (see writeEnvelopeContext) followed by the IV and ciphertext.
The three envelope parts are fed to a multipart HMAC — no concatenation buffer exists, so the cost is independent of cipherLen (the previous shape materialized ctx || iv || cipher in a MaxCipher-sized stack array, which at index capacity put ~15 KB on the worker stack per tag).
- Parameters
-
Name Direction Meaning macKey in File-HMAC sub-key. macKeyLen in Length of macKeyin bytes.context in Record identity fields (type, slot, generation). iv in :: kleidos:: kIvSize-byte IV. cipher in Ciphertext bytes. cipherLen in Length of cipherin bytes.tagOut out Receives the :: kHmacSize-byte tag.
- Return values
-
Value Meaning true Tag computed. false Backend HMAC failure ( tagOutwiped).
- Note
- This wrapper also returns false when
cipherLenexceedsMaxCipher— the backend is never reached andtagOutis left untouched.
computeEnvelopeTagStreamed() #
Compute the bound EtM tag HMAC(macKey, ctx || iv || cipher).
Shared by every record module and the re-key path so all sites are bit-identical. The authenticated message is the context prefix (see writeEnvelopeContext) followed by the IV and ciphertext.
The three envelope parts are fed to a multipart HMAC — no concatenation buffer exists, so the cost is independent of cipherLen (the previous shape materialized ctx || iv || cipher in a MaxCipher-sized stack array, which at index capacity put ~15 KB on the worker stack per tag).
- Parameters
-
Name Direction Meaning macKey in File-HMAC sub-key. macKeyLen in Length of macKeyin bytes.context in Record identity fields (type, slot, generation). iv in :: kleidos:: kIvSize-byte IV. cipher in Ciphertext bytes. cipherLen in Length of cipherin bytes.tagOut out Receives the :: kHmacSize-byte tag.
- Return values
-
Value Meaning true Tag computed. false Backend HMAC failure ( tagOutwiped).
encodeLogEntryHeader() #
Write into out the header bytes an append of these fields writes, checksum included.
The single definition of the entry framing. Anything that has to PRODUCE entry bytes goes through here, so the bytes a scan accepts and the bytes something else lays down cannot come to disagree — the scan's whole tear-or-damage decision rests on the checksum matching the fields beside it.
- Parameters
-
Name Direction Meaning out out The header bytes. type in Record class. tombstone in The entry is the slot's erasure; lenmust be 0.slot in Slot within the class. gen in Generation the entry is written at. len in Payload bytes that follow the header.
indexSegmentEndSlot() #
One past the last credential slot cached by segment segment.
Clamped to the build capacity, so the last segment may be short.
- Parameters
-
Name Direction Meaning segment in Segment number.
- Returns
- One past the highest slot id the segment owns.
indexSegmentFirstSlot() #
First credential slot cached by segment segment.
- Parameters
-
Name Direction Meaning segment in Segment number.
- Returns
- The lowest slot id the segment owns.
indexSegmentOf() #
Segment that caches credential slot id.
- Parameters
-
Name Direction Meaning id in Credential slot id.
- Returns
- The segment number whose file holds that slot's cached row.
listDomain() #
Derive a record's list domain: the index's domain column for url.
Canonicalizes through the brand registry (kleidos::
- Parameters
-
Name Direction Meaning url in URL text from the credential record (null or empty allowed). out out The list domain; empty when urlis empty or names no host.
- Warning
- SECURITY: the domain is record metadata. The canonical scratch is wiped before return; a caller wipes its own
out.
logSegmentOf() #
Segment that owns slot within its class.
Positional and computable, never stored: nothing has to be kept coherent when a slot is written, and a slot's entries can only ever be in one file.
- Parameters
-
Name Direction Meaning slot in Slot id within its class.
- Returns
- The segment number.
logSegmentsOf() #
Segments the class type is split into.
- Parameters
-
Name Direction Meaning type in Record class.
- Returns
- The segment count for that class.
maxLogPayloadBytes() #
The widest payload an entry of type may carry: the widest envelope THAT CLASS is stored as.
The log accepts one payload bound for both classes, so this is what holds an entry of one class to the width its own records have — on the append side, where a wider envelope is refused, and on the read side, where a header declaring more than its class holds is refused before a byte of it is read.
It is a function rather than a constant because the two widths are declared by credential_
- Parameters
-
Name Direction Meaning type in Record class.
- Returns
- Payload bytes, at most ::
kLogEntryMaxPayload.
parseStagedSlot() #
Parse the canonical decimal slot span of a record basename.
The grammar is canonical, i.e. digits → slot is injective: two digits spell every slot below 100 ("07" → 7) and three digits spell every slot at or above it ("123" → 123). A three-digit span starting with '0' is refused, because the writer never emits it and accepting it would alias two basenames onto one slot.
- Parameters
-
Name Direction Meaning digits in First digit of the span (not NUL-terminated). n in Number of digits in the span. slotOut out Receives the parsed slot on success; untouched otherwise.
- Return values
-
Value Meaning true digitsis a canonical 2- or 3-digit slot spelling.false Wrong length, a non-digit, or a non-canonical leading zero.
segmentCount() #
Number of units that cover a slot space of slotCapacity.
Fixed by the build's capacity, not by how much the vault holds, so an empty vault walks the same number of units as a full one.
- Parameters
-
Name Direction Meaning slotCapacity in Size of the slot space being partitioned.
- Returns
- Unit count; 0 for an empty slot space.
segmentEndSlot() #
One past the last slot owned by unit segment.
Clamped to slotCapacity, so the last unit may be short.
- Parameters
-
Name Direction Meaning segment in Unit number. slotCapacity in Size of the slot space being partitioned.
- Returns
- One past the highest slot id in the unit, never above
slotCapacity.
segmentFirstSlot() #
First slot owned by unit segment.
- Parameters
-
Name Direction Meaning segment in Unit number.
- Returns
- The lowest slot id in the unit.
segmentOf() #
Unit that owns slot slotId.
- Parameters
-
Name Direction Meaning slotId in Slot id.
- Returns
- The unit number covering that slot.
verifyEnvelopeBytes() #
Verify an envelope held in memory — the record-log form of a file's verify-before-decrypt: version, block alignment, and the tag under context, compared in constant time.
- Template Parameters
-
Name Meaning MaxCipher Largest ciphertext the caller's scratch holds.
- Parameters
-
Name Direction Meaning macKey in MAC sub-key bytes. macKeyLen in Bytes in macKey.context in What the tag is bound to. env in Envelope bytes. len in Bytes in env.
- Return values
-
Value Meaning true The envelope is authentic for context.false It is not, or it is malformed.
writeEnvelopeContext() #
Write the authenticated context prefix that precedes the IV in the MAC.
Layout: ver(1) || recordType(1) || slotId(2, LE) || generation(4, little-endian). The caller appends the IV and ciphertext after this prefix to form the full authenticated message, then HMACs it with the file MAC sub-key. Centralizing the prefix layout keeps every record module (and the re-key path) bit-identical.
- Parameters
-
Name Direction Meaning out out Buffer of at least :: kEnvelopeContextSize bytes. context in Record identity fields (type, slot, generation).
- Returns
- Number of bytes written (::
kEnvelopeContextSize).
Variable Documentation
kCredCustomFixedBytes #
Value bytes of a custom-field entry before its label and value: [kind u8][hidden u8][labelLen u8].
kCredFieldKindMax #
Highest CredFieldKind this build knows; a higher value decodes as CredFieldKind::
kCredFixedSize #
Bytes of the fixed part that precedes the pool (see credential_
kCredPlaintextSize #
Plaintext bytes every credential record encodes to, padded before encryption. One LittleFS block, so a record never straddles a block.
kEnvelopeContextSize #
Size of the authenticated context prefix that precedes the IV: ver(1) || recordType(1) || slotId(2, LE) || generation(4, LE).
kEnvelopeGroupGeneration #
Fixed generation bound for the group-name file: a singleton with no per-slot counter in meta.bin. A rolled-back groups.bin only restores the owner's own older group labels (no secret disclosure beyond the attacker-supplied old snapshot), so it carries no freshness anchor. The distinct ::
kEnvelopeVersion #
On-disk envelope version byte. Stays 0x01; only the authenticated context (and thus the tag value) changed, never the file layout.
kEnvelopeWifiGeneration #
Fixed generation bound for the WiFi-network file: like the index it is a singleton with no per-slot counter in meta.bin. A rolled-back wifi.bin only restores the owner's own older WiFi list (no secret disclosure beyond what the attacker-supplied old snapshot already contained), so it carries no freshness anchor. The distinct ::
kIndexDomainLen #
Origin-domain length cached in the index (derived from the record URL at save time so list surfaces render a site column / brand mark with zero per-row decrypts).
kIndexRowMaxSize #
Worst-case packed-binary size of one row, as a sum of its per-field maxima (see record_
- order(2, LE) + group(1) + mtime(4) + domain (1 + 24) = 2 + 33 + 33 + 2 + 1 + 2 + 1 + 4 + 25 = 103 bytes.
kIndexSegmentMaxCipherSize #
Worst-case segment ciphertext. PKCS#7 always appends 1..16 bytes and pads to the next block boundary, so this is exact rather than an upper bound.
kIndexSegmentPathCapacity #
Capacity of a segment-path buffer. The segment path itself is built by kleidos::
kIndexSegmentPlainBufferSize #
Capacity of the DECRYPTED-segment buffer.
Sized to the ciphertext, not to the payload: AES-CBC writes the full ciphertext length into the destination and PKCS#7 stripping only shortens the reported length afterwards, so a buffer of ::
kIndexSegmentRows #
Credential slots cached by ONE segment file.
The number that fixes the working set. 32 rows put the worst-case plaintext at 3,301 B and the whole file at 3,361 B, so a segment never spills a 4 KB LittleFS block. 32 is also the hard ceiling of the layout, not just a tuning choice: the per-slot bitmasks that validate, carry and rebuild a segment are uint32_t, and ::
The value itself lives in kleidos::
kLogEntryHeaderBytes #
Bytes an entry adds beyond its payload: nine bytes of header fields plus the two-byte checksum over them.
kLogEntryMaxPayload #
Largest payload an entry may carry — a bound a scan trusts a header against, so a corrupt length cannot walk it off the file.
Sized to the widest envelope the vault stores: a credential record is a fixed 4 KiB plaintext plus one AES padding block plus the 49-byte [ver][iv][tag] header, and the slack above that is room for the envelope to gain a field without a log-format change. credential_
kRecordCompactMinGarbageBytes #
Garbage a log segment must hold before rewriting it is worth the copy: the one policy value the per-mutation compaction and the restore's closing pass share, so neither can drift from the flash model the other is measured by.
kSegmentSlots #
Slots covered by ONE bounded unit.
The single tuning parameter of the whole segmentation, and the only definition site: the index's on-flash geometry (kleidos::) and the TOTP scan both read it, and the build's capacity check parses this line so the capacity model cannot drift from the firmware.
Two minima pull against each other when choosing it. Per unit: small enough that no single unit blocks the UI task long. In total: not so small that the fixed per-unit cost inflates the whole walk. meta.bin authenticates once per session, not once per unit, so the fixed cost per unit is one worker round-trip, the unit's own file read and its decrypt. The total-cost curve still rises as the stride shrinks, so the sweep is looking for the minimum of the two curves, not of either.
The two artifacts pay differently for a change, which matters when sweeping:
- The index: the value is its on-flash geometry. Moving it re-shapes idx_NN.bin, moves every board's capacity ceiling, and is capped at 32 by the layout itself (the per-slot bitmasks are uint32_t) — so it can only be swept DOWN, and a value that wins on time may cost a board capacity. The build's capacity check recomputes the ceilings and fails when it does.
- The TOTP scan: the value is not just control flow here: a TOTP record is an entry of the append-only record log, whose segments are cut on this same stride (record_log.h: one segment per range of ::
kSegmentSlots slots, the same partition the index uses). Moving the value therefore re-shapes rt_NN.bin as well, and the compaction peak — the live vault plus one segment — moves with it.
kSlottedFamilies #
Every slotted family, in the order a basename is tested against. The stems are disjoint prefixes, so the order is presentational only.