ZV3 STREAM AEAD Binary Specification

An authoritative mathematical and byte-level breakdown of the 57-byte container header, chunk IV layouts, associated authenticated data (AAD), and tail manifest framing.

1. Architectural Objectives of the ZV3 Format

The ZV3 STREAM AEAD container format was designed to solve three fundamental challenges in client-side browser cryptography:

  1. Memory Bounding: The format must be streamable in $O(1)$ memory, enabling a browser tab with a 150 MB heap ceiling to encrypt and decrypt multi-gigabyte files.
  2. Cross-Platform Bit-Identity: Vaults generated on a web browser must be bit-for-bit compatible with desktop CLI tools (PowerShell/Bash) and native mobile engines.
  3. Chunk Re-Ordering & Truncation Defense: An adversary must not be able to swap chunks, delete chunks, or truncate the file without triggering immediate AEAD tag verification failure.

2. The 57-Byte Container Header Layout

Every .zsafe (or legacy .zev) file begins with exactly 57 unencrypted header bytes:

Binary Structure · 57-Byte Header (V3_HEADER_SIZE = 57)
Offset (B) | Size | Encoding  | Field Name      | Description
-----------+------+-----------+-----------------+----------------------------------------
0 .. 3     | 4 B  | ASCII     | MAGIC           | Constant: "ZV3\0" (0x5A 0x56 0x33 0x00)
4          | 1 B  | Uint8     | VERSION         | Container schema version (0x03)
5          | 1 B  | Uint8     | FLAGS           | Bit 0: Keyfile 2FA (0x01); Bit 1: Duress (0x02); Bit 2: Argon2id (0x04)
6 .. 9     | 4 B  | Uint32 BE | CHUNK_SIZE      | Default: 4,194,304 bytes (4 MB)
10 .. 41   | 32 B | Raw Bytes | SALT            | CSPRNG salt for Argon2id (64MB) or PBKDF2-SHA512
42 .. 48   | 7 B  | Raw Bytes | BASE_IV_PREFIX  | CSPRNG 7-byte prefix for chunk IVs
49 .. 56   | 8 B  | Uint64 BE | MANIFEST_OFFSET | Byte offset of encrypted tail catalog

3. Interactive 57-Byte Header Inspector

Click any byte segment below to examine its encoding, range, and cryptographic security invariants:

🔬 Interactive ZV3 Container Header Inspector
MAGIC 0..3 (4B)
VERSION 4 (1B)
FLAGS 5 (1B)
CHUNK_SIZE 6..9 (4B)
SALT 10..41 (32B)
BASE_IV 42..48 (7B)
MANIFEST_OFF 49..56 (8B)
Bytes 0..3: Magic Identifier ("ZV3\0")

Fixed 4-byte ASCII constant (0x5A 0x56 0x33 0x00). Formally identifies the file as a Version 3 STREAM AEAD container. Parsers instantly reject any file lacking these 4 bytes before deriving keys.

4. Chunk Wire Framing & 12-Byte IV Construction

AES-GCM mandates that an Initialization Vector (IV) must never repeat under the same key. A repeating IV completely destroys GCM authenticity.

ZevSafe guarantees mathematical IV uniqueness for every chunk:

Byte Construction · 12-Byte Nonce / IV Layout
IV (12 Bytes) = BaseIVPrefix (7B) || Uint32BE(chunkIndex) (4B) || isLast (1B)

5. 42-Byte Associated Authenticated Data (AAD) Invariant

To bind container metadata directly into each cryptographic block without encrypting the metadata, ZevSafe injects a 42-byte Associated Authenticated Data (AAD) vector into every AES-GCM computation:

Cryptographic Invariant · 42-Byte AAD Layout
AAD (42 Bytes) = Magic(4B) || Version(1B) || Salt(32B) || Uint32BE(chunkIndex)(4B) || isLast(1B)

Because the salt and chunk position are authenticated inside the tag, an adversary cannot copy valid ciphertext chunks from Vault A into Vault B, or reorder chunks within the same vault.

6. The 48-Byte Tail Manifest Envelope Trailer

At the byte offset designated by MANIFEST_OFFSET, the encrypted directory catalog is stored:

Binary Wire Format · Tail Manifest Envelope
[Salt (32B) | IV (12B) | PlainLen (4B BE) | Ciphertext (M Bytes) | GCM_Tag (16B)]

This design enables $O(1)$ random directory access: Vault Explorer seeks directly to the manifest offset, decrypts the JSON directory tree, and presents the entire folder hierarchy in under 20 ms without decrypting any multi-gigabyte file chunks.