artemisc / libsalty Goto Github PK
View Code? Open in Web Editor NEWElixir bindings for libsodium (NIF)
License: Apache License 2.0
Elixir bindings for libsodium (NIF)
License: Apache License 2.0
Any NIF invocation that results in SALTY_ERROR behaves unpredictably, and/or crashes.
In libsalty project, run iex -S mix
.
Set up aliases, initialize two passphrases, pass1
and pass2
, a nonce
, and payload data
. Next, seal the data
using nonce
and pass1
:
alias Salty.Random
alias Salty.Secretbox.Xsalsa20poly1305, as: SB
{:ok, pass1} = SB.keybytes() |> Random.buf
{:ok, pass2} = SB.keybytes() |> Random.buf
{:ok, nonce} = SB.noncebytes() |> Random.buf
data = "my secret data"
{:ok, cipher} = SB.seal(data, nonce, pass1)
Next, attempt to open the cipher
with an invalid passphrase, e. g., pass2
:
SB.open(cipher, nonce, pass2)
Things go completely broken. If lucky, {:error, :salty_error_unknown}
is returned, but I've also received
** (FunctionClauseError) no function clause matching in Inspect.Any.inspect/2
The following arguments were given to Inspect.Any.inspect/2:
# 1
118
# 2
%Inspect.Opts{
base: :decimal,
binaries: :infer,
char_lists: :infer,
charlists: :infer,
limit: 50,
pretty: true,
printable_limit: 4096,
safe: true,
structs: true,
syntax_colors: [
reset: [:reset, :yellow],
atom: :cyan,
string: :green,
list: :default_color,
boolean: :magenta,
nil: :magenta,
tuple: :default_color,
binary: :default_color,
map: :default_color
],
width: 80
}
Attempted function clauses (showing 1 out of 1):
def inspect(%module{} = struct, opts)
(elixir) lib/inspect.ex:375: Inspect.Any.inspect/2
(elixir) lib/kernel.ex:1929: Kernel.inspect/2
or
=CRASH REPORT==== 28-Aug-2018::15:58:44.635948 ===
crasher:
initial call: Elixir.IEx.Evaluator:init/4
pid: <0.161.0>
registered_name: []
exception error: no function clause matching
'Elixir.Inspect.Any':inspect("/../lib/logger/ebin/erl_error.beam",
#{'__struct__' =>
'Elixir.Inspect.Opts',
base => decimal,
binaries => infer,
char_lists => infer,
charlists => infer,
limit => 50,
pretty => true,
printable_limit => 4096,
safe => true,
structs => true,
syntax_colors =>
[{atom,cyan},
{string,green},
{list,default_color},
{boolean,magenta},
{nil,magenta},
{tuple,default_color},
{binary,default_color},
{map,default_color}],
width => 80}) (lib/inspect.ex, line 375)
in function 'Elixir.Kernel':inspect/2 (lib/kernel.ex, line 1929)
in call from 'Elixir.FunctionClauseError':'-blame/3-fun-0-'/2 (lib/exception.ex, line 1062)
in call from 'Elixir.Enum':'-map/2-lists^map/1-0-'/2 (lib/enum.ex, line 1314)
in call from 'Elixir.FunctionClauseError':blame/3 (lib/exception.ex, line 1061)
in call from 'Elixir.IEx.Evaluator':print_error/3 (lib/iex/evaluator.ex, line 294)
in call from 'Elixir.IEx.Evaluator':eval/3 (lib/iex/evaluator.ex, line 210)
in call from 'Elixir.IEx.Evaluator':loop/1 (lib/iex/evaluator.ex, line 94)
ancestors: [<0.70.0>]
message_queue_len: 0
messages: []
links: []
dictionary: []
trap_exit: false
status: running
heap_size: 6772
stack_size: 27
reductions: 30508
neighbours:
** (EXIT from #PID<0.161.0>) shell process exited with reason: an exception was raised:
** (FunctionClauseError) no function clause matching in Inspect.Any.inspect/2
(elixir) lib/inspect.ex:375: Inspect.Any.inspect('/../lib/logger/ebin/erl_error.beam', %Inspect.Opts{base: :decimal, binaries: :infer, char_lists: :infer, charlists: :infer, limit: 50, pretty: true, printable_limit: 4096, safe: true, structs: true, syntax_colors:
[atom: :cyan, string: :green, list: :default_color, boolean: :magenta, nil: :magenta, tuple: :default_color, binary: :default_color, map: :default_color], width: 80})
(elixir) lib/kernel.ex:1929: Kernel.inspect/2
(elixir) lib/exception.ex:1062: anonymous fn/2 in FunctionClauseError.blame/3
(elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
(elixir) lib/exception.ex:1061: FunctionClauseError.blame/3
(iex) lib/iex/evaluator.ex:294: IEx.Evaluator.print_error/3
(iex) lib/iex/evaluator.ex:210: IEx.Evaluator.eval/3
(iex) lib/iex/evaluator.ex:94: IEx.Evaluator.loop/1
or
eheap_alloc: Cannot allocate 17517063650848 bytes of memory (of type "message").
Crash dump is being written to: erl_crash.dump...done
or
[1] 15766 segmentation fault (core dumped) iex -S mix
I see that there is the DIRTY
macro defined but never used. Does this actually use ERL_NIF_DIRTY_JOB_CPU_BOUND
?
Hi!
I just noticed seed_keypair/1 and keypair/0 only return the secret key so I have to call sk_to_pk/1 manually.
I was expecting them to return a tuple with the secret and public key, am I wrong?
Thank you!
Hi,
I'm currently using this library and would like to use a non-detached decrypt (specificaly xchacha20poly1305). Is there any reasoning behind why detached decrypting was only implemented and would you accept a PR to implement libsodium's crypto_aead_xchacha20poly1305_ietf_decrypt
?
Thanks!
Currently calls to Salty.Aead.Xchacha20poly1305Ietf.decrypt()
always fail. Calls to Salty.Aead.Xchacha20poly1305Ietf.decrypt_detached()
work as expected. This is probably caused by the following code in lib/salty/aead.ex which extracts the tag (mac) and data in a wrong order. IIRC in combined mode mac comes after the payload.
def decrypt(nsec, cipher, ad, npub, key) do
mac_size = abytes()
<<mac::binary-size(mac_size),
data::binary>> = cipher
decrypt_detached(nsec, data, mac, ad, npub, key)
end
Thank you for porting libsodium to Elixir.
Elixir version: 1.6.3
Erlang/OTP: 20
Build log (libsalty 0.1.1 - I tried to build from any commit and it just won't compile):
https://pastebin.com/raw/fjuYnwM6
Let me know if you need further informations.
Thank you and great job!
Hi! Does it compile on windows?
Tried to check out your documentation from the hex page, https://hexdocs.pm/libsalty/README.md.html told me to open an issue here if there was a problem with documentation.
It looks it's missing entirely, at least on hex.
We're evaluating this library and we're having a very hard time understanding how to use it.
A small paragraph on how its internal types translate to libsodium would be great.
We found several behaviours but they don't seem to be called from anywhere - so understanding what inputs should be used is quite puzzling.
I'm trying to add paseto library in my elixir application. In the doc they say to install libsodium on my macOS, but when I start my app server this error come up.
cc -o priv/salty_nif.so src/salty_nif.c -I/usr/local/Cellar/erlang/21.3.7/lib/erlang/usr/include -O2 -Wall -Wextra -I/usr/local/include/sodium -L/usr/local/Cellar/erlang/21.3.7/lib/erlang/usr/lib -fPIC -shared -lsodium -lei -lerl_interface -L/usr/local/lib -Wl,-rpath /usr/local/lib -flat_namespace -undefined suppress src/salty_nif.c:19:10: fatal error: 'sodium.h' file not found #include "sodium.h"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.