s365b.storage.crypto¶
Repository cryptography: keys, blob IDs and blob encryption.
Key hierarchy:
A random 64-byte repository key is created when the repository is initialised. Its first half encrypts blobs (AES-256-GCM); its second half keys the BLAKE3 hash that names blobs.
The repository key is stored in the repository config, wrapped (AES-256-GCM) with a key-encryption key derived from the admin’s passphrase using Argon2id.
Blob IDs are a keyed hash of the plaintext, so identical content deduplicates, but someone holding only the repository files cannot test whether a known file is present.
Attributes¶
Exceptions¶
Raised when decryption fails: wrong passphrase, wrong key or tampered data. |
Classes¶
Module Contents¶
- exception s365b.storage.crypto.CryptoError[source]¶
Bases:
ExceptionRaised when decryption fails: wrong passphrase, wrong key or tampered data.
- class s365b.storage.crypto.KdfParams[source]¶
Argon2id parameters used to derive the key-encryption key.
- Variables:
time_cost – Iterations.
memory_kib – Memory in KiB.
parallelism – Lanes.
salt – Random salt, hex-encoded.
- class s365b.storage.crypto.RepoKeys[source]¶
The unwrapped repository key, split into its two uses.
- Variables:
enc_key – AES-256-GCM key for blobs and index files.
id_key – BLAKE3 key for blob IDs.
- wrap(kek: bytes) bytes[source]¶
Encrypt this key with a key-encryption key.
- Parameters:
kek – Key from
KdfParams.derive().- Returns:
nonce || ciphertext.
- classmethod unwrap(wrapped: bytes, kek: bytes) RepoKeys[source]¶
Decrypt a wrapped key.
- Parameters:
wrapped – Output of
wrap().kek – Key-encryption key.
- Returns:
The repository keys.
- Raises:
CryptoError – If the passphrase (and so the KEK) is wrong.
- blob_id(plaintext: bytes) str[source]¶
Compute the content address of a blob.
- Parameters:
plaintext – Uncompressed, unencrypted blob content.
- Returns:
64-character hex ID.