Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor AES-GCM method names
Leendert de Borst663519974046
diff --git a/core/rust/src/bindings/uniffi_api.rs b/core/rust/src/bindings/uniffi_api.rsindex 26445ba91..7af3ceb9a 100644--- a/core/rust/src/bindings/uniffi_api.rs+++ b/core/rust/src/bindings/uniffi_api.rs@@ -188,22 +188,22 @@ pub fn argon2_derive_key(password: String, salt: String, encryption_settings: Stcrate::crypto::argon2::argon2_derive_key_from_settings(&password, &salt, &encryption_settings).map(|mut key| std::mem::take(&mut *key))}-/// AES-256-GCM decrypt a base64 `IV | ciphertext | tag` string into UTF-8 with a base64 key; empty stays empty.+/// AES-256-GCM decrypt a base64 `IV | ciphertext | tag` string (no AAD) into UTF-8 with a base64 key. An empty ciphertext is an error.#[uniffi::export]pub fn symmetric_decrypt(base64_ciphertext: String, key_base64: String) -> Result<String, VaultError> {- crate::crypto::symmetric_decrypt(&base64_ciphertext, &key_base64)+ crate::crypto::aes_gcm::decrypt_text(&base64_ciphertext, &key_base64, &[])}/// AES-256-GCM decrypt `IV | ciphertext | tag` bytes with a base64 key.#[uniffi::export]pub fn symmetric_decrypt_bytes(encrypted: Vec<u8>, key_base64: String) -> Result<Vec<u8>, VaultError> {- crate::crypto::symmetric_decrypt_bytes(&encrypted, &key_base64)+ crate::crypto::aes_gcm::decrypt(&encrypted, &key_base64, &[])}/// AES-256-GCM encrypt bytes with a base64 key (random IV, no AAD) into `IV | ciphertext | tag` bytes.#[uniffi::export]pub fn symmetric_encrypt_bytes(plaintext: Vec<u8>, key_base64: String) -> Result<Vec<u8>, VaultError> {- crate::crypto::symmetric_encrypt_raw_with_aad(&plaintext, &key_base64, &[])+ crate::crypto::aes_gcm::encrypt(&plaintext, &key_base64, &[])}/// Encrypt the SQLite database bytes into the locally stored vault blob (base64) under the raw 32-byte VEK.diff --git a/core/rust/src/bindings/wasm.rs b/core/rust/src/bindings/wasm.rsindex e1445674c..51d313f50 100644--- a/core/rust/src/bindings/wasm.rs+++ b/core/rust/src/bindings/wasm.rs@@ -199,22 +199,22 @@ pub fn argon2_derive_key_js(password: String, salt: &str, encryption_settings: &crate::crypto::argon2::argon2_derive_key_from_settings(&password, salt, encryption_settings).map(|key| js_sys::Uint8Array::from(&key[..])).map_err(js_err)}-/// AES-256-GCM decrypt a base64 `IV | ciphertext | tag` string into UTF-8 with a base64 key; empty stays empty.+/// AES-256-GCM decrypt a base64 `IV | ciphertext | tag` string (no AAD) into UTF-8 with a base64 key. An empty ciphertext is an error.#[wasm_bindgen(js_name = symmetricDecrypt)]pub fn symmetric_decrypt_js(base64_ciphertext: &str, key_base64: &str) -> Result<String, JsValue> {- crate::crypto::symmetric_decrypt(base64_ciphertext, key_base64).map_err(js_err)+ crate::crypto::aes_gcm::decrypt_text(base64_ciphertext, key_base64, &[]).map_err(js_err)}/// AES-256-GCM decrypt `IV | ciphertext | tag` bytes with a base64 key.#[wasm_bindgen(js_name = symmetricDecryptBytes)]pub fn symmetric_decrypt_bytes_js(encrypted: &[u8], key_base64: &str) -> Result<Vec<u8>, JsValue> {- crate::crypto::symmetric_decrypt_bytes(encrypted, key_base64).map_err(js_err)+ crate::crypto::aes_gcm::decrypt(encrypted, key_base64, &[]).map_err(js_err)}/// AES-256-GCM encrypt bytes with a base64 key (random IV, no AAD) into `IV | ciphertext | tag` bytes.#[wasm_bindgen(js_name = symmetricEncryptBytes)]pub fn symmetric_encrypt_bytes_js(plaintext: &[u8], key_base64: &str) -> Result<Vec<u8>, JsValue> {- crate::crypto::symmetric_encrypt_raw_with_aad(plaintext, key_base64, &[]).map_err(js_err)+ crate::crypto::aes_gcm::encrypt(plaintext, key_base64, &[]).map_err(js_err)}/// SHA-256 of a mobile login request's public key JWK string, unpadded base64url; the QR code carries it.diff --git a/core/rust/src/crypto/aes_gcm.rs b/core/rust/src/crypto/aes_gcm.rsindex 7c8c44683..616d74d90 100644--- a/core/rust/src/crypto/aes_gcm.rs+++ b/core/rust/src/crypto/aes_gcm.rs@@ -12,62 +12,48 @@ pub(super) const IV_LENGTH: usize = 12;const KEY_LENGTH: usize = 32;/// A fresh random 256-bit key as base64.-pub fn generate_key_base64() -> String {+pub fn generate_key() -> Zeroizing<String> {let mut key = Zeroizing::new([0u8; KEY_LENGTH]);fill_random(&mut key[..]);- base64_encode(&key[..])+ Zeroizing::new(base64_encode(&key[..]))}-// Raw 32-byte key, raw bytes, no associated data.--/// Encrypt bytes with a raw 32-byte key. Returns the raw `IV | ciphertext | tag`.-pub fn symmetric_encrypt_with_raw_key(plaintext: &[u8], key: &[u8]) -> VaultResult<Vec<u8>> {- encrypt_with_cipher(&cipher_from_bytes(key)?, plaintext, &[])-}--/// Decrypt raw `IV | ciphertext | tag` bytes with a raw 32-byte key.-pub fn symmetric_decrypt_with_raw_key(iv_and_ciphertext: &[u8], key: &[u8]) -> VaultResult<Vec<u8>> {- decrypt_with_cipher(&cipher_from_bytes(key)?, iv_and_ciphertext, &[])-}--// Base64 key, bytes in, raw or base64 out.--/// Encrypt bytes bound to `aad`, which decryption must present as-is. Returns the raw `IV | ciphertext | tag`.-pub fn symmetric_encrypt_raw_with_aad(plaintext: &[u8], key_base64: &str, aad: &[u8]) -> VaultResult<Vec<u8>> {- encrypt_with_cipher(&cipher_for(key_base64)?, plaintext, aad)-}+/// Encrypt bytes bound to `aad`, which decryption must present as-is. Returns `IV | ciphertext | tag`.+pub fn encrypt(plaintext: &[u8], key_base64: &str, aad: &[u8]) -> VaultResult<Vec<u8>> {+ let cipher = cipher_for(key_base64)?;+ let mut iv = [0u8; IV_LENGTH];+ fill_random(&mut iv);-/// Encrypt bytes bound to `aad`, which decryption must present as-is. Returns base64 of `IV | ciphertext | tag`.-pub fn symmetric_encrypt_bytes_with_aad(plaintext: &[u8], key_base64: &str, aad: &[u8]) -> VaultResult<String> {- Ok(base64_encode(&symmetric_encrypt_raw_with_aad(plaintext, key_base64, aad)?))-}+ let ciphertext = cipher+ .encrypt(Nonce::from_slice(&iv), Payload { msg: plaintext, aad })+ .map_err(|_| VaultError::General("AES-GCM encryption failed".to_string()))?;-/// Encrypt bytes with no associated data, for local storage and the legacy format. Returns base64 of `IV | ciphertext | tag`.-pub fn symmetric_encrypt_bytes(plaintext: &[u8], key_base64: &str) -> VaultResult<String> {- symmetric_encrypt_bytes_with_aad(plaintext, key_base64, &[])+ let mut combined = Vec::with_capacity(IV_LENGTH + ciphertext.len());+ combined.extend_from_slice(&iv);+ combined.extend_from_slice(&ciphertext);+ Ok(combined)}/// Decrypt `IV | ciphertext | tag` bytes that were encrypted bound to `aad`.-pub fn symmetric_decrypt_bytes_with_aad(iv_and_ciphertext: &[u8], key_base64: &str, aad: &[u8]) -> VaultResult<Vec<u8>> {- decrypt_with_cipher(&cipher_for(key_base64)?, iv_and_ciphertext, aad)-}--/// Decrypt `IV | ciphertext | tag` bytes with no associated data.-pub fn symmetric_decrypt_bytes(iv_and_ciphertext: &[u8], key_base64: &str) -> VaultResult<Vec<u8>> {- symmetric_decrypt_bytes_with_aad(iv_and_ciphertext, key_base64, &[])+pub fn decrypt(iv_ciphertext_tag: &[u8], key_base64: &str, aad: &[u8]) -> VaultResult<Vec<u8>> {+ let cipher = cipher_for(key_base64)?;+ if iv_ciphertext_tag.len() < IV_LENGTH {+ return Err(VaultError::General("AES-GCM ciphertext is too short".to_string()));+ }+ let (iv, ciphertext) = iv_ciphertext_tag.split_at(IV_LENGTH);+ cipher+ .decrypt(Nonce::from_slice(iv), Payload { msg: ciphertext, aad })+ .map_err(|_| VaultError::General("AES-GCM decryption failed (wrong key or corrupt data)".to_string()))}-// Base64 key, UTF-8 text in and out.--/// Encrypt a UTF-8 string bound to `aad`. An empty string is encrypted like any other value.-pub fn symmetric_encrypt_with_aad(plaintext: &str, key_base64: &str, aad: &[u8]) -> VaultResult<String> {- symmetric_encrypt_bytes_with_aad(plaintext.as_bytes(), key_base64, aad)+/// Encrypt a UTF-8 string bound to `aad`. Returns base64 of `IV | ciphertext | tag`. An empty string is encrypted like any other value.+pub fn encrypt_text(plaintext: &str, key_base64: &str, aad: &[u8]) -> VaultResult<String> {+ Ok(base64_encode(&encrypt(plaintext.as_bytes(), key_base64, aad)?))}/// Decrypt a base64 `IV | ciphertext | tag` string bound to `aad` into UTF-8. An empty ciphertext is an error.-pub fn symmetric_decrypt_with_aad(base64_ciphertext: &str, key_base64: &str, aad: &[u8]) -> VaultResult<String> {- let bytes = base64_decode(base64_ciphertext)?;- let plaintext = symmetric_decrypt_bytes_with_aad(&bytes, key_base64, aad)?;+pub fn decrypt_text(base64_ciphertext: &str, key_base64: &str, aad: &[u8]) -> VaultResult<String> {+ let plaintext = decrypt(&base64_decode(base64_ciphertext)?, key_base64, aad)?;match String::from_utf8(plaintext) {Ok(text) => Ok(text),Err(error) => {@@ -77,55 +63,10 @@ pub fn symmetric_decrypt_with_aad(base64_ciphertext: &str, key_base64: &str, aad}}-/// Encrypt a UTF-8 string with no associated data (the legacy field format). An empty string stays empty.-pub fn symmetric_encrypt(plaintext: &str, key_base64: &str) -> VaultResult<String> {- if plaintext.is_empty() {- return Ok(String::new());- }- symmetric_encrypt_bytes(plaintext.as_bytes(), key_base64)-}--/// Decrypt a base64 `IV | ciphertext | tag` string with no associated data into UTF-8. An empty ciphertext stays empty.-pub fn symmetric_decrypt(base64_ciphertext: &str, key_base64: &str) -> VaultResult<String> {- if base64_ciphertext.is_empty() {- return Ok(String::new());- }- symmetric_decrypt_with_aad(base64_ciphertext, key_base64, &[])-}--// The cipher and the one encrypt and decrypt call.-fn cipher_for(key_base64: &str) -> VaultResult<Aes256Gcm> {- cipher_from_bytes(&Zeroizing::new(base64_decode(key_base64)?))-}--fn cipher_from_bytes(key: &[u8]) -> VaultResult<Aes256Gcm> {+ let key = Zeroizing::new(base64_decode(key_base64)?);if key.len() != KEY_LENGTH {return Err(VaultError::General(format!("AES-GCM key must be {} bytes, got {}", KEY_LENGTH, key.len())));}- Ok(Aes256Gcm::new_from_slice(key).expect("key length checked above"))-}--fn encrypt_with_cipher(cipher: &Aes256Gcm, plaintext: &[u8], aad: &[u8]) -> VaultResult<Vec<u8>> {- let mut iv = [0u8; IV_LENGTH];- fill_random(&mut iv);-- let ciphertext = cipher- .encrypt(Nonce::from_slice(&iv), Payload { msg: plaintext, aad })- .map_err(|_| VaultError::General("AES-GCM encryption failed".to_string()))?;-- let mut combined = Vec::with_capacity(IV_LENGTH + ciphertext.len());- combined.extend_from_slice(&iv);- combined.extend_from_slice(&ciphertext);- Ok(combined)-}--fn decrypt_with_cipher(cipher: &Aes256Gcm, iv_and_ciphertext: &[u8], aad: &[u8]) -> VaultResult<Vec<u8>> {- if iv_and_ciphertext.len() < IV_LENGTH {- return Err(VaultError::General("AES-GCM ciphertext is too short".to_string()));- }- let (iv, ciphertext) = iv_and_ciphertext.split_at(IV_LENGTH);- cipher- .decrypt(Nonce::from_slice(iv), Payload { msg: ciphertext, aad })- .map_err(|_| VaultError::General("AES-GCM decryption failed (wrong key or corrupt data)".to_string()))+ Ok(Aes256Gcm::new_from_slice(&key).expect("key length checked above"))}diff --git a/core/rust/src/crypto/key_chain.rs b/core/rust/src/crypto/key_chain.rsindex 9d27b8789..61c0e0c7b 100644--- a/core/rust/src/crypto/key_chain.rs+++ b/core/rust/src/crypto/key_chain.rs@@ -10,7 +10,7 @@ use thiserror::Error;use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};use super::aad;-use super::aes_gcm::{generate_key_base64, symmetric_decrypt_bytes_with_aad, symmetric_decrypt_with_aad, symmetric_encrypt_bytes_with_aad, symmetric_encrypt_with_aad};+use super::aes_gcm::{self, decrypt_text, encrypt_text, generate_key};use super::rsa_oaep::generate_rsa_key_pair;use super::signing::{self, generate_signing_key_pair};use super::tokens::{ALGORITHM_AES256_GCM, ENCRYPTION_TYPE_ARGON2ID, ENCRYPTION_TYPE_ARGON2ID_HKDF};@@ -114,18 +114,18 @@ pub fn decrypt_account_key(encrypted_account_key: &str, unlock_key_base64: &str)/// Encrypt a base64 key with another base64 key, bound to `aad` (see [`aad`]). Returns base64 of `IV | ciphertext | tag`.pub fn encrypt_key(key_base64: &str, with_key_base64: &str, aad: &[u8]) -> VaultResult<String> {- symmetric_encrypt_bytes_with_aad(&Zeroizing::new(base64_decode(key_base64)?), with_key_base64, aad)+ Ok(base64_encode(&aes_gcm::encrypt(&Zeroizing::new(base64_decode(key_base64)?), with_key_base64, aad)?))}/// Decrypt a key encrypted with [`encrypt_key`] bound to `aad`. Returns the key as base64.pub fn decrypt_key(encrypted_key_base64: &str, with_key_base64: &str, aad: &[u8]) -> VaultResult<Zeroizing<String>> {- let raw = Zeroizing::new(symmetric_decrypt_bytes_with_aad(&base64_decode(encrypted_key_base64)?, with_key_base64, aad)?);+ let raw = Zeroizing::new(aes_gcm::decrypt(&base64_decode(encrypted_key_base64)?, with_key_base64, aad)?);Ok(Zeroizing::new(base64_encode(&raw[..])))}/// Decrypt the account private key (a JWK) with the Account Key.pub fn open_account_private_key(encrypted_account_private_key: &str, account_key_base64: &str) -> VaultResult<Zeroizing<String>> {- symmetric_decrypt_with_aad(encrypted_account_private_key, account_key_base64, aad::ACCOUNT_PRIVATE_KEY).map(Zeroizing::new)+ decrypt_text(encrypted_account_private_key, account_key_base64, aad::ACCOUNT_PRIVATE_KEY).map(Zeroizing::new)}/// Decrypt the account signing private key (base64 seed) with the Account Key.@@ -194,8 +194,8 @@ fn open_optional_account_private_key(encrypted_account_private_key: Option<&str>/// Create a new account key hierarchy encrypted with the KEK derived from an unlock key.pub fn create_account_key_hierarchy(unlock_key_base64: &str) -> VaultResult<AccountKeyHierarchy> {let key_pair = generate_rsa_key_pair()?;- let vault_encryption_key = Zeroizing::new(generate_key_base64());- let account_key = Zeroizing::new(generate_key_base64());+ let vault_encryption_key = generate_key();+ let account_key = generate_key();let signing_key_pair = generate_signing_key_pair();let account_public_key_message = signing::account_public_key_message(&key_pair.public_key);@@ -204,7 +204,7 @@ pub fn create_account_key_hierarchy(unlock_key_base64: &str) -> VaultResult<Accoencrypted_account_key_algorithm: account_key_encryption_algorithm(),encrypted_vek: encrypt_key(&vault_encryption_key, &account_key, aad::PERSONAL_VEK)?,account_public_key: key_pair.public_key.clone(),- encrypted_account_private_key: symmetric_encrypt_with_aad(&key_pair.private_key, &account_key, aad::ACCOUNT_PRIVATE_KEY)?,+ encrypted_account_private_key: encrypt_text(&key_pair.private_key, &account_key, aad::ACCOUNT_PRIVATE_KEY)?,signing_public_key: signing_key_pair.public_key.clone(),encrypted_signing_private_key: encrypt_key(&signing_key_pair.private_key, &account_key, aad::ACCOUNT_SIGNING_PRIVATE_KEY)?,account_public_key_signature: signing::sign(&signing_key_pair.private_key, &account_public_key_message)?,diff --git a/core/rust/src/crypto/mobile_login.rs b/core/rust/src/crypto/mobile_login.rsindex 3ab6bc012..2615e6510 100644--- a/core/rust/src/crypto/mobile_login.rs+++ b/core/rust/src/crypto/mobile_login.rs@@ -6,7 +6,7 @@ use sha2::{Digest, Sha256};use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};use super::aad;-use super::aes_gcm::symmetric_decrypt;+use super::aes_gcm::decrypt_text;use super::rsa_oaep::decrypt_with_private_key_and_label;use crate::common::encoding::{base64_encode, base64url_encode};use crate::common::error::VaultResult;@@ -41,5 +41,5 @@ pub struct MobileLoginApproval {pub fn mobile_login_open_approval(private_key_jwk: &str, encrypted_account_key: &str, encrypted_payload_key: &str, encrypted_payload: &str) -> VaultResult<MobileLoginApproval> {let account_key = Zeroizing::new(decrypt_with_private_key_and_label(encrypted_account_key, private_key_jwk, aad::MOBILE_LOGIN_ACCOUNT_KEY)?);let payload_key = Zeroizing::new(base64_encode(&Zeroizing::new(decrypt_with_private_key_and_label(encrypted_payload_key, private_key_jwk, aad::MOBILE_LOGIN_PAYLOAD_KEY)?)));- Ok(MobileLoginApproval { account_key: base64_encode(&account_key), payload: symmetric_decrypt(encrypted_payload, &payload_key)? })+ Ok(MobileLoginApproval { account_key: base64_encode(&account_key), payload: decrypt_text(encrypted_payload, &payload_key, &[])? })}diff --git a/core/rust/src/crypto/mod.rs b/core/rust/src/crypto/mod.rsindex ad573c9c5..0a5bd180d 100644--- a/core/rust/src/crypto/mod.rs+++ b/core/rust/src/crypto/mod.rs@@ -31,10 +31,6 @@ pub mod vault_blob;#[cfg(test)]mod tests;-pub use aes_gcm::{- generate_key_base64, symmetric_decrypt, symmetric_decrypt_bytes, symmetric_decrypt_bytes_with_aad, symmetric_decrypt_with_aad, symmetric_encrypt, symmetric_encrypt_bytes,- symmetric_encrypt_raw_with_aad, symmetric_encrypt_with_aad,-};pub use key_chain::{account_signing_key_fingerprint, create_account_key_hierarchy, derive_srp_password_hash, open_account_private_key, open_account_signing_private_key,decrypt_account_key, decrypt_key, encrypt_key, open_key_chain_with_account_key, open_key_chain_with_unlock_key, reencrypt_account_key, rotate_account_keys, AccountKeyBlobs, AccountKeyHierarchy, KeyChainError,diff --git a/core/rust/src/crypto/pin.rs b/core/rust/src/crypto/pin.rsindex fce37d8db..7f54aa742 100644--- a/core/rust/src/crypto/pin.rs+++ b/core/rust/src/crypto/pin.rs@@ -5,7 +5,8 @@ use zeroize::Zeroizing;use crate::common::error::{VaultError, VaultResult};use crate::common::rng::random_bytes;-use crate::crypto::aes_gcm::{symmetric_decrypt_with_raw_key, symmetric_encrypt_with_raw_key};+use crate::common::encoding::base64_encode;+use crate::crypto::aes_gcm;use crate::crypto::argon2::argon2_derive_key_bytes_from_settings;/// Failed attempts after which the PIN is locked and the host deletes the encrypted key.@@ -37,12 +38,12 @@ pub fn pin_generate_salt() -> Vec<u8> {/// Encrypt `secret` with a key derived from the PIN and salt. Returns `IV | ciphertext | tag`.pub fn pin_encrypt(pin: &str, salt: &[u8], secret: &[u8]) -> VaultResult<Vec<u8>> {- symmetric_encrypt_with_raw_key(secret, &derive_pin_key(pin, salt)?)+ aes_gcm::encrypt(secret, &derive_pin_key(pin, salt)?, &[])}/// Decrypt a key encrypted by [`pin_encrypt`]. Fails for a wrong PIN.pub fn pin_decrypt(pin: &str, salt: &[u8], encrypted: &[u8]) -> VaultResult<Zeroizing<Vec<u8>>> {- symmetric_decrypt_with_raw_key(encrypted, &derive_pin_key(pin, salt)?).map(Zeroizing::new)+ aes_gcm::decrypt(encrypted, &derive_pin_key(pin, salt)?, &[]).map(Zeroizing::new)}/// Whether a stored failed-attempt count means the PIN is locked.@@ -56,6 +57,7 @@ pub fn pin_register_failure(failed_attempts: u32) -> PinFailure {PinFailure { failed_attempts, attempts_remaining: PIN_MAX_ATTEMPTS.saturating_sub(failed_attempts), locked: pin_is_locked(failed_attempts) }}-fn derive_pin_key(pin: &str, salt: &[u8]) -> VaultResult<Zeroizing<Vec<u8>>> {- argon2_derive_key_bytes_from_settings(pin.as_bytes(), salt, PIN_ARGON2_SETTINGS).map_err(|e| VaultError::General(e.to_string()))+fn derive_pin_key(pin: &str, salt: &[u8]) -> VaultResult<Zeroizing<String>> {+ let key = argon2_derive_key_bytes_from_settings(pin.as_bytes(), salt, PIN_ARGON2_SETTINGS).map_err(|e| VaultError::General(e.to_string()))?;+ Ok(Zeroizing::new(base64_encode(&key)))}diff --git a/core/rust/src/crypto/tests/aes_gcm.rs b/core/rust/src/crypto/tests/aes_gcm.rsindex 38a57e020..2c9399434 100644--- a/core/rust/src/crypto/tests/aes_gcm.rs+++ b/core/rust/src/crypto/tests/aes_gcm.rs@@ -1,58 +1,46 @@-use crate::common::encoding::base64_decode;use crate::crypto::aes_gcm::*;#[test]-fn round_trips_bytes_and_strings() {- let key = generate_key_base64();+fn round_trips_bytes_and_text() {+ let key = generate_key();let bytes: Vec<u8> = (0..=255u8).collect();- let encrypted = symmetric_encrypt_bytes(&bytes, &key).unwrap();- assert_eq!(symmetric_decrypt_bytes(&base64_decode(&encrypted).unwrap(), &key).unwrap(), bytes);+ assert_eq!(decrypt(&encrypt(&bytes, &key, &[]).unwrap(), &key, &[]).unwrap(), bytes);- let encrypted = symmetric_encrypt("héllo ✓", &key).unwrap();- assert_eq!(symmetric_decrypt(&encrypted, &key).unwrap(), "héllo ✓");- assert_eq!(symmetric_encrypt("", &key).unwrap(), "");- assert_eq!(symmetric_decrypt("", &key).unwrap(), "");+ let encrypted = encrypt_text("héllo ✓", &key, &[]).unwrap();+ assert_eq!(decrypt_text(&encrypted, &key, &[]).unwrap(), "héllo ✓");}#[test]-fn raw_key_round_trips_and_matches_the_base64_key_layout() {- let key: Vec<u8> = (0..32u8).collect();- let encrypted = symmetric_encrypt_with_raw_key(b"secret", &key).unwrap();- assert_eq!(encrypted.len(), IV_LENGTH + 6 + 16);- assert_eq!(symmetric_decrypt_with_raw_key(&encrypted, &key).unwrap(), b"secret");- assert_eq!(symmetric_decrypt_bytes(&encrypted, &crate::common::encoding::base64_encode(&key)).unwrap(), b"secret", "a raw key and its base64 form are the same key");- assert!(symmetric_encrypt_with_raw_key(b"x", &key[..31]).is_err());+fn encrypts_an_empty_string_and_rejects_an_empty_ciphertext() {+ let key = generate_key();+ let empty = encrypt_text("", &key, &[]).unwrap();+ assert!(!empty.is_empty(), "an empty string is encrypted, not passed through");+ assert_eq!(decrypt_text(&empty, &key, &[]).unwrap(), "");+ assert!(decrypt_text("", &key, &[]).is_err());}#[test]fn rejects_wrong_key_and_short_input() {- let key = generate_key_base64();- let encrypted = symmetric_encrypt("secret", &key).unwrap();- assert!(symmetric_decrypt(&encrypted, &generate_key_base64()).is_err());- assert!(symmetric_decrypt_bytes(&[1, 2, 3], &key).is_err());- assert!(symmetric_encrypt("x", "dG9vc2hvcnQ=").is_err());+ let key = generate_key();+ let encrypted = encrypt_text("secret", &key, &[]).unwrap();+ assert!(decrypt_text(&encrypted, &generate_key(), &[]).is_err());+ assert!(decrypt(&[1, 2, 3], &key, &[]).is_err());+ assert!(encrypt(b"x", "dG9vc2hvcnQ=", &[]).is_err(), "a key must be 32 bytes");}#[test]fn associated_data_must_match() {- let key = generate_key_base64();- let encrypted = symmetric_encrypt_with_aad("secret", &key, b"slot-a").unwrap();- assert_eq!(symmetric_decrypt_with_aad(&encrypted, &key, b"slot-a").unwrap(), "secret");- assert!(symmetric_decrypt_with_aad(&encrypted, &key, b"slot-b").is_err());- assert!(symmetric_decrypt(&encrypted, &key).is_err(), "a bound ciphertext does not open without its associated data");-- let empty = symmetric_encrypt_with_aad("", &key, b"slot-a").unwrap();- assert!(!empty.is_empty(), "an empty string is encrypted, not passed through");- assert_eq!(symmetric_decrypt_with_aad(&empty, &key, b"slot-a").unwrap(), "");- assert!(symmetric_decrypt_with_aad("", &key, b"slot-a").is_err());+ let key = generate_key();+ let encrypted = encrypt_text("secret", &key, b"slot-a").unwrap();+ assert_eq!(decrypt_text(&encrypted, &key, b"slot-a").unwrap(), "secret");+ assert!(decrypt_text(&encrypted, &key, b"slot-b").is_err());+ assert!(decrypt_text(&encrypted, &key, &[]).is_err(), "a bound ciphertext does not open without its associated data");}#[test]fn layout_is_iv_then_ciphertext_then_tag() {- let key = generate_key_base64();- let encrypted = base64_decode(&symmetric_encrypt_bytes(b"abc", &key).unwrap()).unwrap();- assert_eq!(encrypted.len(), IV_LENGTH + 3 + 16);- assert_eq!(symmetric_encrypt_raw_with_aad(b"abc", &key, &[]).unwrap().len(), encrypted.len());+ let key = generate_key();+ assert_eq!(encrypt(b"abc", &key, &[]).unwrap().len(), IV_LENGTH + 3 + 16);}/// Known-answer vectors made with WebCrypto (`crypto.subtle.encrypt`, AES-GCM, key 0x00..0x1f, IV 0x64..0x6f), which the@@ -61,6 +49,6 @@ fn layout_is_iv_then_ciphertext_then_tag() {#[test]fn decrypts_webcrypto_vectors() {let key = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=";- assert_eq!(symmetric_decrypt("ZGVmZ2hpamtsbW5vAH6yChbFdulREDOM+zmyst740xDgbk6roItfB30=", key).unwrap(), "Hello, world!");- assert_eq!(symmetric_decrypt_with_aad("ZGVmZ2hpamtsbW5vAH6yChbFdulREDOM+zPeAfsSNCDHPQrcFHPRnnk=", key, b"aliasvault/v1/test").unwrap(), "Hello, world!");+ assert_eq!(decrypt_text("ZGVmZ2hpamtsbW5vAH6yChbFdulREDOM+zmyst740xDgbk6roItfB30=", key, &[]).unwrap(), "Hello, world!");+ assert_eq!(decrypt_text("ZGVmZ2hpamtsbW5vAH6yChbFdulREDOM+zPeAfsSNCDHPQrcFHPRnnk=", key, b"aliasvault/v1/test").unwrap(), "Hello, world!");}diff --git a/core/rust/src/crypto/tests/key_chain.rs b/core/rust/src/crypto/tests/key_chain.rsindex aaaffaa49..55fd10334 100644--- a/core/rust/src/crypto/tests/key_chain.rs+++ b/core/rust/src/crypto/tests/key_chain.rs@@ -1,6 +1,6 @@use crate::common::encoding::hex_encode_upper;use crate::crypto::aad;-use crate::crypto::aes_gcm::{generate_key_base64, symmetric_decrypt_with_aad};+use crate::crypto::aes_gcm::{decrypt_text, generate_key};use crate::crypto::key_chain::*;use crate::crypto::signing;use crate::crypto::tokens::{ENCRYPTION_TYPE_ARGON2ID, ENCRYPTION_TYPE_ARGON2ID_HKDF};@@ -38,13 +38,13 @@ fn srp_input_and_kek_are_separate() {#[test]fn kek_differs_from_the_unlock_key() {- let unlock_key = generate_key_base64();- assert_ne!(*derive_kek_base64(&unlock_key).unwrap(), unlock_key);+ let unlock_key = generate_key();+ assert_ne!(*derive_kek_base64(&unlock_key).unwrap(), *unlock_key);}#[test]fn account_key_is_not_encrypted_with_the_raw_unlock_key() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();assert!(decrypt_key(&hierarchy.account_keys.encrypted_account_key, &unlock_key, aad::ACCOUNT_KEY).is_err());assert!(decrypt_key(&hierarchy.account_keys.encrypted_account_key, &derive_kek_base64(&unlock_key).unwrap(), aad::ACCOUNT_KEY).is_ok());@@ -52,7 +52,7 @@ fn account_key_is_not_encrypted_with_the_raw_unlock_key() {#[test]fn chain_opens_with_the_unlock_key_and_then_with_the_account_key_it_gave() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();let blobs = &hierarchy.account_keys;@@ -60,7 +60,7 @@ fn chain_opens_with_the_unlock_key_and_then_with_the_account_key_it_gave() {assert_eq!(*opened.vault_encryption_key, hierarchy.vault_encryption_key);assert_eq!(opened.account_private_key.as_deref().map(String::as_str), Some(hierarchy.account_private_key.as_str()));assert_eq!(*opened.account_key, hierarchy.account_key, "a new hierarchy hands the client the Account Key it stores");- assert_ne!(*opened.account_key, unlock_key);+ assert_ne!(*opened.account_key, *unlock_key);let reopened = open_key_chain_with_account_key(&opened.account_key, &blobs.encrypted_vek, Some(&blobs.encrypted_account_private_key)).unwrap();assert_eq!(*reopened.vault_encryption_key, hierarchy.vault_encryption_key);@@ -71,7 +71,7 @@ fn chain_opens_with_the_unlock_key_and_then_with_the_account_key_it_gave() {/// Neither function falls back to the other kind of key: a host has to know which key it holds.#[test]fn each_open_refuses_the_other_kind_of_key() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();let blobs = &hierarchy.account_keys;let account_key = decrypt_account_key(&blobs.encrypted_account_key, &unlock_key).unwrap();@@ -82,18 +82,18 @@ fn each_open_refuses_the_other_kind_of_key() {#[test]fn chain_rejects_a_wrong_key() {- let hierarchy = create_account_key_hierarchy(&generate_key_base64()).unwrap();+ let hierarchy = create_account_key_hierarchy(&generate_key()).unwrap();let blobs = &hierarchy.account_keys;- assert_eq!(open_key_chain_with_unlock_key(&generate_key_base64(), &blobs.encrypted_account_key, &blobs.encrypted_vek, None).err(), Some(KeyChainError::UnlockKeyRejected));- assert_eq!(open_key_chain_with_account_key(&generate_key_base64(), &blobs.encrypted_vek, None).err(), Some(KeyChainError::AccountKeyRejected));+ assert_eq!(open_key_chain_with_unlock_key(&generate_key(), &blobs.encrypted_account_key, &blobs.encrypted_vek, None).err(), Some(KeyChainError::UnlockKeyRejected));+ assert_eq!(open_key_chain_with_account_key(&generate_key(), &blobs.encrypted_vek, None).err(), Some(KeyChainError::AccountKeyRejected));}#[test]fn chain_with_a_foreign_vek_is_unreadable_under_the_unlock_key() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();let account_key = decrypt_account_key(&hierarchy.account_keys.encrypted_account_key, &unlock_key).unwrap();- let foreign_vek = encrypt_key(&generate_key_base64(), &generate_key_base64(), aad::PERSONAL_VEK).unwrap();+ let foreign_vek = encrypt_key(&generate_key(), &generate_key(), aad::PERSONAL_VEK).unwrap();// The Account Key opened, so the unlock key was right: a damaged chain, never a wrong password.assert!(matches!(open_key_chain_with_unlock_key(&unlock_key, &hierarchy.account_keys.encrypted_account_key, &foreign_vek, None), Err(KeyChainError::KeyChainUnreadable(_))));@@ -103,7 +103,7 @@ fn chain_with_a_foreign_vek_is_unreadable_under_the_unlock_key() {#[test]fn a_private_key_that_does_not_open_leaves_grants_closed_but_opens_the_vault() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();let blobs = &hierarchy.account_keys;let account_key = decrypt_account_key(&blobs.encrypted_account_key, &unlock_key).unwrap();@@ -116,8 +116,8 @@ fn a_private_key_that_does_not_open_leaves_grants_closed_but_opens_the_vault() {#[test]fn rotated_keys_open_with_the_new_unlock_key() {- let old_hierarchy = create_account_key_hierarchy(&generate_key_base64()).unwrap();- let new_unlock_key = generate_key_base64();+ let old_hierarchy = create_account_key_hierarchy(&generate_key()).unwrap();+ let new_unlock_key = generate_key();let rotated = rotate_account_keys(&new_unlock_key).unwrap();let blobs = &rotated.account_keys;@@ -137,7 +137,7 @@ fn rotated_keys_open_with_the_new_unlock_key() {#[test]fn hierarchy_carries_a_signing_key_that_signed_the_account_public_key() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();let blobs = &hierarchy.account_keys;let account_key = decrypt_account_key(&blobs.encrypted_account_key, &unlock_key).unwrap();@@ -153,8 +153,8 @@ fn hierarchy_carries_a_signing_key_that_signed_the_account_public_key() {#[test]fn reencrypted_account_key_opens_with_the_new_unlock_key_only() {- let old_unlock_key = generate_key_base64();- let new_unlock_key = generate_key_base64();+ let old_unlock_key = generate_key();+ let new_unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&old_unlock_key).unwrap();let blobs = &hierarchy.account_keys;@@ -167,22 +167,22 @@ fn reencrypted_account_key_opens_with_the_new_unlock_key_only() {#[test]fn reencrypt_rejects_a_wrong_old_unlock_key() {- let hierarchy = create_account_key_hierarchy(&generate_key_base64()).unwrap();- let result = reencrypt_account_key(&hierarchy.account_keys.encrypted_account_key, &generate_key_base64(), &generate_key_base64());+ let hierarchy = create_account_key_hierarchy(&generate_key()).unwrap();+ let result = reencrypt_account_key(&hierarchy.account_keys.encrypted_account_key, &generate_key(), &generate_key());assert_eq!(result.err(), Some(KeyChainError::UnlockKeyRejected));}#[test]fn encrypt_and_decrypt_key_round_trip() {- let outer = generate_key_base64();- let key = generate_key_base64();- assert_eq!(*decrypt_key(&encrypt_key(&key, &outer, b"a").unwrap(), &outer, b"a").unwrap(), key);+ let outer = generate_key();+ let key = generate_key();+ assert_eq!(*decrypt_key(&encrypt_key(&key, &outer, b"a").unwrap(), &outer, b"a").unwrap(), *key);assert!(decrypt_key(&encrypt_key(&key, &outer, b"a").unwrap(), &outer, b"b").is_err());}#[test]fn chain_ciphertexts_do_not_open_in_each_others_slot() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();let blobs = &hierarchy.account_keys;let account_key = decrypt_account_key(&blobs.encrypted_account_key, &unlock_key).unwrap();@@ -192,12 +192,12 @@ fn chain_ciphertexts_do_not_open_in_each_others_slot() {assert_eq!(open_key_chain_with_account_key(&account_key, &blobs.encrypted_account_key, None).err(), Some(KeyChainError::AccountKeyRejected));assert!(decrypt_key(&blobs.encrypted_vek, &account_key, aad::ACCOUNT_KEY).is_err());assert!(open_account_private_key(&blobs.encrypted_account_private_key, &account_key).is_ok());- assert!(symmetric_decrypt_with_aad(&blobs.encrypted_account_private_key, &account_key, aad::PERSONAL_VEK).is_err());+ assert!(decrypt_text(&blobs.encrypted_account_private_key, &account_key, aad::PERSONAL_VEK).is_err());}#[test]fn an_account_key_encrypted_under_any_other_label_is_refused() {- let unlock_key = generate_key_base64();+ let unlock_key = generate_key();let hierarchy = create_account_key_hierarchy(&unlock_key).unwrap();let account_key = decrypt_account_key(&hierarchy.account_keys.encrypted_account_key, &unlock_key).unwrap();let kek = derive_kek_base64(&unlock_key).unwrap();diff --git a/core/rust/src/crypto/tests/mobile_login.rs b/core/rust/src/crypto/tests/mobile_login.rsindex d193d1a14..89125daf8 100644--- a/core/rust/src/crypto/tests/mobile_login.rs+++ b/core/rust/src/crypto/tests/mobile_login.rs@@ -1,5 +1,5 @@use crate::crypto::aad;-use crate::crypto::aes_gcm::{generate_key_base64, symmetric_encrypt};+use crate::crypto::aes_gcm::{encrypt_text, generate_key};use crate::crypto::mobile_login::*;use crate::crypto::rsa_oaep::{encrypt_with_public_key_and_label, generate_rsa_key_pair};@@ -18,10 +18,10 @@ fn known_answers() {fn approval_opens_with_the_request_key_and_rejects_swapped_labels() {let pair = generate_rsa_key_pair().unwrap();let account_key = [7u8; 32];- let payload_key = generate_key_base64();+ let payload_key = generate_key();let encrypted_account_key = encrypt_with_public_key_and_label(&account_key, &pair.public_key, aad::MOBILE_LOGIN_ACCOUNT_KEY).unwrap();let encrypted_payload_key = encrypt_with_public_key_and_label(&crate::common::encoding::base64_decode(&payload_key).unwrap(), &pair.public_key, aad::MOBILE_LOGIN_PAYLOAD_KEY).unwrap();- let encrypted_payload = symmetric_encrypt(r#"{"username":"u"}"#, &payload_key).unwrap();+ let encrypted_payload = encrypt_text(r#"{"username":"u"}"#, &payload_key, &[]).unwrap();let approval = mobile_login_open_approval(&pair.private_key, &encrypted_account_key, &encrypted_payload_key, &encrypted_payload).unwrap();assert_eq!(approval.account_key, crate::common::encoding::base64_encode(&account_key));diff --git a/core/rust/src/crypto/tests/pin.rs b/core/rust/src/crypto/tests/pin.rsindex d1ce09f4f..93c8cfb5f 100644--- a/core/rust/src/crypto/tests/pin.rs+++ b/core/rust/src/crypto/tests/pin.rs@@ -1,4 +1,5 @@-use crate::crypto::aes_gcm::symmetric_encrypt_with_raw_key;+use crate::common::encoding::base64_encode;+use crate::crypto::aes_gcm;use crate::crypto::argon2::argon2_derive_key_bytes_from_settings;use crate::crypto::pin::*;@@ -18,7 +19,7 @@ fn round_trips_and_rejects_a_wrong_pin() {fn opens_a_key_encrypted_with_the_argon2_key_directly() {let salt = b"some-salt-bytes!";let key = argon2_derive_key_bytes_from_settings(b"8765432", salt, PIN_ARGON2_SETTINGS).unwrap();- let encrypted = symmetric_encrypt_with_raw_key(b"secret", &key).unwrap();+ let encrypted = aes_gcm::encrypt(b"secret", &base64_encode(&key), &[]).unwrap();assert_eq!(*pin_decrypt("8765432", salt, &encrypted).unwrap(), b"secret");}diff --git a/core/rust/src/crypto/vault_blob.rs b/core/rust/src/crypto/vault_blob.rsindex b8fba6e55..cbaf753a3 100644--- a/core/rust/src/crypto/vault_blob.rs+++ b/core/rust/src/crypto/vault_blob.rs@@ -3,23 +3,23 @@//! The mobile apps call these through uniffi. The web app and the browser extension keep their own WebCrypto copy//! (`core/client/src/crypto/VaultBlob.ts`) because wasm AES-GCM has no hardware acceleration.-use crate::common::encoding::base64_decode;+use crate::common::encoding::{base64_decode, base64_encode};use crate::common::error::{VaultError, VaultResult};-use super::aes_gcm::{symmetric_decrypt_bytes, symmetric_encrypt_bytes};+use super::aes_gcm;/// The bytes every SQLite database file begins with. Base64 text cannot start with them (the space is not in its alphabet).const SQLITE_HEADER: &[u8] = b"SQLite format 3\0";/// Encrypt a plaintext SQLite database for local storage.pub fn vault_blob_encrypt(sqlite_bytes: &[u8], key_base64: &str) -> VaultResult<String> {- symmetric_encrypt_bytes(sqlite_bytes, key_base64)+ Ok(base64_encode(&aes_gcm::encrypt(sqlite_bytes, key_base64, &[])?))}/// Decrypt a stored vault blob into the SQLite database bytes. Also reads the base64 text of the database that builds/// before 0.31.0 stored; the next write converts such a vault.pub fn vault_blob_decrypt(encrypted_blob: &str, key_base64: &str) -> VaultResult<Vec<u8>> {- let plaintext = symmetric_decrypt_bytes(&base64_decode(encrypted_blob.trim())?, key_base64)?;+ let plaintext = aes_gcm::decrypt(&base64_decode(encrypted_blob.trim())?, key_base64, &[])?;if plaintext.starts_with(SQLITE_HEADER) {return Ok(plaintext);}diff --git a/core/rust/src/vault_sync/blob_keys.rs b/core/rust/src/vault_sync/blob_keys.rsindex 604d15ed6..c726cace1 100644--- a/core/rust/src/vault_sync/blob_keys.rs+++ b/core/rust/src/vault_sync/blob_keys.rs@@ -19,9 +19,9 @@ pub(crate) struct EncryptedBlob {/// Encrypt blob bytes with a fresh blob key, and that key with the manifest's VEK, both bound to the blob's address.pub(crate) fn encrypt_blob(bytes: &[u8], vek: &str, manifest_id: &str, hash: &str) -> VaultResult<EncryptedBlob> {- let blob_key = zeroize::Zeroizing::new(crypto::generate_key_base64());+ let blob_key = crypto::aes_gcm::generate_key();Ok(EncryptedBlob {- encrypted_data: crypto::symmetric_encrypt_raw_with_aad(bytes, &blob_key, &aad::blob_data(manifest_id, hash))?,+ encrypted_data: crypto::aes_gcm::encrypt(bytes, &blob_key, &aad::blob_data(manifest_id, hash))?,encrypted_blob_key: crypto::encrypt_key(&blob_key, vek, &aad::blob_key(manifest_id, hash))?,})}@@ -29,7 +29,7 @@ pub(crate) fn encrypt_blob(bytes: &[u8], vek: &str, manifest_id: &str, hash: &st/// Decrypt the blob stored at `(manifest_id, hash)` with the manifest's VEK.pub(crate) fn decrypt_blob(blob: &EncryptedBlob, vek: &str, manifest_id: &str, hash: &str) -> VaultResult<Vec<u8>> {let blob_key = crypto::decrypt_key(&blob.encrypted_blob_key, vek, &aad::blob_key(manifest_id, hash))?;- crypto::symmetric_decrypt_bytes_with_aad(&blob.encrypted_data, &blob_key, &aad::blob_data(manifest_id, hash))+ crypto::aes_gcm::decrypt(&blob.encrypted_data, &blob_key, &aad::blob_data(manifest_id, hash))}/// Serde for bytes stored as a standard base64 string.diff --git a/core/rust/src/vault_sync/keys.rs b/core/rust/src/vault_sync/keys.rsindex 66cac2d6c..fea0ff716 100644--- a/core/rust/src/vault_sync/keys.rs+++ b/core/rust/src/vault_sync/keys.rs@@ -211,7 +211,7 @@ pub(crate) async fn signing_private_key(ctx: &mut Ctx) -> SyncResult<Option<Secrpub(crate) async fn shared_manifest_records(ctx: &Ctx) -> SyncResult<HashMap<String, SharedManifestDto>> {let Some(ciphertext) = state::get::<String>(&ctx.host, state::SHARED_MANIFESTS).await? else { return Ok(HashMap::new()) };let Some(key) = &ctx.encryption_key else { return Ok(HashMap::new()) };- match crypto::symmetric_decrypt(&ciphertext, key.expose_secret()).and_then(|json| serde_json::from_str(&json).map_err(Into::into)) {+ match crypto::aes_gcm::decrypt_text(&ciphertext, key.expose_secret(), &[]).and_then(|json| serde_json::from_str(&json).map_err(Into::into)) {Ok(records) => Ok(records),Err(error) => {ctx.warn(format!("[Sharing] The stored shared-manifest key records did not decrypt (re-keyed vault?); treating them as absent. {}", error)).await;@@ -222,7 +222,7 @@ pub(crate) async fn shared_manifest_records(ctx: &Ctx) -> SyncResult<HashMap<Str/// Persist the shared-manifest key records under `key`.pub(crate) async fn set_shared_manifest_records(ctx: &Ctx, records: &HashMap<String, SharedManifestDto>, key: &str) -> SyncResult<()> {- let ciphertext = crypto::symmetric_encrypt(&serde_json::to_string(records)?, key)?;+ let ciphertext = crypto::aes_gcm::encrypt_text(&serde_json::to_string(records)?, key, &[])?;state::set(&ctx.host, state::SHARED_MANIFESTS, &ciphertext).await?;ctx.cache_shared_veks(None);Ok(())diff --git a/core/rust/src/vault_sync/pull.rs b/core/rust/src/vault_sync/pull.rsindex 714c9bd3c..b0871bed4 100644--- a/core/rust/src/vault_sync/pull.rs+++ b/core/rust/src/vault_sync/pull.rs@@ -89,7 +89,7 @@ pub(crate) fn verify_decrypt_unpack(ciphertext: &[u8], vek: &str, aad: &[u8], ex}}let unreadable = |e: crate::common::error::VaultError| SyncError::ServerVaultUnreadable(format!("{}: {}", label, e));- let plain = crypto::symmetric_decrypt_bytes_with_aad(ciphertext, vek, aad).map_err(unreadable)?;+ let plain = crypto::aes_gcm::decrypt(ciphertext, vek, aad).map_err(unreadable)?;match vault_codec::unpack_versioned_payload(&plain).map_err(unreadable)? {UnpackedPayload::Readable(payload_json) => Ok(payload_json),UnpackedPayload::NewerFormat(version) => Err(newer_format(label, version)),@@ -247,12 +247,12 @@ fn served_encrypted_name(ctx: &Ctx, previous: &HashMap<String, SharedManifestDto/// Decrypt a shared manifest's name with the manifest's own key.pub(crate) fn open_manifest_name(ciphertext: &str, manifest_id: &str, manifest_key: &str) -> Option<String> {- crypto::symmetric_decrypt_with_aad(ciphertext, manifest_key, &crypto::aad::manifest_name(manifest_id)).ok().filter(|name| !name.is_empty())+ crypto::aes_gcm::decrypt_text(ciphertext, manifest_key, &crypto::aad::manifest_name(manifest_id)).ok().filter(|name| !name.is_empty())}/// Encrypt a shared manifest's name with the manifest's own key.pub(crate) fn encrypt_manifest_name(name: &str, manifest_id: &str, manifest_key: &str) -> SyncResult<String> {- Ok(crypto::symmetric_encrypt_with_aad(name, manifest_key, &crypto::aad::manifest_name(manifest_id))?)+ Ok(crypto::aes_gcm::encrypt_text(name, manifest_key, &crypto::aad::manifest_name(manifest_id))?)}/// Commit a pulled vault's revisions as the local believed-current revisions, manifests and buckets together.diff --git a/core/rust/src/vault_sync/push.rs b/core/rust/src/vault_sync/push.rsindex b7199e8cd..0d1ce6d81 100644--- a/core/rust/src/vault_sync/push.rs+++ b/core/rust/src/vault_sync/push.rs@@ -407,7 +407,7 @@ pub(crate) struct EncryptedPayload {/// Pack and encrypt a JSON payload under `key` bound to `aad`, logging its size at every stage.pub(crate) async fn encrypt_payload(ctx: &Ctx, label: &str, plaintext: &str, key: &str, aad: &[u8]) -> SyncResult<EncryptedPayload> {let packed = vault_codec::pack_payload(plaintext)?;- let ciphertext = crypto::symmetric_encrypt_raw_with_aad(&packed, key, aad)?;+ let ciphertext = crypto::aes_gcm::encrypt(&packed, key, aad)?;ctx.log(format!("[Push] {}: raw {} > compressed {} > encrypted {}.", label, format_kb(plaintext.len()), format_kb(packed.len()), format_kb(ciphertext.len()))).await;let hash = vault_codec::compute_ciphertext_hash(&ciphertext);Ok(EncryptedPayload { ciphertext, hash })diff --git a/core/rust/src/vault_sync/sharing.rs b/core/rust/src/vault_sync/sharing.rsindex 1c012e2be..3871ed7f0 100644--- a/core/rust/src/vault_sync/sharing.rs+++ b/core/rust/src/vault_sync/sharing.rs@@ -444,7 +444,7 @@ async fn create_shared_manifest(ctx: &mut Ctx) -> Outcome {return Ok(Err(Refusal::VaultUpgradeRequired));}- let manifest_vek = zeroize::Zeroizing::new(crypto::generate_key_base64());+ let manifest_vek = crypto::aes_gcm::generate_key();let requested_id = db::new_id();let self_encrypted_vek = keys::encrypt_manifest_vek(&manifest_vek, &requested_id, &self_public_key)?;let self_grant_signature = me.sign(&crypto::signing::grant_message(&requested_id, NEW_MANIFEST_KEY_VERSION, &me.user_id, &self_public_key, ALGORITHM_RSA_OAEP_SHA256, &self_encrypted_vek))?;diff --git a/core/rust/src/vault_sync/tests/blob_keys.rs b/core/rust/src/vault_sync/tests/blob_keys.rsindex 815ba1b3e..0b097b641 100644--- a/core/rust/src/vault_sync/tests/blob_keys.rs+++ b/core/rust/src/vault_sync/tests/blob_keys.rs@@ -6,17 +6,17 @@ const HASH: &str = "aa11";#[test]fn a_blob_opens_with_the_vek_through_its_own_key() {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let blob = encrypt_blob(&[1, 2, 3, 4], &vek, MANIFEST, HASH).unwrap();assert_eq!(decrypt_blob(&blob, &vek, MANIFEST, HASH).unwrap(), vec![1, 2, 3, 4]);- assert!(crypto::symmetric_decrypt_bytes(&blob.encrypted_data, &vek).is_err(), "the bytes are not encrypted with the VEK itself");- assert!(decrypt_blob(&blob, &crypto::generate_key_base64(), MANIFEST, HASH).is_err());+ assert!(crypto::aes_gcm::decrypt(&blob.encrypted_data, &vek, &[]).is_err(), "the bytes are not encrypted with the VEK itself");+ assert!(decrypt_blob(&blob, &crypto::aes_gcm::generate_key(), MANIFEST, HASH).is_err());}#[test]fn a_blob_does_not_open_at_another_address() {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let blob = encrypt_blob(&[1, 2, 3, 4], &vek, MANIFEST, HASH).unwrap();assert!(decrypt_blob(&blob, &vek, MANIFEST, "bb22").is_err(), "served under another hash");assert!(decrypt_blob(&blob, &vek, "0a1b2c3d-0000-0000-0000-000000000002", HASH).is_err(), "served under another manifest");@@ -29,7 +29,7 @@ fn a_blob_does_not_open_at_another_address() {#[test]fn changing_the_vek_only_encrypts_the_blob_key_again() {- let (old_vek, new_vek) = (crypto::generate_key_base64(), crypto::generate_key_base64());+ let (old_vek, new_vek) = (crypto::aes_gcm::generate_key(), crypto::aes_gcm::generate_key());let blob = encrypt_blob(&[9; 64], &old_vek, MANIFEST, HASH).unwrap();let key_aad = aad::blob_key(MANIFEST, HASH);@@ -42,7 +42,7 @@ fn changing_the_vek_only_encrypts_the_blob_key_again() {#[test]fn a_cached_blob_reads_back_as_it_was_written() {- let blob = encrypt_blob(&[5], &crypto::generate_key_base64(), MANIFEST, HASH).unwrap();+ let blob = encrypt_blob(&[5], &crypto::aes_gcm::generate_key(), MANIFEST, HASH).unwrap();let read: EncryptedBlob = serde_json::from_value(serde_json::to_value(&blob).unwrap()).unwrap();assert_eq!(read, blob);}diff --git a/core/rust/src/vault_sync/tests/blobs.rs b/core/rust/src/vault_sync/tests/blobs.rsindex 48c43dcf7..583322d27 100644--- a/core/rust/src/vault_sync/tests/blobs.rs+++ b/core/rust/src/vault_sync/tests/blobs.rs@@ -37,7 +37,7 @@ enum NotLoaded {/// A device that pulled `vault_with_blobs` while none of its blobs loaded.fn synced_without_blobs(how: NotLoaded) -> Synced {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let salt = vault_codec::generate_manifest_salt();let db = open_schema_db();vault_with_blobs(&db);@@ -47,7 +47,7 @@ fn synced_without_blobs(how: NotLoaded) -> Synced {server.borrow_mut().publish(&db, &vek, &salt, 7);server.borrow_mut().faults.withhold_blobs = true;}- NotLoaded::Undecryptable => server.borrow_mut().publish_with_blob_key(&db, &vek, &salt, 7, &crypto::generate_key_base64()),+ NotLoaded::Undecryptable => server.borrow_mut().publish_with_blob_key(&db, &vek, &salt, 7, &crypto::aes_gcm::generate_key()),}let mut host = TestHost::logged_in(&vek, &server);let pulled = host.sync();@@ -55,7 +55,7 @@ fn synced_without_blobs(how: NotLoaded) -> Synced {assert_eq!(host.item_names(), vec!["Server item"]);let not_loaded = query(&host.local, "SELECT Id FROM Attachments WHERE IsDeleted = 0 AND Blob IS NULL AND BlobHash IS NOT NULL", &[]).unwrap();assert_eq!(not_loaded.len(), 1, "the attachment row is there, not loaded, and knows its blob");- Synced { server, host, db, vek, salt }+ Synced { server, host, db, vek: vek.to_string(), salt }}#[test]diff --git a/core/rust/src/vault_sync/tests/fake_server.rs b/core/rust/src/vault_sync/tests/fake_server.rsindex dbb25f09c..b29420621 100644--- a/core/rust/src/vault_sync/tests/fake_server.rs+++ b/core/rust/src/vault_sync/tests/fake_server.rs@@ -144,7 +144,7 @@ impl FakeServer {/// LEGACY: hold the account as a sqlite blob under `unlock_key`.pub fn publish_legacy(&mut self, db: &Connection, unlock_key: &str, revision: i64) {let bytes = db.serialize(rusqlite::MAIN_DB).unwrap().to_vec();- self.legacy = Some(LegacyVault { blob: crypto::symmetric_encrypt_bytes(&bytes, unlock_key).unwrap(), revision });+ self.legacy = Some(LegacyVault { blob: crypto::vault_blob_encrypt(&bytes, unlock_key).unwrap(), revision });}/// Serve a shared manifest exactly as given (a manifest dto), for the grant tests.@@ -387,7 +387,7 @@ impl FakeServer {/// A manifest or bucket payload packed and encrypted under `vek`, with its ciphertext hash.fn encrypt_payload(json: &str, vek: &str, aad: &[u8]) -> (String, String) {let packed = vault_codec::pack_payload(json).unwrap();- let blob = crypto::symmetric_encrypt_raw_with_aad(&packed, vek, aad).unwrap();+ let blob = crypto::aes_gcm::encrypt(&packed, vek, aad).unwrap();let hash = vault_codec::compute_ciphertext_hash(&blob);(crate::common::encoding::base64_encode(&blob), hash)}@@ -407,6 +407,6 @@ pub fn decrypt_manifest(blob: &str, vek: &str, manifest_id: &str) -> Value {}fn decrypt_payload(blob: &str, vek: &str, aad: &[u8]) -> Value {- let plain = crypto::symmetric_decrypt_bytes_with_aad(&crate::common::encoding::base64_decode(blob).unwrap(), vek, aad).unwrap();+ let plain = crypto::aes_gcm::decrypt(&crate::common::encoding::base64_decode(blob).unwrap(), vek, aad).unwrap();serde_json::from_str(&vault_codec::unpack_payload(&plain).unwrap()).unwrap()}diff --git a/core/rust/src/vault_sync/tests/grants.rs b/core/rust/src/vault_sync/tests/grants.rsindex d1851499c..2fe5f7ec8 100644--- a/core/rust/src/vault_sync/tests/grants.rs+++ b/core/rust/src/vault_sync/tests/grants.rs@@ -9,7 +9,7 @@ use crate::crypto;/// Sync a fresh device against a personal vault plus the given shared manifest dto.fn sync_with_shared_manifest(shared: Value) -> (TestHost, Value) {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let server = server_with_item(&vek);server.borrow_mut().add_manifest_dto(shared);let mut host = TestHost::logged_in(&vek, &server);diff --git a/core/rust/src/vault_sync/tests/keys.rs b/core/rust/src/vault_sync/tests/keys.rsindex b80464d2e..db1ee3052 100644--- a/core/rust/src/vault_sync/tests/keys.rs+++ b/core/rust/src/vault_sync/tests/keys.rs@@ -14,7 +14,7 @@ use secrecy::ExposeSecret;/// cached for offline unlock, and the VEK comes back as the key to store.#[test]fn resolve_vault_key_opens_the_chain_from_the_server() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let hierarchy = crypto::create_account_key_hierarchy(&unlock_key).unwrap();let server = FakeServer::new();server.borrow_mut().set_vault_key(&hierarchy);@@ -44,7 +44,7 @@ fn resolve_vault_key_opens_the_chain_from_the_server() {/// A legacy account has no chain: the password-derived key is the vault key and any stale cached chain is dropped.#[test]fn resolve_vault_key_keeps_the_unlock_key_for_a_legacy_account() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let mut host = TestHost::new(&unlock_key);host.serve(&FakeServer::new());host.set_state(state::ENCRYPTED_ACCOUNT_KEY, json!("stale"));@@ -53,14 +53,14 @@ fn resolve_vault_key_keeps_the_unlock_key_for_a_legacy_account() {assert_eq!(result["success"], true, "{}", result);assert_eq!(result["hasVaultKey"], false);- assert_eq!(result["encryptionKey"], unlock_key);+ assert_eq!(result["encryptionKey"], *unlock_key);assert!(!host.state.contains_key(state::ENCRYPTED_ACCOUNT_KEY));}/// Offline, the cached chain opens with the password-derived key (a re-login after a forced logout).#[test]fn resolve_vault_key_opens_the_cached_chain_when_the_server_is_unreachable() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let hierarchy = crypto::create_account_key_hierarchy(&unlock_key).unwrap();let mut host = TestHost::new(&unlock_key);host.set_state(state::ENCRYPTED_ACCOUNT_KEY, json!(hierarchy.account_keys.encrypted_account_key));@@ -77,19 +77,19 @@ fn resolve_vault_key_opens_the_cached_chain_when_the_server_is_unreachable() {/// own account key is damage, not a wrong password (E-207); an unknown encryption algorithm asks for an app update.#[test]fn resolve_vault_key_tells_the_failure_modes_apart() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let hierarchy = crypto::create_account_key_hierarchy(&unlock_key).unwrap();let server = FakeServer::new();server.borrow_mut().set_vault_key(&hierarchy);- let mut host = TestHost::new(&crypto::generate_key_base64());+ let mut host = TestHost::new(&crypto::aes_gcm::generate_key());host.serve(&server);let result = host.run("resolveVaultKey");assert_eq!(result["errorCode"], "E-206", "{}", result);assert!(result.get("encryptionKey").is_none());let mut damaged = hierarchy.clone();- damaged.account_keys.encrypted_vek = crypto::encrypt_key(&crypto::generate_key_base64(), &crypto::generate_key_base64(), crypto::aad::PERSONAL_VEK).unwrap();+ damaged.account_keys.encrypted_vek = crypto::encrypt_key(&crypto::aes_gcm::generate_key(), &crypto::aes_gcm::generate_key(), crypto::aad::PERSONAL_VEK).unwrap();server.borrow_mut().set_vault_key(&damaged);let mut host = TestHost::new(&unlock_key);host.serve(&server);@@ -109,7 +109,7 @@ fn resolve_vault_key_tells_the_failure_modes_apart() {/// together with the VEK it is now encrypted under.#[test]fn a_hierarchy_created_on_another_device_is_accepted_on_the_next_pull() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let hierarchy = crypto::create_account_key_hierarchy(&unlock_key).unwrap();let vek = hierarchy.vault_encryption_key.clone();let server = server_with_item(&vek);@@ -132,7 +132,7 @@ fn a_hierarchy_created_on_another_device_is_accepted_on_the_next_pull() {/// is not silently upgraded. Resolving the key is the host's job.#[test]fn a_device_with_a_cached_chain_is_not_probed_and_its_session_key_is_left_alone() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let hierarchy = crypto::create_account_key_hierarchy(&unlock_key).unwrap();let vek = hierarchy.vault_encryption_key.clone();let server = FakeServer::new();@@ -155,7 +155,7 @@ fn a_device_with_a_cached_chain_is_not_probed_and_its_session_key_is_left_alone(/// and then once per run.#[test]fn a_legacy_account_is_probed_for_a_vault_key_only_when_it_pulls_or_pushes() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(3);let mut host = legacy_device(&unlock_key, &server, |_| {});diff --git a/core/rust/src/vault_sync/tests/migration.rs b/core/rust/src/vault_sync/tests/migration.rsindex 088c3e3a7..93e8144b8 100644--- a/core/rust/src/vault_sync/tests/migration.rs+++ b/core/rust/src/vault_sync/tests/migration.rs@@ -11,7 +11,7 @@ use crate::vault_codec;#[test]fn legacy_account_without_vault_key_reports_the_manifest_migration() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish(&open_schema_db(), &unlock_key, &vault_codec::generate_manifest_salt(), 3);let mut host = legacy_device(&unlock_key, &server, |_| {});@@ -25,7 +25,7 @@ fn legacy_account_without_vault_key_reports_the_manifest_migration() {#[test]fn manifest_migration_generates_the_key_hierarchy_and_pushes() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(3);let mut host = legacy_device(&unlock_key, &server, |db| insert_item(db, ITEM_A, "Old item"));@@ -35,7 +35,7 @@ fn manifest_migration_generates_the_key_hierarchy_and_pushes() {assert_eq!(result["success"], true, "{}", result);assert_eq!(result["pushed"], true);let new_key = host.vault_key.clone();- assert_ne!(new_key, unlock_key, "the host receives the new VEK through the store command");+ assert_ne!(new_key, *unlock_key, "the host receives the new VEK through the store command");let write = host.last_vault_write();let account_keys = &write["migration"]["accountKeys"];assert!(account_keys["encryptedAccountKey"].is_string(), "the migration push carries the key hierarchy");@@ -54,7 +54,7 @@ fn manifest_migration_generates_the_key_hierarchy_and_pushes() {#[test]fn account_upgrade_decodes_base64_text_that_0_30_merges_left_in_blob_columns() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let bytes = vec![0x00u8, 0xFF, 0xC3, 0x28, 0x10];let text = crate::common::encoding::base64_encode(&bytes);let server = FakeServer::new();@@ -78,7 +78,7 @@ fn account_upgrade_decodes_base64_text_that_0_30_merges_left_in_blob_columns() {fn a_key_migration_push_is_refused_while_a_personal_blob_is_not_loaded() {// The migration encrypts every personal blob again under the new key; one it has no bytes for would stay under// the old key and never open again. The vault stays dirty and the migration runs again once the blob loads.- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(3);let mut host = legacy_device(&unlock_key, &server, |db| {@@ -90,12 +90,12 @@ fn a_key_migration_push_is_refused_while_a_personal_blob_is_not_loaded() {assert_eq!(result["pushed"], false, "{}", result);assert!(host.vault_writes().is_empty(), "nothing was written with the new key");- assert_eq!(host.vault_key, unlock_key, "and the session keeps its key");+ assert_eq!(host.vault_key, *unlock_key, "and the session keeps its key");}#[test]fn schema_rebuild_of_a_stale_vault_pushes_without_touching_the_key_hierarchy() {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(3);let mut host = legacy_device(&vek, &server, |db| {@@ -115,13 +115,13 @@ fn schema_rebuild_of_a_stale_vault_pushes_without_touching_the_key_hierarchy() {assert_eq!(host.item_names(), vec!["Kept item"]);assert!(host.requests_to("VaultKey/Password").is_empty(), "a migrated account is not probed for a key hierarchy");assert!(host.last_vault_write()["migration"].is_null(), "no key hierarchy is created");- assert_eq!(host.vault_key, vek, "the session key stays the VEK");+ assert_eq!(host.vault_key, *vek, "the session key stays the VEK");}/// Two legacy sessions of one account: the first upgrades the account, the second still holds its sqlite-blob vault/// with a row that names no manifest, which the schema rebuild refuses.fn session_of_an_account_upgraded_elsewhere() -> TestHost {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(3);let mut upgraded = legacy_device(&unlock_key, &server, |db| insert_item(db, ITEM_A, "Upgraded item"));@@ -170,7 +170,7 @@ fn pre_format_session(unlock_key: &str, dirty: bool) -> TestHost {#[test]fn manifest_migration_of_a_pre_format_session_pulls_the_server_vault_first() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let mut host = pre_format_session(&unlock_key, false);let result = host.run("migrateManifest");@@ -188,7 +188,7 @@ fn manifest_migration_of_a_pre_format_session_pulls_the_server_vault_first() {#[test]fn manifest_migration_of_a_dirty_pre_format_session_keeps_the_local_vault() {- let unlock_key = crypto::generate_key_base64();+ let unlock_key = crypto::aes_gcm::generate_key();let mut host = pre_format_session(&unlock_key, true);let result = host.run("migrateManifest");diff --git a/core/rust/src/vault_sync/tests/mod.rs b/core/rust/src/vault_sync/tests/mod.rsindex d96710c8e..8e41754d4 100644--- a/core/rust/src/vault_sync/tests/mod.rs+++ b/core/rust/src/vault_sync/tests/mod.rs@@ -125,7 +125,7 @@ pub fn legacy_device(unlock_key: &str, server: &Server, seed: impl FnOnce(&Conne/// A server at revision 7 holding the vault `seed` builds, pulled by a logged-in device.pub fn synced(seed: impl FnOnce(&Connection)) -> Synced {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let salt = vault_codec::generate_manifest_salt();let db = open_schema_db();seed(&db);@@ -136,7 +136,7 @@ pub fn synced(seed: impl FnOnce(&Connection)) -> Synced {assert_eq!(pulled["success"], true, "{}", pulled);host.requests.clear();host.store_calls.clear();- Synced { server, host, db, vek, salt }+ Synced { server, host, db, vek: vek.to_string(), salt }}impl Synced {diff --git a/core/rust/src/vault_sync/tests/sync.rs b/core/rust/src/vault_sync/tests/sync.rsindex 7c1f20036..c17087973 100644--- a/core/rust/src/vault_sync/tests/sync.rs+++ b/core/rust/src/vault_sync/tests/sync.rs@@ -15,7 +15,7 @@ const OTHER_DEVICE: &str = "0a9b8c7d-6e5f-4a3b-9c2d-1e0f2a3b4c5d";#[test]fn fresh_client_pulls_and_materializes_the_server_vault() {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let server = server_with_item(&vek);let mut host = TestHost::logged_in(&vek, &server);@@ -41,7 +41,7 @@ fn fresh_client_pulls_and_materializes_the_server_vault() {#[test]fn new_account_starts_from_an_empty_vault_and_writes_its_first_revision() {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(0);let mut host = TestHost::logged_in(&vek, &server);@@ -67,7 +67,7 @@ fn new_account_starts_from_an_empty_vault_and_writes_its_first_revision() {#[test]fn new_account_whose_first_write_fails_retries_it_on_the_next_sync() {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(0);server.borrow_mut().faults.drop_writes = true;@@ -91,7 +91,7 @@ fn new_account_whose_first_write_fails_retries_it_on_the_next_sync() {fn contentless_personal_manifest_past_revision_zero_is_refused() {let server = FakeServer::new();server.borrow_mut().publish_contentless_personal(4);- let mut host = TestHost::logged_in(&crypto::generate_key_base64(), &server);+ let mut host = TestHost::logged_in(&crypto::aes_gcm::generate_key(), &server);let result = host.sync();@@ -102,7 +102,7 @@ fn contentless_personal_manifest_past_revision_zero_is_refused() {#[test]fn unknown_storage_format_is_refused_not_read_as_legacy() {- let vek = crypto::generate_key_base64();+ let vek = crypto::aes_gcm::generate_key();let server = server_with_item(&vek);let mut vault = server.borrow().vault();vault["storageFormat"] = json!("manifest-v2");@@ -336,7 +336,7 @@ fn a_write_the_server_keeps_refusing_gives_up_after_three_resyncs() {#[test]fn unreachable_server_with_a_local_vault_goes_offline() {- let mut host = TestHost::new(&crypto::generate_key_base64());+ let mut host = TestHost::new(&crypto::aes_gcm::generate_key());host.store_local_as_blob();let result = host.sync();@@ -350,7 +350,7 @@ fn unreachable_server_with_a_local_vault_goes_offline() {fn expired_session_requires_logout() {let server = FakeServer::new();server.borrow_mut().faults.status_http = Some(401);- let mut host = TestHost::logged_in(&crypto::generate_key_base64(), &server);+ let mut host = TestHost::logged_in(&crypto::aes_gcm::generate_key(), &server);let result = host.sync();@@ -363,7 +363,7 @@ fn expired_session_requires_logout() {fn password_changed_elsewhere_requires_logout() {let server = FakeServer::new();server.borrow_mut().srp_salt = "new-salt".to_string();- let mut host = TestHost::logged_in(&crypto::generate_key_base64(), &server);+ let mut host = TestHost::logged_in(&crypto::aes_gcm::generate_key(), &server);host.set_state(state::UNLOCK_KEY_DERIVATION_PARAMS, json!({ "salt": "old-salt", "encryptionType": "Argon2Id", "encryptionSettings": "{}" }));let result = host.sync();diff --git a/core/rust/src/vault_sync/tests/test_host.rs b/core/rust/src/vault_sync/tests/test_host.rsindex bf358f414..0a83a75aa 100644--- a/core/rust/src/vault_sync/tests/test_host.rs+++ b/core/rust/src/vault_sync/tests/test_host.rs@@ -147,7 +147,7 @@ impl TestHost {/// Encrypt the local database as the at-rest blob, the way the app stores it.pub fn store_local_as_blob(&mut self) {let bytes = self.local.serialize(MAIN_DB).unwrap().to_vec();- self.vault_blob = Some(crypto::symmetric_encrypt_bytes(&bytes, &self.vault_key).unwrap());+ self.vault_blob = Some(crypto::vault_blob_encrypt(&bytes, &self.vault_key).unwrap());}/// Change the local vault the way the app does: write rows, store the blob, count the mutation, mark dirty.