Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

General doc tweaks

Manav Rathi439eb7b8d327
diff --git a/rust/crates/core/src/crypto/argon.rs b/rust/crates/core/src/crypto/argon.rs
index ebede29033..bc3adbab3b 100644
--- a/rust/crates/core/src/crypto/argon.rs
+++ b/rust/crates/core/src/crypto/argon.rs
@@ -105,7 +105,7 @@ impl fmt::Debug for DerivedKey {
/// `params` fall below the accepted minimum or memory is not a multiple of 1024
/// bytes.
///
-/// Wire-compatible with libsodium's `crypto_pwhash` using
+/// Produces the same key as libsodium's `crypto_pwhash` with
/// `crypto_pwhash_ALG_ARGON2ID13`.
pub fn derive_key(password: &str, salt: &Salt, params: Params) -> Result<Key> {
derive_key_impl(password.as_bytes(), salt, params)
diff --git a/rust/crates/core/src/crypto/blob.rs b/rust/crates/core/src/crypto/blob.rs
index 220485b9b2..1518af569b 100644
--- a/rust/crates/core/src/crypto/blob.rs
+++ b/rust/crates/core/src/crypto/blob.rs
@@ -2,8 +2,8 @@
//!
//! A blob is one secretstream message: the data is encrypted and authenticated
//! in a single shot, without the chunking that [`stream`](super::stream) applies
-//! to large file contents. Use it for the small, bounded values attached to an
-//! Ente object, such as file or collection metadata.
+//! to large file contents. Ente uses it for the small, bounded values attached
+//! to an object, such as file or collection metadata.
//! ([`secretbox`](super::secretbox) fills the same single-value role for data
//! not tied to an object.)
//!
@@ -104,10 +104,21 @@ pub fn decrypt(data: &[u8], header: &Header, key: &Key) -> Result<Vec<u8>> {
Ok(plaintext)
}
-/// Decrypt a blob that may not carry the secretstream final tag.
+/// Decrypt a blob that might be missing the secretstream final tag.
///
-/// Prefer [`decrypt`]. This exists as a migration fallback for older data
-/// written without the final tag; it skips the truncation check.
+/// Same as [`decrypt`], but it doesn't require the final tag, so it can't tell
+/// whether the blob was cut short. The MAC still guarantees that whatever it
+/// returns wasn't tampered with. Use this only to read old data written without
+/// the tag; use [`decrypt`] everywhere else.
+///
+/// Affected blobs: Auth's authenticator entities, pre Nov-2025. Locker also
+/// briefly did this, but only in internal builds pre-launch; no public Locker
+/// release was affected.
+///
+/// # Errors
+///
+/// Same as [`decrypt`], except it never returns
+/// [`StreamTruncated`](CryptoError::StreamTruncated).
pub fn decrypt_legacy(data: &[u8], header: &Header, key: &Key) -> Result<Vec<u8>> {
Ok(decrypt_impl(data, header, key)?.0)
}
diff --git a/rust/crates/core/src/crypto/hash.rs b/rust/crates/core/src/crypto/hash.rs
index 187e7faaec..4a9ec109f5 100644
--- a/rust/crates/core/src/crypto/hash.rs
+++ b/rust/crates/core/src/crypto/hash.rs
@@ -6,7 +6,7 @@
//! ([`HashState`]), or straight from a reader ([`hash_reader`]).
//!
//! The construction is libsodium's `crypto_generichash`; the implementation
-//! here wraps the pure-Rust `blake2b_simd` crate and is wire-compatible.
+//! here wraps the pure-Rust `blake2b_simd` crate and produces the same digests.
use blake2b_simd::{Params as Blake2bParams, State as Blake2bState};
use std::io::Read;
@@ -34,15 +34,15 @@ pub const KEY_BYTES_MAX: usize = 64;
/// Hash `data` with BLAKE2b.
///
/// `out_len` chooses the digest length (16 to 64 bytes), defaulting to 32.
-/// Passing a `key` of 16 to 64 bytes computes a keyed hash, that is a MAC;
-/// `None` or an empty key hashes without one.
+/// Passing a `key` of 16 to 64 bytes computes a keyed hash (a MAC); `None` or
+/// an empty key hashes without one.
///
/// # Errors
///
/// Returns [`InvalidKeyLength`](CryptoError::InvalidKeyLength) if `out_len` is
/// outside 16 to 64 bytes, or if a non-empty `key` is outside that range.
///
-/// Wire-compatible with libsodium's `crypto_generichash`.
+/// Produces the same digest as libsodium's `crypto_generichash`.
pub fn hash(data: &[u8], out_len: Option<usize>, key: Option<&[u8]>) -> Result<Vec<u8>> {
let out_len = out_len.unwrap_or(HASH_BYTES);
diff --git a/rust/crates/core/src/crypto/kdf.rs b/rust/crates/core/src/crypto/kdf.rs
index d24427d9a7..54869649cd 100644
--- a/rust/crates/core/src/crypto/kdf.rs
+++ b/rust/crates/core/src/crypto/kdf.rs
@@ -8,8 +8,8 @@
//! Unlike [`argon`](super::argon), the input must already be high-entropy (a
//! key, not a password): this is fast keyed hashing, not password stretching.
//!
-//! The construction is libsodium's `crypto_kdf_derive_from_key`; the
-//! implementation here is pure Rust but wire-compatible.
+//! The construction is libsodium's `crypto_kdf_derive_from_key`; this pure-Rust
+//! implementation derives the same subkeys.
use blake2b_simd::Params as Blake2bParams;
@@ -56,7 +56,7 @@ pub const LOGIN_SUBKEY_CONTEXT: &[u8; CONTEXT_BYTES] = b"loginctx";
/// Returns [`InvalidKeyLength`](crate::crypto::CryptoError::InvalidKeyLength) if
/// `subkey_len` is outside 16 to 64 bytes.
///
-/// Wire-compatible with libsodium's `crypto_kdf_derive_from_key`.
+/// Produces the same subkey as libsodium's `crypto_kdf_derive_from_key`.
pub fn derive_subkey(
key: &Key,
subkey_len: usize,
diff --git a/rust/crates/core/src/crypto/mod.rs b/rust/crates/core/src/crypto/mod.rs
index 5190bdab52..51ec1523f5 100644
--- a/rust/crates/core/src/crypto/mod.rs
+++ b/rust/crates/core/src/crypto/mod.rs
@@ -1,4 +1,4 @@
-//! Cryptographic utilities for Ente.
+//! Cryptographic primitives for Ente.
//!
//! This module provides all the cryptographic primitives used by Ente clients.
//!
diff --git a/rust/crates/core/src/crypto/secretbox.rs b/rust/crates/core/src/crypto/secretbox.rs
index 6f9213a65d..f763adea2c 100644
--- a/rust/crates/core/src/crypto/secretbox.rs
+++ b/rust/crates/core/src/crypto/secretbox.rs
@@ -2,9 +2,9 @@
//!
//! SecretBox encrypts and authenticates a single, self-contained value under a
//! 256-bit key. It suits small, independent pieces of data such as a wrapped
-//! key or a short field. For data attached to an Ente object (file or
-//! collection metadata and the like) prefer [`blob`](super::blob), and for file
-//! contents, which are encrypted in chunks, use [`stream`](super::stream).
+//! key or a short field. Ente uses [`blob`](super::blob) for data attached to
+//! an object (file or collection metadata and the like), and
+//! [`stream`](super::stream) for file contents, which are encrypted in chunks.
//!
//! The name comes from libsodium, which exposes this same construction as
//! `crypto_secretbox`; the implementation here is pure Rust but wire-compatible
diff --git a/rust/crates/core/src/crypto/stream.rs b/rust/crates/core/src/crypto/stream.rs
index e4d6c910d8..93ac2734f9 100644
--- a/rust/crates/core/src/crypto/stream.rs
+++ b/rust/crates/core/src/crypto/stream.rs
@@ -497,10 +497,9 @@ impl<R: Read> StreamingDecryptor<R> {
/// Encrypt everything from `reader` to `writer`, returning the decryption
/// header.
///
-/// The header is not written to the writer; it travels separately (for
-/// instance, in the file's server-side metadata). The ciphertext is the chunk
-/// stream described at the module level, byte-for-byte the same as a
-/// [`StreamingEncryptor`] produces; predict its size with
+/// The header is not written to the `writer` but is returned; store or send
+/// it separately (for instance, in the file's server-side metadata). Only the
+/// encrypted chunks are written, and you can predict their total length with
/// [`estimate_encrypted_size`].
///
/// Reuses buffers and encrypts in place, so memory stays bounded to about twice