Browse Source

removed debugging, a bit more documentation, etc.

master
Herbert Poul 5 years ago
parent
commit
fcd453afa0
  1. 10
      .gitignore
  2. 2
      .idea/libraries/Flutter_Plugins.xml
  3. 217
      .idea/workspace.xml
  4. 20
      README.md
  5. 7
      example/pubspec.lock
  6. 19
      ios/Classes/CMakeLists.txt
  7. 146
      ios/Classes/argon2_ffi.c
  8. 3
      lib/argon2_ffi.dart
  9. 7
      pubspec.lock
  10. 1
      pubspec.yaml

10
.gitignore vendored

@ -8,3 +8,13 @@ build/
android/.cxx android/.cxx
android/cmake_install.cmake
android/CMakeCache.txt
android/Makefile
android/CMakeFiles
ios/Classes/cmake_install.cmake
ios/Classes/CMakeCache.txt
ios/Classes/cmake-*
ios/Classes/CMakeFiles

2
.idea/libraries/Flutter_Plugins.xml

@ -1,5 +1,5 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Flutter Plugins" type="FlutterPluginsLibraryType"> <library name="Flutter Plugins">
<CLASSES> <CLASSES>
<root url="file://$PROJECT_DIR$" /> <root url="file://$PROJECT_DIR$" />
</CLASSES> </CLASSES>

217
.idea/workspace.xml

