Kleidos API Search

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/vault/derivation_input.h
The one seam that turns a typed secret into the bytes a vault derivation may consume.
file src/vault/rotation_view.h
The only place a reader may choose between the current and the previous vault key while a rotation is live.
file src/vault/vault_keys.h
Vault key derivation: the two keys of the scheme and what each gives.
file src/vault/vault_meta.h
Authenticated vault metadata (meta.bin): salts, secret verifier, per-slot generation table, and a MAC over all of it.
file src/vault/vault_rotate.h
The rotation order: one total ordering over every artifact the vault owns, and the encode / decode pair that walks it.

Classes

struct kleidos::vault::StoredVaultTag
Tag selecting the input the vault ALREADY ON FLASH declares in its meta. More about kleidos::vault::StoredVaultTag
struct kleidos::vault::FreshVaultTag
Tag selecting the input a FRESH vault should be provisioned with. More about kleidos::vault::FreshVaultTag
struct kleidos::vault::StagedVaultTag
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::vault::StagedVaultTag
class kleidos::vault::DerivationInput
The assembled PBKDF2 input for one vault operation. More about kleidos::vault::DerivationInput
class kleidos::vault::RotationView
The rotation as a reader sees it: one frontier and the rules over it. More about kleidos::vault::RotationView
struct kleidos::vault::WrapKeys
The two sub-keys derived from a key-encryption key (KEK). More about kleidos::vault::WrapKeys
struct kleidos::vault::DerivedKeys
The AES encryption key and file-HMAC key for an unlocked vault. More about kleidos::vault::DerivedKeys
class kleidos::vault::VaultKeys
Derivation of vault sub-keys from a vault key, with a session cache. More about kleidos::vault::VaultKeys
class kleidos::vault::MetaKekHalf
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::vault::MetaKekHalf
class kleidos::vault::MetaRotState
The in-place rotation's state, as ONE sealed value. More about kleidos::vault::MetaRotState
struct kleidos::vault::RotationOpening
Everything a rotation needs to begin, minted around ONE vault key. More about kleidos::vault::RotationOpening
class kleidos::vault::MetaSecretKindSource
Where a mint gets the unlock modality it stamps. More about kleidos::vault::MetaSecretKindSource
struct kleidos::vault::VaultMetaRecord
In-memory form of the vault metadata record. More about kleidos::vault::VaultMetaRecord
struct kleidos::vault::ProvisionResult
Result of VaultMeta::provision (the new record plus its key). More about kleidos::vault::ProvisionResult
class kleidos::vault::VaultMeta
Provisioning, unlock, (de)serialization and authentication for the vault metadata. More about kleidos::vault::VaultMeta
struct kleidos::vault::RotArtifact
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::vault::RotArtifact

Typedefs

usingkleidos::vault::VaultKey
A vault key (VK): 32 random bytes minted at provisioning.

Enumerations

