Skip to content

armgit / ente

Public Imported from GitHub
0

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

Apply review fixes: doc accuracy and zeroizing holders

Manav Rathibc8b5e7365d6
diff --git a/rust/apps/ensu/src-tauri/src/commands.rs b/rust/apps/ensu/src-tauri/src/commands.rs
index 81ac774511..92d404d4bb 100644
--- a/rust/apps/ensu/src-tauri/src/commands.rs
+++ b/rust/apps/ensu/src-tauri/src/commands.rs
@@ -303,7 +303,6 @@ impl From<core_crypto::CryptoError> for ApiError {
E::StreamTrailingData => "stream_trailing_data",
E::SealedBoxOpenFailed => "sealed_box_open_failed",
E::InvalidPublicKey => "invalid_public_key",
- E::HashFailed => "hash_failed",
E::Json(_) => "json",
E::Argon2(_) => "argon2",
E::Aead => "aead",
diff --git a/rust/bindings/wasm/ente-wasm/src/crypto.rs b/rust/bindings/wasm/ente-wasm/src/crypto.rs
index b33e55ae8e..11ca3463e7 100644
--- a/rust/bindings/wasm/ente-wasm/src/crypto.rs
+++ b/rust/bindings/wasm/ente-wasm/src/crypto.rs
@@ -49,7 +49,6 @@ impl From<core_crypto::CryptoError> for CryptoError {
E::StreamTrailingData => "stream_trailing_data",
E::SealedBoxOpenFailed => "sealed_box_open_failed",
E::InvalidPublicKey => "invalid_public_key",
- E::HashFailed => "hash_failed",
E::Json(_) => "json",
E::Argon2(_) => "argon2",
E::Aead => "aead",
diff --git a/rust/crates/contacts/src/client.rs b/rust/crates/contacts/src/client.rs
index efdc42bfc0..741fd832b4 100644
--- a/rust/crates/contacts/src/client.rs
+++ b/rust/crates/contacts/src/client.rs
@@ -1,7 +1,7 @@
use std::sync::{Arc, RwLock};
use ente_core::auth::{self, KeyAttributes, SrpSession};
-use ente_core::crypto::{self, Key, SecretVec, sealed, secretbox};
+use ente_core::crypto::{self, SecretVec, sealed, secretbox};
use ente_core::http::{Error as HttpError, HttpClient, HttpConfig};
use sha2::{Digest, Sha256};
use uuid::Uuid;
@@ -156,7 +156,7 @@ impl ContactsCtx {
contacts_crypto::validate_contact_data(data)?;
self.ensure_confirmed_root_contact_key().await?;
- let contact_key = Key::generate().as_bytes().to_vec();
+ let contact_key = SecretVec::new(crypto::random_bytes(32));
let wrapped_contact_key = {
let root_contact_key_guard = self
.root_contact_key
@@ -834,7 +834,7 @@ impl ContactsCtx {
remote_root_key,
))?;
} else {
- let generated_root_contact_key = Key::generate().as_bytes().to_vec();
+ let generated_root_contact_key = SecretVec::new(crypto::random_bytes(32));
let generated_wrapped_root_contact_key = {
let master_key = self.master_key.read().expect("master key lock poisoned");
contacts_crypto::encrypt_root_contact_key(&generated_root_contact_key, &master_key)?
diff --git a/rust/crates/contacts/src/legacy_kit/mod.rs b/rust/crates/contacts/src/legacy_kit/mod.rs
index 1cb852d4a6..c75312c1ea 100644
--- a/rust/crates/contacts/src/legacy_kit/mod.rs
+++ b/rust/crates/contacts/src/legacy_kit/mod.rs
@@ -47,7 +47,7 @@ pub(crate) fn create_legacy_kit_request(
let kit_id = Uuid::new_v4().to_string();
let variant = LegacyKitVariant::TwoOfThree;
- let kit_secret = crypto::Key::generate().as_bytes().to_vec();
+ let kit_secret = SecretVec::new(crypto::random_bytes(32));
let checksum = checksum(LEGACY_KIT_PAYLOAD_VERSION, variant, &kit_id, &kit_secret);
let shares = split_secret_2_of_3(&kit_secret)?;
let result_shares = shares
diff --git a/rust/crates/contacts/src/legacy_kit/shares.rs b/rust/crates/contacts/src/legacy_kit/shares.rs
index db80b2e10f..1346f4012c 100644
--- a/rust/crates/contacts/src/legacy_kit/shares.rs
+++ b/rust/crates/contacts/src/legacy_kit/shares.rs
@@ -26,7 +26,7 @@ pub(super) fn split_secret_2_of_3(secret: &[u8]) -> Result<Vec<Vec<u8>>> {
"legacy kit secret must be 32 bytes".into(),
));
}
- let slope = crypto::Key::generate().as_bytes().to_vec();
+ let slope = crypto::SecretVec::new(crypto::random_bytes(32));
let xs = [1u8, 2u8, 3u8];
let mut shares = Vec::with_capacity(3);
for x in xs {
diff --git a/rust/crates/core/src/crypto/blob.rs b/rust/crates/core/src/crypto/blob.rs
index 8410229265..dda26270e2 100644
--- a/rust/crates/core/src/crypto/blob.rs
+++ b/rust/crates/core/src/crypto/blob.rs
@@ -27,7 +27,8 @@ pub use super::stream::ABYTES;
/// The result of blob encryption: ciphertext and decryption header, separate.
#[derive(Debug, Clone)]
pub struct EncryptedBlob {
- /// The encrypted data: `ciphertext β€– MAC β€– tag` (secretstream message).
+ /// The encrypted data: a single secretstream message (plaintext length +
+ /// [`ABYTES`] bytes).
pub encrypted_data: Vec<u8>,
/// The decryption header. Required for decryption; not secret.
pub decryption_header: Header,
diff --git a/rust/crates/core/src/crypto/error.rs b/rust/crates/core/src/crypto/error.rs
index cd45b92e7b..8c5d207572 100644
--- a/rust/crates/core/src/crypto/error.rs
+++ b/rust/crates/core/src/crypto/error.rs
@@ -102,10 +102,6 @@ pub enum CryptoError {
#[error("Invalid public key")]
InvalidPublicKey,
- /// Hash computation failed.
- #[error("Hash computation failed")]
- HashFailed,
-
/// JSON serialization or deserialization failed.
#[error("JSON error: {0}")]
Json(String),
diff --git a/rust/crates/core/src/crypto/stream.rs b/rust/crates/core/src/crypto/stream.rs
index f27318d8c4..de2e53346b 100644
--- a/rust/crates/core/src/crypto/stream.rs
+++ b/rust/crates/core/src/crypto/stream.rs
@@ -7,7 +7,8 @@
//!
//! # Wire Format
//! - Header: 24 bytes
-//! - Each message: `ciphertext β€– MAC β€– tag` (plaintext length + [`ABYTES`])
+//! - Each message: plaintext length + [`ABYTES`] bytes (an encrypted tag
+//! byte, the ciphertext, and a trailing 16-byte MAC)
use crypto_secretstream::{
Header as UpstreamHeader, Key as UpstreamKey, PullStream, PushStream, Stream, Tag,
diff --git a/rust/crates/core/src/crypto/types.rs b/rust/crates/core/src/crypto/types.rs
index c5e462bbf4..4b28e26342 100644
--- a/rust/crates/core/src/crypto/types.rs
+++ b/rust/crates/core/src/crypto/types.rs
@@ -243,8 +243,10 @@ impl SecretKey {
/// Deterministically derive a secret key from a 32-byte seed.
///
- /// The seed is clamped per the X25519 construction, making this suitable
- /// for deriving stable box keys from a higher-entropy master secret.
+ /// The seed bytes are stored as-is and used as the X25519 secret scalar
+ /// (clamping happens during scalar multiplication, per the X25519
+ /// construction). Suitable for deriving stable box keys from a
+ /// higher-entropy master secret.
pub fn from_seed(seed: &[u8]) -> Result<Self> {
Ok(Self(seed.try_into().map_err(|_| {
CryptoError::InvalidKeyLength {