Commit Graph

12 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
ee1d5c96d8 Move the codecs tests to their own test file 2017-09-19 22:51:05 +02:00
Frank Denis
7423408cd3 Make the behavior of hex2bin() consistent with base642bin()
Return -1 on incomplete sequences and on complete sequences
with trailing, non-ignored characters if no pointers to store the
last parsed byte has been provided
2017-09-19 18:45:23 +02:00
Frank Denis
265bdcfe07 bin2hex & bin2base64: return a null size on error
This might prevent applications that don't properly check return codes
from reusing previous data.
2017-08-09 22:41:20 +02:00
Frank Denis
cdbb43f444 base64 tests 2017-08-09 15:56:58 +02:00
Frank Denis
ec6b86611f More checks for sodium_add() (overlaps) and sodium_increment() 2015-12-06 19:06:27 +01:00
Frank Denis
e2fca8cac5 Add sodium_increment() 2015-06-22 15:44:58 +02:00
Frank Denis
37580f4f52 More tests 2014-09-16 20:46:43 -07:00
Frank Denis
219db714cf Add sodium_hex2bin() 2014-04-15 00:39:14 -07:00
Frank Denis
1ca05f6b16 Have sodium_memcmp(a,b,s) return -1 if a != b, document return value. 2013-10-30 06:47:13 -07:00
Frank Denis
1a3786705e Add a sodium_bin2hex utility function. 2013-07-07 23:38:14 -07:00
Frank Denis
4c31bb5ef1 Add tests for sodium_*() functions. 2013-04-25 22:37:15 -07:00