Browse Source

depend on argon2_ffi_base

remove-cryptography-dependency
Herbert Poul 5 years ago
parent
commit
0ebc8c5d2c
  1. 28
      bin/_argon2.dart
  2. 17
      example/pubspec.lock
  3. 2
      example/pubspec.yaml
  4. 1
      lib/kdbx.dart
  5. 95
      lib/src/crypto/argon2.dart
  6. 2
      lib/src/crypto/key_encrypter_kdf.dart
  7. 2
      lib/src/kdbx_format.dart
  8. 5
      pubspec.yaml
  9. 27
      test/internal/test_utils.dart

28
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<Utf8> Function(
Pointer<Uint8> key,
IntPtr keyLen,
Pointer<Uint8> 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<Utf8> Function(
Pointer<Uint8> key,
int keyLen,
Pointer<Uint8> 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

17
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:

2
example/pubspec.yaml

@ -7,8 +7,6 @@ environment:
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
kdbx:
path: ../

1
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;

95
lib/src/crypto/argon2.dart

@ -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<Utf8> Function(
Pointer<Uint8> key,
Uint32 keyLen,
Pointer<Uint8> 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<Utf8> Function(
Pointer<Uint8> key,
int keyLen,
Pointer<Uint8> 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<Uint8List> 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<Uint8>(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<Uint8List> argon2Async(Argon2Arguments args) async {
return argon2(args);
}
}

2
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';

2
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';

5
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'

27
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<Utf8> Function(
Pointer<Uint8> key,
IntPtr keyLen,
Pointer<Uint8> 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<Utf8> Function(
Pointer<Uint8> key,
int keyLen,
Pointer<Uint8> 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

Loading…
Cancel
Save