enum class kleidos::vault::DerivationInputKind : uint8_t { kleidos::vault::DerivationInputKind::SecretOnly , kleidos::vault::DerivationInputKind::Combined , kleidos::vault::DerivationInputKind::KeyfileUnavailable , kleidos::vault::DerivationInputKind::FactorUnknown }
Which input a DerivationInput ended up carrying. More about kleidos::vault::DerivationInputKind
enum class kleidos::vault::MetaSecretKind : uint8_t { kleidos::vault::MetaSecretKind::Pin , kleidos::vault::MetaSecretKind::Passphrase }
Unlock modality persisted in the meta record (typed boundary). More about kleidos::vault::MetaSecretKind
enum class kleidos::vault::MetaKeyfileFactor : uint8_t { kleidos::vault::MetaKeyfileFactor::None , kleidos::vault::MetaKeyfileFactor::Keyfile }
Whether this vault's key derivation takes an SD key file as a second factor (typed boundary). More about kleidos::vault::MetaKeyfileFactor
enum class kleidos::vault::StoredKeyfileFactor : uint8_t { kleidos::vault::StoredKeyfileFactor::None , kleidos::vault::StoredKeyfileFactor::Keyfile , kleidos::vault::StoredKeyfileFactor::Unknown }
The answer to "which factor does the vault ON FLASH declare?", including the answer "that could not be established". More about kleidos::vault::StoredKeyfileFactor
enum class kleidos::vault::MetaWriteVerdict : uint8_t { kleidos::vault::MetaWriteVerdict::Ok, kleidos::vault::MetaWriteVerdict::KekNotForThisKey, kleidos::vault::MetaWriteVerdict::ForeignHmacSalt, kleidos::vault::MetaWriteVerdict::RotStateNotForThisKey, kleidos::vault::MetaWriteVerdict::KeyfileFactorMismatch }
Which of the write choke point's gates refused a candidate. More about kleidos::vault::MetaWriteVerdict
enum class kleidos::vault::MetaUnlockOutcome : uint8_t { kleidos::vault::MetaUnlockOutcome::Unlocked, kleidos::vault::MetaUnlockOutcome::WrongSecret, kleidos::vault::MetaUnlockOutcome::Unusable, kleidos::vault::MetaUnlockOutcome::NotChecked, kleidos::vault::MetaUnlockOutcome::RecordTampered }
What VaultMeta::unlock found out about a secret. More about kleidos::vault::MetaUnlockOutcome
enum class kleidos::vault::RotClass : uint8_t { kleidos::vault::RotClass::Record , kleidos::vault::RotClass::Singleton , kleidos::vault::RotClass::Segment }

Functions

constexpr uint32_tkleidos::vault::metaMaxKdfIterations (uint32_t costNs)
The highest work factor a record may declare at costNs per iteration: what fits kKdfDerivationBudgetMs, capped at kKdfIterationsPolicyMax.
constexpr boolkleidos::vault::kdfIterationsUsable (uint32_t iterations)
Whether a persisted work factor may drive a key derivation ON THIS BUILD.
constexpr boolkleidos::vault::carriedKdfIterationsPlausible (uint32_t iterations)
Whether a work factor read from a meta record a backup CARRIES is one some board may have written.
constexpr MetaSecretKindkleidos::vault::secretKindFromByte (uint8_t raw)
Coerce a persisted modality byte to the typed enumerator.
constexpr MetaKeyfileFactorkleidos::vault::keyfileFactorFromByte (uint8_t raw)
Coerce a persisted second-factor byte to the typed enumerator.
constexpr StoredKeyfileFactorkleidos::vault::storedKeyfileFactorFromByte (uint8_t raw)
Coerce a persisted second-factor byte from a record that WAS read.
constexpr boolkleidos::vault::metaPinLengthUsable (uint8_t n)
Whether n is a PIN length a record may declare.
constexpr uint16_tkleidos::vault::rotSkipByte (uint16_t ordinal)
Byte index within a skip bitmap holding ordinal's bit.
constexpr uint8_tkleidos::vault::rotSkipMask (uint16_t ordinal)
Mask selecting ordinal's bit within rotSkipByte's byte.
constexpr uint16_tkleidos::vault::rotOrdinalOfCredential (uint16_t slot)
Ordinal of a credential slot.
constexpr uint16_tkleidos::vault::rotOrdinalOfTotp (uint16_t slot)
Ordinal of a TOTP slot.
constexpr uint16_tkleidos::vault::rotOrdinalOfSegment (uint16_t segment)
Ordinal of an index segment.
constexpr RotArtifactkleidos::vault::rotArtifactAt (uint16_t ordinal)
Decode an ordinal back into the artifact it names.
constexpr RotClasskleidos::vault::rotClassOf (uint16_t ordinal)
Class of the artifact at ordinal, without decoding its slot.

Variables

