diff --git a/bin/_argon2.dart b/bin/_argon2.dart index f49c070..c536463 100644 --- a/bin/_argon2.dart +++ b/bin/_argon2.dart @@ -4,37 +4,11 @@ import 'dart:ffi'; import 'dart:io'; -import 'package:ffi/ffi.dart'; -import 'package:kdbx/kdbx.dart'; +import 'package:argon2_ffi_base/argon2_ffi_base.dart'; // TODO: This should be somehow combined with the test variant // which also loads the requierd dylib/so files. -typedef Argon2HashNative = Pointer Function( - Pointer key, - IntPtr keyLen, - Pointer salt, - Uint64 saltlen, - Uint32 m_cost, // memory cost - Uint32 t_cost, // time cost (number iterations) - Uint32 parallelism, - IntPtr hashlen, - Uint8 type, - Uint32 version, -); -typedef Argon2Hash = Pointer Function( - Pointer key, - int keyLen, - Pointer salt, - int saltlen, - int m_cost, // memory cost - int t_cost, // time cost (number iterations) - int parallelism, - int hashlen, - int type, - int version, -); - class Argon2Test extends Argon2Base { Argon2Test() { final argon2lib = Platform.isMacOS diff --git a/example/pubspec.lock b/example/pubspec.lock index de62edf..188055a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -85,11 +85,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" intl: dependency: transitive description: @@ -188,11 +183,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.22.2" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" source_span: dependency: transitive description: @@ -235,13 +225,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.2" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.8" xml: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 88f9809..287a631 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -7,8 +7,6 @@ environment: sdk: ">=2.2.2 <3.0.0" dependencies: - flutter: - sdk: flutter kdbx: path: ../ diff --git a/lib/kdbx.dart b/lib/kdbx.dart index fba1fc8..a8b690d 100644 --- a/lib/kdbx.dart +++ b/lib/kdbx.dart @@ -1,7 +1,6 @@ /// dart library for reading keepass file format (kdbx). library kdbx; -export 'src/crypto/argon2.dart'; export 'src/crypto/protected_value.dart' show ProtectedValue, StringValue, PlainValue; export 'src/kdbx_binary.dart' show KdbxBinary; diff --git a/lib/src/crypto/argon2.dart b/lib/src/crypto/argon2.dart deleted file mode 100644 index dc30d80..0000000 --- a/lib/src/crypto/argon2.dart +++ /dev/null @@ -1,95 +0,0 @@ -import 'dart:convert'; -import 'dart:ffi'; -import 'dart:typed_data'; - -import 'package:ffi/ffi.dart'; -import 'package:ffi_helper/ffi_helper.dart'; -import 'package:meta/meta.dart'; - -// ignore_for_file: non_constant_identifier_names -typedef Argon2HashNative = Pointer Function( - Pointer key, - Uint32 keyLen, - Pointer salt, - Uint32 saltlen, - Uint32 m_cost, // memory cost - Uint32 t_cost, // time cost (number iterations) - Uint32 parallelism, - Uint32 hashlen, - Uint8 type, - Uint32 version, -); - -typedef Argon2Hash = Pointer Function( - Pointer key, - int keyLen, - Pointer salt, - int saltlen, - int m_cost, // memory cost - int t_cost, // time cost (number iterations) - int parallelism, - int hashlen, - int type, - int version, -); - -abstract class Argon2 { - Uint8List argon2(Argon2Arguments args); - - Future argon2Async(Argon2Arguments args); -} - -class Argon2Arguments { - Argon2Arguments(this.key, this.salt, this.memory, this.iterations, - this.length, this.parallelism, this.type, this.version); - - final Uint8List key; - final Uint8List salt; - final int memory; - final int iterations; - final int length; - final int parallelism; - final int type; - final int version; -} - -abstract class Argon2Base extends Argon2 { - @protected - Argon2Hash get argon2hash; - - @override - Uint8List argon2(Argon2Arguments args) { - final keyArray = Uint8Array.fromTypedList(args.key); - final saltArray = Uint8Array.fromTypedList(args.salt); -// final saltArray = allocate(count: args.salt.length); -// final saltList = saltArray.asTypedList(args.length); -// saltList.setAll(0, args.salt); -// const memoryCost = 1 << 16; - -// _logger.fine('saltArray: ${ByteUtils.toHexList(saltArray.view)}'); - - final result = argon2hash( - keyArray.rawPtr, - keyArray.length, - saltArray.rawPtr, - saltArray.length, - args.memory, - args.iterations, - args.parallelism, - args.length, - args.type, - args.version, - ); - - keyArray.free(); - saltArray.free(); -// free(saltArray); - final resultString = Utf8.fromUtf8(result); - return base64.decode(resultString); - } - - @override - Future argon2Async(Argon2Arguments args) async { - return argon2(args); - } -} diff --git a/lib/src/crypto/key_encrypter_kdf.dart b/lib/src/crypto/key_encrypter_kdf.dart index 3e848fb..b3c930d 100644 --- a/lib/src/crypto/key_encrypter_kdf.dart +++ b/lib/src/crypto/key_encrypter_kdf.dart @@ -1,10 +1,10 @@ import 'dart:convert'; import 'dart:typed_data'; +import 'package:argon2_ffi_base/argon2_ffi_base.dart'; import 'package:crypto/crypto.dart' as crypto; import 'package:isolate/isolate_runner.dart'; import 'package:kdbx/kdbx.dart'; -import 'package:kdbx/src/crypto/argon2.dart'; import 'package:kdbx/src/internal/byte_utils.dart'; import 'package:kdbx/src/internal/crypto_utils.dart'; import 'package:kdbx/src/kdbx_var_dictionary.dart'; diff --git a/lib/src/kdbx_format.dart b/lib/src/kdbx_format.dart index bd2f6a8..eec8c27 100644 --- a/lib/src/kdbx_format.dart +++ b/lib/src/kdbx_format.dart @@ -3,11 +3,11 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; +import 'package:argon2_ffi_base/argon2_ffi_base.dart'; import 'package:convert/convert.dart' as convert; import 'package:crypto/crypto.dart' as crypto; import 'package:cryptography/cryptography.dart' as cryptography; import 'package:kdbx/kdbx.dart'; -import 'package:kdbx/src/crypto/argon2.dart'; import 'package:kdbx/src/crypto/key_encrypter_kdf.dart'; import 'package:kdbx/src/crypto/protected_salt_generator.dart'; import 'package:kdbx/src/crypto/protected_value.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index b01f7f1..f55bd2f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,11 +29,8 @@ dependencies: args: '>1.5.0 <2.0.0' prompts: '>=1.3.0 <2.0.0' logging_appenders: '>=0.1.0 <1.0.0' - ffi: ^0.1.3 - ffi_helper: ^1.4.0 + argon2_ffi_base: ^0.0.1 dev_dependencies: pedantic: '>=1.7.0 <2.0.0' test: '>=1.6.0 <2.0.0' - - diff --git a/test/internal/test_utils.dart b/test/internal/test_utils.dart index ec075a7..0b221bd 100644 --- a/test/internal/test_utils.dart +++ b/test/internal/test_utils.dart @@ -3,36 +3,11 @@ import 'dart:ffi'; import 'dart:io'; import 'dart:typed_data'; -import 'package:ffi/ffi.dart'; +import 'package:argon2_ffi_base/argon2_ffi_base.dart'; import 'package:kdbx/kdbx.dart'; // ignore_for_file: non_constant_identifier_names -typedef Argon2HashNative = Pointer Function( - Pointer key, - IntPtr keyLen, - Pointer salt, - Uint64 saltlen, - Uint32 m_cost, // memory cost - Uint32 t_cost, // time cost (number iterations) - Uint32 parallelism, - IntPtr hashlen, - Uint8 type, - Uint32 version, -); -typedef Argon2Hash = Pointer Function( - Pointer key, - int keyLen, - Pointer salt, - int saltlen, - int m_cost, // memory cost - int t_cost, // time cost (number iterations) - int parallelism, - int hashlen, - int type, - int version, -); - class Argon2Test extends Argon2Base { Argon2Test() { final argon2lib = Platform.isMacOS