82 Commits

Author SHA1 Message Date
Jesper Louis Andersen
b7533d3b9c Release resources under failure
sign and generichash failed to release their resources under failure.

This can lead to subtle memory leaks in the very unlikely event
we can't initialize.
2020-01-16 15:45:42 +01:00
Jesper Louis Andersen
f43a730758 Merge branch 'multi-part-signatures' of github.com:hazy/enacl 2020-01-16 15:38:48 +01:00
Jesper Louis Andersen
3f284be0cb Merge branch 'sign-seed-keypair' of github.com:termoose/enacl 2020-01-16 15:21:50 +01:00
Jesper Louis Andersen
e6cb85fb24 Merge branch 'master' of github.com:syfgkjasdkn/enacl 2020-01-16 13:45:31 +01:00
Jesper Louis Andersen
25d411aa7d Merge branch 'fix-constant-and-more-tests' of github.com:aeternity/enacl 2020-01-16 13:27:58 +01:00
Jesper Louis Andersen
7f8e0a0e07 Merge branch 'xchacha20' of github.com:ECrownofFire/enacl 2020-01-16 13:15:54 +01:00
Jesper Louis Andersen
600020620b Merge branch 'master' of github.com:ECrownofFire/enacl 2020-01-15 16:11:30 +01:00
Jesper Louis Andersen
97ee4bbdcf Use randombytes_uint32
Better name. Says what you are getting.
2020-01-15 14:05:25 +01:00
Jesper Louis Andersen
3c8d54d87b Merge branch 'master' of github.com:jlouis/enacl 2020-01-15 14:01:32 +01:00
Jesper Louis Andersen
f9d6034e84 Implement missing random functions* enacl:randombytes_int32/0* enacl:randombytes_uniform/1 2020-01-15 13:56:00 +01:00
Jesper Louis Andersen
e66855c029 Use LLVM style C-formattting 2020-01-15 13:21:51 +01:00
Garry Hill
279c2c32c8
Add support for multi-part signatures 2019-11-20 12:11:21 +00:00
Ole Andre Birkedal
6f4a0c2521 Added bindings for crypto_sign_seed_keypair in libsodium 2019-06-15 14:29:15 +02:00
Tino Breddin
26180f42c0 Add win32 support
Replace Make-based compilation of the nif to using rebar's port
compiler.
2018-11-29 11:29:40 +01:00
ECrownofFire
2b183e1974
Add support for aead_xchacha20poly1305 2018-11-25 11:30:34 -05:00
alsdiufgoaiwuegflweuvflasjkdhvlajhsdfg666272727asfgfdsagdlsafg
3442655c5b add crypto_sign_ed25519_sk_to_pk 2018-11-22 13:04:24 +00:00
Hans Svensson
1121321573 Generic hash state needs to be 64-byte aligned
At least according to:
  https://libsodium.gitbook.io/doc/hashing/generic_hashing

We noticed crashes when it was not 16-byte aligned - probably is
architecture dependent. This makes the safe choice and always 64-byte
align it.
2018-11-08 10:44:02 +01:00
ECrownofFire
4afa6fc093
Add checks for ops/mem limit sizes 2018-10-27 23:25:23 -04:00
ECrownofFire
26f4a40eb4
Mark pwhash functions as CPU bound 2018-10-27 23:25:16 -04:00
ECrownofFire
07bcd87294
Add choice of ops and mem limits to pwhash 2018-10-27 23:23:16 -04:00
ECrownofFire
d779071285
Add choice of ops and mem limits to pwhash_str
It natively checks atoms, which is kinda messy, but it avoids having to
export the libsodium pwhash constants, which is nice.
2018-10-27 23:22:55 -04:00
Thomas Arts
40fde1807b Variable is assigned but never used
This is just a warning, but elliminating warnings makes the code go cleanly through clang static code analyzer.
2018-06-13 07:03:04 +02:00
Thomas Arts
04b8fa3ecb Dangerous use of constant 2018-06-12 14:26:14 +02:00
Jesper Louis Andersen
edd95498d1 Fix pwhash_str* functions.
The API for pwhash_str returns a cstring in the output buffer. These
are null terminated. However, we return the full buffer as a binary
back to Erlang. This means that we have a buffer with 0'es in the end.

The tests take this buffer and passes it back in as is. Hence all the
tests pass. However, it is conceivable that if we write said buffer to
disk somewhere, we are not going to write those 0's out.

When we then load the ASCII-armored Argon2 string into memory again,
it is not 0-terminated as a cstring should be, and this produces
errors all over the place.

The fix is twofold:

* Return the full buffer to Erlang, but use binary:split/2 to create a
  subbinary with the relevant part.
* Add a 0 in the end of ASCII Argon2 string before passing it to
  libsodium