@ -2,26 +2,14 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="58e8cf80-3fad-47f4-8df5-2071d32769ef" name="Default Changelist" comment=""> <list default="true" id="58e8cf80-3fad-47f4-8df5-2071d32769ef" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/libraries/Flutter_Plugins.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/libraries/Flutter_Plugins.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/android/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/argon2_ffi.iml" beforeDir="false" afterPath="$PROJECT_DIR$/argon2_ffi.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/project.pbxproj" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/project.pbxproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/contents.xcworkspacedata" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/contents.xcworkspacedata" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/lib/main.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/main.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/example/pubspec.lock" afterDir="false" /> <change beforePath="$PROJECT_DIR$/example/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/example/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/argon2_ffi.podspec" beforeDir="false" afterPath="$PROJECT_DIR$/ios/argon2_ffi.podspec" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ios/Classes/argon2_ffi.c" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/argon2_ffi.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/argon2_ffi.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/argon2_ffi.dart" afterDir="false" /> <change beforePath="$PROJECT_DIR$/lib/argon2_ffi.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/argon2_ffi.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.lock" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.yaml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/argon2_ffi_test.dart" beforeDir="false" afterPath="$PROJECT_DIR$/test/argon2_ffi_test.dart" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" />
<ignored path="$PROJECT_DIR$/.pub/" />
<ignored path="$PROJECT_DIR$/build/" />
<ignored path="$PROJECT_DIR$/example/.pub/" />
<ignored path="$PROJECT_DIR$/example/build/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -31,14 +19,14 @@
<option name="testRunner" value="GRADLE" /> <option name="testRunner" value="GRADLE" />
<option name="delegatedBuild" value="true" /> <option name="delegatedBuild" value="true" />
</component> </component>
<component name="ExecutionTargetManager" SELECTED_TARGET="Pixel_3a_API_27" /> <component name="ExecutionTargetManager" SELECTED_TARGET="Pixel_2_API_23" />
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/argon2_ffi.dart"> <entry file="file://$PROJECT_DIR$/lib/argon2_ffi.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270"> <state relative-caret-position="405">
<caret line="18" column="38" selection-start-line="18" selection-start-column="38" selection-end-line="18" selection-end-column="38" /> <caret line="27" selection-start-line="27" selection-end-line="27" />
<folding> <folding>
<element signature="e#0#20#0" expanded="true" /> <element signature="e#0#20#0" expanded="true" />
</folding> </folding>
@ -58,11 +46,20 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2_ffi.c"> <entry file="file://$PROJECT_DIR$/ios/Classes/argon2_ffi.c">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-640"> <state relative-caret-position="330">
<caret line="20" column="15" selection-start-line="20" selection-start-column="15" selection-end-line="20" selection-end-column="15" /> <caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/argon2.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="183">
<caret line="189" column="4" selection-start-line="189" selection-start-column="4" selection-end-line="189" selection-end-column="4" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -76,7 +73,7 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/android/build.gradle"> <entry file="file://$PROJECT_DIR$/android/build.gradle">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308"> <state relative-caret-position="308">
@ -85,14 +82,26 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="13" selection-start-line="13" selection-end-line="13" />
</state>
</provider>
</entry>
</file>
</leaf> </leaf>
</component> </component>
<component name="FindInProjectRecents"> <component name="FindInProjectRecents">
<findStrings> <findStrings>
<find>argon2_ffi</find> <find>argon2_ffi</find>
<find>Plat</find> <find>Plat</find>
<find>argon2i_hash_raw</find>
<find>main</find> <find>main</find>
<find>hashpwd</find>
<find>argon2i_hash_raw</find>
<find>print</find>
<find>printf</find>
</findStrings> </findStrings>
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
@ -101,24 +110,10 @@
<component name="IdeDocumentHistory"> <component name="IdeDocumentHistory">
<option name="CHANGED_PATHS"> <option name="CHANGED_PATHS">
<list> <list>
<option value="$PROJECT_DIR$/test/argon2_ffi_test.dart" />
<option value="$PROJECT_DIR$/ios/argon2_ffi.podspec" />
<option value="$PROJECT_DIR$/ios/Classes/argon2src/blake2/blake2.h" />
<option value="$PROJECT_DIR$/pubspec.yaml" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
<option value="$PROJECT_DIR$/ios/Classes/argon2_ffi.c" /> <option value="$PROJECT_DIR$/ios/Classes/argon2_ffi.c" />
<option value="$PROJECT_DIR$/lib/argon2_ffi.dart" />
<option value="$PROJECT_DIR$/android/CMakeLists.txt" />
<option value="$PROJECT_DIR$/android/build.gradle" />
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds">
<option name="x" value="116" />
<option name="y" value="23" />
<option name="width" value="1445" />
<option name="height" value="948" />
</component>
<component name="ProjectView"> <component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1"> <navigator currentView="ProjectPane" proportions="" version="1">
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
@ -211,10 +206,13 @@
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="dart.analysis.tool.window.force.activate" value="false" /> <property name="dart.analysis.tool.window.force.activate" value="false" />
<property name="io.flutter.reload.alreadyRun" value="true" /> <property name="io.flutter.reload.alreadyRun" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="flutter.settings" /> <property name="node.js.path.for.package.tslint" value="project" />
<property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
<property name="show.migrate.to.gradle.popup" value="false" /> <property name="show.migrate.to.gradle.popup" value="false" />
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
@ -243,153 +241,40 @@
<servers /> <servers />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="116" y="23" width="1445" height="948" extended-state="0" /> <frame x="31" y="23" width="1445" height="948" extended-state="0" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info id="Capture Tool" /> <window_info id="Captures" order="0" weight="0.25" />
<window_info id="Structure" side_tool="true" />
<window_info id="Favorites" side_tool="true" />
<window_info id="Build Variants" side_tool="true" />
<window_info id="Image Layers" />
<window_info id="Designer" />
<window_info id="Captures" side_tool="true" />
<window_info id="Resources Explorer" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24946544" />
<window_info active="true" anchor="bottom" id="Run" visible="true" weight="0.32943925" />
<window_info anchor="bottom" id="Dart Analysis" weight="0.32943925" />
<window_info anchor="bottom" id="Logcat" />
<window_info anchor="bottom" id="TODO" />
<window_info anchor="bottom" id="Debug" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Find" />
<window_info anchor="bottom" id="Messages" weight="0.32943925" />
<window_info anchor="bottom" id="Android Profiler" show_stripe_button="false" />
<window_info anchor="right" id="Device File Explorer" side_tool="true" />
<window_info anchor="right" id="Capture Analysis" />
<window_info anchor="right" id="Theme Preview" />
<window_info anchor="right" id="Flutter Inspector" />
<window_info anchor="right" id="Flutter Outline" />
<window_info anchor="right" id="Palette&#9;" />
<window_info anchor="right" id="Flutter Performance" />
</layout> </layout>
</component> </component>
<component name="WindowStateProjectService">
<state x="645" y="174" width="670" height="676" key="search.everywhere.popup" timestamp="1582094890309">
<screen x="0" y="23" width="1680" height="984" />
</state>
<state x="645" y="174" width="670" height="676" key="search.everywhere.popup/0.23.1680.984@0.23.1680.984" timestamp="1582094890309" />
</component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/../flutter/flutter__dev/bin/cache/pkg/sky_engine/lib/ffi/ffi.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="183">
<caret line="75" column="13" selection-start-line="75" selection-start-column="13" selection-end-line="75" selection-end-column="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/argon2_ffi_test.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="17" selection-start-line="17" selection-end-line="17" />
<folding>
<element signature="e#0#39#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ios/argon2_ffi.podspec">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="15" column="44" selection-start-line="15" selection-start-column="44" selection-end-line="15" selection-end-column="44" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/blake2/blake2.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="300">
<caret line="20" column="22" selection-start-line="20" selection-start-column="22" selection-end-line="20" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/blake2/blake2-impl.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/blake2/blake2b.c">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/blake2/blamka-round-opt.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/argon2.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-3208" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../flutter/flutter__dev/bin/cache/pkg/sky_engine/lib/ffi/native_type.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="213">
<caret line="54" column="1" selection-start-line="54" selection-start-column="1" selection-end-line="54" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="13" selection-start-line="13" selection-end-line="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/blake2/blamka-round-ref.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/../flutter/flutter__dev/.pub-cache/hosted/pub.dartlang.org/ffi-0.1.3/lib/src/utf8.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="86">
<caret line="22" column="6" selection-start-line="22" selection-start-column="6" selection-end-line="22" selection-end-column="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2_ffi.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-640">
<caret line="20" column="15" selection-start-line="20" selection-start-column="15" selection-end-line="20" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/argon2.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="166">
<caret line="189" column="4" selection-start-line="189" selection-start-column="4" selection-end-line="189" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="197">
<caret line="16" column="18" selection-start-line="16" selection-start-column="18" selection-end-line="16" selection-end-column="18" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/argon2_ffi.dart"> <entry file="file://$PROJECT_DIR$/lib/argon2_ffi.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270"> <state relative-caret-position="405">
<caret line="18" column="38" selection-start-line="18" selection-start-column="38" selection-end-line="18" selection-end-column="38" /> <caret line="27" selection-start-line="27" selection-end-line="27" />
<folding> <folding>
<element signature="e#0#20#0" expanded="true" /> <element signature="e#0#20#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/android/CMakeLists.txt"> <entry file="file://$PROJECT_DIR$/ios/Classes/argon2src/argon2.c">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285"> <state relative-caret-position="183">
<caret line="19" selection-start-line="19" selection-end-line="19" /> <caret line="189" column="4" selection-start-line="189" selection-start-column="4" selection-end-line="189" selection-end-column="4" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/android/build.gradle"> <entry file="file://$PROJECT_DIR$/ios/Classes/argon2_ffi.c">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308"> <state relative-caret-position="330">
<caret line="43" column="14" selection-start-line="43" selection-start-column="14" selection-end-line="43" selection-end-column="14" /> <caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
</state> </state>
</provider> </provider>
</entry> </entry>

