59 Commits

Author SHA1 Message Date
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
Parnell Springmeyer
35515e465a Improvements re: suggestions from @jlouis. 2015-07-26 13:49:15 -05:00
Joel Stanley
7e7ac67fb3 Add bindings to the libsodium DSA operations 'crypto_sign_detached' and 'crypto_sign_verify_detached' 2015-07-26 08:00:48 -05:00
Jesper Louis Andersen
bec29dfbe1 Mark internal functions as static functions.
This quells a number of warnings in the library when compiling.
2015-05-11 17:25:11 +02:00
Alexander Færøy
de0ce86473
Add Ed 25519 Utility API. 2015-04-02 18:43:58 +02:00
Alexander Færøy
b544a37a72
Fix warning: missing declaration for memcpy(). 2015-04-02 18:43:58 +02:00
Alexander Færøy
d61d363426
Zero out temporary secret key memory. 2015-02-22 13:26:11 +01:00
Alexander Færøy
4e66fc3b94
Add curve25519_keypair/0 and curve25519_shared/2. 2015-02-21 22:49:44 +01:00
Jesper Louis Andersen
238907e2a7 Fix bug in box_open_afternm + Improve readability of C code.
If we write

	EXP != 0

and EXP is a very large term, it is hard to see what it gets checked against, so we rewrite it as

	0 != EXP

so we instanly see what we check against. While here, teset against 0 != crypto_box_afternm(…)
2014-12-17 16:15:29 +01:00
Jesper Louis Andersen
e456f4ea9b Introduce blocking variants. 2014-12-17 15:50:02 +01:00
Jesper Louis Andersen
e594146f67 Implement the beforenm/afternm calls at the NIF layer. 2014-12-17 12:46:54 +01:00
Jesper Louis Andersen
e10b7c8cfe Fail compilation if the Erlang/OTP system has no dirty scheduler support. 2014-12-16 15:12:52 +01:00
Jesper Louis Andersen
5fec48c091 EQC Test improvements
* Generalize binary generation because it is used again and again.
* Use generalized binary generation in the hash functions since they are much faster as generators.
2014-12-13 02:00:52 +01:00
Jesper Louis Andersen
fd9f421621 Introduce enacl:randombytes/1. 2014-12-09 00:33:55 +01:00
Jesper Louis Andersen
33a47e4fd4 Do not accept iolist data when binary data is what is forced by the input code. 2014-11-29 17:14:53 +01:00
Jesper Louis Andersen
90509026ce reduction handling, iodata() conversion. 2014-11-29 16:45:58 +01:00
Jesper Louis Andersen
281c3e8fbf Provide (scheduler) blocking variants of all the expensive calls. 2014-11-28 14:53:18 +01:00
Jesper Louis Andersen
2d39e2535e Properly initialize libsodium. 2014-11-28 14:41:20 +01:00
Jesper Louis Andersen
57bb93683b Introduce tests for authentication verification and provide basis for signatures. 2014-11-26 20:05:59 +01:00
Jesper Louis Andersen
7c8272baa8 Keypair generation cannot fail.
Do not return an `ok` style tuple if key generation cannot fail.
2014-11-25 15:43:15 +01:00
Jesper Louis Andersen
c33225cb77 Implement the low-level functions for signing. 2014-11-25 13:48:51 +01:00
Jesper Louis Andersen
30cb016078 Introduce low-level functions for handling string comparison. 2014-11-25 13:23:14 +01:00
Jesper Louis Andersen
265d8c7636 Handle signing keypair generation. 2014-11-24 19:30:04 +01:00
Jesper Louis Andersen
2324b73534 Implement the low-level codes for onetime authentication. 2014-11-24 15:17:02 +01:00