Commit Graph
33 Commits
Author SHA1 Message Date
Ilya Maykov 6bece9c8c4 Relax most __attribute__ ((nonnull)) to allow 0-length inputs to be NULL.
Justifications:
- crypto_(auth|hash|generichash|onetimeauth|shorthash)*:
  it's legal to hash or HMAC a 0-length message
- crypto_box*: it's legal to encrypt a 0-length message
- crypto_sign*: it's legal to sign a 0-length message
- utils:
  comparing two 0-length byte arrays is legal
  memzero on a 0-length byte array is a no-op
  converting an empty hex string to binary results in an empty binary string
  converting an empty binary string to hex results in an empty hex string
  converting an empty b64 string to binary results in an empty binary string
  converting an empty binary string to b64 results in an empty b64 string
  sodium_add / sodium_sub on zero-length arrays is a no-op

For the functions declared in utils.h, I moved the logic into private functions that
have the __attribute__ ((nonnull)) check, but they are only called when the
corresponding length argument is non-0. I didn't do this for the hash/box/sign
functions since it would have been a lot more work and quite a large refactor.

Only memset() may have issues with a zero length.

Fix tests, use guard page instead of NULL because of Wasm
2019-04-26 15:36:58 +02:00
Frank Denis 7ac557498f C++ compat 2019-01-03 09:49:33 +01:00
Frank Denis 34e787030f Use a guard page instead of NULL for opt arguments in tests 2018-12-24 15:02:59 +01:00
Frank Denis 8a2833f01a Remove the dummy FS call from the Javascript tests 2017-12-21 21:37:02 +01:00
Frank Denis bd631649c1 Emscripten: run the tests in benchmark mode 2017-12-21 18:52:59 +01:00
Frank Denis d7f8f6bc80 Static 2017-12-21 18:47:43 +01:00
Frank Denis dce1614eee Use default randombytes implementation for tests on emscripten 2017-12-21 02:02:39 +01:00
Frank Denis 69642f0409 Undefine printf if required 2017-12-16 21:01:23 +01:00
Frank Denis bfc8ec1248 Add a memleak checker to the benchmark code
Plug the leaks it surfaced in pwhash_argon2* tests
2017-12-16 14:51:11 +01:00
Frank Denis 99fe302562 Make things more explicit 2017-12-16 13:12:07 +01:00
Frank Denis b6dab1029d Sort 2017-12-16 13:08:55 +01:00
Frank Denis 31b13ada14 + #include <limits.h> 2017-12-16 13:08:34 +01:00
Frank Denis 18d5940bc6 Use a simple memory pool for benchmarks
In the test suite, a significant amount of time is spent in memory
allocations. A memory pool helps achieve more relevant results with
less iterations.
2017-12-16 13:07:15 +01:00
Frank Denis 0b6370dd0a Always undef NDEBUG in tests 2017-12-06 12:17:57 +00:00
Frank Denis cde31281d1 Bench: don't tie the printed result to the number of iterations 2017-08-04 23:30:30 +02:00
Frank Denis 6d59a5897d Make the number of iterations configurable; reduce the default 2017-08-04 23:16:42 +02:00
Frank Denis 5b4db091df Add a benchmark mode 2017-08-04 23:08:22 +02:00
Emil Bay 94760400a6 Add crypto_pwhash_MISMATCH errno (#541)
* Add crypto_pwhash_MISMATCH errno

* Use EINVAL for invalid password

* Only set errno on mismatch
2017-05-12 14:30:26 +02:00
Frank Denis 3d1e11fe81 Support a BROWSER_TESTS env variable to build tests for browsers 2015-12-07 01:44:33 +01:00
Frank Denis 4921836512 Move quirks inclusion to cmptest.h, emscsripten quirks to quirks.h 2015-01-23 10:41:28 +01:00
Frank Denis 8088e486ee strcmp() with optimization level > 1 is broken on Emscripten (!)
Trivial workaround that should eventually go to the quirks file
until this is fixed in Emscripten.
2015-01-22 19:06:21 +01:00
Frank Denis df1a75858c Mount the current dir as /test-data (nodefs) for testing Javascript code 2014-11-22 13:46:09 -08:00
Frank Denis 4d276a81e7 Include header files commonly used by the tests to cmptest.h 2014-09-13 14:11:12 -07:00
Frank Denis e2262de49c Add a default value for TEST_SRCDIR 2014-04-14 15:52:55 -07:00
Frank Denis 3fbbffc2c6 Check xmain() return code in tests. 2013-12-31 18:37:05 +01:00
Frank Denis 2c7aba48f3 Use arc4random() in tests if available. 2013-10-06 15:51:45 -07:00
Frank Denis 404237d09b Fix "make check" target when compiled in a dedicated directory. 2013-04-27 11:43:26 -07:00
Frank Denis 162b485cf6 printf can be a macro already, so #undef it 2013-04-25 23:25:39 -07:00
Frank Denis b52f513f90 Untab, remove trailing spaces and other no-ops. 2013-04-21 17:32:09 -07:00
Frank Denis fc98102f2a sodium_reinit() and sodium_shutdown() are gone. 2013-04-21 17:32:05 -07:00
Frank Denis 47bc0aab79 sodium_init() doesn't take any options any more. 2013-04-21 17:32:04 -07:00
Frank Denis fd11d8b7d7 Include sodium.h in cmptest.h and call sodium_init()/sodium_shutdown() 2013-04-21 17:32:04 -07:00
Frank Denis 5c946f9c61 Move tests to test/default and windows to quirks/windows.
test/default contains only tests using the default primitives
for a given operation. We need to add other tests as well.
2013-02-09 04:21:32 +08:00