π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
type
Manav Rathi40f3ad592fb7
diff --git a/web/packages/base/crypto/libsodium.ts b/web/packages/base/crypto/libsodium.tsindex a9b4f2d829..3a1714b35a 100644--- a/web/packages/base/crypto/libsodium.ts+++ b/web/packages/base/crypto/libsodium.ts@@ -12,6 +12,7 @@ import { mergeUint8Arrays } from "ente-utils/array";import sodium, { type StateAddress } from "libsodium-wrappers-sumo";import type {BytesOrB64,+ DerivedKey,EncryptedBlob,EncryptedBlobB64,EncryptedBlobBytes,@@ -865,7 +866,10 @@ export const deriveKey = async (* during the derivation (this information will be needed the user's other* clients to derive the same result).*/-export const deriveSensitiveKey = async (passphrase: string, salt: string) => {+export const deriveSensitiveKey = async (+ passphrase: string,+ salt: string,+): Promise<DerivedKey> => {await sodium.ready;const desiredStrength =@@ -896,7 +900,7 @@ export const deriveSensitiveKey = async (passphrase: string, salt: string) => {while (memLimit > minMemLimit) {try {const key = await deriveKey(passphrase, salt, opsLimit, memLimit);- return { key, opsLimit, memLimit };+ return { key, salt, opsLimit, memLimit };} catch {opsLimit *= 2;memLimit /= 2;@@ -912,12 +916,12 @@ export const deriveSensitiveKey = async (passphrase: string, salt: string) => {export const deriveInteractiveKey = async (passphrase: string,salt: string,-) => {+): Promise<DerivedKey> => {const opsLimit = sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE;const memLimit = sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE;const key = await deriveKey(passphrase, salt, opsLimit, memLimit);- return { key, opsLimit, memLimit };+ return { key, salt, opsLimit, memLimit };};export async function generateSubKey(diff --git a/web/packages/base/crypto/types.ts b/web/packages/base/crypto/types.tsindex d79a32f85e..64b29248b5 100644--- a/web/packages/base/crypto/types.ts+++ b/web/packages/base/crypto/types.ts@@ -129,3 +129,26 @@ export interface EncryptedFile {*/decryptionHeader: string;}++/**+ * A key derived from a user provided passphrase, and the various attributes+ * that were used during the key derivation.+ */+export interface DerivedKey {+ /**+ * The newly derived key itself, as a base64 encoded string.+ */+ key: string;+ /**+ * The randomly generated salt (as a base64 string) that was used when deriving the key.+ */+ salt: string;+ /**+ * opsLimit used during key derivation.+ */+ opsLimit: number;+ /**+ * memLimit used during key derivation.+ * */+ memLimit: number;+}