constexpr size_tkleidos::vault::kMaxTypedSecretLen
constexpr size_tkleidos::vault::kKeyfileDigestLen
Size of the SD key file and of its SHA-256 digest, in bytes.
constexpr size_tkleidos::vault::kMaxDerivationInputLen
Capacity of the combined buffer: the longest secret plus the digest.
constexpr StoredVaultTagkleidos::vault::kStoredVault
constexpr FreshVaultTagkleidos::vault::kFreshVault
constexpr StagedVaultTagkleidos::vault::kStagedVault
constexpr size_tkleidos::vault::kKeySize
constexpr size_tkleidos::vault::kHmacSaltSize
Size of the HMAC salt bound into the MAC-key label, in bytes.
constexpr size_tkleidos::vault::kPinVerifierSize
Size of the stored secret verifier (HMAC-SHA256 output), in bytes.
constexpr charkleidos::vault::kEncKeyLabel []
Domain-separation label for the AES encryption sub-key.
constexpr charkleidos::vault::kMacKeyLabel []
Domain-separation label prefix for the file-HMAC sub-key (hmacSalt appended).
constexpr charkleidos::vault::kPinVerifierLabel []
Domain-separation label for the secret verifier.
constexpr size_tkleidos::vault::kVkCheckSize
constexpr size_tkleidos::vault::kWrapIvSize
Size of the vault-key wrap IV, in bytes.
constexpr size_tkleidos::vault::kWrapCipherSize
Size of the wrapped vault key, in bytes (two AES blocks, no padding).
constexpr charkleidos::vault::kWrapEncKeyLabel []
Domain-separation label for the AES key that wraps the vault key.
constexpr charkleidos::vault::kWrapMacKeyLabel []
Domain-separation label for the HMAC key that authenticates the KEK half.
constexpr charkleidos::vault::kMetaMacKeyLabel []
Domain-separation label for the HMAC key that authenticates the VK half.
constexpr charkleidos::vault::kVkCheckLabel []
Domain-separation label for the vault-key pairing tag.
constexpr charkleidos::vault::kPrevEncKeyLabel []
constexpr charkleidos::vault::kPrevCheckLabel []
Domain-separation label for the previous-vault-key pairing tag.
constexpr size_tkleidos::vault::kMetaCredGenCount
Credential generation-table length (mirrors kMaxCredentialSlots).
constexpr size_tkleidos::vault::kMetaTotpGenCount
TOTP generation-table length (mirrors kMaxTotpSlots).
constexpr size_tkleidos::vault::kMetaGenEntrySize
Width of one generation counter, in bytes (u32 little-endian).
constexpr std::array< uint8_t, 2 >kleidos::vault::kMetaMagic
Magic bytes identifying a Kleidos vault metadata record.
constexpr uint8_tkleidos::vault::kMetaFormatVersion
constexpr uint8_tkleidos::vault::kMetaPinLengthDefault
constexpr uint8_tkleidos::vault::kMetaSecretKindDefault
constexpr uint8_tkleidos::vault::kMetaKeyfileFactorDefault
constexpr size_tkleidos::vault::kMetaKdfIterationsSize
Width of the persisted PBKDF2 work factor, in bytes (u32 little-endian).
constexpr uint32_tkleidos::vault::kKdfIterationsPolicyMax
constexpr uint32_tkleidos::vault::kKdfIterationCostNsEsp32S3
constexpr uint32_tkleidos::vault::kKdfIterationCostNsEsp32
constexpr uint32_tkleidos::vault::kKdfIterationCostNs
constexpr uint32_tkleidos::vault::kKdfDerivationBudgetMs
constexpr uint32_tkleidos::vault::kMetaMaxKdfIterations
constexpr uint32_tkleidos::vault::kMetaKdfWeakeningSlack
constexpr uint32_tkleidos::vault::kMetaMinKdfIterations
constexpr uint32_tkleidos::vault::kFleetFastestKdfIterationCostNs
constexpr uint32_tkleidos::vault::kCarriedMetaMinKdfIterations
constexpr uint32_tkleidos::vault::kCarriedMetaMaxKdfIterations
constexpr size_tkleidos::vault::kKdfSaltSize
PBKDF2 salt size, in bytes.
constexpr size_tkleidos::vault::kMetaTagSize
Size of the metadata authentication tag (HMAC-SHA256 output), in bytes.
constexpr std::array< uint8_t, 3 >kleidos::vault::kMetaPinLengthOptions
constexpr uint8_tkleidos::vault::kMetaPinLengthFree
constexpr size_tkleidos::vault::kMetaPinLengthOffset
Active PIN length byte (authenticated by wrapTag).
constexpr size_tkleidos::vault::kMetaSecretKindOffset
Unlock-modality discriminator byte (authenticated by wrapTag).
constexpr size_tkleidos::vault::kMetaKeyfileFactorOffset
Second-factor discriminator byte (authenticated by wrapTag).
constexpr size_tkleidos::vault::kMetaVkCheckOffset
The pairing tag naming the vault key this half wraps.
constexpr size_tkleidos::vault::kMetaKekAuthedSize
Size of the content wrapTag covers (the KEK half up to but not including it).
constexpr size_tkleidos::vault::kMetaKekHalfSize
Total size of the KEK half, in bytes. Fixed; never capacity-scaled.
constexpr size_tkleidos::vault::kMetaPortablePrefixSize
constexpr size_tkleidos::vault::kMetaRotStateSize
constexpr size_tkleidos::vault::kMetaSecretEpochOffset
The secret epoch (u32 LE), the last field metaTag covers.
constexpr size_tkleidos::vault::kMetaSecretEpochSize
Bytes the secret epoch takes.
constexpr size_tkleidos::vault::kMetaVkAuthedOffset
Offset at which the content metaTag covers begins — the KEK half's own tag.
constexpr size_tkleidos::vault::kMetaVkAuthedSize
Size of the content metaTag covers.
constexpr size_tkleidos::vault::kMetaSize
Total serialized record size, in bytes.
constexpr uint16_tkleidos::vault::kRotCredentialCount
Number of credential ordinals — the first run of the order.
constexpr uint16_tkleidos::vault::kRotTotpCount
Number of TOTP ordinals, immediately after the credentials.
constexpr uint16_tkleidos::vault::kRotOrdinalGroups
Ordinal of groups.bin.
constexpr uint16_tkleidos::vault::kRotOrdinalWifi
Ordinal of wifi.bin.
constexpr uint16_tkleidos::vault::kRotOrdinalSegment0
Ordinal of index segment 0; segment s is at kRotOrdinalSegment0 + s.
constexpr uint16_tkleidos::vault::kRotOrdinalEnd
constexpr uint16_tkleidos::vault::kRotSkipBytes

