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.
A lot of people who pushed functions they missed have not pushed any
kind of test cases for them. To make sure we have test coverage, I've
marked the functions we have under test and the functions we are still
missing tests for.
This involves:
- Removing calls to conjunction function
- Modifying fault* functions to _always_ return "Good" generator
- Commenting-out the eqc_parallelize parse_transform
* 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
Provide non-dirty-scheduler variants for small strings, accurately bump
reductions for these strings.
While here, provide EQC test cases for the two functions.
This further verifies the test cases and also the enacl API. By injecting
wrong data, we verify that given incorrect data will make the system fail
and error(badarg) all over the place.
Introduce a type for iodata() in the EQC tests. Use this type throughout
the tests in order to make sure we can supply iodata() in all places where
we claim we can supply iodata().
* 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.
To avoid the common mistake of re-arranging keypairs, provide them in a map which
forces the programmer to unpack the map in order to obtain the keys. This in turn makes
it harder to swap the PK/SK pair around and mistakenly giving out the secret key to the world.
Negative testing means we inject faulty data into the test now and then. When this happens, we make sure the SUT will
return some kind of badarg error for bad arguments. This means we should make sure things actually work out as they should.
As a side-effect, this can also be used to test for memory leaks. If run for a while, it makes sure there are no leaks in the code base,
and it probably also makes sure there are no ways to crash the server by any means of use of these NIFs. As such, it looks like the
NIFs are fairly stable.