Skip to content

Commit

Permalink
initial ffi commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kozw committed May 5, 2020
1 parent e7fa6b7 commit a4f0f60
Show file tree
Hide file tree
Showing 155 changed files with 1,135 additions and 11,347 deletions.
182 changes: 182 additions & 0 deletions .dart_tool/package_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"configVersion": 2,
"packages": [
{
"name": "archive",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/archive-2.0.11",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "args",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.5.2",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "async",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.4.0",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "boolean_selector",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.5",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "charcode",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.2",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "collection",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "convert",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/convert-2.1.1",
"packageUri": "lib/",
"languageVersion": "1.17"
},
{
"name": "crypto",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.3",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "ffi",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-0.1.3",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "flutter",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/packages/flutter",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "flutter_test",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/packages/flutter_test",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "image",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/image-2.1.4",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "matcher",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.6",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "meta",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.8",
"packageUri": "lib/",
"languageVersion": "1.12"
},
{
"name": "path",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.6.4",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "pedantic",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.8.0+1",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "petitparser",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/petitparser-2.4.0",
"packageUri": "lib/",
"languageVersion": "2.4"
},
{
"name": "quiver",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.0.5",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "sky_engine",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/bin/cache/pkg/sky_engine",
"packageUri": "lib/",
"languageVersion": "1.11"
},
{
"name": "source_span",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.5.5",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "stack_trace",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3",
"packageUri": "lib/",
"languageVersion": "1.23"
},
{
"name": "stream_channel",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-2.0.0",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "string_scanner",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.5",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "term_glyph",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "test_api",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.11",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "typed_data",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "vector_math",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.0.8",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "xml",
"rootUri": "file:///Users/koenzwikstra/Source/flutter/.pub-cache/hosted/pub.dartlang.org/xml-3.5.0",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "flutter_sodium",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.6"
}
],
"generated": "2020-05-05T19:46:43.703423Z",
"generator": "pub",
"generatorVersion": "2.7.2"
}
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: f139b11009aeb8ed2a3a3aa8b0066e482709dde3
channel: stable

project_type: plugin
3 changes: 1 addition & 2 deletions ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

The flutter_sodium plugin uses code from the following libraries:

- [libsodium](https://github.com/jedisct1/libsodium), ISC license
- [libsodium-jni](https://github.com/joshjdevl/libsodium-jni), Apache-2.0
- [libsodium](https://github.com/jedisct1/libsodium), ISC license
46 changes: 2 additions & 44 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,3 @@
## 0.0.11 - Oct 21, 2019
* Fixes Android dependency issues
## 0.9.0 - May 6, 2020
* Rewrite flutter_sodium using FFI

## 0.0.10 - June 27, 2019
* Adds support for kdf to Android (by rmtmckenzie)
* Update to Swift 5 & fix all warnings in iOS code (by rmtmckenzie)

## 0.0.9 - February 24, 2019
* Adds support for crypto_sign_ed25519_sk_to_curve25519 (by sporkins)
* Fixes sample app issues

## 0.0.8 - September 10, 2018
* Adds support for crypto_box_curve25519xchacha20poly1305_*
* Fixes iOS build warnings

## 0.0.7 - August 28, 2018
* Adds support for executing crypto tasks on a background thread
* Implements missing Android bindings for crypto_aead_*
* Completes argument assertions and range checks

## 0.0.6 - August 21, 2018
* Adds ChaCha20Poly1305, ChaCha20Poly1305Ietf and XChaCha20Poly1305Ietf APIs
* Adds argument assertions and range checks
* Upgrades libsodiumjni dependency to v2.0.1

## 0.0.5 - August 5, 2018
* Breaking high-level API changes
* String operations now default
* Randombytes renamed to RandomBytes
* Adds CryptoBox, KeyDerivation, KeyExchange and ScalarMult highlevel APIs

## 0.0.4 - July 31, 2018
* No functional changes
* Fixes SDK constraint and source file formatting

## 0.0.3 - July 30, 2018
* Adds Dart-friendly APIs
* Introduces example app with runnable code samples
* Replaces deprecated code constructs

## 0.0.2 - April 12, 2018
* Adds support for Flutter Beta 2 and Dart 2

## 0.0.1 - March 20, 2018
* Initial release with core libsodium API support.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 First Floor Software. All rights reserved.
// Copyright 2020 First Floor Software. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
Expand Down
33 changes: 5 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ dependencies:
...
flutter_sodium: any
```
__Important:__ For iOS you'll need to [manually update](https://github.com/firstfloorsoftware/flutter_sodium/issues/1#issuecomment-403973858) the Podfile in your ios project.
## Usage example
```dart
import 'package:flutter_sodium/flutter_sodium.dart';

// Password hashing (using Argon)
final password = 'my password';
final str = await PasswordHash.hashStorage(password);
final str = PasswordHash.hashStorage(password);

print(str);

// verify hash str
final valid = await PasswordHash.verifyStorage(str, password);
final valid = PasswordHash.verifyStorage(str, password);

assert(valid);
```
Expand All @@ -38,35 +35,15 @@ This project includes an extensive example app with runnable code samples. Be su
<img src="https://raw.githubusercontent.com/firstfloorsoftware/flutter_sodium/develop/example/assets/screenshots/screenshot1.png" width="300">

## API coverage
The flutter_sodium plugin implements the following libsodium APIs *):
- crypto_aead
- crypto_auth
- crypto_box
- crypto_generichash
- crypto_kdf
- crypto_kx
- crypto_onetimeauth
The flutter_sodium plugin implements the following libsodium APIs:
- crypto_pwhash
- crypto_scalarmult
- crypto_secretbox
- crypto_shorthash
- crypto_sign
- randombytes
- sodium_version

*) Some APIs are not available on Android. See [this issue](https://github.com/firstfloorsoftware/flutter_sodium/issues/7) for details.

## Dart APIs
The plugin includes a core API that maps native libsodium functions 1:1 to Dart equivalents. The core API is available in the class [`Sodium`](https://github.com/firstfloorsoftware/flutter_sodium/blob/master/lib/flutter_sodium.dart). Dart naming conventions are used for core API function names. A native libsodium function such as `crypto_pwhash_str`, is available in flutter as `Sodium.cryptoPwhashStr`.

Also included in flutter_sodium is a high-level, opinionated API providing access to libsodium in a Dart friendly manner. The various functions are available in separate Dart classes. Password hashing for example is available in the `PasswordHash` class. The high-level API depends on the core API to get things done.

## Threading
The flutter_sodium APIs can be executed on the UI thread, or on a background thread. Most crypto tasks can safely run on the UI thread, some tasks take considerable time to execute (most notable crypto_pwhash_* ), and will run on a background thread by default. All methods of the core API includes an optional ```useBackgroundThread``` argument to switch from UI to background thread or vice versa. Background execution is implemented using ```AsyncTask``` in Android, and ```DispatchQueue``` in iOS.

Please note that the entire API is asynchronous. Even when a crypto task is executed on the UI thread, the method returns an async ```Future``` which needs to be awaited.

## Current issues
- Some APIs are not available on Android. An issue has been created with the [complete list](https://github.com/firstfloorsoftware/flutter_sodium/issues/7).
- Using flutter_sodium in iOS doesn't work right out of the box. [Manual installation](https://github.com/firstfloorsoftware/flutter_sodium/issues/1#issuecomment-403973858) steps are required.
- Since Flutter does [not support native binaries](https://github.com/flutter/flutter/issues/7053), a [platform channel](https://flutter.io/platform-channels/) is established to enable native function invocation. One side effect of this approach is that the entire flutter_sodium API is asynchronous. This is great for potential long-running operations such as Argon password hashing, but does not make much sense for other short-running functions.
## Known issues
- Previous incarnations of flutter_sodium used platform channels for native interop. The latest version has been rewritten to take full advantage of Dart FFI. FFI offers fast native interop and is the obvious choice for flutter_sodium. One minor problem, FFI is still in beta and its API may change. This may affect flutter_sodium.
6 changes: 0 additions & 6 deletions android/.classpath

This file was deleted.

23 changes: 0 additions & 23 deletions android/.project

This file was deleted.

2 changes: 0 additions & 2 deletions android/.settings/org.eclipse.buildship.core.prefs

This file was deleted.

Loading

0 comments on commit a4f0f60

Please sign in to comment.