Back to the top

Typedef Documentation

VaultKey #

using kleidos::vault::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::secureWipe on every exit path.

Back to the top

Enumeration Type Documentation

DerivationInputKind #

enum class kleidos::vault::DerivationInputKind : uint8_t

Which input a DerivationInput ended up carrying.

DerivationInputKind::KeyfileUnavailable and DerivationInputKind::FactorUnknown 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::KeyfileUnavailable because the owner can do nothing about it and the card is not at fault: the surface must say the record was unreadable, not "seat the key file".

MetaKeyfileFactor #

enum class kleidos::vault::MetaKeyfileFactor : uint8_t

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::Keyfile and from the secret alone when it is MetaKeyfileFactor::None. Which of the two a vault uses is therefore part of its key, and nothing outside the vault can be asked about it: an SD card that is unseated, unmounted or simply unreadable reports the same "no key file" as a card that never carried one, and deriving from the wrong half yields a key that no correct secret can fix. The vault records the answer HERE, next to the verifier the derivation is checked against and under the same MAC, so an unlock knows which input to build before it builds one, and a card that cannot supply a factor the vault requires is a refusal to derive rather than a failed authentication.

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.

Enumerator
None 

The secret alone derives the KEK.

Keyfile 

secret || SHA-256(keyfile) derives the KEK.

MetaSecretKind #

enum class kleidos::vault::MetaSecretKind : uint8_t

Unlock modality persisted in the meta record (typed boundary).

