Keeps every at-rest write on the key the store uses. A writer holds a Sealing ticket from
before it reads the vault (or the enabled flag) until its row is written; a migration holds
KeyChange from before its transaction until the vault and the flag show the result. A value
sealed under one key can then never land after the store has moved to another.
AES-256-GCM with a 16-byte nonce and no associated data: the attachment cipher
(0xChat-compatible). A stitched AES-NI/PCLMULQDQ engine where it has been measured
to win, RustCrypto’s ctr + ghash everywhere else; both produce the same bytes.
Attachment AES-256-GCM over a file, a chunk at a time: the cipher of
super::decrypt_data (16-byte nonce, 16-byte tag appended) without the file
ever sitting whole in memory.
How an account’s at-rest key is derived from its PIN or password. Stored as the kdf
settings row, in plaintext since it is needed before the key exists. No row is Legacy: the
fixed salt every account used before per-account salts. A label names a whole parameter set,
so a stored value can never ask for costs this build doesn’t know.
Detect MIME type from file magic bytes.
Supports PNG, JPEG, GIF, WebP, TIFF, ICO, and SVG.
Returns “application/octet-stream” for unrecognized formats.
Every type mime_from_magic_bytes can name.
Wraps opened per vault read, however many a batch holds. It bounds how long the key stays
materialised: two ECDHs per wrap, about 1.5 ms per read on a desktop core.
If bytes is an animated image we must not re-encode, return its extension
("gif"/"webp"/"png"); otherwise None. Biased toward detecting
animation: a false positive only skips stripping/compression, whereas a false
negative would flatten the animation to a still.
Identity basis for a RECEIVED attachment: the sender’s ox (plaintext
hash) when provided — it’s what enables honest cross-message dedup — else
a digest of nonce+url. Never the raw nonce: senders can and do reuse
nonces, which cross-bound DIFFERENT files to one identity (the “new image
renders as an old one” class). The upload URL is unique per ciphertext,
so the digest is collision-resistant even against nonce reuse. Nothing
honest ever writes a file under the digest name, so existence of one is
never proof of download — reuse decisions stay with the content-verified
download path.
Decode an image with allocation limits. A tiny file declaring 60000×60000
would otherwise allocate ~14 GB before a single pixel decodes — every
decode of bytes we didn’t author must go through this.
decrypt_data in place, for a caller that owns the ciphertext: the plaintext
comes back in the same allocation, so nothing the size of the file is copied.
Install the key an unlock derived under kdf, once it proves against this account and the
account still derives that way. Under a key change, so it can’t interleave with an upgrade
another unlock is running: a key derived before that upgrade committed is refused, never
installed over the one the store moved to.
Decrypt a secret key BLOB. Tolerant of the half-migrated DB: a 32-byte value
is a raw (not-yet-wrapped / encryption-off) key, and anything that fails to
authenticate is returned as-is, so a mixed store always reads back correctly.
Opens many at-rest strings for one vault read and one key schedule, where
maybe_decrypt pays both per string (the vault read is nearly all of it). Sync, and the
opener cannot leave the closure, so the key never crosses an await.
Seals many at-rest strings for one vault read, where maybe_encrypt_text pays it per string.
Sync, so the caller’s at-rest ticket covers every seal and the write that follows.