π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rename
Manav Rathia5fe20b0e988
diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.tsindex 0a909254b1..4498208df8 100644--- a/web/packages/base/crypto/ente-impl.ts+++ b/web/packages/base/crypto/ente-impl.ts@@ -39,3 +39,4 @@ export const _generateDeriveKeySalt = libsodium.generateDeriveKeySalt;export const _deriveKey = libsodium.deriveKey;export const _deriveSensitiveKey = libsodium.deriveSensitiveKey;export const _deriveInteractiveKey = libsodium.deriveInteractiveKey;+export const _deriveSubKey = libsodium.deriveSubKey;diff --git a/web/packages/base/crypto/index.ts b/web/packages/base/crypto/index.tsindex 0862454d19..2fb20e5a01 100644--- a/web/packages/base/crypto/index.ts+++ b/web/packages/base/crypto/index.ts@@ -507,3 +507,18 @@ export const deriveInteractiveKey = (inWorker()? ei._deriveInteractiveKey(passphrase): sharedWorker().then((w) => w.deriveInteractiveKey(passphrase));++/**+ * Derive a subkey of the given {@link key} using the specified parameters.+ */+export const deriveSubKey = async (+ key: string,+ subKeyLength: number,+ subKeyID: number,+ context: string,+) =>+ inWorker()+ ? ei._deriveSubKey(key, subKeyLength, subKeyID, context)+ : sharedWorker().then((w) =>+ w.deriveSubKey(key, subKeyLength, subKeyID, context),+ );diff --git a/web/packages/base/crypto/libsodium.ts b/web/packages/base/crypto/libsodium.tsindex 77b1e517c2..45f511c9f8 100644--- a/web/packages/base/crypto/libsodium.ts+++ b/web/packages/base/crypto/libsodium.ts@@ -924,12 +924,33 @@ export const deriveInteractiveKey = async (return { key, salt, opsLimit, memLimit };};-export async function generateSubKey(+/**+ * Derive a {@link subKeyID}-th subkey of length {@link subKeyLength} bytes+ * using the given {@link key} and the {@link context}.+ *+ * Multiple secret subkeys can be (deterministically) derived from a single+ * high-entropy key. Knowledge of the derived key does not impact the security+ * of the key from which it was derived, or of its potential sibling subkeys.+ *+ * See: https://doc.libsodium.org/key_derivation+ *+ * @param key The key whose subkey we are deriving. In the context of key+ * derivation, this is usually referred to as the "master key", but we try to+ * deemphasize that nomenclature to avoid confusion with the user's master key.+ *+ * @param subKeyLength The length of the required subkey.+ *+ * @param subKeyID An identifier of the subkey.+ *+ * @param context A short but otherwise arbitrary string (non-secret) used to+ * separate domains in which the subkeys are going to be used.+ */+export const deriveSubKey = async (key: string,subKeyLength: number,subKeyID: number,context: string,-) {+) => {await sodium.ready;return await toB64(sodium.crypto_kdf_derive_from_key(@@ -939,4 +960,4 @@ export async function generateSubKey(await fromB64(key),),);-}+};diff --git a/web/packages/base/crypto/worker.ts b/web/packages/base/crypto/worker.tsindex f1c46f7571..99b890539d 100644--- a/web/packages/base/crypto/worker.ts+++ b/web/packages/base/crypto/worker.ts@@ -47,21 +47,13 @@ export class CryptoWorker {deriveKey = ei._deriveKey;deriveSensitiveKey = ei._deriveSensitiveKey;deriveInteractiveKey = ei._deriveInteractiveKey;+ deriveSubKey = ei._deriveSubKey;// TODO: -- AUDIT BELOW --async generateKeyAndEncryptToB64(data: string) {return libsodium.generateKeyAndEncryptToB64(data);}-- async generateSubKey(- key: string,- subKeyLength: number,- subKeyID: number,- context: string,- ) {- return libsodium.generateSubKey(key, subKeyLength, subKeyID, context);- }}expose(CryptoWorker);