Expand description
Asset and metadata encryption — the only place AES-256-GCM is invoked for user data.
Three constructions (SSoT: Cryptography — Encryption):
stream— AES-256-GCM STREAM for asset bytes (originals + derivatives), supporting streaming, ranged reads, and per-chunk authentication.blob— standalone AES-256-GCM with a fixed wire format for small metadata blobs.keywrap—asset-keywrap/v1seal/unseal for an externally-chosen file key carried underkey_mode = wrapped(an adopted web-upload drop).rekey— the re-keying writers that fold a fresh nonce into the key salt and refuse to reuse the nonce they supersede (a same-epochreplace/metadata-update).
Structs§
- Asset
Encryption - Result of encrypting an asset: everything the signed manifest commits to.
- Ciphertext
Reader - Random-access re-derivation of a STREAM ciphertext from its plaintext.
- Stream
Decryptor - Incremental STREAM decryption of a ciphertext that arrives in pieces of any size.
Enums§
- Rekey
Stream Error - Why a streaming re-keyed write failed: the reuse refusal, or the reader or writer.
- Stream
Error - Errors from streaming encrypt/decrypt.
Constants§
- CIPHERTEXT_
CHUNK - Ciphertext bytes per full STREAM chunk (plaintext chunk + 16-byte GCM tag = 64 KiB).
- MIN_
BLOB_ LEN - Minimum valid blob length: header + nonce + empty ciphertext + tag.
- NONCE_
LEN - Length of the per-blob AES-256-GCM nonce (fresh CSPRNG draw per seal).
- NONCE_
PREFIX_ LEN - STREAM nonce prefix length (12-byte nonce − 4-byte counter − 1-byte last flag).
- PLAINTEXT_
CHUNK - Plaintext bytes per STREAM chunk.
- TAG_LEN
- GCM authentication tag length.
- WRAPPED_
FILE_ KEY_ LEN - Length of the wrapped file key:
wrap_nonce(12) ‖ ciphertext(32) ‖ tag(16). - WRAP_
NONCE_ LEN - Length of the fresh per-wrap nonce (the AES-256-GCM nonce for the wrap).
Functions§
- blob_
ciphertext_ hash - The content hash of a metadata blob: SHA-256 over the full wire byte string (header ‖ nonce ‖ ciphertext ‖ tag). This is the value the manifest commits to.
- blob_
nonce - The 12-byte nonce a blob carries in its header, needed to re-derive the folded
blob_keybefore opening.Noneif the wire is shorter than the fixed prefix. - blob_
suite_ id - The
crypto_suite_iddeclared in a blob’s header, without decrypting. - chunk_
count - The number of STREAM chunks a
plaintext_size-byte plaintext encrypts to. An empty plaintext is still one (empty, last) chunk: its ciphertext is a bare tag. - ciphertext_
len - The exact ciphertext length a
plaintext_size-byte plaintext encrypts to: the plaintext plus oneTAG_LENtag per chunk. - decrypt_
asset - Decrypt a STREAM ciphertext from
readertowriter. Every chunk’s tag is verified; any tamper/truncation/reorder yieldsStreamError::Auth. - decrypt_
asset_ vec - Convenience: decrypt a whole ciphertext slice in memory.
- decrypt_
chunk - Decrypt a single ciphertext chunk in isolation (ranged read).
indexis the 0-based chunk number;is_lastmust be true only for the final chunk of the file (it carries the STREAM last-block flag). Returnscrate::crypto::CryptoError::Authon tamper. - encrypt_
asset - Encrypt
readertowriterunderfile_key, returning the content metadata. Computes the ciphertext hash incrementally — the whole file is never buffered. Draws a fresh random nonce prefix. - encrypt_
asset_ rekey - Encrypt
plaintextas a first or re-rolled asset write underamkscoped tofile_id: draw a freshnonce_prefix, fold it into the file-key salt, and STREAM-encrypt. - encrypt_
asset_ rekey_ stream encrypt_asset_rekeyfrom a reader to a writer, one STREAM chunk at a time: the same prefix draw, key fold and reuse refusal, without the plaintext or the ciphertext ever being whole in memory. Returns theAssetEncryptionmetadata (whoseciphertext_hashis computed as the chunks pass) and the derived file key.- encrypt_
asset_ rekey_ stream_ with_ prefix encrypt_asset_rekey_streamwith an explicitnonce_prefix— the one implementation of the fold and the reuse refusal, whichencrypt_asset_rekey_with_prefixdrives over a slice, so the two cannot produce different bytes.- encrypt_
asset_ rekey_ with_ prefix encrypt_asset_rekeywith an explicitnonce_prefix— the deterministic, testable core of the fold and the reuse refusal.- encrypt_
asset_ vec - Convenience: encrypt a whole slice in memory, returning (metadata, ciphertext).
- encrypt_
asset_ vec_ full - Convenience: encrypt a whole slice in memory and also return the ciphertext bytes.
- encrypt_
asset_ vec_ with_ prefix - Convenience: encrypt a whole slice in memory with an explicit prefix (deterministic).
- encrypt_
asset_ with_ prefix - As
encrypt_assetbut with an explicit nonce prefix, so a client can regenerate the exact ciphertext from the plaintext + file key + the prefix recorded in the manifest (the client stores plaintext locally; ciphertext is derived for upload/backup). - encrypt_
chunk - Encrypt a single plaintext chunk in isolation: the inverse of
decrypt_chunk, and byte-identical to chunkindexofencrypt_asset_with_prefix’s output for the same key and prefix.pt_chunkmust bePLAINTEXT_CHUNKbytes unlessis_last. - open_
blob - Open a metadata-blob wire string under
blob_key. Rejects an unknowncrypto_suite_id(fail-closed) before attempting decryption, and rejects tampered ciphertext. - recover_
file_ key - Recover the file key of the original a manifest describes, honouring its
key_mode. - recover_
file_ key_ parts recover_file_keyover the manifest fields it reads, for a reader that holds those fields but not the manifest: the share viewer, which is served an asset’s key-free crypto parameters and never its signed manifest (that would carry the device and account ids the export strip removes). Same dispatch and the same fail-closed errors.- seal_
blob - Seal
plaintext(canonical CBOR) into the metadata-blob wire format underblob_key, tagging it with the currentcrypto_suite_id. A fresh nonce is drawn per call. - seal_
blob_ with_ nonce seal_blobwith an explicitnonce, so a metadata-blob writer can fold that same nonce into the derivedblob_keysalt before sealing (the salt depends on the nonce).- seal_
file_ key - Seal an externally-chosen 32-byte file key
Kunderamk, scoped tofile_id. - seal_
metadata_ blob - Seal
plaintext(canonical CBOR sidecar) into a metadata blob underamkscoped toblob_id: draw a fresh blobnonce, fold it into the blob-key salt, and AEAD-seal. - seal_
metadata_ blob_ with_ nonce seal_metadata_blobwith an explicitnonce— the deterministic, testable core.- unseal_
file_ key - Recover the file key
Kfrom awrapped_file_keyunderamk, scoped tofile_id.