The record stores the discriminator as a raw byte (the serialized form and VaultMetaRecord::secretKind 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::pin_policy::SecretKind, and reads are coerced through security::pin_policy::clampSecretKind.

Enumerator
Pin 

Numeric PIN (dialed, or typed on a touch keypad).

Passphrase 

Free-length keyboard passphrase.

MetaUnlockOutcome #

enum class kleidos::vault::MetaUnlockOutcome : uint8_t

What VaultMeta::unlock found out about a secret.

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::WrongSecret is an authentication failure.

Enumerator
Unlocked 

The verifier matched; the vault key is written out.

WrongSecret 

The verifier was recomputed and did not match.

Unusable 

The record declares a work factor this build may not derive with.

NotChecked 

PBKDF2, the device binding or the verifier derivation failed to run.

RecordTampered 

The verifier matched but the KEK half failed its own MAC: the secret is right and the record is damaged. Not an attempt at the secret, so it must not reach the brute-force counter — every one of those bytes leaves the vault key recoverable, and charging them wipes an intact vault for typing the correct secret ten times.

MetaWriteVerdict #

enum class kleidos::vault::MetaWriteVerdict : uint8_t

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.

Enumerator
Ok 

Every gate passed; the record may be serialized.

KekNotForThisKey 

R2: the KEK half belongs to another vault key.

ForeignHmacSalt 

HS: the key set was derived under another salt.

RotStateNotForThisKey 

RG: the live rotation state's wrap does not close.

KeyfileFactorMismatch 

KF: the candidate declares the other second factor.

RotClass #

enum class kleidos::vault::RotClass : uint8_t

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.

Enumerator
Record 

A credential or TOTP file. The frontier is co-committed with the slot's generation counter, so the frontier never disagrees with the file.

Singleton 

groups.bin or wifi.bin. The frontier is a bookmark and may lag the file by one ordinal.

Segment 

An idx_NN.bin segment. Bookmark, exactly as for a singleton.

StoredKeyfileFactor #

enum class kleidos::vault::StoredKeyfileFactor : uint8_t

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::None makes the unreadable case indistinguishable from a vault that genuinely takes no key file. Downstream, the bare secret then reaches PBKDF2 on a key-file vault, the verdict comes back kleidos::vault::UnlockOutcome::WrongSecret, and ten of those erase the vault of an owner who typed the right secret with the right card seated.

Only StoredKeyfileFactor::None and StoredKeyfileFactor::Keyfile may drive an assembly; StoredKeyfileFactor::Unknown must refuse.

See also
VaultStore::getStoredKeyfileFactor, kleidos::vault::DerivationInput
Enumerator
None 

The record was READ and declares no second factor.

Keyfile 

The record was READ and declares the SD key file.

Unknown 

The record was NOT read. Nothing may be derived on this answer.

Back to the top

Function Documentation

carriedKdfIterationsPlausible() #

bool kleidos::vault::carriedKdfIterationsPlausible(uint32_t iterations)
constexpr

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_backup.h), so the carried count never drives a derivation and is not held to this build's window (kdfIterationsUsable). It is held to that of every board: the same answer on every board, so a backup restores on every board or on none.

Parameters
NameDirectionMeaning
iterationsinWork factor read from a carried record.
Return values
ValueMeaning
trueInside [kCarriedMetaMinKdfIterations, kCarriedMetaMaxKdfIterations].
falseAbsent (zero), or beyond what any board derives with.

kdfIterationsUsable() #

bool kleidos::vault::kdfIterationsUsable(uint32_t iterations)
constexpr

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
NameDirectionMeaning
iterationsinWork factor read from (or destined for) a record.
Return values
ValueMeaning
trueInside [kMetaMinKdfIterations, kMetaMaxKdfIterations].
falseAbsent (zero), below this build's floor, or beyond the derivation budget — treat the record as malformed and fail closed; never substitute a default.

keyfileFactorFromByte() #

MetaKeyfileFactor kleidos::vault::keyfileFactorFromByte(uint8_t raw)
constexpr

Coerce a persisted second-factor byte to the typed enumerator.

