@@ -12,34 +12,34 @@ import 'package:openhaystack_mobile/ffi/ffi.dart'
1212
1313class DecryptReports {
1414 /// Decrypts a given [FindMyReport] with the given private key.
15- static Future <List <FindMyLocationReport >> decryptReportChunk (List <FindMyReport > reportChunk , Uint8List privateKeyBytes) async {
15+ static Future <List <FindMyLocationReport >> decryptReports (List <FindMyReport > reports , Uint8List privateKeyBytes) async {
1616 final curveDomainParam = ECCurve_secp224r1 ();
1717
18- final ephemeralKeyChunk = reportChunk .map ((report) {
18+ final ephemeralKeys = reports .map ((report) {
1919 final payloadData = report.payload;
2020 final ephemeralKeyBytes = payloadData.sublist (5 , 62 );
2121 return ephemeralKeyBytes;
2222 }).toList ();
2323
24- late final List <Uint8List > sharedKeyChunk ;
24+ late final List <Uint8List > sharedKeys ;
2525
2626 try {
2727 debugPrint ("Trying native ECDH" );
28- final ephemeralKeyBlob = Uint8List .fromList (ephemeralKeyChunk .expand ((element) => element).toList ());
28+ final ephemeralKeyBlob = Uint8List .fromList (ephemeralKeys .expand ((element) => element).toList ());
2929 final sharedKeyBlob = await api.ecdh (publicKeyBlob: ephemeralKeyBlob, privateKey: privateKeyBytes);
30- final chunkSize = (sharedKeyBlob.length / ephemeralKeyChunk .length).ceil ();
31- sharedKeyChunk = [
32- for (var i = 0 ; i < sharedKeyBlob.length; i += chunkSize )
33- sharedKeyBlob.sublist (i, i + chunkSize < sharedKeyBlob.length ? i + chunkSize : sharedKeyBlob.length),
30+ final keySize = (sharedKeyBlob.length / ephemeralKeys .length).ceil ();
31+ sharedKeys = [
32+ for (var i = 0 ; i < sharedKeyBlob.length; i += keySize )
33+ sharedKeyBlob.sublist (i, i + keySize < sharedKeyBlob.length ? i + keySize : sharedKeyBlob.length),
3434 ];
3535 }
3636 catch (e) {
3737 debugPrint ("Native ECDH failed: $e " );
38- debugPrint ("Falling back to pure Dart ECDH!" );
38+ debugPrint ("Falling back to pure Dart ECDH on single thread !" );
3939 final privateKey = ECPrivateKey (
4040 pc_utils.decodeBigIntWithSign (1 , privateKeyBytes),
4141 curveDomainParam);
42- sharedKeyChunk = ephemeralKeyChunk .map ((ephemeralKey) {
42+ sharedKeys = ephemeralKeys .map ((ephemeralKey) {
4343 final decodePoint = curveDomainParam.curve.decodePoint (ephemeralKey);
4444 final ephemeralPublicKey = ECPublicKey (decodePoint, curveDomainParam);
4545
@@ -48,8 +48,8 @@ class DecryptReports {
4848 }).toList ();
4949 }
5050
51- final decryptedLocationChunk = reportChunk .mapIndexed ((index, report) {
52- final derivedKey = _kdf (sharedKeyChunk [index], ephemeralKeyChunk [index]);
51+ final decryptedLocations = reports .mapIndexed ((index, report) {
52+ final derivedKey = _kdf (sharedKeys [index], ephemeralKeys [index]);
5353 final payloadData = report.payload;
5454 _decodeTimeAndConfidence (payloadData, report);
5555 final encData = payloadData.sublist (62 , 72 );
@@ -59,7 +59,7 @@ class DecryptReports {
5959 return locationReport;
6060 }).toList ();
6161
62- return decryptedLocationChunk ;
62+ return decryptedLocations ;
6363 }
6464
6565 /// Decodes the unencrypted timestamp and confidence
0 commit comments