Designing an encrypted USB vault format without inventing any crypto
We needed a way to keep an encrypted copy of a password vault on a USB stick: something you can pull out of the computer at any moment without corrupting it, that reveals as little as possible to whoever finds the stick, and that a reviewer can check without reading our code. This post walks through the design of the format we ended up with, GKDF (Guardikey Key Drive Format). The full byte-level spec is public; this is the reasoning behind it.
Rule zero: no new cryptography. Every primitive is standard and widely implemented: Argon2id (RFC 9106) for passwords, XChaCha20-Poly1305 for encryption, HKDF-SHA256 (RFC 5869) for key derivation, and BLAKE3 for hashing. The only thing that is ours is how they are arranged.
1. A fixed-size file that looks like noise
The container is one pre-allocated file: a 1 MiB header area followed by 64 KiB chunks. Its size never changes. Everything that is not meaningful is filled with random bytes, and empty key slots are random too, so from outside a full slot and an empty slot look the same.
Recognition uses a 16-byte tag derived from a random per-container salt with a fixed key shipped in the app. That tag is camouflage, not security, and the spec says so: anyone who reverse-engineers the app can compute it. A "hidden mode" replaces the tag with random bytes so the app does not even auto-detect the container.
2. Key slots instead of one password
The data is encrypted under a random drive master key (DMK). Up to eight 512-byte slots each wrap that DMK under a key-encryption key built from one or more factors: master password, recovery key, a key file, a "quick unlock on this computer" secret. Each factor is stretched once (Argon2id for passwords), then combined with HKDF:
ikm = for each factor bit in policy (ascending): u8(bit) ‖ K_factor KEK_i = HKDF(ikm, salt = slot_salt_i, info = "GKDF1/slot|" ‖ drive_id ‖ u8(policy)) The slot's associated data includes its table and index, so swapping two slots breaks both. The (unmasked) KDF parameters are in the associated data too: lowering the Argon2 cost in the header without the key breaks every slot instead of making cracking cheaper.
3. Never write in place
Pulling a USB stick mid-write is normal, so nothing critical is ever overwritten in place. There are two slot tables and two superblocks. A save writes new chunks into free space, flushes, then writes a new superblock over the older of the two, then flushes again. Interrupted before the second flush? The previous generation is still intact, and the half-written superblock simply fails authentication and is ignored.
Password changes rotate the DMK the same way: write everything under the new key into free space, activate it with a new superblock flagged cleanup_pending, then wipe the old slot table. A rule that every writable unlock wipes the inactive table first closes the window where an old password could otherwise stay valid forever.
4. Skipping the Merkle tree
Our first draft had a Merkle tree over the chunks. We removed it. Every reference to a chunk carries the chunk's write generation, and that generation, the chunk index, the key epoch and the chunk's purpose are all in the AEAD associated data:
AAD_chunk = "GKDF1/chunk" ‖ drive_id ‖ suite ‖ key_epoch ‖ chunk_index ‖ write_gen ‖ purpose The chain of trust becomes: superblock (opened with the key) → meta chunk → index chunks → data chunks, each checked by the AEAD tag. A stale, moved, mistyped or foreign chunk fails to decrypt. That is the property the tree provided, with fewer moving parts. We list this as the first open question for reviewers, because removing a structure should be checked by someone other than the person who removed it.
5. Rollback detection
Someone could keep an old copy of the stick and later swap it back. The current generation is anchored in the encrypted vault on the computer and, optionally, on the sync server as a keyed tag the server cannot forge or link to a particular stick. An older generation than the newest anchor opens read-only, with a warning.
6. What we wrote down as limits
- If you change the password and pull the stick in the few seconds before cleanup finishes, someone with the old password and that stick can open the old version.
- Flash controllers may keep old physical blocks; recovering them yields only old data under old keys.
- There is no independent second implementation yet, and no external audit.
Reviewing it
The spec has test vectors (positive and negative) and six explicit questions for reviewers: https://github.com/mrmohammadi1983/guardikey-security
If you can write a second implementation in another language from the spec alone, that is the most useful review we could get. Issues and corrections are welcome.
Guardikey is a zero-knowledge password manager, self-custody wallet and encrypted messenger (pre-launch), built by Apexium Technology. More at https://guardikey.com/?utm_source=devto&utm_medium=article&utm_campaign=gkdf