An unknown value falls back to MetaKeyfileFactor::None so a record written by a future firmware cannot make this build demand a factor it does not know how to assemble. The byte is authenticated, so an attacker cannot reach this with a chosen value and still pass VaultMeta::verifyMac.

Parameters
NameDirectionMeaning
rawinThe byte as stored in the record.
Returns
MetaKeyfileFactor::Keyfile for 1, MetaKeyfileFactor::None for every other value.

metaMaxKdfIterations() #

uint32_t kleidos::vault::metaMaxKdfIterations(uint32_t costNs)
constexpr

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
NameDirectionMeaning
costNsinNanoseconds per iteration on the production engine (> 0).
Returns
The ceiling.

metaPinLengthUsable() #

bool kleidos::vault::metaPinLengthUsable(uint8_t n)
constexpr

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
NameDirectionMeaning
ninCandidate PIN length.
Return values
ValueMeaning
truen is one of kMetaPinLengthOptions or kMetaPinLengthFree.

rotArtifactAt() #

RotArtifact kleidos::vault::rotArtifactAt(uint16_t ordinal)
constexpr

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
NameDirectionMeaning
ordinalinPosition in the rotation order.
Returns
The artifact at ordinal.

rotClassOf() #

RotClass kleidos::vault::rotClassOf(uint16_t ordinal)
constexpr

Class of the artifact at ordinal, without decoding its slot.

Parameters
NameDirectionMeaning
ordinalinRotation ordinal.
Returns
Which class of artifact stands there.

rotOrdinalOfCredential() #

uint16_t kleidos::vault::rotOrdinalOfCredential(uint16_t slot)
constexpr

Ordinal of a credential slot.

Parameters
NameDirectionMeaning
slotinCredential id, < kRotCredentialCount.
Returns
The rotation ordinal.

rotOrdinalOfSegment() #

uint16_t kleidos::vault::rotOrdinalOfSegment(uint16_t segment)
constexpr

Ordinal of an index segment.

Parameters
NameDirectionMeaning
segmentinSegment number, < kIndexSegmentCount.
Returns
The rotation ordinal.

rotOrdinalOfTotp() #

uint16_t kleidos::vault::rotOrdinalOfTotp(uint16_t slot)
constexpr

Ordinal of a TOTP slot.

Parameters
NameDirectionMeaning
slotinTOTP id, < kRotTotpCount.
Returns
The rotation ordinal.

rotSkipByte() #

uint16_t kleidos::vault::rotSkipByte(uint16_t ordinal)
constexpr

Byte index within a skip bitmap holding ordinal's bit.

Parameters
NameDirectionMeaning
ordinalinRotation ordinal.
Returns
The byte index.

rotSkipMask() #

uint8_t kleidos::vault::rotSkipMask(uint16_t ordinal)
constexpr

Mask selecting ordinal's bit within rotSkipByte's byte.

Parameters
NameDirectionMeaning
ordinalinRotation ordinal.
Returns
The one-bit mask.

secretKindFromByte() #

MetaSecretKind kleidos::vault::secretKindFromByte(uint8_t raw)
constexpr

Coerce a persisted modality byte to the typed enumerator.

An unknown value falls back to MetaSecretKind::Pin. The byte is authenticated, so an attacker cannot reach this with a chosen value and still pass the record's own tag.

Parameters
NameDirectionMeaning
rawinThe byte as stored in the record.
Returns
MetaSecretKind::Passphrase for 1, MetaSecretKind::Pin for every other value.

storedKeyfileFactorFromByte() #

StoredKeyfileFactor kleidos::vault::storedKeyfileFactorFromByte(uint8_t raw)
constexpr

Coerce a persisted second-factor byte from a record that WAS read.

Parameters
NameDirectionMeaning
rawinThe byte as stored in the record.
Returns
The StoredKeyfileFactor twin of keyfileFactorFromByte — never StoredKeyfileFactor::Unknown, which only a failed read produces.

Back to the top

Variable Documentation

kCarriedMetaMaxKdfIterations #

uint32_t kleidos::vault::kCarriedMetaMaxKdfIterations
inlineconstexpr

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 #

