Commit Graph

21 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
34e787030f Use a guard page instead of NULL for opt arguments in tests 2018-12-24 15:02:59 +01:00
Frank Denis
c90ddae75e Use the right state type for the auth256 test 2017-07-24 23:04:23 +02:00
Frank Denis
51a0b96f1d Test crypto_hmac_sha256_update() with empty chunks 2017-07-24 22:25:33 +02:00
Frank Denis
33d6908f9b Test crypto_auth_hmacsha256_*() 2017-07-24 22:08:07 +02:00
Frank Denis
5351efb122 Indentx 2017-02-23 11:15:29 +01:00
Brian Silverman
63b82c28e9 Use the right type for sizeof's result 2015-12-16 22:54:06 -05:00
Frank Denis
d8b9b395a3 Mark everything as static in tests 2015-11-23 16:07:13 +01:00
Frank Denis
ee97d5e3f8 Add tests for custom randombytes_uniform.
Check for crypto_auth_hmacsha512256_statebytes() presence.
2015-05-09 15:54:18 +02:00
Frank Denis
5db61c617b Add statebytes for crypto_hmac_* 2015-01-23 23:08:49 +01:00
Frank Denis
6837c2d2c2 Include extra 0 in the key used for the hmacsha512 test 2014-09-16 15:25:38 -07:00
Frank Denis
a721543b58 Test hmacsha512 with keys larger than the block size 2014-09-16 14:59:19 -07:00
Frank Denis
82bc039d6c Consistent syle for the tests. 2014-09-14 11:32:55 -07:00
Frank Denis
0e559b94d5 Make the tests a little bit more readable 2014-09-14 10:34:16 -07:00
Frank Denis
2c1b507045 More constant tests 2014-09-13 14:29:59 -07:00
Frank Denis
b7b0436fb8 Test the presence of some extra functions 2014-09-13 14:12:40 -07: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
3b680e0a52 Use high-level APIs in tests 2014-09-13 13:56:41 -07:00
Frank Denis
47de75e935 Keep ming Visual C++ happy 2013-04-26 21:52:21 -07:00
Frank Denis
faa399c3df Only include sodium.h in tests.
Tests should always be passing by just including that.
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