SecurityVault cryptography
Vault cryptography
This page describes the vault crate. For a user-level introduction see The vault.
Primitives
| Purpose | Algorithm |
|---|---|
| Record encryption | XChaCha20-Poly1305, random 192-bit nonce per encryption |
| Password KDF | Argon2id v1.3 |
| Subkeys | HKDF-SHA256 (salt = vault id) |
| Randomness | Operating-system CSPRNG |
Ciphertext blobs have the layout version (1 byte) ‖ nonce (24) ‖ ciphertext ‖ tag (16). All key material lives in zeroizing buffers.
Key hierarchy
master password ─Argon2id─┐
PIN ─────────────Argon2id─┤
key-store secret ─────────┤
passkey PRF output ───────┼─HKDF─▶ KEK (per slot) ──wraps──▶ vault key (random, 256-bit)
Windows Hello signature ──┤ │
Secure Enclave secret ────┘ ├──▶ encrypts records and ops
└──HKDF──▶ subkeys: session logs,
sync segments, exports- The vault key (VK) is generated randomly when the vault is created and never stored in the clear.
- It is stored wrapped (encrypted) once per key slot. Every slot wraps the same VK, so adding, removing or changing an unlock method re-wraps the VK; it never re-encrypts the data.
- Slots live in the vault header on this device only. They are not synced: another device of the same vault (paired or restored) has its own header and its own slots.
Key slots
Each slot has an id, a kind, a label, a creation time, optional Argon2id parameters, public metadata and the wrapped VK:
ikm = Argon2id(password or PIN, slot salt) kinds with a password
‖ factor kinds with a factor
KEK = HKDF-SHA256(salt = "vaultport/kek/v2", ikm, info = "<vault id>|<slot id>|<kind>")
blob = XChaCha20-Poly1305(KEK, VK,
aad = "vaultport/vk-wrap/v2|<vault id>|<slot id>|<kind>|" ‖ hex(SHA-256(json(kdf, meta))))The AAD authenticates the slot's kind, KDF parameters and metadata (credential ids, PRF inputs, public keys, challenges), so nothing in a slot can be swapped or edited without the unwrap failing. The only unauthenticated field is a PIN slot's failure counter, which is state, not key material.
| Kind | Password input | Factor | Where it can be set up |
|---|---|---|---|
password | master password | — | everywhere |
password-passkey | master password | FIDO2 hmac-secret / WebAuthn PRF output (two-factor unlock) | desktop |
device | — | Windows Hello signature · Secure Enclave-unwrapped secret · OS key-store key | Windows · macOS · Linux, iOS, Android |
pin | PIN | 32 random bytes in the OS key store | everywhere |
passkey | — | FIDO2 hmac-secret / WebAuthn PRF output | desktop |
auto-unlock | — | 32 random bytes in the OS key store, opened without a prompt (opt-in) | everywhere |
Rules enforced by the core:
- At least one slot that can stand alone always remains. A PIN slot deletes itself after too many wrong PINs, so it never counts: you cannot remove the last other method, and a vault cannot be created with only a PIN.
- Slot changes need the unlocked vault (the VK). Removing a slot also deletes its key-store entry and its Windows Hello or Secure Enclave key.
- With two-factor unlock on, the password-only slot is replaced by a
password-passkeyslot, so the password alone no longer opens the vault. Several security keys can be added for two-factor unlock (each its own combined slot).
Windows Hello (device, Windows)
A per-vault Windows Hello key is created with KeyCredentialManager (RSA-2048, in the TPM when one exists). The slot stores the credential name, its public key (BCRYPT_RSAPUBLIC_BLOB) and a random 32-byte challenge. The factor is the key's RSASSA-PKCS1-v1_5/SHA-256 signature over "vaultport/vault-unlock/windows-hello/v1|" ‖ challenge:
- PKCS#1 v1.5 signatures are deterministic, so the same challenge always gives the same signature; every signature is verified with Windows CNG against the stored public key before use.
- Producing the signature needs the TPM-held private key and a Windows Hello gesture (face, fingerprint or Hello PIN). Nothing that opens the vault is stored in Credential Manager.
- Why a signature rather than decryption:
KeyCredentialManager(the public, safe WinRT API for Hello) can only sign. NCrypt's Passport key storage provider could decrypt, but only through undocumented UI policies and raw FFI. - Setting it up shows two Hello prompts (create the key, then sign once to derive the factor).
Threat model: protects against copying the vault file and against other programs reading Credential Manager. Malware running as you can still ask for a Hello signature (Windows then shows the prompt, which you would have to approve) or wait for you to unlock and read memory. If Windows Hello is reset or the TPM is cleared, the key is gone — keep another method.
Touch ID (device, macOS)
A Secure Enclave P-256 key with the access control privateKeyUsage | userPresence (Touch ID or the Mac password) wraps 32 random bytes with ECIES (kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM); the slot stores the key reference and the ciphertext. Only the Secure Enclave, after Touch ID or the password, can unwrap it. The app needs the keychain-access-groups entitlement. This path is compiled and reviewed but has not yet been run on a Mac.
Linux, iOS and Android (device)
A random 32-byte key in the OS key store: the Secret Service on Linux (GNOME Keyring, KWallet), the iOS Keychain (this device only), or on Android encrypted with an AES-256-GCM key held in the Android Keystore (StrongBox when available). There is no biometric binding on these platforms: the store's own protection (login keyring, device lock) is what guards the key.
PIN (pin)
The KEK combines Argon2id(PIN) with a random 32-byte device secret held in the OS key store (on Windows in Credential Manager: binding the PIN to Windows Hello would turn every PIN entry into a Hello prompt). PINs have at least 4 characters; digits and letters are allowed.
- The attempt limit is enforced by the app: the failure counter is written to the header before each attempt (so killing the app mid-attempt does not save a guess), reset on success, and the 5th wrong PIN deletes the slot and its device secret.
- That limit protects against someone at the keyboard. Someone with full access to your user account can copy the vault file and the device secret before trying, and then guess offline. Against that, only Argon2id helps: PINs use 512 MiB and 4 passes on desktop (128 MiB on phones), roughly a second per guess on a fast CPU — a 4-digit PIN falls within hours, a 6-character alphanumeric PIN takes far longer. Use a longer PIN, or no PIN, if that matters to you.
Passkeys and security keys (passkey)
A non-resident ES256 credential is registered under the dedicated relying party id vaultport-vault (never ssh:) with the CTAP2 hmac-secret extension. The slot stores the credential id and a random 32-byte PRF input; the factor is HMAC-SHA-256(CredRandom, SHA-256("WebAuthn PRF" ‖ 0x00 ‖ input)) — the WebAuthn PRF mapping, so the raw HID path and the Windows WebAuthn API give the same output.
- User verification is always required (the key's PIN or fingerprint):
hmac-secretderives a different value with and without UV, so a fixed choice keeps the output stable, and it adds the key's PIN as a factor. - Several passkeys can be added. At unlock, every registered credential is offered; the key you touch answers for its own.
- Transports: on Windows 11 22H2 and later (WebAuthn API v4, which takes PRF inputs) always through
webauthn.dll, which also reaches NFC/BLE keys and phones and shows its own PIN dialog; elsewhere CTAP2 over USB HID with the PIN typed in Vaultport. Unelevated processes on older Windows builds get a clear error (no PRF in the API, no raw HID access). - Registration needs two touches: one to create the credential, one to evaluate the PRF.
Threat model: the PRF output never leaves the authenticator without a touch and user verification. Anyone holding the key and its PIN can open a copy of the vault file. Losing the key loses this method only.
Two-factor unlock (password-passkey)
ikm = Argon2id(password) ‖ PRF output, so neither the password nor the security key alone decrypts the vault — this holds for a stolen copy of the file too. TOTP codes are deliberately not offered: a code from an authenticator app cannot take part in encrypting a file, so it would only be a check the app performs, which an offline attacker simply skips.
Auto-unlock (auto-unlock)
An opt-in, no-prompt device slot: 32 random bytes in the OS key store. Anyone who can use your OS account — and on Windows any program running as you, since Credential Manager entries are readable by the user's processes — can open the vault without a password. It is off by default, and turning it off deletes the key-store entry.
Auto-unlock is used only when Vaultport starts (for the last selected vault) and when you switch to a vault. A vault you lock yourself — or that locks after inactivity or sleep — stays locked until Vaultport restarts or you unlock it with another method; the lock screen never offers auto-unlock.
Recovery
Slots are per device, so recovery always goes through something you have elsewhere: the master password, another device of the same vault (pair again), or an encrypted .vaultport backup. Keep at least one of them.
Format versions
Format version 2 introduced key slots. Version 1 headers (one password wrap, one device wrap, AAD vaultport/vk-wrap/v1|<method>|<vault id>) are still read: the password wrap becomes a version 2 password slot (fresh salt) on the first unlock with the password, and the old device wrap — a key in the OS key store opened without a prompt — becomes an auto-unlock slot with a new key on its first use. Pairing and encrypted backups keep their own transfer wrap of the VK, unchanged.
Argon2id parameters
| Use | Memory | Iterations | Parallelism |
|---|---|---|---|
| Master password, desktop | 256 MiB | 3 | 1 |
| Master password, phones | 64 MiB | 3 | 1 |
| PIN, desktop | 512 MiB | 4 | 1 |
| PIN, phones | 128 MiB | 4 | 1 |
Parameters and the random 16-byte salt are stored in each slot (and authenticated with it). When a vault is opened, parameters read from the file are checked against hard bounds (at least 19 MiB, at most 4 GiB of memory, 1–64 iterations, 1–16 lanes), so an attacker who modifies the file cannot downgrade the KDF to make guessing cheap — or upgrade it to exhaust memory.
Records, ops and associated data
Data is stored as an append-only log of operations plus materialized documents, both encrypted with the VK. Associated data binds every ciphertext to its place:
ops: vaultport/op/v1|<vault id>|<op id>
documents: vaultport/doc/v1|<vault id>|<record id>A ciphertext copied to another record, another op or another vault fails authentication.
The CRDT is a per-field last-writer-wins document: every leaf path (for example /config/ssh/port) is a register ordered by a hybrid logical clock (wall ms, counter, device), and record deletion is a tombstone. Applying the same set of operations in any order yields the same documents.
Secrets
Passwords, private keys and tokens are separate secret records. They are decrypted only when the core needs them — for example to authenticate a connection — and never cached in memory. Secrets can be marked local-only (sync-target and cloud credentials are), in which case they are not replicated to other devices.
Subkeys
Other components never use the VK directly. They derive domain-separated subkeys with HKDF-SHA256 (info = "vaultport/subkey/v1|<purpose>" or "vaultport/sync/<purpose>/v1", salt = vault id):
- session logs — see Session logs,
- sync segments and exports — see Sync protocol.
Device pairing sends the VK itself to the new device, inside a channel keyed by SPAKE2 over the pairing code (an export carries it wrapped with the passphrase).
Subkeys cannot decrypt vault records.
What is not encrypted
The vault is an SQLite file. Its schema, the vault id, the key slots (their kinds, KDF parameters, public metadata such as passkey credential ids, and wrapped keys), the number of records and their record identifiers (an entity kind and a random UUID, such as host:…) are visible to someone who has the file. Labels, addresses, usernames, settings and all secrets are encrypted.
Locking
Locking drops the VK and all decrypted documents from memory, closes sessions, stops port forwards and closes pooled connections. The UI locks after inactivity and, on mobile, when the app goes to the background (both configurable).