Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remove the no-op crypto init and the stale docs folder

Manav Rathi3e0f377288ce
diff --git a/rust/apps/cli/src/auth_flow.rs b/rust/apps/cli/src/auth_flow.rs
index d6e76adf8c..4b9de46d45 100644
--- a/rust/apps/cli/src/auth_flow.rs
+++ b/rust/apps/cli/src/auth_flow.rs
@@ -303,7 +303,6 @@ where
#[cfg(test)]
mod tests {
use super::*;
- use ente_core::crypto;
use mockito::{Matcher, Server};
use serde::{Deserialize, de::DeserializeOwned};
use sha2::{Digest, Sha256};
@@ -429,8 +428,6 @@ mod tests {
#[tokio::test]
async fn create_account_persists_token_for_setup_two_factor() {
- crypto::init().unwrap();
-
let email = "[email protected]";
let encoded_email = urlencoding::encode(email).into_owned();
let signup_token_bytes = b"signup-session-token";
diff --git a/rust/apps/cli/src/commands/export.rs b/rust/apps/cli/src/commands/export.rs
index ea361da9d3..857bc82b77 100644
--- a/rust/apps/cli/src/commands/export.rs
+++ b/rust/apps/cli/src/commands/export.rs
@@ -99,8 +99,6 @@ async fn load_album_metadata(
pub async fn run_export(account_email: Option<String>, filter: ExportFilter) -> Result<()> {
// Initialize crypto
- crypto::init()?;
-
// Open database
let config_dir = crate::utils::get_cli_config_dir()?;
let db_path = config_dir.join("ente.db");
diff --git a/rust/apps/cli/src/commands/paste.rs b/rust/apps/cli/src/commands/paste.rs
index 661f8a3ed5..4de432628f 100644
--- a/rust/apps/cli/src/commands/paste.rs
+++ b/rust/apps/cli/src/commands/paste.rs
@@ -662,8 +662,6 @@ mod tests {
#[test]
fn encrypt_then_decrypt_paste_payload() {
- crypto::init().unwrap();
-
let (paste_key, payload) = encrypt_paste_for_create("hello paste", None).unwrap();
let text = decrypt_consumed_paste(&paste_key, None, &payload).unwrap();
@@ -674,8 +672,6 @@ mod tests {
#[test]
fn encrypt_then_decrypt_password_protected_paste_payload() {
- crypto::init().unwrap();
-
let (paste_key, payload) =
encrypt_paste_for_create("protected paste", Some("correct horse")).unwrap();
let text = decrypt_consumed_paste(&paste_key, Some("correct horse"), &payload).unwrap();
@@ -693,8 +689,6 @@ mod tests {
#[test]
fn reject_wrong_paste_password() {
- crypto::init().unwrap();
-
let (paste_key, payload) =
encrypt_paste_for_create("protected paste", Some("correct horse")).unwrap();
let error = decrypt_consumed_paste(&paste_key, Some("wrong horse"), &payload).unwrap_err();
@@ -704,8 +698,6 @@ mod tests {
#[test]
fn reject_wrong_env_paste_password() {
- crypto::init().unwrap();
-
let (paste_key, payload) =
encrypt_paste_for_create("protected paste", Some("correct horse")).unwrap();
let error = decrypt_password_protected_paste(
@@ -720,8 +712,6 @@ mod tests {
#[test]
fn prompted_password_retry_can_recover() {
- crypto::init().unwrap();
-
let (paste_key, payload) =
encrypt_paste_for_create("protected paste", Some("correct horse")).unwrap();
let mut retry_passwords = ["correct horse"].into_iter();
@@ -739,8 +729,6 @@ mod tests {
#[test]
fn prompted_password_retry_ignores_empty_password() {
- crypto::init().unwrap();
-
let (paste_key, payload) =
encrypt_paste_for_create("protected paste", Some("correct horse")).unwrap();
let mut retry_passwords = ["", "correct horse"].into_iter();
@@ -758,8 +746,6 @@ mod tests {
#[test]
fn prompted_password_retry_does_not_hide_structural_payload_errors() {
- crypto::init().unwrap();
-
let (paste_key, mut payload) =
encrypt_paste_for_create("protected paste", Some("correct horse")).unwrap();
payload.kdf_nonce = "not base64".to_string();
@@ -781,8 +767,6 @@ mod tests {
#[test]
fn prompted_password_retry_does_not_hide_wrapped_key_payload_errors() {
- crypto::init().unwrap();
-
let (paste_key, mut payload) =
encrypt_paste_for_create("protected paste", Some("correct horse")).unwrap();
payload.encrypted_paste_key = "not base64".to_string();
@@ -875,8 +859,6 @@ mod tests {
#[tokio::test]
async fn consume_paste_uses_guard_cookie_and_decrypts_payload() {
- crypto::init().unwrap();
-
let access_token = "ABC123";
let paste_key = PasteKey::parse("AbCd1234EfGh").unwrap();
let payload = test_payload("guarded paste", &paste_key, None);
@@ -916,8 +898,6 @@ mod tests {
#[tokio::test]
async fn password_paste_refreshes_guard_after_password_resolution() {
- crypto::init().unwrap();
-
let access_token = "ABC123";
let paste_key = PasteKey::parse("p-AbCd1234EfGh").unwrap();
let payload = test_payload("guarded paste", &paste_key, Some("correct horse"));
diff --git a/rust/apps/cli/src/commands/sync.rs b/rust/apps/cli/src/commands/sync.rs
index 99daaa7eaf..126f447476 100644
--- a/rust/apps/cli/src/commands/sync.rs
+++ b/rust/apps/cli/src/commands/sync.rs
@@ -15,8 +15,6 @@ pub async fn run_sync(
full_sync: bool,
) -> Result<()> {
// Initialize crypto
- crypto::init()?;
-
// Open database
let config_dir = crate::utils::get_cli_config_dir()?;
let db_path = config_dir.join("ente.db");
diff --git a/rust/apps/cli/src/main.rs b/rust/apps/cli/src/main.rs
index 00d799f392..305ac7c881 100644
--- a/rust/apps/cli/src/main.rs
+++ b/rust/apps/cli/src/main.rs
@@ -17,8 +17,6 @@ async fn main() {
async fn run() -> Result<()> {
env_logger::init();
- ente_core::crypto::init()?;
-
let config_dir = ente_rs::utils::get_cli_config_dir()?;
let db_path = config_dir.join("ente.db");
let storage = Storage::new(&db_path)?;
diff --git a/rust/apps/ensu/src-tauri/src/commands.rs b/rust/apps/ensu/src-tauri/src/commands.rs
index 6354c076d1..81ac774511 100644
--- a/rust/apps/ensu/src-tauri/src/commands.rs
+++ b/rust/apps/ensu/src-tauri/src/commands.rs
@@ -467,7 +467,9 @@ pub struct CryptoBlobDecryptInput {
#[tauri::command]
pub fn crypto_init() -> Result<(), ApiError> {
- core_crypto::init().map_err(ApiError::from)
+ // No-op, kept only for frontend compatibility: the pure-Rust crypto
+ // needs no initialization.
+ Ok(())
}
#[tauri::command]
diff --git a/rust/bindings/uniffi/core/src/lib.rs b/rust/bindings/uniffi/core/src/lib.rs
index f70907f25d..cd78293f88 100644
--- a/rust/bindings/uniffi/core/src/lib.rs
+++ b/rust/bindings/uniffi/core/src/lib.rs
@@ -145,9 +145,9 @@ fn verify_srp_m2(session: &auth::SrpSession, srp_m2_b64: &str) -> Result<(), Ens
}
pub fn init_crypto() -> Result<(), EnsuError> {
- crypto::init().map_err(|e| EnsuError::Message {
- reason: e.to_string(),
- })
+ // No-op, kept only for binding compatibility: the pure-Rust crypto needs
+ // no initialization.
+ Ok(())
}
pub fn srp_start(
diff --git a/rust/bindings/wasm/ente-wasm/src/crypto.rs b/rust/bindings/wasm/ente-wasm/src/crypto.rs
index e8a56fbc3a..b33e55ae8e 100644
--- a/rust/bindings/wasm/ente-wasm/src/crypto.rs
+++ b/rust/bindings/wasm/ente-wasm/src/crypto.rs
@@ -65,13 +65,13 @@ impl From<core_crypto::CryptoError> for CryptoError {
}
}
-/// Initialize the crypto backend.
+/// No-op, kept only for binding compatibility.
///
-/// This is a no-op for the pure-Rust implementation, but is provided for API
-/// symmetry with other platforms.
+/// The pure-Rust crypto needs no initialization; existing web callers invoke
+/// this before using the other functions. Remove once the web callers drop it.
#[wasm_bindgen]
pub fn crypto_init() -> Result<(), CryptoError> {
- core_crypto::init().map_err(Into::into)
+ Ok(())
}
/// Generate a random 32-byte SecretBox key and return it as base64.
diff --git a/rust/crates/accounts/src/flow.rs b/rust/crates/accounts/src/flow.rs
index 37741b9912..53eea00fd6 100644
--- a/rust/crates/accounts/src/flow.rs
+++ b/rust/crates/accounts/src/flow.rs
@@ -307,8 +307,6 @@ where
/// Login to an existing account.
pub async fn login(&mut self, params: LoginParams) -> Result<AuthenticatedAccount> {
- crypto::init()?;
-
let srp_attrs = self.client.get_srp_attributes(&params.email).await?;
let (auth_response, kek) = if srp_attrs.is_email_mfa_enabled {
@@ -343,8 +341,6 @@ where
&mut self,
params: SetupTwoFactorParams,
) -> Result<SetupTwoFactorResult> {
- crypto::init()?;
-
let key_attributes = if let Some(key_attributes) = params.key_attributes {
key_attributes
} else {
@@ -393,8 +389,6 @@ where
&self,
params: ChangePasswordParams,
) -> Result<ChangePasswordResult> {
- crypto::init()?;
-
let (updated_key_attributes_core, _) = auth::generate_key_attributes_for_new_password(
&params.master_key,
&to_core_key_attributes(&params.key_attributes),
@@ -638,8 +632,6 @@ where
params: CreateAccountParams,
key_derivation_strength: KeyDerivationStrength,
) -> Result<AuthenticatedAccount> {
- crypto::init()?;
-
let email = params.email;
let password = params.password;
@@ -1252,8 +1244,6 @@ mod tests {
#[tokio::test]
async fn login_with_email_mfa_and_totp_decrypts_account() {
- crypto::init().unwrap();
-
let password = "hunter2";
let (key_attributes, encrypted_token, recovery_key, _, _) =
build_login_response(password, "plain-auth-token");
@@ -1342,8 +1332,6 @@ mod tests {
#[tokio::test]
async fn login_with_email_mfa_treats_429_as_terminal_error() {
- crypto::init().unwrap();
-
let password = "hunter2";
let key_gen =
auth::generate_keys_with_strength(password, auth::KeyDerivationStrength::Interactive)
@@ -1419,8 +1407,6 @@ mod tests {
#[tokio::test]
async fn login_with_totp_treats_404_as_expired_session() {
- crypto::init().unwrap();
-
let password = "hunter2";
let key_gen =
auth::generate_keys_with_strength(password, auth::KeyDerivationStrength::Interactive)
@@ -1507,8 +1493,6 @@ mod tests {
#[tokio::test]
async fn login_with_totp_treats_429_as_terminal_error() {
- crypto::init().unwrap();
-
let password = "hunter2";
let key_gen =
auth::generate_keys_with_strength(password, auth::KeyDerivationStrength::Interactive)
@@ -1599,8 +1583,6 @@ mod tests {
#[tokio::test]
async fn setup_two_factor_encrypts_secret_with_recovery_key() {
- crypto::init().unwrap();
-
let password = "pw";
let key_gen =
auth::generate_keys_with_strength(password, auth::KeyDerivationStrength::Interactive)
@@ -1659,8 +1641,6 @@ mod tests {
#[tokio::test]
async fn configure_passkey_recovery_accepts_hex_recovery_key() {
- crypto::init().unwrap();
-
let key_gen =
auth::generate_keys_with_strength("pw", auth::KeyDerivationStrength::Interactive)
.unwrap();
@@ -1704,8 +1684,6 @@ mod tests {
#[tokio::test]
async fn login_with_passkey_treats_404_as_expired_session() {
- crypto::init().unwrap();
-
let password = "hunter2";
let key_gen =
auth::generate_keys_with_strength(password, auth::KeyDerivationStrength::Interactive)
@@ -1797,8 +1775,6 @@ mod tests {
#[tokio::test]
async fn create_account_uploads_keys_and_completes_srp_setup() {
- crypto::init().unwrap();
-
let email = "[email protected]";
let encoded_email = urlencoding::encode(email).into_owned();
let signup_token_bytes = b"signup-session-token";
@@ -2021,8 +1997,6 @@ mod tests {
#[tokio::test]
async fn change_password_updates_srp_and_keys() {
- crypto::init().unwrap();
-
let original = auth::generate_keys_with_strength(
"old-password",
auth::KeyDerivationStrength::Interactive,
diff --git a/rust/crates/core/README.md b/rust/crates/core/README.md
index 854cc47873..32542a21b9 100644
--- a/rust/crates/core/README.md
+++ b/rust/crates/core/README.md
@@ -9,6 +9,7 @@ Common Rust code for Ente apps.
| `auth` | Authentication helpers (signup/login/recovery, SRP credentials) |
| `crypto` | Cryptographic utilities (pure Rust, libsodium-wire-compatible) |
| `http` | HTTP client for Ente API |
+| `io` | I/O adapters (e.g. single-pass MD5 of written data) |
| `urls` | URL construction utilities |
## Auth
@@ -20,11 +21,12 @@ High-level authentication helpers for Ente clients:
- Signup key generation
- Account recovery
-πŸ“– **[Full Auth Docs](docs/auth.md)**
-
## Crypto
-Pure Rust cryptography, byte-compatible with JS/Dart clients.
+Pure Rust cryptography, byte-compatible with JS/Dart clients. Key material is
+typed (`Key`, `Nonce`, `Salt`, `Header`, `PublicKey`, `SecretKey`), so sizes
+are validated once at the boundary where raw bytes enter, and secret types
+zeroize on drop.
| Submodule | Algorithm | Use Case |
| ----------- | -------------------------- | -------------------------------- |
@@ -35,18 +37,13 @@ Pure Rust cryptography, byte-compatible with JS/Dart clients.
| `argon` | Argon2id | Password-based key derivation |
| `kdf` | BLAKE2b | Subkey derivation |
| `hash` | BLAKE2b | Cryptographic hashing |
-| `keys` | - | Key generation |
### Quick Start
```rust
-use ente_core::crypto;
-
-crypto::init().unwrap();
+use ente_core::crypto::{Key, secretbox};
-let key = crypto::keys::generate_key();
-let encrypted = crypto::secretbox::encrypt(b"Hello", &key).unwrap();
-let decrypted = crypto::secretbox::decrypt_box(&encrypted, &key).unwrap();
+let key = Key::generate();
+let encrypted = secretbox::encrypt(b"Hello", &key);
+let decrypted = encrypted.decrypt(&key).unwrap();
```
-
-πŸ“– **[Full Crypto Docs](docs/crypto.md)**
diff --git a/rust/crates/core/docs/auth.md b/rust/crates/core/docs/auth.md
deleted file mode 100644
index aa686d3048..0000000000
--- a/rust/crates/core/docs/auth.md
+++ /dev/null
@@ -1,305 +0,0 @@
-# Auth Module
-
-The `auth` module provides high-level authentication operations for Ente clients. It handles:
-
-- **Login**: Password verification via SRP or email MFA
-- **Signup**: Key generation for new accounts
-- **Recovery**: Account recovery with recovery key
-- **SRP Login**: Client-side SRP exchange using derived credentials
-
-SRP protocol exchange is orchestrated in the application layer (HTTP calls), but `ente-core` provides `SrpSession` (behind the `srp` feature) to compute SRP proofs and verify the server response. This module provides credential derivation, SRP session helpers, and secret decryption.
-
-## Architecture
-
-```
-β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-β”‚ Application Layer (CLI/GUI) β”‚
-β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-β”‚ β€’ User interaction (prompts, passwords) β”‚
-β”‚ β€’ HTTP API calls (send OTP, verify email, SRP sessions) β”‚
-β”‚ β€’ State management (storage, accounts) β”‚
-β”‚ β€’ Flow orchestration (which auth method, retry logic) β”‚
-β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
- β”‚ calls
-β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-β”‚ ente-core/auth (This Module) β”‚
-β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
-β”‚ β€’ derive_srp_credentials() - Password β†’ KEK + login key β”‚
-β”‚ β€’ SrpSession - SRP proofs (A/M1/M2) β”‚
-β”‚ β€’ derive_kek() - Password β†’ KEK only β”‚
-β”‚ β€’ decrypt_secrets() - KEK β†’ master key, secret key, tokenβ”‚
-β”‚ β€’ generate_keys() - Signup key generation β”‚
-β”‚ β€’ recover_with_key() - Recovery key β†’ keys β”‚
-β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
-```
-
-## Authentication Flows
-
-### Flow 1: SRP Login (Email MFA Disabled)
-
-```
-User App Server ente-core
- β”‚ β”‚ β”‚ β”‚
- β”‚ Enter password ──────►│ β”‚ β”‚
- β”‚ β”‚ get_srp_attributes ───►│ β”‚
- β”‚ │◄─── srp_attrs ─────────│ β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ derive_srp_credentials(password, srp_attrs) ─►│
- β”‚ │◄──────── (login_key, kek) ───────────────────│
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ SrpSession::new(...).public_a() β”‚
- β”‚ β”‚ create_srp_session(a_pub) ──►│ β”‚
- β”‚ │◄─── session_id, srp_b ─│ β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ SrpSession::compute_m1(srp_b) β”‚
- β”‚ β”‚ verify_srp_session(m1) β–Ίβ”‚ β”‚
- β”‚ │◄── auth_response ──────│ β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ [If 2FA required: TOTP/Passkey flow] β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ decrypt_secrets(kek, key_attrs, token) ─────►│
- β”‚ │◄────────── DecryptedSecrets ─────────────────│
- β”‚ β”‚ β”‚ β”‚
- │◄── Login success ─────│ β”‚ β”‚
-```
-
-### Flow 2: Email MFA Login (Email MFA Enabled)
-
-```
-User App Server ente-core
- β”‚ β”‚ β”‚ β”‚
- β”‚ Enter email ─────────►│ β”‚ β”‚
- β”‚ β”‚ get_srp_attributes ───►│ β”‚
- β”‚ │◄─ is_email_mfa: true ──│ β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ Enter password ──────►│ (store for later) β”‚ β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ send_otp(email) ──────►│ β”‚
- β”‚ │◄─── OK ────────────────│ β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ Enter OTP ──────────►│ β”‚ β”‚
- β”‚ β”‚ verify_email(otp) ────►│ β”‚
- β”‚ │◄── auth_response ──────│ β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ [If 2FA required: TOTP/Passkey flow] β”‚
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ derive_kek(password, kek_salt, ...) ────────►│
- β”‚ │◄─────────────────────────────── kek ──────────│
- β”‚ β”‚ β”‚ β”‚
- β”‚ β”‚ decrypt_secrets(kek, key_attrs, token) ─────►│
- β”‚ │◄────────── DecryptedSecrets ─────────────────│
- β”‚ β”‚ β”‚ β”‚
- │◄── Login success ─────│ β”‚ β”‚
-```
-
-## API Reference
-
-### Types
-
-#### `SrpAttributes`
-
-Server-provided attributes for SRP authentication.
-
-```rust
-pub struct SrpAttributes {
- pub srp_user_id: String, // UUID for SRP identity
- pub srp_salt: String, // Base64-encoded salt
- pub mem_limit: u32, // Argon2 memory limit
- pub ops_limit: u32, // Argon2 ops limit
- pub kek_salt: String, // Base64-encoded KEK salt
- pub is_email_mfa_enabled: bool,
-}
-```
-
-If `is_email_mfa_enabled` is missing, clients should fall back to the email OTP flow for safety (matching mobile/web behavior).
-
-#### `KeyAttributes`
-
-Server-provided encrypted key material.
-
-```rust
-pub struct KeyAttributes {
- pub kek_salt: String, // Salt for KEK derivation
- pub encrypted_key: String, // Master key encrypted with KEK
- pub key_decryption_nonce: String, // Nonce for master key
- pub public_key: String, // X25519 public key
- pub encrypted_secret_key: String, // Secret key encrypted with master key
- pub secret_key_decryption_nonce: String, // Nonce for secret key
- pub mem_limit: Option<u32>, // Argon2 memory limit
- pub ops_limit: Option<u32>, // Argon2 ops limit
- // ... recovery key fields (optional)
-}
-```
-
-#### `SrpCredentials`
-
-Derived credentials for SRP authentication.
-
-```rust
-pub struct SrpCredentials {
- pub kek: SecretVec, // Key encryption key (32 bytes)
- pub login_key: SecretVec, // SRP password (16 bytes)
-}
-```
-
-#### `SrpSession`
-
-Client-side SRP helper (requires the `srp` feature). It pads public values to the 4096-bit group length and derives proofs as:
-
-- `M1 = H(A | B | S)`
-- `K = H(S)`
-- `M2 = H(A | M1 | K)`
-
-```rust
-let mut session = auth::SrpSession::new(srp_user_id, &srp_salt, &login_key)?;
-let a_pub = session.public_a();
-let m1 = session.compute_m1(&srp_b)?;
-session.verify_m2(&srp_m2)?; // optional
-```
-
-#### `DecryptedSecrets`
-
-Result of successful decryption.
-
-```rust
-pub struct DecryptedSecrets {
- pub master_key: SecretVec, // For data encryption
- pub secret_key: SecretVec, // X25519 private key
- pub token: SecretVec, // Auth token
-}
-```
-
-### Functions
-
-#### `derive_srp_credentials`
-
-Derive both KEK and login key from password.
-
-```rust
-pub fn derive_srp_credentials(
- password: &str,
- srp_attrs: &SrpAttributes,
-) -> Result<SrpCredentials>
-```
-
-Use `login_key` with `auth::SrpSession` to compute srpA/srpM1 (and optionally verify srpM2). Keep `kek` for `decrypt_secrets`.
-
-#### `derive_kek`
-
-Derive only the KEK (for email MFA flow).
-
-```rust
-pub fn derive_kek(
- password: &str,
- kek_salt: &str,
- mem_limit: u32,
- ops_limit: u32,
-) -> Result<SecretVec>
-```
-
-#### `decrypt_secrets`
-
-Decrypt master key, secret key, and token.
-
-```rust
-pub fn decrypt_secrets(
- kek: &[u8],
- key_attrs: &KeyAttributes,
- encrypted_token: &str,
-) -> Result<DecryptedSecrets>
-```
-
-## Error Handling
-
-```rust
-pub enum AuthError {
- IncorrectPassword, // Wrong password
- IncorrectRecoveryKey, // Wrong recovery key
- InvalidKeyAttributes, // Corrupted key data
- MissingField(&'static str), // Missing required field
- Crypto(CryptoError), // Underlying crypto error
- Decode(String), // Base64/hex decode error
- InvalidKey(String), // Invalid key format
- Srp(String), // SRP protocol error
-}
-```
-
-## Key Derivation
-
-Ente uses Argon2id for password-based key derivation:
-
-| Strength | Memory | Ops | Use Case |
-| ----------- | ------ | --- | ----------------- |
-| Interactive | 64 MB | 2 | Normal login |
-| Moderate | 256 MB | 3 | Enhanced security |
-| Sensitive | 1 GB | 4 | Maximum security |
-
-Sensitive derivation uses an adaptive mem/ops fallback that preserves the same strength while reducing memory on constrained devices. The selected `mem_limit` and `ops_limit` are stored in key attributes for other clients.
-
-The server specifies `mem_limit` and `ops_limit` in `SrpAttributes`.
-
-## Security Notes
-
-1. **KEK never leaves the client** - Only the login key (derived from KEK) is used in SRP
-2. **SRP prevents password exposure** - Server never sees the password
-3. **Argon2 is slow by design** - Prevents brute-force attacks
-4. **Recovery key is separate** - Can recover without password
-
-## Example: Full Login Flow
-
-```rust
-use ente_core::{auth, crypto};
-
-async fn login(email: &str, password: &str, api: &ApiClient) -> Result<Secrets> {
- // 1. Get SRP attributes
- let srp_attrs = api.get_srp_attributes(email).await?;
-
- // 2. Check auth method
- if srp_attrs.is_email_mfa_enabled {
- // Email MFA flow
- api.send_otp(email).await?;
- let otp = prompt_user("Enter OTP:")?;
- let auth_resp = api.verify_email(email, &otp).await?;
-
- // Handle 2FA if required
- let auth_resp = handle_2fa_if_needed(auth_resp, api).await?;
-
- // Derive KEK and decrypt
- let kek = auth::derive_kek(
- password,
- &srp_attrs.kek_salt,
- srp_attrs.mem_limit,
- srp_attrs.ops_limit,
- )?;
-
- let key_attrs = auth_resp.key_attributes.unwrap();
- let encrypted_token = auth_resp.encrypted_token.unwrap();
-
- auth::decrypt_secrets(&kek, &key_attrs, &encrypted_token)
- } else {
- // SRP flow
- let creds = auth::derive_srp_credentials(password, &srp_attrs)?;
-
- let srp_salt = crypto::decode_b64(&srp_attrs.srp_salt)?;
- let mut srp = auth::SrpSession::new(
- &srp_attrs.srp_user_id,
- &srp_salt,
- &creds.login_key,
- )?;
- let a_pub = srp.public_a();
- let server_session = api.create_srp_session(&srp_attrs.srp_user_id, &a_pub).await?;
- let m1 = srp.compute_m1(&server_session.srp_b)?;
-
- let auth_resp = api.verify_srp_session(&server_session.id, &m1).await?;
- // If the API returns srp_m2, call srp.verify_m2(&srp_m2).
-
- // Handle 2FA if required
- let auth_resp = handle_2fa_if_needed(auth_resp, api).await?;
-
- let key_attrs = auth_resp.key_attributes.unwrap();
- let encrypted_token = auth_resp.encrypted_token.unwrap();
-
- auth::decrypt_secrets(&creds.kek, &key_attrs, &encrypted_token)
- }
-}
-```
diff --git a/rust/crates/core/docs/crypto.md b/rust/crates/core/docs/crypto.md
deleted file mode 100644
index 13ef094ae4..0000000000
--- a/rust/crates/core/docs/crypto.md
+++ /dev/null
@@ -1,107 +0,0 @@
-# Crypto Module
-
-Pure Rust cryptographic utilities, wire-compatible with JS/Dart clients.
-
-## Quick Reference
-
-```rust
-use ente_core::crypto;
-
-crypto::init().unwrap(); // Optional (no-op for pure Rust)
-```
-
-| Task | Module | Example |
-| ------------------- | ----------- | ------------------------------------------------ |
-| Encrypt keys/tokens | `secretbox` | `secretbox::encrypt(data, &key)` |
-| Encrypt metadata | `blob` | `blob::encrypt(data, &key)` |
-| Encrypt files | `stream` | `stream::encrypt_file(&mut src, &mut dst, None)` |
-| Anonymous encrypt | `sealed` | `sealed::seal(data, &public_key)` |
-| Password β†’ Key | `argon` | `argon::derive_sensitive_key("password")` |
-| Master β†’ Subkey | `kdf` | `kdf::derive_login_key(&master_key)` |
-| Hash data/files | `hash` | `hash::hash_reader(&mut file, None)` |
-| Generate keys | `keys` | `keys::generate_key()` |
-
-## Common Patterns
-
-### Encrypt user data with password
-
-```rust
-let derived = argon::derive_sensitive_key("password")?;
-let encrypted = secretbox::encrypt(&user_data, &derived.key)?;
-// Store: encrypted.encrypted_data, encrypted.nonce, derived.salt
-```
-
-### Encrypt a file
-
-```rust
-let mut src = File::open("photo.jpg")?;
-let mut dst = File::create("photo.enc")?;
-let (key, header) = stream::encrypt_file(&mut src, &mut dst, None)?;
-// Store key and header for decryption
-```
-
-### Encrypt a file with MD5
-
-MD5 is computed over the encrypted output (header excluded).
-
-```rust
-let mut src = File::open("photo.jpg")?;
-let mut dst = File::create("photo.enc")?;
-let (key, header, md5) = stream::encrypt_file_with_md5(&mut src, &mut dst, None)?;
-let md5_b64 = crypto::encode_b64(&md5);
-```
-
-### Share data with public key
-
-```rust
-let sealed = sealed::seal(&secret_data, &recipient_public_key)?;
-// Only recipient can open with their secret key
-let opened = sealed::open(&sealed, &recipient_pk, &recipient_sk)?;
-```
-
-### Derive login key for SRP
-
-```rust
-let kek = argon::derive_key("password", &salt, mem_limit, ops_limit)?;
-let login_key = kdf::derive_login_key(&kek)?;
-```
-
-## Dart β†’ Rust Mapping
-
-| Dart | Rust |
-| ----------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
-| `encryptSync()` / `decryptSync()` | `secretbox::encrypt()` / `decrypt_box()` |
-| `encryptChaCha()` / `decryptChaCha()` | `blob::encrypt()` / `decrypt()` |
-| `encryptFile()` / `decryptFile()` | `stream::encrypt_file()` / `decrypt_file()` |
-| `encryptFileWithMD5()` | `stream::encrypt_file_with_md5()` |
-| `sealSync()` / `openSealSync()` | `sealed::seal()` / `open()` |
-| `deriveSensitiveKey()` | `argon::derive_sensitive_key_with_salt_adaptive(password.as_bytes(), &salt)` |
-| `deriveInteractiveKey()` | `argon::derive_interactive_key_with_salt(password, &salt)` (`derive_interactive_key` generates salt) |
-| `cryptoPwHash()` | `argon::derive_key(password, &salt, mem_limit, ops_limit)` |
-| `pwhashMemLimitInteractive` / `pwhashMemLimitSensitive` / `pwhashOpsLimitInteractive` / `pwhashOpsLimitSensitive` | `argon::MEMLIMIT_INTERACTIVE`, `argon::MEMLIMIT_SENSITIVE`, `argon::OPSLIMIT_INTERACTIVE`, `argon::OPSLIMIT_SENSITIVE` |
-| `deriveLoginKey()` | `kdf::derive_login_key()` |
-| `getHash()` | `hash::hash_reader()` |
-| `generateKey()` | `keys::generate_key()` |
-| `strToBin()` | `str_to_bin(input)` |
-| `base642bin()` / `bin2base64()` | `base642bin(input)` / `bin2base64(input, url_safe)` (`url_safe=false` for standard, `true` for URL-safe) |
-
-## Key Constants
-
-| Constant | Value | Where |
-| ----------------------- | ----- | ----------- |
-| `ENCRYPTION_CHUNK_SIZE` | 4 MB | stream |
-| `KEY_BYTES` | 32 | all modules |
-| `NONCE_BYTES` | 24 | secretbox |
-| `HEADER_BYTES` | 24 | stream/blob |
-| `SALT_BYTES` | 16 | argon |
-| `MEMLIMIT_INTERACTIVE` | 64 MB | argon |
-| `MEMLIMIT_SENSITIVE` | 1 GB | argon |
-| `OPSLIMIT_INTERACTIVE` | 2 | argon |
-| `OPSLIMIT_SENSITIVE` | 4 | argon |
-| `SEAL_OVERHEAD` | 48 | sealed |
-
-## Wire Formats
-
-- **SecretBox**: `MAC (16) || ciphertext`
-- **Stream chunk**: `ciphertext (plaintext + 17 bytes with tag embedded)`
-- **Sealed**: `ephemeral_pk (32) || MAC (16) || ciphertext`
diff --git a/rust/crates/core/src/auth/api.rs b/rust/crates/core/src/auth/api.rs
index 397ec30a34..da5fb0f070 100644
--- a/rust/crates/core/src/auth/api.rs
+++ b/rust/crates/core/src/auth/api.rs
@@ -332,8 +332,6 @@ mod tests {
#[test]
fn test_derive_srp_credentials() {
- crate::crypto::init().unwrap();
-
let password = "test_password";
let gen_result =
generate_keys_with_strength(password, KeyDerivationStrength::Interactive).unwrap();
@@ -356,8 +354,6 @@ mod tests {
#[test]
fn test_decrypt_secrets_roundtrip() {
- crate::crypto::init().unwrap();
-
let password = "test_password";
let gen_result =
generate_keys_with_strength(password, KeyDerivationStrength::Interactive).unwrap();
@@ -398,8 +394,6 @@ mod tests {
#[test]
fn test_wrong_password_fails() {
- crate::crypto::init().unwrap();
-
let gen_result =
generate_keys_with_strength("correct_password", KeyDerivationStrength::Interactive)
.unwrap();
@@ -428,8 +422,6 @@ mod tests {
#[test]
fn test_generate_sensitive_kek() {
- crate::crypto::init().unwrap();
-
let generated = generate_sensitive_kek("test_password").unwrap();
assert_eq!(generated.key.len(), 32);
@@ -455,8 +447,6 @@ mod tests {
#[test]
fn test_generate_interactive_kek() {
- crate::crypto::init().unwrap();
-
let generated = generate_interactive_kek("test_password").unwrap();
assert_eq!(generated.key.len(), 32);
@@ -474,8 +464,6 @@ mod tests {
#[cfg(feature = "srp")]
#[test]
fn test_generate_srp_setup() {
- crate::crypto::init().unwrap();
-
let generated = generate_sensitive_kek("test_password").unwrap();
let srp_setup = generate_srp_setup(&generated.key, "test-user-id").unwrap();
@@ -487,8 +475,6 @@ mod tests {
#[cfg(feature = "srp")]
#[test]
fn test_generate_srp_setup_with_login_key() {
- crate::crypto::init().unwrap();
-
let login_key = [1u8; 16];
let srp_setup = generate_srp_setup_with_login_key(&login_key, "test-user-id").unwrap();
@@ -500,8 +486,6 @@ mod tests {
#[cfg(feature = "srp")]
#[test]
fn test_start_srp_session() {
- crate::crypto::init().unwrap();
-
let password = "test_password";
let gen_result =
generate_keys_with_strength(password, KeyDerivationStrength::Interactive).unwrap();
diff --git a/rust/crates/core/src/auth/key_gen.rs b/rust/crates/core/src/auth/key_gen.rs
index 4e328f0885..868f21740a 100644
--- a/rust/crates/core/src/auth/key_gen.rs
+++ b/rust/crates/core/src/auth/key_gen.rs
@@ -194,8 +194,6 @@ mod tests {
#[test]
fn test_generate_keys() {
- crypto::init().unwrap();
-
let result = generate_test_keys("test_password_123").unwrap();
assert!(!result.key_attributes.kek_salt.is_empty());
@@ -212,8 +210,6 @@ mod tests {
#[test]
fn test_generate_keys_can_decrypt_master_key() {
- crypto::init().unwrap();
-
let result = generate_test_keys("my_secure_password").unwrap();
let encrypted_key = crypto::decode_b64(&result.key_attributes.encrypted_key).unwrap();
@@ -226,8 +222,6 @@ mod tests {
#[test]
fn test_generate_keys_can_decrypt_secret_key() {
- crypto::init().unwrap();
-
let result = generate_test_keys("password").unwrap();
let master_key = crypto::decode_b64(&result.private_key_attributes.key).unwrap();
@@ -241,8 +235,6 @@ mod tests {
#[test]
fn test_generate_keys_recovery_key_can_decrypt_master() {
- crypto::init().unwrap();
-
let result = generate_test_keys("password").unwrap();
let recovery_key = crypto::decode_hex(&result.private_key_attributes.recovery_key).unwrap();
@@ -270,8 +262,6 @@ mod tests {
#[test]
fn test_generate_keys_master_can_decrypt_recovery() {
- crypto::init().unwrap();
-
let result = generate_test_keys("password").unwrap();
let master_key = crypto::decode_b64(&result.private_key_attributes.key).unwrap();
@@ -299,8 +289,6 @@ mod tests {
#[test]
fn test_password_change() {
- crypto::init().unwrap();
-
let initial = generate_test_keys("old_password").unwrap();
let master_key = crypto::decode_b64(&initial.private_key_attributes.key).unwrap();
@@ -335,8 +323,6 @@ mod tests {
#[test]
fn test_create_new_recovery_key() {
- crypto::init().unwrap();
-
let master_key = Key::generate().as_bytes().to_vec();
let (recovery_hex, enc_master, nonce_master, enc_recovery, nonce_recovery) =
create_new_recovery_key(&master_key).unwrap();
@@ -361,8 +347,6 @@ mod tests {
#[test]
fn test_different_passwords_produce_different_keys() {
- crypto::init().unwrap();
-
let result1 = generate_test_keys("password1").unwrap();
let result2 = generate_test_keys("password2").unwrap();
diff --git a/rust/crates/core/src/auth/login.rs b/rust/crates/core/src/auth/login.rs
index aa0c09a473..d0989b425c 100644
--- a/rust/crates/core/src/auth/login.rs
+++ b/rust/crates/core/src/auth/login.rs
@@ -157,8 +157,6 @@ mod tests {
#[test]
fn test_decrypt_secrets_roundtrip() {
- crypto::init().unwrap();
-
let password = "test_password_123";
let gen_result = generate_test_keys(password);
@@ -188,8 +186,6 @@ mod tests {
#[test]
fn test_wrong_password() {
- crypto::init().unwrap();
-
let gen_result = generate_test_keys("correct_password");
let public_key = crypto::decode_b64(&gen_result.key_attributes.public_key).unwrap();
let encrypted_token = create_sealed_token(b"token", &public_key);
@@ -204,8 +200,6 @@ mod tests {
#[test]
fn test_derive_login_key_for_srp() {
- crypto::init().unwrap();
-
let password = "test_password";
let gen_result = generate_test_keys(password);
diff --git a/rust/crates/core/src/auth/recovery.rs b/rust/crates/core/src/auth/recovery.rs
index 22fafde93a..3ebdcc6f60 100644
--- a/rust/crates/core/src/auth/recovery.rs
+++ b/rust/crates/core/src/auth/recovery.rs
@@ -181,8 +181,6 @@ mod tests {
#[test]
fn test_recovery_roundtrip() {
- crypto::init().unwrap();
-
let gen_result = generate_test_keys("original_password");
let public_key = crypto::decode_b64(&gen_result.key_attributes.public_key).unwrap();
let encrypted_token = create_sealed_token(b"my_token", &public_key);
@@ -204,8 +202,6 @@ mod tests {
#[test]
fn test_wrong_recovery_key() {
- crypto::init().unwrap();
-
let gen_result = generate_test_keys("password");
let public_key = crypto::decode_b64(&gen_result.key_attributes.public_key).unwrap();
let encrypted_token = create_sealed_token(b"token", &public_key);
@@ -217,8 +213,6 @@ mod tests {
#[test]
fn test_get_recovery_key() {
- crypto::init().unwrap();
-
let gen_result = generate_test_keys("password");
let master_key = crypto::decode_b64(&gen_result.private_key_attributes.key).unwrap();
@@ -231,8 +225,6 @@ mod tests {
#[test]
fn test_recovery_key_mnemonic_roundtrip() {
- crypto::init().unwrap();
-
let gen_result = generate_test_keys("password");
let master_key = crypto::decode_b64(&gen_result.private_key_attributes.key).unwrap();
let recovery_key_hex = get_recovery_key(&master_key, &gen_result.key_attributes).unwrap();
@@ -249,8 +241,6 @@ mod tests {
#[test]
fn test_recovery_key_from_hex_accepts_legacy_format() {
- crypto::init().unwrap();
-
let gen_result = generate_test_keys("password");
let decoded =
recovery_key_from_mnemonic_or_hex(&gen_result.private_key_attributes.recovery_key)
diff --git a/rust/crates/core/src/auth/srp.rs b/rust/crates/core/src/auth/srp.rs
index 12ad2809e8..f51d58ad45 100644
--- a/rust/crates/core/src/auth/srp.rs
+++ b/rust/crates/core/src/auth/srp.rs
@@ -184,12 +184,9 @@ impl Drop for SrpSession {
#[cfg(test)]
mod tests {
use super::*;
- use crate::crypto;
#[test]
fn test_srp_session_creation() {
- crypto::init().unwrap();
-
let srp_user_id = "test-user-id";
let srp_salt = [0u8; 16];
let login_key = [0u8; 16];
@@ -229,8 +226,6 @@ mod tests {
#[test]
fn test_compute_m1_and_verify_m2_match_expected() {
- crypto::init().unwrap();
-
use srp::ServerG4096;
let srp_user_id = "test-user-id";
@@ -308,8 +303,6 @@ mod tests {
#[test]
fn test_sensitive_buffers_zeroized_after_compute_m1() {
- crypto::init().unwrap();
-
use rand_core::RngCore;
use srp::ServerG4096;
@@ -334,8 +327,6 @@ mod tests {
#[test]
fn test_m1_and_k_zeroized_via_drop_impl() {
- crypto::init().unwrap();
-
use rand_core::RngCore;
use srp::ServerG4096;
use zeroize::Zeroize;
diff --git a/rust/crates/core/src/crypto/mod.rs b/rust/crates/core/src/crypto/mod.rs
index 1c6aaee637..7e0b8ccb14 100644
--- a/rust/crates/core/src/crypto/mod.rs
+++ b/rust/crates/core/src/crypto/mod.rs
@@ -38,9 +38,6 @@
//! ```rust
//! use ente_core::crypto;
//!
-//! // Initialize crypto backend (no-op for the pure Rust backend)
-//! crypto::init().unwrap();
-//!
//! // Generate a key and encrypt some data
//! let key = crypto::Key::generate();
//! let plaintext = b"Hello, World!";
@@ -56,8 +53,6 @@
//! assert_eq!(decrypted, plaintext);
//! ```
-use std::sync::Once;
-
mod encoding;
mod error;
mod secret;
@@ -78,28 +73,3 @@ pub use encoding::{
pub use error::{CryptoError, Result};
pub use secret::{SecretString, SecretVec};
pub use types::{Header, Key, Nonce, PublicKey, Salt, SecretKey, random_bytes};
-
-static INIT: Once = Once::new();
-
-/// Initialize crypto backend. For the pure Rust implementation, this is a no-op.
-///
-/// This function is provided for API compatibility with the libsodium backend.
-pub fn init() -> Result<()> {
- INIT.call_once(|| {
- // Pure Rust implementation doesn't require initialization
- });
- Ok(())
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_init() {
- // Should not panic
- init().unwrap();
- // Safe to call multiple times
- init().unwrap();
- }
-}