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. 56
      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/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">
<library name="Flutter Plugins" type="FlutterPluginsLibraryType">
<library name="Flutter Plugins">
<CLASSES>
<root url="file://$PROJECT_DIR$" />
</CLASSES>

217
.idea/workspace.xml

@ -2,26 +2,14 @@
<project version="4">
<component name="ChangeListManager">
<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$/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$/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$/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$/test/argon2_ffi_test.dart" beforeDir="false" afterPath="$PROJECT_DIR$/test/argon2_ffi_test.dart" afterDir="false" />
</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="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -31,14 +19,14 @@
<option name="testRunner" value="GRADLE" />
<option name="delegatedBuild" value="true" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="Pixel_3a_API_27" />
<component name="ExecutionTargetManager" SELECTED_TARGET="Pixel_2_API_23" />
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/argon2_ffi.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="18" column="38" selection-start-line="18" selection-start-column="38" selection-end-line="18" selection-end-column="38" />
<state relative-caret-position="405">
<caret line="27" selection-start-line="27" selection-end-line="27" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -58,11 +46,20 @@
</provider>
</entry>
</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">
<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 relative-caret-position="330">
<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>
</provider>
</entry>
@ -76,7 +73,7 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/android/build.gradle">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
@ -85,14 +82,26 @@
</provider>
</entry>
</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>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>argon2_ffi</find>
<find>Plat</find>
<find>argon2i_hash_raw</find>
<find>main</find>
<find>hashpwd</find>
<find>argon2i_hash_raw</find>
<find>print</find>
<find>printf</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -101,24 +110,10 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<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$/lib/argon2_ffi.dart" />
<option value="$PROJECT_DIR$/android/CMakeLists.txt" />
<option value="$PROJECT_DIR$/android/build.gradle" />
</list>
</option>
</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">
<navigator currentView="ProjectPane" proportions="" version="1">
<foldersAlwaysOnTop value="true" />
@ -211,10 +206,13 @@
</panes>
</component>
<component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="dart.analysis.tool.window.force.activate" value="false" />
<property name="io.flutter.reload.alreadyRun" value="true" />
<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" />
</component>
<component name="RunDashboard">
@ -243,153 +241,40 @@
<servers />
</component>
<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" />
<layout>
<window_info id="Capture Tool" />
<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" />
<window_info id="Captures" order="0" weight="0.25" />
</layout>
</component>
<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" />
<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>
</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>
<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">
<entry file="file://$PROJECT_DIR$/lib/argon2_ffi.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="18" column="38" selection-start-line="18" selection-start-column="38" selection-end-line="18" selection-end-column="38" />
<state relative-caret-position="405">
<caret line="27" selection-start-line="27" selection-end-line="27" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</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">
<state relative-caret-position="285">
<caret line="19" selection-start-line="19" selection-end-line="19" />
<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>
</provider>
</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">
<state relative-caret-position="308">
<caret line="43" column="14" selection-start-line="43" selection-start-column="14" selection-end-line="43" selection-end-column="14" />
<state relative-caret-position="330">
<caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
</state>
</provider>
</entry>

20
README.md

@ -1,14 +1,16 @@
# 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/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
```
cd ios/Classes
cmake --build .
```
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
### Using docker:
```
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"
source: hosted
version: "0.1.3"
ffi_helper:
dependency: transitive
description:
name: ffi_helper
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
flutter:
dependency: "direct main"
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)

56
ios/Classes/argon2_ffi.c

@ -1,6 +1,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "argon2src/argon2.h"
//extern "C" __attribute__((visibility("default"))) __attribute__((used))
@ -13,11 +14,14 @@ int32_t native_add(int32_t x, int32_t y) {
#define SALTLEN 16
#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/
size_t b64_encoded_size(size_t inlen)
{
size_t b64_encoded_size(size_t inlen) {
size_t ret;
ret = inlen;
@ -31,8 +35,7 @@ size_t b64_encoded_size(size_t inlen)
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;
size_t elen;
size_t i;
@ -80,11 +83,54 @@ char* hashStuff(char* hashPwd) {
uint32_t t_cost = 2; // 1-pass computation
uint32_t m_cost = (1 << 16); // 64 mebibytes memory usage
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);
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);
String hashStuff(String password) =>
Utf8.fromUtf8(_hashStuff(Utf8.toUtf8(password)));
}

7
pubspec.lock

@ -64,6 +64,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: "direct main"
description: flutter

1
pubspec.yaml

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

Loading…
Cancel
Save