-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/origin/dev'
# Conflicts: # benchmark/crypt_benchmark.dart # benchmark/models.dart
- Loading branch information
Showing
10 changed files
with
75 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:convert/convert.dart'; | ||
import 'package:safe_file_sender/benchmark/models.dart'; | ||
import 'package:safe_file_sender/crypto/crypto.dart'; | ||
|
||
final _file = File("${Directory.current.path}/files/input.exe"); | ||
late Uint8List _testKey; | ||
|
||
void main() { | ||
final start = DateTime.now().millisecondsSinceEpoch; | ||
final userA = AppCrypto.generateECKeyPair(); | ||
final userB = AppCrypto.generateECKeyPair(); | ||
final sharedKey = | ||
AppCrypto.deriveSharedSecret(userA.privateKey, userB.publicKey); | ||
|
||
final file = File("${Directory.current.path}/files/input.exe"); | ||
final endDeriveSharedKey = DateTime.now().millisecondsSinceEpoch; | ||
print("Benchmark derive shared key: ${(endDeriveSharedKey - start)}ms"); | ||
final hmac = AppCrypto.generateHMAC(sharedKey, file.readAsBytesSync()); | ||
print("HMAC ${hex.encode(hmac)}"); | ||
final end = DateTime.now().millisecondsSinceEpoch; | ||
print("Benchmark generate HMAC: ${(end - start)}ms"); | ||
|
||
///Benchmark encryption | ||
final startEnc = DateTime.now().millisecondsSinceEpoch; | ||
AppCrypto.encryptAES(file.readAsBytesSync(), sharedKey); | ||
final endEnc = DateTime.now().millisecondsSinceEpoch; | ||
|
||
print("Benchmark encryption: ${(endEnc - startEnc)}ms"); | ||
_testKey = base64Decode( | ||
AppCrypto.encodeECPublicKey(AppCrypto.generateECKeyPair().publicKey)); | ||
_benchmarkSharedKey(); | ||
_benchmarkEncryption(); | ||
_benchmarkHmacGeneration(); | ||
} | ||
|
||
void _benchmarkSharedKey() { | ||
final benchmark = BenchmarkTimer("share key derive"); | ||
|
||
benchmark.run(() { | ||
final userA = AppCrypto.generateECKeyPair(); | ||
final userB = AppCrypto.generateECKeyPair(); | ||
AppCrypto.deriveSharedSecret(userA.privateKey, userB.publicKey); | ||
}); | ||
} | ||
|
||
void _benchmarkHmacGeneration() { | ||
final benchmark = BenchmarkTimer("hmac generation"); | ||
|
||
benchmark.run(() { | ||
AppCrypto.generateHMAC(_testKey, _file.readAsBytesSync()); | ||
}); | ||
} | ||
|
||
void _benchmarkEncryption() { | ||
final benchmark = BenchmarkTimer("file encryption"); | ||
benchmark.run(() { | ||
AppCrypto.encryptAES(_file.readAsBytesSync(), _testKey); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class BenchmarkTimer { | ||
final String _name; | ||
|
||
int run(Function() action) { | ||
final start = DateTime.now().millisecondsSinceEpoch; | ||
action.call(); | ||
final end = DateTime.now().millisecondsSinceEpoch; | ||
final result = end - start; | ||
print("Benchmark for ($_name): $result ms"); | ||
return result; | ||
} | ||
|
||
BenchmarkTimer(this._name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
abstract class BaseEventListeners { | ||
Future<void> onPublicKeyReceived(String publicKey); | ||
|
||
Future<void> onConnected(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:safe_file_sender/models/base/base_event_listener.dart'; | ||
|
||
abstract class ReceiverListeners extends BaseEventListeners { | ||
Future<void> onIdentifierReceived(String publicKey); | ||
|
||
Future<void> onFileReceived(String fileId, String fileName, String hmac); | ||
} | ||
|
||
abstract class SenderListeners extends BaseEventListeners {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters