π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Use file stream to improve hashing speed
Neeraj Gupta85c14b884b3d
diff --git a/mobile/plugins/ente_crypto/lib/src/crypto.dart b/mobile/plugins/ente_crypto/lib/src/crypto.dartindex 7a3ec6c3c5..9f7a10f8c2 100644--- a/mobile/plugins/ente_crypto/lib/src/crypto.dart+++ b/mobile/plugins/ente_crypto/lib/src/crypto.dart@@ -51,26 +51,14 @@ Uint8List cryptoKdfDeriveFromKey();}-// Returns the hash for a given file, chunking it in batches of hashChunkSize+// Returns the hash for a given fileFuture<Uint8List> cryptoGenericHash(Map<String, dynamic> args) async {- final sourceFile = File(args["sourceFilePath"]);- final sourceFileLength = await sourceFile.length();- final inputFile = sourceFile.openSync(mode: FileMode.read);+ final file = File(args["sourceFilePath"]);final state =Sodium.cryptoGenerichashInit(null, Sodium.cryptoGenerichashBytesMax);- var bytesRead = 0;- bool isDone = false;- while (!isDone) {- var chunkSize = hashChunkSize;- if (bytesRead + chunkSize >= sourceFileLength) {- chunkSize = sourceFileLength - bytesRead;- isDone = true;- }- final buffer = await inputFile.read(chunkSize);- bytesRead += chunkSize;- Sodium.cryptoGenerichashUpdate(state, buffer);+ await for (final chunk in file.openRead()) {+ Sodium.cryptoGenerichashUpdate(state, Uint8List.fromList(chunk));}- await inputFile.close();return Sodium.cryptoGenerichashFinal(state, Sodium.cryptoGenerichashBytesMax);}