uint32_t kleidos::vault::kCarriedMetaMinKdfIterations
inlineconstexpr

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 #

uint32_t kleidos::vault::kFleetFastestKdfIterationCostNs
inlineconstexpr

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 #

FreshVaultTag kleidos::vault::kFreshVault
inlineconstexpr
See also
FreshVaultTag

kKdfDerivationBudgetMs #

uint32_t kleidos::vault::kKdfDerivationBudgetMs
inlineconstexpr

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 #

uint32_t kleidos::vault::kKdfIterationCostNs
inlineconstexpr

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 #

uint32_t kleidos::vault::kKdfIterationCostNsEsp32
inlineconstexpr

Cost of one iteration on classic ESP32 and the host (IRAM raw-transform software core), in ns.

kKdfIterationCostNsEsp32S3 #

uint32_t kleidos::vault::kKdfIterationCostNsEsp32S3
inlineconstexpr

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 #

uint32_t kleidos::vault::kKdfIterationsPolicyMax
inlineconstexpr

The largest work factor any record may declare on any family: the sealed backup's count, the heaviest derivation the firmware runs.

kKeySize #

size_t kleidos::vault::kKeySize
inlineconstexpr

Size of every key in the scheme — the KEK, the VK and each sub-key — in bytes: one size for all of them.

kMaxTypedSecretLen #

size_t kleidos::vault::kMaxTypedSecretLen
inlineconstexpr

Longest typed secret any Kleidos surface accepts, in bytes. Mirrors security::pin_policy::kPassphraseMax; 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).

kMetaFormatVersion #

uint8_t kleidos::vault::kMetaFormatVersion
inlineconstexpr

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 #

uint32_t kleidos::vault::kMetaKdfWeakeningSlack
inlineconstexpr

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 #

uint8_t kleidos::vault::kMetaKeyfileFactorDefault
inlineconstexpr

Default second factor for freshly provisioned vaults (0 = secret only). Kept as the raw persisted byte; the typed twin is MetaKeyfileFactor::None.

kMetaMaxKdfIterations #

uint32_t kleidos::vault::kMetaMaxKdfIterations
inlineconstexpr

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 ::kleidos::kPbkdF2Iterations: 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 #

uint32_t kleidos::vault::kMetaMinKdfIterations
inlineconstexpr

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 #

uint8_t kleidos::vault::kMetaPinLengthDefault
inlineconstexpr

Default length of a dialed PIN for freshly provisioned vaults: 6 digits. Mirrors security::pin_policy::kPinLengthDefault (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 #

uint8_t kleidos::vault::kMetaPinLengthFree
inlineconstexpr

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::pin_policy::kPinLengthFree (pinned where the other mirrors are).

kMetaPinLengthOptions #

std::array<uint8_t, 3> kleidos::vault::kMetaPinLengthOptions
inlineconstexpr

Lengths of a dialed PIN a record may declare. Mirrors security::pin_policy::kPinLengthOptions; 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 #

size_t kleidos::vault::kMetaPortablePrefixSize
inlineconstexpr

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 #

size_t kleidos::vault::kMetaRotStateSize
inlineconstexpr

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 #

uint8_t kleidos::vault::kMetaSecretKindDefault
inlineconstexpr

Default unlock modality for freshly provisioned vaults (0 = numeric PIN). Kept as the raw persisted byte; the typed twin is MetaSecretKind::Pin.

kPrevEncKeyLabel #

char kleidos::vault::kPrevEncKeyLabel[]
inlineconstexpr

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 #

uint16_t kleidos::vault::kRotOrdinalEnd
inlineconstexpr

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 #

uint16_t kleidos::vault::kRotSkipBytes
inlineconstexpr

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 #

StagedVaultTag kleidos::vault::kStagedVault
inlineconstexpr
See also
StagedVaultTag

kStoredVault #

StoredVaultTag kleidos::vault::kStoredVault
inlineconstexpr
See also
StoredVaultTag

kVkCheckSize #

size_t kleidos::vault::kVkCheckSize
inlineconstexpr

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.

Back to the top