Herbert Poul
5 years ago
7 changed files with 47 additions and 74 deletions
@ -1,53 +1 @@ |
|||||||
import 'dart:async'; |
// use argon2_ffi_base |
||||||
import 'dart:ffi'; |
|
||||||
import 'dart:io'; |
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart'; |
|
||||||
import 'package:flutter/services.dart'; |
|
||||||
|
|
||||||
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, |
|
||||||
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 Argon2Ffi { |
|
||||||
int Function(int x, int y) _nativeAdd; |
|
||||||
Argon2Hash argon2hash; |
|
||||||
|
|
||||||
Argon2Ffi() { |
|
||||||
final argon2lib = Platform.isAndroid |
|
||||||
? DynamicLibrary.open('libargon2_ffi.so') |
|
||||||
: Platform.isLinux |
|
||||||
? DynamicLibrary.open('libargon2_ffi_plugin.so') |
|
||||||
: DynamicLibrary.executable(); |
|
||||||
_nativeAdd = argon2lib |
|
||||||
.lookup<NativeFunction<Int32 Function(Int32, Int32)>>('native_add') |
|
||||||
.asFunction(); |
|
||||||
argon2hash = argon2lib |
|
||||||
.lookup<NativeFunction<Argon2HashNative>>('hp_argon2_hash') |
|
||||||
.asFunction(); |
|
||||||
} |
|
||||||
|
|
||||||
int addIt(int x, int y) => _nativeAdd(x, y); |
|
||||||
} |
|
||||||
|
Loading…
Reference in new issue