Format and security
Every file Cipher writes is a .mdstn container. There is one format, version byte 0x03,
frozen since v0.3.0. The format specification
is detailed enough to write a compatible implementation without reading Cipher’s code. It comes
with test vectors that any implementation must decrypt or refuse in the same way.
How a file is protected
| Method | Who can open the file | File key |
|---|---|---|
| X25519 | 1 to 16 recipients, each with their own key | A random 32-byte key, wrapped once per recipient |
| File password | Anyone with the password | Argon2id(password, 16-byte salt, 64 MiB, 3 passes, 4 lanes) |
| Shared key | Holders of a sharing-policy key | The policy key (the CLI does not decrypt this method) |
From the file key, HKDF-SHA256 derives two keys:
- A header MAC key. An HMAC over the header commits the file to one file key. Every recipient gets the same plaintext, or an error. For password files, it also checks the password before any of the body is read.
- A payload key. The body is encrypted with AES-256-GCM in chunks. Each chunk is authenticated with its position and a final-chunk flag, so a removed, reordered or truncated chunk fails.
Recipient blocks name no recipient: a decryptor finds its block by trying its keys. Recipient public keys must be canonical, and low-order points are refused before anything is written.
What Cipher guarantees
- Tampering is detected. Any changed header byte, flipped body bit, swapped or repeated chunk, truncation or trailing data fails decryption.
- No partial output. Output is written to a temporary file and published only on success, so a failed or cancelled operation leaves no file at the output path.
- No surprise overwrites. The default output path never replaces an existing file, and nothing ever writes over the input file or into the key database’s folder.
- The sender’s file name is never used as a path. It is shown, and file names with path separators or control characters are refused.
Exit codes
| Code | Meaning |
|---|---|
0 | Success |
1 | Usage or parse error (including retired format versions 0x01 and 0x02) |
2 | Tampered or damaged file |
3 | Not a recipient: none of your keys opens the file |
4 | Wrong file password, or a damaged header |
5 | Key directory: publish or unpublish rejected because of the current binding |
6 | Key directory: an answer failed its signature, key ID or key-type check |
Limitations
These are deliberate design decisions, not bugs:
- No sender authentication. A file proves who can read it, not who made it. Anyone with your public key can encrypt to you, and one recipient of a multi-recipient file could produce a new file for the others. Sign files outside Cipher if you need to prove the sender.
- A wrong password and a damaged header look the same for password files (exit
4). Once the header checks out, any later failure is reported as tampering. - A damaged recipient block looks like “not a recipient” (exit
3), because blocks don’t name their recipient. - Shared-key files can’t be recovered from a recovery phrase. They need the policy key from the sharing protocol.
Reporting a vulnerability
Email security@madstone.io with “cipher-core security” in the subject. Don’t open a public issue. Reports are acknowledged within 3 business days. The security policy covers scope and disclosure.