Menu
weirdlock1: locked albums and files
The published format of locked content: encrypted on your device, opened with a password, a link, a recovery kit or a person's key.
Revision 1 (2026-11-18). Copyright 2026 IRD SRL. Licence: Apache-2.0 (see LICENSE in
this directory).
The key words MUST, MUST NOT, SHOULD and MAY are used as in RFC 2119.
Integers are unsigned and big-endian. || is concatenation. Byte strings
written in quotes are ASCII without a terminator ("weirdlock1\n" is 11
bytes ending in 0x0A). Section numbers are referred to as §n.
Reference implementation: the Go package in this directory
(github.com/weird-ro/weird-cli/weirdlock). Test vectors:
testdata/vectors/ (§16). Where this text and the code disagree, that is
a bug in one of them; report it.
1. What this is#
weirdlock1 is how a person puts an album (many files) or a single file on public storage locked: encrypted on their own device, opened with a password, a secret link, a recovery kit or a named person's key, while the storage service and its providers hold only ciphertext and never a key.
Design goals, in order:
- Confidentiality and integrity of file contents, names, types and (optionally) exact sizes against everyone without a way in — the storage operator included.
- Several ways in to one album (a password and two people and a link), changeable without re-encrypting the content.
- Decryption in a browser with WebCrypto only for every byte of content (AES-256-GCM, HKDF, HMAC, SHA-256, X25519), so large files and video need no JavaScript cipher. The one exception is the password KDF (scrypt, §14.3).
- Streaming in constant memory, and random access to any byte range of a file (for range requests and video seeking).
- A format the owner can decrypt without the service: documented here, with test vectors, under an open licence.
It extends the weirdenc1 envelope of the weird CLI (same STREAM segment
construction, same primitives); weirdenc1 and the previous platform's
irdenc1 stay readable by the CLI and are not specified here.
2. Threat model#
2.1 Protected against#
- The storage operator (weird: its staff, a compromised server or storage node, a legal order to hand over data). It holds ciphertext, sizes and upload metadata; never a key, a password or a link secret.
- Storage providers and the public IPFS network: anyone with the content id fetches ciphertext.
- Anyone who finds or guesses the URL or the content id without a way in.
- Tampering in storage: every segment of every stream is authenticated; a modified, truncated, extended, reordered, duplicated or swapped file fails to open and no unauthenticated plaintext is released (§10.1).
- Mixing parts of different albums or versions (a manifest from another album, a thumbnail in place of a file, one file under another's name): bound by ids and kinds (§4.4, §7.2).
- Offline password guessing, slowed: the password KDF is memory-hard (scrypt, 128 MiB by default). It slows; it does not save a weak password.
2.2 Not protected against (said plainly in the product)#
- A weak password. The ciphertext is public for ever; guessing is offline and unlimited. The CLI warns about weak passwords (it does not refuse them) and suggests a passphrase.
- A compromised device of the owner or a visitor (malware, a browser extension, someone looking over the shoulder).
- A recipient who keeps a copy. Removing a way in later does not take back what was opened, the album key a person already learned, or the old key list that still opens the old copy (§11).
- Metadata (§9): the number of encrypted files and their approximate sizes, the number and kind of ways in, upload and access times, the account and hostname.
- The code that opens the album. A browser viewer is served by whoever serves the album; a malicious or compelled server could serve a viewer that leaks the password. §17.3 narrows this; the CLI and a locally saved viewer avoid it.
- Leaked links: a link secret travels in the URL fragment (never sent to servers) but lives in chat histories, browser history and synced bookmarks.
- Authenticity of the sender for person stanzas. Anyone can lock something to a person's public key. A person stanza says "this was meant for you", not "this came from X". A signature stanza (§5.4, reserved) is the future answer. Password and link stanzas do not have this problem: forging one requires the password or link secret.
- Insiders holding the album key. Every holder of K (every way in) can forge new content under K, a new keyring with K, or a manifest. The format authenticates "made by a holder of K", not "made by the owner".
- Quantum adversaries against X25519 (store now, decrypt later). Password and link stanzas are symmetric and not affected in practice. A hybrid ML-KEM + X25519 stanza can be added as a new type (§15).
- Expiry. It cannot be cryptographic (§12).
2.3 Non-goals#
Hiding that an album is locked; hiding the number of files; deniability;
forward secrecy; multi-writer albums; revocation without re-encryption;
streaming sites (reserved, site in §7).
3. Containers#
3.1 An album folder#
A locked album is a folder (served by IPFS as a directory):
index.html the viewer bootstrap or a static page (not part of the format)
lock/keyring the keyring (§4)
lock/manifest a stream of kind 0x10 (§6): the manifest (§7)
lock/b/<id> a stream of kind 0x11 (a file) or 0x12 (a thumbnail)<id> is the stream's 16-byte id in RFC 4648 base32, lowercase, no
padding: 26 characters whose last one carries 2 unused bits that MUST be
zero (so it is one of a e i m q u y 4). Decoders MUST accept only this
spelling. Ids are random,
so paths reveal nothing about names. Other files in the folder are not
part of the format; decoders ignore them (a viewer is shipped alongside).
3.2 A single locked file#
One file holding everything:
| Offset | Size | Field |
|---|---|---|
| 0 | 12 | "weirdlock1f\n" |
| 12 | 4 | keyring length k (MUST be ≤ 65 536) |
| 16 | k | the keyring (§4) |
| 16+k | 8 | manifest stream length m (MUST be ≤ CipherSize(16 MiB)) |
| 24+k | m | the manifest stream (kind 0x10) |
| 24+k+m | rest | the file stream (kind 0x11), to the end of the file |
Its manifest has "kind":"file" and exactly one entry, without a
thumbnail; the file stream's id MUST be that entry's id.
4. The keyring#
4.1 Layout#
| Offset | Size | Field |
|---|---|---|
| 0 | 11 | magic "weirdlock1\n" |
| 11 | 1 | version = 0x01 |
| 12 | 1 | suite = 0x01 (§14.1) |
| 13 | 16 | album-id (random) |
| 29 | 16 | manifest-id: the stream id of this album's manifest |
| 45 | 8 | created, Unix seconds |
| 53 | 8 | not-after, Unix seconds, 0 = none (advisory, §12) |
| 61 | 2 | stanza count n, 1 ≤ n ≤ 64 |
| 63 | … | n stanzas, each: type (1) || body length L (2) || body (L ≤ 4096) |
| end−32 | 32 | MAC = HMAC-SHA-256(MACKey, every byte before the MAC) |
The keyring is at most 65 536 bytes. not-after, when non-zero, MUST NOT be earlier than created. There MUST be no bytes between the last stanza and the MAC. At most 8 stanzas may be password stanzas (each costs a KDF run to try).
MACKey = HKDF-SHA-256(IKM = K, salt = album-id, info = "weirdlock1 keyring mac", L = 32)4.2 Stanza types#
| Type | Meaning | Body length |
|---|---|---|
| 0x00 | invalid — refuse (malformed) | |
| 0x01 | password (§5.1) | 81 + hint length |
| 0x02 | link secret (§5.2) | 76 |
| 0x03 | person, X25519 (§5.3) | 100 |
| 0x04 | reserved: owner's Ed25519 signature (§5.4) | any |
| 0x05–0x7F | future ways in | any |
| 0x80–0xFF | critical: a decoder that does not know one MUST refuse the keyring (unsupported) | any |
A decoder MUST check the exact body length of the types it knows (0x01– 0x03) and refuse a mismatch (malformed). It MUST skip types 0x04–0x7F it does not implement: they are ways in it cannot use (they are still covered by the MAC). A future revision that changes how content is decrypted uses a new suite or version, not a stanza.
4.3 Wrapping the album key#
Each stanza wraps the 32-byte album key K under its own 32-byte wrapping key W (derived in §5):
wrapped = AES-256-GCM-Seal(key = W, nonce = the stanza's 12-byte nonce,
plaintext = K, AD = StanzaAD) — 48 bytes
StanzaAD = "weirdlock1 stanza" || album-id || type (1) || body[0 : L−48]body[0 : L−48] is every field of the stanza before the wrapped key (it
ends with the nonce). The AD binds a stanza to its album and its type and
fields (KDF parameters, hint, salt, key id, ephemeral key); it does not
cover the other stanzas, created, not-after or the count, so that adding
or removing a way in needs only K (no other password). Those fields are
covered by the MAC, which is checked as soon as K is known.
Every W is used for exactly one seal (fresh salt or ephemeral key per stanza), so the random nonce is defence in depth, not a requirement.
4.4 Opening (normative order)#
- Parse the whole keyring (§4.1–4.2) before any cryptography. Errors: magic → malformed; version ≠ 1 → unsupported; suite ≠ 1 → unsupported; framing, lengths, count 0, extra bytes, invalid UTF-8 hint, not-after < created → malformed; over a bound → limit; a type ≥ 0x80 → unsupported.
- For each identity the user supplied, in the order supplied, try the stanzas of its type in keyring order (a person key: only stanzas whose key id is its own or zero, §6). The first stanza whose wrapped key opens gives K.
- If none opened: unsupported if at least one stanza of a supplied kind was unusable (an unknown KDF id, or parameters outside §5.1's range), else no-key.
- Verify the MAC with K in constant time (
hmac.Equal,crypto.subtle.verify). Failure → auth; K MUST be discarded. - Only now use K: open the manifest stream with the keyring's manifest-id (§6.2), then files with the ids the manifest names.
The MAC makes K's recovery committing: a crafted stanza that opens under several candidate keys (AES-GCM is not key-committing) yields a K whose MAC fails, and every way in yields the same K (an HMAC tag cannot be made to verify under two keys). So every recipient sees the same content.
5. Ways in#
5.1 Password (type 0x01)#
Body:
| Size | Field |
|---|---|
| 1 | hint length h, 0 ≤ h ≤ 32 |
| h | hint: UTF-8, public (usually empty; the UI warns never to put the password or a clue there) |
| 1 | KDF id: 0x01 scrypt; 0x02 Argon2id (reserved, not in revision 1) |
| 1 | log2 N |
| 1 | r |
| 1 | p |
| 16 | salt (random) |
| 12 | nonce (random) |
| 48 | wrapped K |
P = UTF-8( NFC( password with leading and trailing U+0020, U+0009, U+000A, U+000D removed ) )
W = scrypt(P, salt, N = 2^log2N, r, p, dkLen = 32) (RFC 7914)Revision 1 accepts only KDF 0x01 with 15 ≤ log2 N ≤ 20, r = 8, p = 1 (128·r·N bytes of memory: 32 MiB at 2^15, 128 MiB at the default 2^17, 1 GiB at 2^20). A stanza outside that range is unusable (§4.4 step 3): the floor protects against a writer that chose a weak cost, the ceiling protects decoders' memory. Writers use 2^17 unless the device cannot (then 2^16, with a warning to the owner); the floor is 2^15.
Normalization: NFC so that the same characters typed on different systems
(precomposed or decomposed diacritics, e.g. "ă" as U+0103 or U+0061
U+0306) give the same key; trimming only the four ASCII white-space
characters, so that every implementation trims identically (JavaScript's
trim() and Go's TrimSpace disagree on other white space; neither is
used). An empty P is refused by writers.
5.2 Link secret (type 0x02)#
A link secret L is 32 random bytes. Body: salt (16) || nonce (12) || wrapped K (48).
W = HKDF-SHA-256(IKM = L, salt = salt, info = "weirdlock1 link", L = 32)L travels in a share link's fragment (§12): #k= followed by
base64url(L) without padding (43 characters). Decoders MUST accept exactly
43 characters of the URL-safe alphabet with zero trailing bits.
5.3 Person, X25519 (type 0x03)#
Body: ephemeral public key E (32) || key id (8) || nonce (12) || wrapped K (48). The writer draws a fresh ephemeral private key e per stanza.
shared = X25519(e, R) (writer) = X25519(r, E) (reader)
shared MUST NOT be all zero (a low-order point): refuse to write; the stanza does not open
W = HKDF-SHA-256(IKM = shared, salt = E || R, info = "weirdlock1 x25519", L = 32)
KeyID(R) = first 8 bytes of SHA-256("weirdlock1 key id" || R)R is the recipient's 32-byte X25519 public key, r its private key. The key id is either KeyID(R) or eight zero bytes (hidden, §6).
5.4 Signature (type 0x04, reserved)#
Reserved for an Ed25519 signature by the owner over a commitment to the keyring's fixed fields and the manifest stream, so that person stanzas can carry sender authenticity. Not specified in revision 1; writers MUST NOT emit it; decoders skip it.
6. Key ids and hiding them#
A person stanza's key id lets a decoder holding several keys try only its
own stanzas, and lets anyone check whether a given public key can open the
album (that is what the CLI's lock show reports as "your keys"). It
reveals, to anyone who knows a person's public key, that this person has a
way in. A writer MAY hide it per stanza (eight zero bytes); a decoder then
tries every hidden stanza with every key it holds (one X25519 and one
AES-GCM open per stanza: cheap). With hidden ids, X25519 stanzas reveal
nothing about the recipient (E is fresh and uniformly random-looking).
Hidden stanzas can be removed later only by slot number (the owner cannot
tell whose they are either). The chance of a real key id being all zero
is 2^-64 and is ignored.
7. Streams#
7.1 Layout#
| Offset | Size | Field |
|---|---|---|
| 0 | 9 | "weirdenc2" |
| 9 | 1 | suite = 0x01 |
| 10 | 1 | kind: 0x10 manifest, 0x11 file, 0x12 thumbnail |
| 11 | 16 | stream id (random) |
| 27 | … | segments |
StreamKey = HKDF-SHA-256(IKM = K, salt = album-id || stream id,
info = "weirdlock1 stream" || suite || kind, L = 32)
segment i = AES-256-GCM-Seal(StreamKey, nonce_i, plaintext_i, AD = the 27-byte header)
nonce_i = 0x00 × 7 || i (4 bytes, big-endian) || last (0x01 for the final segment, else 0x00)The plaintext is cut into segments of exactly 65 536 bytes, the final one 1 to 65 536 bytes — or 0 bytes only when the whole plaintext is empty (then there is exactly one, empty, final segment). Each sealed segment is its plaintext plus a 16-byte tag (65 552 bytes for a full one). At most 2^32 segments (256 TiB) per stream.
CipherSize(n) = 27 + n + 16 × max(1, ceil(n / 65536))Decoders MUST:
- check magic (malformed), suite (≠ 1 → unsupported), and that kind and stream id are exactly those expected — the keyring's manifest-id for the manifest, the manifest's entry id for a file or thumbnail — and not merely what the header says (auth). Otherwise a file could be presented under another file's name: its key would derive from its own header and it would decrypt.
- treat a segment as final iff it is the last one in the stream (known from EOF when reading sequentially, from the size when reading by range);
- refuse a final segment shorter than 16 bytes, and an empty final segment after segment 0 (auth) — the full-final-segment encoding is the only one;
- release a segment's plaintext only after its tag verified (§10.1).
The STREAM construction (Hoang, Reyhanitabar, Rogaway, Vizár 2015; as used
by age) makes truncation, extension, reordering, duplication and
dropping of segments fail: each nonce fixes the position, the final flag
fixes the end, the header in the AD fixes the stream.
Stream ids MUST be fresh random values for every stream ever written under a K. Re-encrypting different plaintext under the same K and stream id reuses GCM nonces (catastrophic). Rewrapping (§11) never re-encrypts a stream; re-locking draws a new K.
7.2 Random access#
A byte range [a, b) of a plaintext lies in segments ⌊a/65536⌋ …
⌊(b−1)/65536⌋; segment i starts at ciphertext offset 27 + i × 65 552. A
reader fetches exactly those bytes (one HTTP range request) and the header,
and decrypts each segment with the final flag set iff i is the stream's
last segment. The reader MUST take the stream's total size from
authenticated data — the manifest's stored (§8), through CipherSize —
and check that the served size equals it: a stream truncated at a segment
boundary is detected only through its new final segment, which a range
read may never touch. The size rules give n = ceil((size − 27) / 65552)
segments; a final segment of fewer than 16 bytes, or of exactly 16 bytes
with n > 1, is impossible (auth).
8. The manifest#
The manifest stream's plaintext is one JSON object (RFC 8259, UTF-8):
{"v":1,"kind":"album","title":"Nunta","created":"2026-11-18T12:00:00Z","pad":"none",
"entries":[{"id":"<26-char stream id>","path":"zi1/IMG_0412.jpg","type":"image/jpeg",
"size":4128331,"stored":4128331,"mtime":"2026-06-01T10:00:00Z",
"thumb":{"id":"<26-char stream id>","type":"image/jpeg","width":320,"height":240,"size":18310,"stored":18310}}],
"site":null}| Field | Rule |
|---|---|
v | 1 (another value: unsupported) |
kind | "album" (a folder) or "file" (§3.2, exactly one entry, no thumbnail) |
title | optional, ≤ 1024 bytes |
created | optional, RFC 3339 (informational) |
pad | "none" or "padme" (§8.2); another value: unsupported |
entries | ≤ 100 000 |
entries[].id | stream id of the file (kind 0x11); unique across ids and thumb ids |
entries[].path | §8.1; unique; no path may be a prefix folder of another (a and a/b) |
entries[].type | media type, ≤ 255 bytes, no NUL/CR/LF; may be empty |
entries[].size | the file's length, 0 ≤ size ≤ 2^53 − 1 |
entries[].stored | the stream's plaintext length: size, or Padmé(size) when padded |
entries[].mtime | optional, RFC 3339 |
entries[].thumb | null or an object: id (kind 0x12), type, width, height (1–4096), size, stored |
site | null (reserved for locked sites; non-null: unsupported) |
Strictness (so that parsers cannot differ): decoders MUST refuse a
manifest in which any object key is not made only of lowercase ASCII
letters, digits and _, or appears twice in one object, or that holds more
than one JSON value, or nests deeper than 8 (malformed or limit). They MUST
ignore unknown keys (forward compatibility). Sizes are bounded by 2^53 − 1
so that they survive JavaScript numbers. The plaintext is at most 16 MiB.
A decoder reads a file's stream to its end and MUST check that the stream
holds exactly stored bytes and that bytes size … stored−1 are zero
(auth). Writers emit compact JSON in the field order shown (not required
for decoding).
8.1 Paths#
A path is relative, /-separated, valid UTF-8, 1–4096 bytes; it holds no
control character (U+0000–U+001F, U+007F) and no backslash; no component
is empty, . or .., and none is longer than 255 bytes. Decoders writing
to a file system MUST still confine output to the chosen folder, refuse to
replace existing files unless asked, and expect collisions on
case-insensitive or normalizing file systems (two paths that differ only
in case are valid in the format). Writers SHOULD NOT emit such pairs.
8.2 Padding (optional, off by default)#
With "pad":"padme", each file and thumbnail stream holds its plaintext
followed by zero bytes up to Padmé(size), and the manifest's JSON is
followed by ASCII spaces up to Padmé(its length) (JSON allows trailing
white space). Padmé (Nikitin et al., "Reducing Metadata Leakage from
Encrypted Files and Communication with PURBs", PETS 2019):
Padmé(n) = n if n < 2
E = floor(log2 n); S = floor(log2 E) + 1; z = E − S; mask = 2^z − 1
Padmé(n) = (n + mask) AND NOT maskAt most about 12 % overhead; it leaves O(log log n) bits of each size visible instead of all of them. The number of files stays visible.
9. What remains visible#
To the storage operator and to anyone with the content id:
- that the item is locked (the layout, the magic); its total size, the upload time, the paying account, the hostname; access times and volumes from logs;
- the number of encrypted files (files + thumbnails) and each one's size (plaintext + 16 bytes per 64 KiB + 27; exact unless padded);
- the keyring: version, suite, album id, created, not-after, the number of stanzas and their types, each password's hint and scrypt cost, each person's key id unless hidden;
- the manifest's size (≈ the number of files and the length of their names, unless padded).
Encrypted: file names, folders, types, sizes (when padded), file dates, the title, the contents; and of course every password, link secret, private key and the album key.
10. Rules for implementations#
10.1 Releasing plaintext#
A segment's plaintext MUST NOT be released before its tag verified. A whole-stream failure (truncation, wrong length, non-zero padding) is detected only at the end, so a decoder that streams to a destination MUST treat everything it wrote as provisional until the stream's end authenticated, and remove it on failure (the reference CLI writes to a temporary file and renames it). A viewer playing media from authenticated segments MAY show them before the end, and MUST stop and say the file is damaged when a later segment fails.
10.2 Failure classes#
Every failure on input data is one of: malformed, unsupported, no-key, auth, limit (the test vectors name the class a decoder must report). Users should see two messages at most: "wrong password or key (or the key list was altered)" for no-key, and "damaged or altered" for auth/malformed/limit; unsupported says to update. Implementations MUST NOT tell apart, to anyone but the local user, which stanza failed or why — there is no remote oracle in this format, and none should be added (a viewer never reports failures to a server).
Comparisons of secret-dependent values (the keyring MAC) MUST be constant time; AEAD tag checks are done by the AEAD implementation. Key ids are public and may be compared normally.
10.3 Limits#
| Bound | Value | On excess |
|---|---|---|
| keyring size | 65 536 bytes | limit |
| stanzas | 1–64 | limit (0: malformed) |
| stanza body | 4096 bytes | limit |
| password stanzas | 8 | limit |
| hint | 32 bytes | malformed |
| scrypt log2 N | 15–20, r = 8, p = 1 | stanza unusable |
| manifest plaintext | 16 MiB | limit |
| entries | 100 000 | limit |
| JSON nesting | 8 | limit |
| path / component | 4096 / 255 bytes | malformed |
| size, stored | ≤ 2^53 − 1 | limit |
| segments per stream | 2^32 | auth |
There is no compression anywhere in the format, so no decompression bomb:
every plaintext byte costs a ciphertext byte, and declared sizes are
checked against the streams. A decoder SHOULD check free memory or disk
against size before writing, and a viewer MUST cap in-memory files
(§17.2). Thumbnail decoding (an image decoder in the viewer) is the one
place where a small input can expand; viewers SHOULD decode thumbnails
with the platform's image decoder only and bound the dimensions.
10.4 not-after#
Viewers SHOULD refuse to open after not-after (it is the owner's wish) and say why. Other decoders MAY ignore it and SHOULD report it. It is not a security property (§12).
11. Changing who may open#
Adding a way in (a person, a password, a link, a recovery kit): open the keyring with any way in (K), append a stanza, recompute the MAC, write the new keyring. The manifest and every file stay byte for byte the same. On stored content that means publishing a new folder (new content id: the blocks of the unchanged files are the same) and pointing the hostname at it.
Removing a way in (or changing a password = add the new, remove the old): the same, without the stanza. What removal does not achieve: whoever opened the album before may hold K (a viewer's memory, a saved file, a modified client) and can still decrypt the files, which have not changed; the old keyring still exists wherever a copy of the old version exists (any IPFS node or person that kept it), and still opens with the old password or link. Removing a way in stops new openings through this copy; it is not revocation.
Real revocation = re-lock: a new K, every file encrypted again under
fresh stream ids, a new upload, the hostname pointed at it, the old copy
deleted (which stops serving it, and cannot recall copies others made).
The CLI says this wherever a way in is removed; the commands are
weird storage get <cid> --unlock -o dir then
weird storage add dir --lock ….
12. Link-only sharing and expiry#
A share link is the album's own address with the link secret in the
fragment: https://<album hostname>/#k=<base64url(L)>. Browsers never
send the fragment to a server (not in requests, not in Referer), so the
service never learns it; it is still kept in browser history, synced
bookmarks and chat histories (chat previews fetch the URL without the
fragment and cannot decrypt). A viewer SHOULD remove the fragment from
the address bar after reading it (history.replaceState).
Expiry cannot be cryptographic: the ciphertext is public and immutable, and anyone who saved it and the link can decrypt for ever. What can honestly be offered: (1) not-after in the keyring, honoured by cooperating viewers; (2) the service deleting the content at that date, which stops serving it but cannot recall copies; (3) both. The product's words: "After this date the link stops working on weird. Anyone who already downloaded the album keeps it."
13. Recovery kit#
A recovery kit is an extra link stanza whose secret is given to the owner
instead of being shared, and never uploaded. The reference CLI writes it
as a text file (mode 0600, never overwritten) holding the album id, the
fragment line #k=<base64url(L)>, and the same 32 bytes in RFC 4648
base32 (uppercase, no padding) in groups of four separated by -, after
base32: , for writing down by hand. Either line opens the album.
Anyone holding the kit can open the album.
The owner's own X25519 key (--lock-key) is the other recovery path; its
private key can be exported to a 0600 file (weird storage keys export).
14. Primitives#
14.1 Suite 1#
| Use | Primitive | Parameters | Why |
|---|---|---|---|
| Content | AES-256-GCM in STREAM segments | 64 KiB segments, 96-bit counter nonces, 128-bit tags | native in WebCrypto in every browser and in Go's standard library; hardware-accelerated (video); nonces are counters under a per-stream key, never random draws under one key |
| Key derivation | HKDF-SHA-256 (RFC 5869) | 32-byte outputs, labels per use | native in WebCrypto and Go; domain separation by info |
| Keyring MAC | HMAC-SHA-256 | key from HKDF | native; key-committing (§4.4) |
| Key wrapping | AES-256-GCM | per-stanza W, random nonce | the same primitive again; W is single-use |
| Password KDF | scrypt (RFC 7914) | N = 2^17 (2^15–2^20), r = 8, p = 1 | memory-hard; the CLI's existing choice; an audited JS implementation exists (§14.3) |
| Person | X25519 (RFC 7748) + HKDF | ephemeral-static | native in WebCrypto in current browsers; the CLI's existing key type |
| Key id | SHA-256 | truncated to 64 bits, labelled | public identifier only |
Not chosen: ChaCha20-Poly1305 / XChaCha20 (not in WebCrypto; every byte of video would go through JavaScript); Argon2id (the current password-hashing recommendation, RFC 9106, but not in WebCrypto and only in WASM or slow JS; reserved as KDF id 2); PBKDF2 (native and simple, but not memory-hard: GPUs guess far faster than against scrypt at 128 MiB); AES-GCM-SIV / key-committing AEADs (not in WebCrypto; the keyring MAC gives the commitment where it matters); the age format (reviewed and well specified, but it forbids a password stanza next to others, uses ChaCha20-Poly1305 for the payload, and has no album manifest or per-file random access).
AES-GCM bounds: per stream key at most 2^32 segments (the counter), each far below GCM's 2^39−256-bit message limit; keys are unique per stream (random 128-bit ids under a random K), so the multi-user bounds are those of independent random keys.
14.2 What a browser uses (WebCrypto)#
| Operation | WebCrypto |
|---|---|
| AES-256-GCM seal/open | importKey("raw", k, "AES-GCM"), encrypt/decrypt({name:"AES-GCM", iv, additionalData, tagLength:128}) |
| HKDF-SHA-256 | importKey("raw", ikm, "HKDF"), deriveBits({name:"HKDF", hash:"SHA-256", salt, info}, key, 256) |
| HMAC-SHA-256 verify | importKey("raw", k, {name:"HMAC", hash:"SHA-256"}), verify("HMAC", key, mac, data) (do not compare in JavaScript) |
| SHA-256 | digest("SHA-256", …) |
| X25519 | generateKey/importKey({name:"X25519"}), deriveBits({name:"X25519", public}, priv, 256) — rejects an all-zero result itself; a raw private key is imported as PKCS#8 (302e020100300506032b656e04220420 ‖ 32 bytes) |
| NFC | String.prototype.normalize("NFC") |
| random | crypto.getRandomValues |
Native X25519 in WebCrypto, per MDN's browser-compat data read on
2026-11-18: Chrome 133, Firefox 130, Safari 17 (other sources disagree on
Safari's first version — feature-detect, do not version-check). Fallback:
@noble/curves (x25519), vendored at a pinned version — its README
lists audits by Cure53 (v1.6.0, Sep 2024, scope including "montgomery"),
Trail of Bits (v0.7.3, Feb 2023; and v2.3.0, Aug 2026, "everything") and
Kudelski (v1.2.0, scope not covering x25519). These are the project's own
claims, as its README states them.
14.3 scrypt in browsers#
scrypt is not in WebCrypto. The viewer's memory-hard core (BlockMix and
the ROMix loop) is @noble/hashes 1.8.0's, copied verbatim at a pinned
version and never loaded from a CDN; its two PBKDF2-HMAC-SHA256 steps are
WebCrypto's. The library's README states an audit by Cure53 at v1.0.0
(January 2022) with scope "everything besides blake3, sha3-addons, sha1
and argon2": scrypt is not named and not excluded.
Its default maxmem (1 GiB + 2 KiB) admits log2 N ≤ 20. Its README
reports 0.1 s for N = 2^16 on an Apple M4 and mobile phones 1–4× slower;
N = 2^17 needs 128 MiB; the floor (2^15) bounds the cost on low-memory
phones. scrypt is used because it is memory-hard, widely deployed and has
audited JavaScript; Argon2id would need WASM without an audit that can be
verified; PBKDF2 is rejected for its GPU cost.
14.4 Versioning and agility#
- version (keyring byte 11): a different layout. Decoders refuse versions they do not know (unsupported).
- suite (keyring byte 12, stream byte 9): the content and keyring algorithms. It is in the MAC'd keyring, in every stream's AD and in every stream key's derivation, so changing it on the way (a downgrade) makes the MAC or every segment fail; a decoder refuses an unknown suite before doing work. A suite 2 (for example key-committing or post-quantum) would be a new value, never a reinterpretation.
- KDF id (password stanzas): a new KDF is a new id; parameters are bound by the stanza AD (a lowered cost does not unwrap). A forged stanza with a too-low cost cannot be made without the password; the floor exists to refuse weak writers.
- stanza types: new ways in are new types (skipped by older decoders); anything an old decoder must not ignore uses 0x80–0xFF.
- manifest
v: a new manifest schema.
There is no negotiation and no field that selects a weaker option at decode time: every algorithm choice is fixed by the authenticated bytes.
15. Reserved identifiers#
Reserved and not specified in this revision: Ed25519 owner signatures
(type 0x04); hybrid ML-KEM-768 + X25519 person stanzas (a new type);
Argon2id (KDF 0x02); locked sites (site). A reader that decrypts ranges
for streamed video needs no format change (§7.2 allows it).
16. Test vectors#
testdata/vectors/vectors.json lists the identities (passwords — one
also in decomposed form —, link secrets with their fragments, X25519
private and public keys with key ids) and the vectors. Each vector names
its container (file: a .wlk file; album: a folder), the SHA-256 of
every file, every random value the writer drew in order (so an encryptor
can reproduce the bytes exactly), the inputs, and the cases: which
identity opens it, the expected slot and plaintexts, or the expected
failure class. Positive vectors also give the intermediates: K, album id,
manifest id, MAC key and MAC, the keyring in hex, each stanza's body,
associated data and wrapping key, each stream's key, header, first nonce,
segment count and size, and the manifest plaintext.
Positive: one password (log2 N 15), one password at the default cost with a hint and NFC, one link, one person, one hidden person, all mixed, an empty file, exactly 64 KiB, 64 KiB + 1, three segments, padded, with not-after, an album with a folder, a thumbnail, an empty file and three segments, a padded album; an unknown non-critical stanza that is skipped.
Negative: truncated tail, truncated at a segment boundary, segments swapped, a segment duplicated, a segment dropped, magic, version 2, suite 0, album-id bit (no-key), created bit (auth), MAC bit, wrapped-key bit (no-key), stream id bit, stream suite, stream kind, manifest length, wrong password, scrypt log2 N 14 (unsupported), Argon2id (unsupported), a critical stanza (unsupported), an empty final segment after a full one, non-zero padding, a stream longer than the manifest says, album files swapped, an album file missing, a thumbnail in a file's place, a truncated manifest, another album's manifest.
go test ./weirdlock -run TestVectors -update regenerates them; a plain
go test checks that the writer still produces them byte for byte and
that every case opens or fails as recorded.
17. Notes for the browser viewer (normative where it says MUST)#
17.1 Where it runs#
Only on the album's own hostname — the customer's domain, a free name, or
a per-content hostname <cid>.ipfs.<gateway domain> — never on a path-style shared gateway origin, where every
customer's scripts share one origin. The bootstrap MUST refuse to unlock
on a shared origin and say so. It MUST NOT contact any host but its own
origin (no update check, no analytics, no fonts, no CDN).
17.2 Memory#
scrypt needs 128·r·N bytes for the duration of one KDF run (128 MiB at the
default). Decrypted files are kept in memory as Blobs built from
per-segment chunks (new Blob(chunks)), so peak memory is the file plus
one segment; v1 caps a file shown in memory (default 512 MiB; lower on
phones) and sends larger ones to the CLI (a reader that decrypts ranges,
§7.2, has no such cap). Object URLs are revoked when an
item leaves the screen, and keys dropped on "lock again" and page close.
17.3 Integrity of the viewer#
The viewer is the weakest point (§2.2). Requirements: served from the
album's own folder, a content-addressed release (a published CID,
reproducibly built); the bootstrap loads the script with Subresource
Integrity; a strict Content-Security-Policy in a <meta> (no inline
script other than hashed, connect-src 'self', base-uri 'none',
form-action 'none'); <meta name="referrer" content="no-referrer">;
refuses to run framed; never stores keys or passwords (no
localStorage, IndexedDB, cookies); keys in memory only. The bootstrap
itself can be altered by whoever serves it; careful users open with the
CLI or a locally saved viewer, or compare the served bootstrap's hash with
the published one.
Content integrity does not depend on the gateway: every byte under
lock/ is authenticated by the format. What a server can still do is
serve another album; it cannot make one that opens with the victim's
password or link (that needs the secret), but it can for a person stanza
(anyone can encrypt to a public key; §2.2).
18. Design notes#
- The keyring carries a suite byte and the manifest id, so a manifest of another album or another version of this one is refused.
- A stanza's AD is a label, the album id, the type and its fields: a stanza cannot move between albums.
- Key ids are domain-separated: SHA-256("weirdlock1 key id" ‖ R)[0:8].
- Streams carry a suite byte; stream keys derive with suite and kind; thumbnails have their own kind (0x12); decoders must check the expected id and kind.
- scrypt r and p are fixed (8, 1) in revision 1; only log2 N varies (15–20).
- Password normalization is ASCII trim + NFC.
- The manifest has
pathonly (no separatename),kind,stored, and a thumbnail object instead of a bare id; there are no video posters; keys are strictly lowercase and unique. - A single locked file carries length prefixes and its own manifest stream, so its name and type are encrypted and padding works.
- Unknown stanza types 0x01–0x7F are skipped, 0x80–0xFF refused.
- The signature stanza is reserved, not specified.
- With padding on, the manifest is padded too.
- The recovery kit is a text file.
This page is generated from the weird CLI; it changes when the CLI does.