In development. It changes without notice.
Topic
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.
The metadata has two halves. The first holds the salt, the work factor, the verifier and the wrapped vault key, and only an operation that has the secret can replace it. The second holds what an unlocked session changes: a generation counter for each slot and the state of a rotation. Each half has a tag under the key of whoever may write it.
Changing the secret wraps the same vault key again and re-encrypts nothing, so it does not revoke a vault key somebody already copied. A rotation does: it gives the vault a new key and re-encrypts one artifact after another, in one fixed order, with how far it got kept in the metadata, so a cut in power resumes it.
- See also
- Vault Storage, Record Log & Envelopes, Cryptography
Files | |
| file | src/ |
| The one seam that turns a typed secret into the bytes a vault derivation may consume. | |
| file | src/ |
| The only place a reader may choose between the current and the previous vault key while a rotation is live. | |
| file | src/ |
| Vault key derivation: the two keys of the scheme and what each gives. | |
| file | src/ |
| Authenticated vault metadata (meta.bin): salts, secret verifier, per-slot generation table, and a MAC over all of it. | |
| file | src/ |
| The rotation order: one total ordering over every artifact the vault owns, and the encode / decode pair that walks it. | |
Classes | |
| struct | kleidos:: |
| Tag selecting the input the vault ALREADY ON FLASH declares in its meta. More about kleidos:: | |
| struct | kleidos:: |
| Tag selecting the input a FRESH vault should be provisioned with. More about kleidos:: | |
| struct | kleidos:: |
| Tag selecting the input a record that is NOT the mounted vault declares — an SD backup staged for restore, whose own meta.bin names its own factor. More about kleidos:: | |
| class | kleidos:: |
| The assembled PBKDF2 input for one vault operation. More about kleidos:: | |
| class | kleidos:: |
| The rotation as a reader sees it: one frontier and the rules over it. More about kleidos:: | |
| struct | kleidos:: |
| The two sub-keys derived from a key-encryption key (KEK). More about kleidos:: | |
| struct | kleidos:: |
| The AES encryption key and file-HMAC key for an unlocked vault. More about kleidos:: | |
| class | kleidos:: |
| Derivation of vault sub-keys from a vault key, with a session cache. More about kleidos:: | |
| class | kleidos:: |
| The secret's half of meta.bin: the key schedule and the wrapped vault key, as ONE value with exactly two writers. More about kleidos:: | |
| class | kleidos:: |
| The in-place rotation's state, as ONE sealed value. More about kleidos:: | |
| struct | kleidos:: |
| Everything a rotation needs to begin, minted around ONE vault key. More about kleidos:: | |
| class | kleidos:: |
| Where a mint gets the unlock modality it stamps. More about kleidos:: | |
| struct | kleidos:: |
| In-memory form of the vault metadata record. More about kleidos:: | |
| struct | kleidos:: |
| Result of VaultMeta:: | |
| class | kleidos:: |
| Provisioning, unlock, (de)serialization and authentication for the vault metadata. More about kleidos:: | |
| struct | kleidos:: |
Which artifact an ordinal names, as the decode half of the ordinal map. slot is the credential id, TOTP id or segment number for its class, and is meaningless (0) for a singleton, which ordinal already identifies. More about kleidos:: | |
Typedefs | |
| using | kleidos:: |
| A vault key (VK): 32 random bytes minted at provisioning. | |
Functions | |
| constexpr uint32_t | kleidos:: |
The highest work factor a record may declare at costNs per iteration: what fits kKdfDerivationBudgetMs, capped at kKdfIterationsPolicyMax. | |
| constexpr bool | kleidos:: |
| Whether a persisted work factor may drive a key derivation ON THIS BUILD. | |
| constexpr bool | kleidos:: |
| Whether a work factor read from a meta record a backup CARRIES is one some board may have written. | |
| constexpr MetaSecretKind | kleidos:: |
| Coerce a persisted modality byte to the typed enumerator. | |
| constexpr MetaKeyfileFactor | kleidos:: |
| Coerce a persisted second-factor byte to the typed enumerator. | |
| constexpr StoredKeyfileFactor | kleidos:: |
| Coerce a persisted second-factor byte from a record that WAS read. | |
| constexpr bool | kleidos:: |
Whether n is a PIN length a record may declare. | |
| constexpr uint16_t | kleidos:: |
Byte index within a skip bitmap holding ordinal's bit. | |
| constexpr uint8_t | kleidos:: |
Mask selecting ordinal's bit within rotSkipByte's byte. | |
| constexpr uint16_t | kleidos:: |
| Ordinal of a credential slot. | |
| constexpr uint16_t | kleidos:: |
| Ordinal of a TOTP slot. | |
| constexpr uint16_t | kleidos:: |
| Ordinal of an index segment. | |
| constexpr RotArtifact | kleidos:: |
| Decode an ordinal back into the artifact it names. | |
| constexpr RotClass | kleidos:: |
Class of the artifact at ordinal, without decoding its slot. | |
Variables | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Size of the SD key file and of its SHA-256 digest, in bytes. | |
| constexpr size_t | kleidos:: |
| Capacity of the combined buffer: the longest secret plus the digest. | |
| constexpr StoredVaultTag | kleidos:: |
| constexpr FreshVaultTag | kleidos:: |
| constexpr StagedVaultTag | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Size of the HMAC salt bound into the MAC-key label, in bytes. | |
| constexpr size_t | kleidos:: |
| Size of the stored secret verifier (HMAC-SHA256 output), in bytes. | |
| constexpr char | kleidos:: |
| Domain-separation label for the AES encryption sub-key. | |
| constexpr char | kleidos:: |
| Domain-separation label prefix for the file-HMAC sub-key (hmacSalt appended). | |
| constexpr char | kleidos:: |
| Domain-separation label for the secret verifier. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Size of the vault-key wrap IV, in bytes. | |
| constexpr size_t | kleidos:: |
| Size of the wrapped vault key, in bytes (two AES blocks, no padding). | |
| constexpr char | kleidos:: |
| Domain-separation label for the AES key that wraps the vault key. | |
| constexpr char | kleidos:: |
| Domain-separation label for the HMAC key that authenticates the KEK half. | |
| constexpr char | kleidos:: |
| Domain-separation label for the HMAC key that authenticates the VK half. | |
| constexpr char | kleidos:: |
| Domain-separation label for the vault-key pairing tag. | |
| constexpr char | kleidos:: |
| constexpr char | kleidos:: |
| Domain-separation label for the previous-vault-key pairing tag. | |
| constexpr size_t | kleidos:: |
| Credential generation-table length (mirrors kMaxCredentialSlots). | |
| constexpr size_t | kleidos:: |
| TOTP generation-table length (mirrors kMaxTotpSlots). | |
| constexpr size_t | kleidos:: |
| Width of one generation counter, in bytes (u32 little-endian). | |
| constexpr std::array< uint8_t, 2 > | kleidos:: |
| Magic bytes identifying a Kleidos vault metadata record. | |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Width of the persisted PBKDF2 work factor, in bytes (u32 little-endian). | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr size_t | kleidos:: |
| PBKDF2 salt size, in bytes. | |
| constexpr size_t | kleidos:: |
| Size of the metadata authentication tag (HMAC-SHA256 output), in bytes. | |
| constexpr std::array< uint8_t, 3 > | kleidos:: |
| constexpr uint8_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Active PIN length byte (authenticated by wrapTag). | |
| constexpr size_t | kleidos:: |
| Unlock-modality discriminator byte (authenticated by wrapTag). | |
| constexpr size_t | kleidos:: |
| Second-factor discriminator byte (authenticated by wrapTag). | |
| constexpr size_t | kleidos:: |
| The pairing tag naming the vault key this half wraps. | |
| constexpr size_t | kleidos:: |
| Size of the content wrapTag covers (the KEK half up to but not including it). | |
| constexpr size_t | kleidos:: |
| Total size of the KEK half, in bytes. Fixed; never capacity-scaled. | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| The secret epoch (u32 LE), the last field metaTag covers. | |
| constexpr size_t | kleidos:: |
| Bytes the secret epoch takes. | |
| constexpr size_t | kleidos:: |
| Offset at which the content metaTag covers begins — the KEK half's own tag. | |
| constexpr size_t | kleidos:: |
| Size of the content metaTag covers. | |
| constexpr size_t | kleidos:: |
| Total serialized record size, in bytes. | |
| constexpr uint16_t | kleidos:: |
| Number of credential ordinals — the first run of the order. | |
| constexpr uint16_t | kleidos:: |
| Number of TOTP ordinals, immediately after the credentials. | |
| constexpr uint16_t | kleidos:: |
| Ordinal of groups.bin. | |
| constexpr uint16_t | kleidos:: |
| Ordinal of wifi.bin. | |
| constexpr uint16_t | kleidos:: |
Ordinal of index segment 0; segment s is at kRotOrdinalSegment0 + s. | |
| constexpr uint16_t | kleidos:: |
| constexpr uint16_t | kleidos:: |
Typedef Documentation
VaultKey #
A vault key (VK): 32 random bytes minted at provisioning.
What every record file on flash is keyed to. It is NOT a PBKDF2 output: the secret derives the key-encryption key that WRAPS this, so replacing the secret rewrites one 154-byte half of meta.bin and leaves every record untouched.
- Warning
- SECURITY: wipe with
VaultCrypto::on every exit path.secureWipe
Enumeration Type Documentation
DerivationInputKind #
Which input a DerivationInput ended up carrying.
DerivationInputKind:: and DerivationInputKind:: are the two verdicts that must never be confused with a wrong guess: in one the vault asked for a factor the card did not give up, in the other the vault's record never said which factor it takes. Either way nothing was assembled and nothing may be derived. Falling back to the secret alone would derive a key the correct secret cannot rescue, and the caller would have no way to see that the device, not the owner, was at fault.
| Enumerator | |
|---|---|
| SecretOnly | The vault derives from the typed secret alone. |
| Combined | The vault takes a key file and the card supplied it. |
| KeyfileUnavailable | The vault takes a key file and the card could not supply one. |
| FactorUnknown | The vault's own record could not be read, so WHICH input it takes is not known. Distinct from DerivationInputKind:: |
MetaKeyfileFactor #
Whether this vault's key derivation takes an SD key file as a second factor (typed boundary).
The key file is half of the PBKDF2 input: the KEK is derived from secret || SHA-256(keyfile) when the factor is MetaKeyfileFactor::
The enumerator values ARE the on-flash byte values — append, never renumber. The factor is fixed at provisioning time: creating or deleting a key file on the card does NOT move it (the vault must be re-provisioned), which is what the SD key-file endpoints have always said and can now enforce.
MetaSecretKind #
Unlock modality persisted in the meta record (typed boundary).
The record stores the discriminator as a raw byte (the serialized form and VaultMetaRecord:: stay uint8_t); this enum is the type the provisioning API accepts, so the kind can never be transposed with the adjacent raw pinLength byte at a call site. The enumerator values ARE the on-flash byte values — append, never renumber. The vault layer deliberately owns no UI vocabulary: the app-layer twin is security::, and reads are coerced through security::.
MetaUnlockOutcome #
What VaultMeta::
A bare false conflates a secret that was checked and did not match with a derivation that never ran, and the two are not interchangeable: the first is evidence of a guess, the second is evidence of nothing. Only MetaUnlockOutcome::
MetaWriteVerdict #
Which of the write choke point's gates refused a candidate.
A verdict rather than a bool: the caller logs which agreement failed, and a future gate is a new enumerator rather than a second meaning for false.
RotClass #
Which of the three artifact classes an ordinal names. The class decides how a reader recovers when the first key does not verify, so it is part of the ordinal's meaning rather than a caller's annotation.
StoredKeyfileFactor #
The answer to "which factor does the vault ON FLASH declare?", including the answer "that could not be established".
MetaKeyfileFactor has two states because a RECORD has two states: the byte is either 0 or 1. Reading that byte is a different question, and it has a third answer — the meta record was not read at all. A worker dispatch that never ran the body and a meta.bin open that failed both leave the reader knowing nothing, and folding that into MetaKeyfileFactor::
Only StoredKeyfileFactor::
Function Documentation
carriedKdfIterationsPlausible() #
Whether a work factor read from a meta record a backup CARRIES is one some board may have written.
The restore keeps the target's own meta and throws the carried one away (vault_
- Parameters
-
Name Direction Meaning iterations in Work factor read from a carried record.
- Return values
-
Value Meaning true Inside [kCarriedMetaMinKdfIterations, kCarriedMetaMaxKdfIterations]. false Absent (zero), or beyond what any board derives with.
kdfIterationsUsable() #
Whether a persisted work factor may drive a key derivation ON THIS BUILD.
The single predicate every derivation site shares — provisioning, unlock, serialization, parse and the SD-import admission check — so a record this device would refuse to unlock can never be provisioned, written or promoted either. Evaluated before PBKDF2 runs. A meta record a backup carries is NOT judged by it: it is never derived with (carriedKdfIterationsPlausible).
The window is build-relative on purpose (see kMetaMinKdfIterations and kMetaMaxKdfIterations): too weak to be anything but a development record, or heavier than the derivation budget, are both malformed.
- Parameters
-
Name Direction Meaning iterations in Work factor read from (or destined for) a record.
- Return values
-
Value Meaning true Inside [kMetaMinKdfIterations, kMetaMaxKdfIterations]. false Absent (zero), below this build's floor, or beyond the derivation budget — treat the record as malformed and fail closed; never substitute a default.
keyfileFactorFromByte() #
Coerce a persisted second-factor byte to the typed enumerator.
An unknown value falls back to MetaKeyfileFactor::
- Parameters
-
Name Direction Meaning raw in The byte as stored in the record.
- Returns
- MetaKeyfileFactor::
Keyfile for 1, MetaKeyfileFactor:: None for every other value.
metaMaxKdfIterations() #
The highest work factor a record may declare at costNs per iteration: what fits kKdfDerivationBudgetMs, capped at kKdfIterationsPolicyMax.
A pure function so the host can check every family's answer.
- Parameters
-
Name Direction Meaning costNs in Nanoseconds per iteration on the production engine (> 0).
- Returns
- The ceiling.
metaPinLengthUsable() #
Whether n is a PIN length a record may declare.
Refused at the MINT rather than coerced at the read: a silent read-time coercion turns a bad write into a PIN the owner cannot complete, and every failed completion is charged to the ten attempts that start the factory reset.
- Parameters
-
Name Direction Meaning n in Candidate PIN length.
- Return values
-
Value Meaning true nis one of kMetaPinLengthOptions or kMetaPinLengthFree.
rotArtifactAt() #
Decode an ordinal back into the artifact it names.
The inverse of the three encoders above, and the only place the boundaries are compared. An ordinal at or past kRotOrdinalEnd names no artifact; callers reach that value as the terminating frontier, never as a thing to open, so it decodes to segment kIndexSegmentCount — one past the last — and is caught by the caller's own bound rather than silently aliasing a real file.
- Parameters
-
Name Direction Meaning ordinal in Position in the rotation order.
- Returns
- The artifact at
ordinal.
rotClassOf() #
Class of the artifact at ordinal, without decoding its slot.
- Parameters
-
Name Direction Meaning ordinal in Rotation ordinal.
- Returns
- Which class of artifact stands there.
rotOrdinalOfCredential() #
Ordinal of a credential slot.
- Parameters
-
Name Direction Meaning slot in Credential id, < kRotCredentialCount.
- Returns
- The rotation ordinal.
rotOrdinalOfSegment() #
Ordinal of an index segment.
- Parameters
-
Name Direction Meaning segment in Segment number, < kIndexSegmentCount.
- Returns
- The rotation ordinal.
rotOrdinalOfTotp() #
Ordinal of a TOTP slot.
- Parameters
-
Name Direction Meaning slot in TOTP id, < kRotTotpCount.
- Returns
- The rotation ordinal.
rotSkipByte() #
Byte index within a skip bitmap holding ordinal's bit.
- Parameters
-
Name Direction Meaning ordinal in Rotation ordinal.
- Returns
- The byte index.
rotSkipMask() #
Mask selecting ordinal's bit within rotSkipByte's byte.
- Parameters
-
Name Direction Meaning ordinal in Rotation ordinal.
- Returns
- The one-bit mask.
secretKindFromByte() #
Coerce a persisted modality byte to the typed enumerator.
An unknown value falls back to MetaSecretKind::
- Parameters
-
Name Direction Meaning raw in The byte as stored in the record.
- Returns
- MetaSecretKind::
Passphrase for 1, MetaSecretKind:: Pin for every other value.
storedKeyfileFactorFromByte() #
Coerce a persisted second-factor byte from a record that WAS read.
- Parameters
-
Name Direction Meaning raw in The byte as stored in the record.
- Returns
- The StoredKeyfileFactor twin of keyfileFactorFromByte — never StoredKeyfileFactor::
Unknown, which only a failed read produces.
Variable Documentation
kCarriedMetaMaxKdfIterations #
Highest work factor a meta record CARRIED by a backup may declare: the ceiling of the fastest family (metaMaxKdfIterations at its cost) — 600,000, the ESP32-S3 ceiling — whatever chip reads it. A backup is written by any board and restored on any other, and a bound taken from the importing chip would refuse every ESP32-S3 backup on a classic ESP32, whose own ceiling is 152,284.
kCarriedMetaMinKdfIterations #
Lowest work factor a meta record CARRIED by a backup may declare: the count a debug build provisions with. A backup's meta is validated and discarded, never derived with, so the floor that keeps a production build from OPENING a debug-strength vault (kMetaMinKdfIterations) does not apply to it.
kFleetFastestKdfIterationCostNs #
Cost of one iteration on the fastest family the firmware builds for, in ns: the family whose derivation ceiling is the highest any board may write.
kFreshVault #
- See also
- FreshVaultTag
kKdfDerivationBudgetMs #
Longest derivation a record may impose on this family's production engine, in milliseconds. What it bounds is the work a foreign or tampered meta.bin can make the vault worker pay before any tag of the record is checked: the worker is not watched by the task watchdog, and every engine feeds the watchdog of whoever runs it between slices of the chain, so the bound is a denial-of-service limit, not a watchdog one. Such an attempt is charged as a wrong secret, as a flipped salt is.
kKdfIterationCostNs #
Measured cost of one PBKDF2-HMAC-SHA256 iteration on the engine this SoC family derives with, in nanoseconds, at the 240 MHz the unlock boosts to: 4.8 us on ESP32-S3 and 39.4 us on classic ESP32 and the native host. It exists only to express kMetaMaxKdfIterations in wall-clock terms. A build that cannot see the family macro lands on the slower figure.
kKdfIterationCostNsEsp32 #
Cost of one iteration on classic ESP32 and the host (IRAM raw-transform software core), in ns.
kKdfIterationCostNsEsp32S3 #
Cost of one iteration on ESP32-S3, in ns, rounded up to 100 ns: the lean register loop, 828 ms for 175,000 iterations at 240 MHz.
kKdfIterationsPolicyMax #
The largest work factor any record may declare on any family: the sealed backup's count, the heaviest derivation the firmware runs.
kKeySize #
Size of every key in the scheme — the KEK, the VK and each sub-key — in bytes: one size for all of them.
kMaxTypedSecretLen #
Longest typed secret any Kleidos surface accepts, in bytes. Mirrors security::
kMetaFormatVersion #
Current metadata format version (the two-half layout in the file note). A record with any other version byte is rejected (see the file note).
kMetaKdfWeakeningSlack #
How far below this build's own work factor a record may sit and still be derived against. Sized so that raising the firmware's work factor by up to this factor never refuses a vault provisioned before the raise (175,000 to 600,000 would be 3.4x), while a debug build's record, provisioned at 1, is nowhere near the window.
kMetaKeyfileFactorDefault #
Default second factor for freshly provisioned vaults (0 = secret only). Kept as the raw persisted byte; the typed twin is MetaKeyfileFactor::
kMetaMaxKdfIterations #
Highest work factor a record may declare on this build: metaMaxKdfIterations at this family's cost — 600,000 on ESP32-S3 (2.9 s on the lean loop), 152,284 on classic ESP32 and the host. The count drives the derivation BEFORE the record's MAC can be checked. It is deliberately independent of this build's own :: a vault provisioned at a higher count than the running firmware uses must still open. Raising a family's provisioning count past its ceiling fails the assertion below.
kMetaMinKdfIterations #
Lowest work factor a record may declare on THIS build: a fraction of the count it provisions with. Nothing erases the vault between flashing a debug image and a production one, so a production build meets a 1-iteration debug vault sooner or later; deriving with the stored count would open it at debug strength, which is why the floor scales with the build's own figure instead of sitting at 1. A debug build keeps a floor of 1 (its own count divides to zero, clamped) and so still opens its own vaults. A record below the floor is refused as malformed, exactly like an absent (zero) count.
kMetaPinLengthDefault #
Default length of a dialed PIN for freshly provisioned vaults: 6 digits. Mirrors security:: (pinned by a static_assert where both are seen). A record carries its own length, which is what every read returns; this default is written only by a provision or a secret change that names none.
kMetaPinLengthFree #
The PIN length a record declares for a PIN of free length (the touch keypad, 6 to 32 digits): no number of digits. The real length is stored nowhere, so the unauthenticated pre-unlock read gives none away. Mirrors security:: (pinned where the other mirrors are).
kMetaPinLengthOptions #
Lengths of a dialed PIN a record may declare. Mirrors security::; duplicated rather than included so the vault layer keeps no dependency on the UI layer (a static_assert where both are seen pins the agreement).
kMetaPortablePrefixSize #
Bytes every device writes identically, whatever its capacity: the magic, the format version, the KDF parameters, the secret verifier, the wrap and its tag, and the hmac salt. Everything past it is scaled by the slot counts, so only this prefix can be read from another board's record.
- See also
- VaultMeta::
prefixLooksLikeRecord
kMetaRotStateSize #
Total size of the rotation state, in bytes. The fixed 67-byte head plus the skip bitmap, which is one bit per rotation ordinal and therefore the one capacity-scaled term in the state.
kMetaSecretKindDefault #
Default unlock modality for freshly provisioned vaults (0 = numeric PIN). Kept as the raw persisted byte; the typed twin is MetaSecretKind::
kPrevEncKeyLabel #
Domain-separation label for the AES key that wraps the PREVIOUS vault key while a rotation is live. Reserved by slice 1; produced from slice 4 on.
kRotOrdinalEnd #
One past the last ordinal. A frontier equal to this means every artifact has been rotated, which is the only state from which a rotation may be retired.
kRotSkipBytes #
Bytes of skip bitmap needed to carry one bit per ordinal. The bitmap lives in the authenticated half of meta.bin rather than in RAM, and the reason is not tidiness: it is the input to the only irreversible decision the rotation makes — retiring the previous key. After a reset the frontier is already at kRotOrdinalEnd, so the steps that would rebuild a RAM-only list never run again; the retirement would then see an empty list, revoke without asking, and leave every skipped artifact permanently unreadable. A skip list that does not survive a reset is a confirmation prompt that does not survive a reset, and the thing it gates cannot be undone.
kStagedVault #
- See also
- StagedVaultTag
kStoredVault #
- See also
- StoredVaultTag
kVkCheckSize #
Size of the vault-key pairing tag stored in the KEK half, in bytes. A truncated HMAC over a 256-bit random key: a NAME for the wrapped key, not a secret, so 16 bytes is the right width.