Since we are looking at pwhashing, and Argon2, we expect the
computational problem to be memory bound. Thus, spending a bit more
work in memory is not going to have any considerable impact on the
speed of this system.
2018-05-21 15:21:09 +02:00
Jesper Louis Andersen
fb7de2cbb4
Merge pull request #21 from aeternity/add_aead_chacha20poly1305
Add AEAD chacha20poly1305
2018-05-20 19:38:14 +02:00
Hans Svensson
2f50ba6289 Also expose crypto_curve25519_scalarmult_base 2018-03-05 15:33:17 +01:00
Hans Svensson
9dfbe8cc90 Expose AEAD ChaCha20 Poly1305 functionality
Note: We expose the modern IETF version but still name it plain
aead_chacha20poly1305.
2018-03-05 09:52:39 +01:00
Hans Svensson
a5dab7acf0 Whitespace 2018-03-01 08:41:53 +01:00
daveed-al
cd183efd34 pwhash_str_verify respects specs second param as iodata() 2018-01-31 18:41:31 +08:00
Zane Beckwith
bf4d61680c Change size_t variables to unsigned int's.
These variables are being initialized via calls to `enif_get_uint`,
so it's safer to declare them as unsigned int's rather than size_t's.
Their being used in calls to `enif_alloc_binary`, which takes a size_t
as its size.
However, the resulting ErlNifBinary keeps its size as an unsigned int,
so asking for a size that's an unsigned int should be safe.

This would be problematic in the case where sizeof(size_t) <
sizeof(unsigned), which would mean we're getting fewer bytes allocated
than expected.
Perhaps an explicit check for, for example, `hashSize > MAX_SIZE` would
be good here?
2017-08-14 17:01:50 +00:00
Irina Guberman
e524c2d5c8 Fix 32-bit arch warnings: replace enif_get_uint64 with enif_get_uint 2017-08-12 16:46:47 -05:00
Venkatakumar Srinivasan
ba640b0659 Added generic hash NIF 2017-08-11 13:32:04 -05:00
Venkatakumar Srinivasan
36eedc6751 Pulled in latest version of enacl. Added nif's for password hashing functions 2017-08-11 13:32:04 -05:00
Venkatakumar Srinivasan
c938d3c6e8 Fix to pwhash_str_verify() to accept only binary arguments 2017-08-11 13:32:04 -05:00
Venkatakumar Srinivasan
ee0d800a9a Implemented nif for crypto_pwhash_str(), crypto_pwhash_str_verify() 2017-08-11 13:32:04 -05:00
Venkatakumar Srinivasan
43cae7c7ea Implemented nif for crypto_pwhash() 2017-08-11 13:32:04 -05:00
Venkatakumar Srinivasan
f395f65389 Removed experimental feature flag ERL_NIF_DIRTY_JOB_CPU_BOUND 2017-08-11 13:32:04 -05:00
Alexander Malaev
2da2ba138f Add kx_* functions from libsodium 1.0.12 2017-03-19 18:24:06 +03:00
Jesper Louis Andersen
a708d0b11e Merge pull request #9 from jrmithdobbs/expose_more_libsodium_functions
Expose more libsodium functions
2016-06-23 22:04:21 +02:00
Jesper Louis Andersen
2ee171bcbf The test macro for dirty schedulers are gone in 19.x Erlang/OTP
Remove it from the code, making the code able to compile.
2016-05-16 19:20:47 +02:00
Doug Huff
9849e7310a Add unsafe_memzero/1 2015-10-28 21:54:08 +00:00
Doug Huff
4d5524db61 Add chacha stream function access. 2015-10-28 21:53:42 +00:00
Doug Huff
ca005d32f9 Add access to siphash-2-4 (no dirty scheduler necessary). 2015-10-28 21:52:25 +00:00
Jesper Louis Andersen
b1c3e69fb5 Change randombytes/1 so it always executes on a DS
Investigation shows erratic behaviour of the CSPRNG. It may block at times
because it needs to go to the kernel and obtain more random information in
the system. Once this happens, you are blocked for quite a long time, but
we don't generally know when this happens. So just execute these directly
on the dirty scheduler.
2015-08-29 22:09:51 +02:00
Jesper Louis Andersen
2cad66ac2a Handle the ED25519 to Curve25519 conversion routines.
Make sure these either execute on the Dirty Scheduler or execute with bumping
reductions.
2015-08-29 22:08:34 +02:00
Jesper Louis Andersen
2e5163a934 Clean up things which are not needed anymore. 2015-08-29 21:50:16 +02:00
Jesper Louis Andersen
a135bce9d3 Simplify the code base, first round:
* Introduce enacl:verify/0 to verify the integrity of the library.
* Always run keypair functions on the dirty schedulers.
* Do not call NIFs when creating zerobytes. Avoid constructing new binary data, but reuse a constant.
* The box/box_open and box_seal/box_seal_open API is so expensive to call there is little overhead in
  running it on the DS always.
2015-08-23 21:44:28 +02:00
Jesper Louis Andersen
f444d1e4ac Fix box_seal/2 and box_seal_open/3.
* Call the functions `box_seal` and `box_seal_open` to match the libsodium names in module `enacl`.
* Fix a bug in the C NIF: We should fail if the input is `<` SEALBYTES but not on `<=` SEALBYTES. The latter made it impossible to encode empty messages.
* Add variants which run directly on the interpreter scheduler for small messages.

Also:

* Provide full EQC functions for the testing purposes. This generated around 13000 random test cases in a 5 minute run, all passing.# Please enter the commit message for your changes. Lines starting
2015-08-14 22:03:33 +02:00
Jesper Louis Andersen
92109eb354 Improve and verify sign_*_detached functions.
Provide non-dirty-scheduler variants for small strings, accurately bump
reductions for these strings.

While here, provide EQC test cases for the two functions.
2015-08-12 23:11:41 +02:00
Amir Ghassemi Nasr
64c03a1425 added bindings for crypto_box_seal_open\' functions 2015-08-07 00:24:50 +04:30