GithubHelp home page GithubHelp logo

artemisc / libsalty Goto Github PK

View Code? Open in Web Editor NEW
21.0 5.0 25.0 62 KB

Elixir bindings for libsodium (NIF)

License: Apache License 2.0

Makefile 0.67% Elixir 37.95% C 61.38%
libsodium elixir elixir-library c erlang-nif

libsalty's Introduction

Salty

Libsalty provides bindings to libsodium for Elixir, based on Erlang nif.

credits to Libsodium: author Frank Denis and Contributors. Libsodium is licensed under ISC License

Hex

This package is available through Hex.

Requirements

Libsalty requires that libsodium 1.0.12 or later is already installed on your system. If you receive compiler warnings or a missing symbol error when trying to use libsalty, it's likely that you're running on a system with an old version of libsodium.

License

Copyright 2017 Project ArteMisc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

libsalty's People

Contributors

artemisc avatar fhunleth avatar magnetised avatar tuupola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

libsalty's Issues

Lack of examples / tests.

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.

Dirty Schedulers?

I see that there is the DIRTY macro defined but never used. Does this actually use ERL_NIF_DIRTY_JOB_CPU_BOUND?

Wrong order of mac and data for Aead.Xchacha20poly1305Ietf.decrypt()

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

It does not compile

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!

Reasoning behind only detached decrypting?

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!

Unpredictable behaviour/crashes when a NIF returns with SALTY_ERROR.

Description

Any NIF invocation that results in SALTY_ERROR behaves unpredictably, and/or crashes.

Environment

  • libsalty 0.1.3
  • Elixir 1.7.2, 1.6.6
  • Erlang/OTP 21
  • libsodium 1.0.16-2
  • Ubuntu 18.04.1

Steps to reproduce

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

Still does not compile

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.