Browse Source

use uint32 for length parameters.

remove-cryptography-dependency
Herbert Poul 5 years ago
parent
commit
4273c6ef99
  1. 23
      lib/src/crypto/argon2.dart
  2. BIN
      libargon2_ffi.dylib
  3. BIN
      libargon2_ffi.so

23
lib/src/crypto/argon2.dart

@ -7,16 +7,15 @@ import 'package:ffi_helper/ffi_helper.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
// ignore_for_file: non_constant_identifier_names // ignore_for_file: non_constant_identifier_names
typedef Argon2HashNative = Pointer<Utf8> Function( typedef Argon2HashNative = Pointer<Utf8> Function(
Pointer<Uint8> key, Pointer<Uint8> key,
IntPtr keyLen, Uint32 keyLen,
Pointer<Uint8> salt, Pointer<Uint8> salt,
Uint64 saltlen, Uint32 saltlen,
Uint32 m_cost, // memory cost Uint32 m_cost, // memory cost
Uint32 t_cost, // time cost (number iterations) Uint32 t_cost, // time cost (number iterations)
Uint32 parallelism, Uint32 parallelism,
IntPtr hashlen, Uint32 hashlen,
Uint8 type, Uint8 type,
Uint32 version, Uint32 version,
); );
@ -61,10 +60,10 @@ abstract class Argon2Base extends Argon2 {
@override @override
Uint8List argon2(Argon2Arguments args) { Uint8List argon2(Argon2Arguments args) {
final keyArray = Uint8Array.fromTypedList(args.key); final keyArray = Uint8Array.fromTypedList(args.key);
// final saltArray = Uint8Array.fromTypedList(salt); final saltArray = Uint8Array.fromTypedList(args.salt);
final saltArray = allocate<Uint8>(count: args.salt.length); // final saltArray = allocate<Uint8>(count: args.salt.length);
final saltList = saltArray.asTypedList(args.length); // final saltList = saltArray.asTypedList(args.length);
saltList.setAll(0, args.salt); // saltList.setAll(0, args.salt);
// const memoryCost = 1 << 16; // const memoryCost = 1 << 16;
// _logger.fine('saltArray: ${ByteUtils.toHexList(saltArray.view)}'); // _logger.fine('saltArray: ${ByteUtils.toHexList(saltArray.view)}');
@ -72,8 +71,8 @@ abstract class Argon2Base extends Argon2 {
final result = argon2hash( final result = argon2hash(
keyArray.rawPtr, keyArray.rawPtr,
keyArray.length, keyArray.length,
saltArray, saltArray.rawPtr,
args.salt.length, saltArray.length,
args.memory, args.memory,
args.iterations, args.iterations,
args.parallelism, args.parallelism,
@ -83,8 +82,8 @@ abstract class Argon2Base extends Argon2 {
); );
keyArray.free(); keyArray.free();
// saltArray.free(); saltArray.free();
free(saltArray); // free(saltArray);
final resultString = Utf8.fromUtf8(result); final resultString = Utf8.fromUtf8(result);
return base64.decode(resultString); return base64.decode(resultString);
} }

BIN
libargon2_ffi.dylib

Binary file not shown.

BIN
libargon2_ffi.so

Binary file not shown.
Loading…
Cancel
Save