20
README.md

@ -1,14 +1,16 @@
# argon2_ffi # argon2_ffi
A new flutter plugin project. Simple wrapper around argon2 for usage in https://github.com/authpass/kdbx.dart
## Getting Started ## To compile
This project is a starting point for a Flutter ```
[plug-in package](https://flutter.dev/developing-packages/), cd ios/Classes
a specialized package that includes platform-specific implementation code for cmake --build .
Android and/or iOS. ```
For help getting started with Flutter, view our ### Using docker:
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference. ```
docker run -v `pwd`:/build --rm rikorose/gcc-cmake bash -c "cd /build/ios/Classes && cmake . && cmake --build ."
```

7
example/pubspec.lock

@ -78,6 +78,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.3"
ffi_helper:
dependency: transitive
description:
name: ffi_helper
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter

19
ios/Classes/CMakeLists.txt

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.4.1) # for example
add_library(argon2_ffi
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
argon2_ffi.c
argon2src/argon2.c
argon2src/core.c
argon2src/encoding.c
argon2src/genkat.c
argon2src/ref.c
argon2src/thread.c
argon2src/blake2/blake2b.c
)
#set_target_properties(argon2_ffi PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/argon2_ffi.so)

146
ios/Classes/argon2_ffi.c

@ -1,6 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include "argon2src/argon2.h" #include "argon2src/argon2.h"
//extern "C" __attribute__((visibility("default"))) __attribute__((used)) //extern "C" __attribute__((visibility("default"))) __attribute__((used))
@ -13,78 +14,123 @@ int32_t native_add(int32_t x, int32_t y) {
#define SALTLEN 16 #define SALTLEN 16
#define PWD "password" #define PWD "password"
#define DEBUG 0
#define PRINT_DEBUG(fmt, ...) \
do { if (DEBUG) printf(fmt, ##__VA_ARGS__); } while (0)
// base64 encoding https://nachtimwald.com/2017/11/18/base64-encode-and-decode-in-c/ // base64 encoding https://nachtimwald.com/2017/11/18/base64-encode-and-decode-in-c/
size_t b64_encoded_size(size_t inlen) size_t b64_encoded_size(size_t inlen) {
{ size_t ret;
size_t ret;
ret = inlen; ret = inlen;
if (inlen % 3 != 0) if (inlen % 3 != 0)
ret += 3 - (inlen % 3); ret += 3 - (inlen % 3);
ret /= 3; ret /= 3;
ret *= 4; ret *= 4;
return ret; return ret;
} }
const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *b64_encode(const unsigned char *in, size_t len) char *b64_encode(const unsigned char *in, size_t len) {
{ char *out;
char *out; size_t elen;
size_t elen; size_t i;
size_t i; size_t j;
size_t j; size_t v;
size_t v;
if (in == NULL || len == 0)
if (in == NULL || len == 0) return NULL;
return NULL;
elen = b64_encoded_size(len);
elen = b64_encoded_size(len); out = malloc(elen + 1);
out = malloc(elen+1); out[elen] = '\0';
out[elen] = '\0';
for (i = 0, j = 0; i < len; i += 3, j += 4) {
for (i=0, j=0; i<len; i+=3, j+=4) { v = in[i];
v = in[i]; v = i + 1 < len ? v << 8 | in[i + 1] : v << 8;
v = i+1 < len ? v << 8 | in[i+1] : v << 8; v = i + 2 < len ? v << 8 | in[i + 2] : v << 8;
v = i+2 < len ? v << 8 | in[i+2] : v << 8;
out[j] = b64chars[(v >> 18) & 0x3F];
out[j] = b64chars[(v >> 18) & 0x3F]; out[j + 1] = b64chars[(v >> 12) & 0x3F];
out[j+1] = b64chars[(v >> 12) & 0x3F]; if (i + 1 < len) {
if (i+1 < len) { out[j + 2] = b64chars[(v >> 6) & 0x3F];
out[j+2] = b64chars[(v >> 6) & 0x3F]; } else {
} else { out[j + 2] = '=';
out[j+2] = '='; }
} if (i + 2 < len) {
if (i+2 < len) { out[j + 3] = b64chars[v & 0x3F];
out[j+3] = b64chars[v & 0x3F]; } else {
} else { out[j + 3] = '=';
out[j+3] = '='; }
} }
}
return out;
return out;
} }
char* hashStuff(char* hashPwd) { char *hashStuff(char *hashPwd) {
uint8_t hash1[HASHLEN]; uint8_t hash1[HASHLEN];
uint8_t salt[SALTLEN]; uint8_t salt[SALTLEN];
memset( salt, 0x00, SALTLEN ); memset(salt, 0x00, SALTLEN);
uint8_t *pwd = (uint8_t *)strdup(PWD); uint8_t *pwd = (uint8_t *) strdup(PWD);
uint32_t pwdlen = strlen((char *)pwd); uint32_t pwdlen = strlen((char *) pwd);
uint32_t t_cost = 2; // 1-pass computation uint32_t t_cost = 2; // 1-pass computation
uint32_t m_cost = (1<<16); // 64 mebibytes memory usage uint32_t m_cost = (1 << 16); // 64 mebibytes memory usage
uint32_t parallelism = 1; // number of threads and lanes uint32_t parallelism = 1; // number of threads and lanes
argon2i_hash_raw(t_cost, m_cost, parallelism, pwd, pwdlen, salt, SALTLEN, hash1, HASHLEN); argon2i_hash_raw(t_cost, m_cost, parallelism, pwd, pwdlen, salt, SALTLEN,
hash1, HASHLEN);
char *b64ret = b64_encode(hash1, HASHLEN); char *b64ret = b64_encode(hash1, HASHLEN);
return b64ret; return b64ret;
} }
void debugBytes(uint8_t *bytes, int length) {
PRINT_DEBUG("length: %d -- ", length);
for (int i = 0; i < length; i++) {
PRINT_DEBUG("%02x ", bytes[i]);
}
}
char *hp_argon2_hash(uint8_t *key, size_t keylen, uint8_t *salt, size_t saltlen,
uint32_t m_cost,
uint32_t t_cost /* iterations*/, uint32_t parallelism,
size_t hashlen,
uint8_t type, int32_t version) {
uint8_t hash1[hashlen];
PRINT_DEBUG("keylen: %ld, saltlen: %ld, m_cost: %ld, t_cost: %ld, hashlen: %ld, type: %d, version: %02x\n",
keylen, saltlen, m_cost, t_cost, hashlen, type, version);
PRINT_DEBUG("key: ");
debugBytes(key, keylen);
PRINT_DEBUG("\n");
PRINT_DEBUG("salt: ");
debugBytes(salt, saltlen);
PRINT_DEBUG("\n");
if (type == 0) {
PRINT_DEBUG("argon2d\n");
argon2d_hash_raw(t_cost, m_cost, parallelism, key, keylen, salt,
saltlen,
hash1, hashlen);
} else if (type == 1) {
argon2i_hash_raw(t_cost, m_cost, parallelism, key, keylen, salt,
saltlen,
hash1, hashlen);
}
PRINT_DEBUG("hash: ");
debugBytes(hash1, hashlen);
PRINT_DEBUG("\n");
char *b64ret = b64_encode(hash1, hashlen);
return b64ret;
}

3
lib/argon2_ffi.dart

@ -25,7 +25,4 @@ class Argon2Ffi {
} }
int addIt(int x, int y) => _nativeAdd(x, y); int addIt(int x, int y) => _nativeAdd(x, y);
String hashStuff(String password) =>
Utf8.fromUtf8(_hashStuff(Utf8.toUtf8(password)));
} }

7
pubspec.lock

@ -64,6 +64,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.3"
ffi_helper:
dependency: "direct main"
description:
name: ffi_helper
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter

1
pubspec.yaml

@ -11,6 +11,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
ffi: ^0.1.3 ffi: ^0.1.3
ffi_helper: ^1.4.0
dev_dependencies: dev_dependencies:

Loading…
Cancel
Save