From 6934a8d0c8eea550e5ab664beff0352e4b569efd Mon Sep 17 00:00:00 2001 From: Ilya Maykov Date: Sat, 2 Feb 2019 13:47:31 -0800 Subject: [PATCH] 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. --- .../sodium/crypto_aead_xchacha20poly1305.h | 2 +- src/libsodium/include/sodium/crypto_auth.h | 4 +- .../include/sodium/crypto_auth_hmacsha256.h | 6 +-- .../include/sodium/crypto_auth_hmacsha512.h | 6 +-- .../sodium/crypto_auth_hmacsha512256.h | 10 ++-- src/libsodium/include/sodium/crypto_box.h | 14 ++--- .../crypto_box_curve25519xchacha20poly1305.h | 10 ++-- .../crypto_box_curve25519xsalsa20poly1305.h | 4 +- .../include/sodium/crypto_generichash.h | 2 +- .../sodium/crypto_generichash_blake2b.h | 2 +- src/libsodium/include/sodium/crypto_hash.h | 2 +- .../include/sodium/crypto_hash_sha256.h | 4 +- .../include/sodium/crypto_hash_sha512.h | 4 +- .../include/sodium/crypto_onetimeauth.h | 6 +-- .../sodium/crypto_onetimeauth_poly1305.h | 6 +-- .../include/sodium/crypto_secretbox.h | 6 +-- .../crypto_secretbox_xchacha20poly1305.h | 4 +- .../crypto_secretbox_xsalsa20poly1305.h | 2 +- .../include/sodium/crypto_shorthash.h | 2 +- .../sodium/crypto_shorthash_siphash24.h | 4 +- src/libsodium/include/sodium/crypto_sign.h | 8 +-- .../include/sodium/crypto_sign_ed25519.h | 10 ++-- .../crypto_sign_edwards25519sha512batch.h | 2 +- src/libsodium/include/sodium/utils.h | 21 ++++---- src/libsodium/sodium/utils.c | 5 +- test/default/auth.c | 54 +++++++++++++++++++ test/default/auth3.c | 6 +++ test/default/auth5.c | 6 +++ test/default/auth7.c | 6 +++ test/default/box_easy.c | 3 +- test/default/codecs.c | 21 ++++++++ test/default/codecs.exp | 3 ++ test/default/sodium_utils.c | 21 ++++++++ test/default/sodium_utils.exp | 9 ++++ 34 files changed, 202 insertions(+), 73 deletions(-) diff --git a/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h b/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h index a13b2247..6643b0cb 100644 --- a/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h +++ b/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h @@ -79,7 +79,7 @@ int crypto_aead_xchacha20poly1305_ietf_decrypt_detached(unsigned char *m, unsigned long long adlen, const unsigned char *npub, const unsigned char *k) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 9, 9))); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(3, 5, 8, 9))); SODIUM_EXPORT void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char k[crypto_aead_xchacha20poly1305_ietf_KEYBYTES]) diff --git a/src/libsodium/include/sodium/crypto_auth.h b/src/libsodium/include/sodium/crypto_auth.h index d0fc8ee2..540aee0e 100644 --- a/src/libsodium/include/sodium/crypto_auth.h +++ b/src/libsodium/include/sodium/crypto_auth.h @@ -28,12 +28,12 @@ const char *crypto_auth_primitive(void); SODIUM_EXPORT int crypto_auth(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_auth_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT void crypto_auth_keygen(unsigned char k[crypto_auth_KEYBYTES]) diff --git a/src/libsodium/include/sodium/crypto_auth_hmacsha256.h b/src/libsodium/include/sodium/crypto_auth_hmacsha256.h index aa4ecfd8..3da864c7 100644 --- a/src/libsodium/include/sodium/crypto_auth_hmacsha256.h +++ b/src/libsodium/include/sodium/crypto_auth_hmacsha256.h @@ -24,14 +24,14 @@ SODIUM_EXPORT int crypto_auth_hmacsha256(unsigned char *out, const unsigned char *in, unsigned long long inlen, - const unsigned char *k) __attribute__ ((nonnull)); + const unsigned char *k) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_auth_hmacsha256_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); /* ------------------------------------------------------------------------- */ @@ -52,7 +52,7 @@ SODIUM_EXPORT int crypto_auth_hmacsha256_update(crypto_auth_hmacsha256_state *state, const unsigned char *in, unsigned long long inlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_auth_hmacsha256_final(crypto_auth_hmacsha256_state *state, diff --git a/src/libsodium/include/sodium/crypto_auth_hmacsha512.h b/src/libsodium/include/sodium/crypto_auth_hmacsha512.h index c5012583..d992cb81 100644 --- a/src/libsodium/include/sodium/crypto_auth_hmacsha512.h +++ b/src/libsodium/include/sodium/crypto_auth_hmacsha512.h @@ -24,14 +24,14 @@ SODIUM_EXPORT int crypto_auth_hmacsha512(unsigned char *out, const unsigned char *in, unsigned long long inlen, - const unsigned char *k) __attribute__ ((nonnull)); + const unsigned char *k) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_auth_hmacsha512_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); /* ------------------------------------------------------------------------- */ @@ -51,7 +51,7 @@ int crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state, SODIUM_EXPORT int crypto_auth_hmacsha512_update(crypto_auth_hmacsha512_state *state, const unsigned char *in, - unsigned long long inlen) __attribute__ ((nonnull)); + unsigned long long inlen) __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_auth_hmacsha512_final(crypto_auth_hmacsha512_state *state, diff --git a/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h b/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h index 0f266104..3fb52638 100644 --- a/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h +++ b/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h @@ -21,15 +21,17 @@ SODIUM_EXPORT size_t crypto_auth_hmacsha512256_keybytes(void); SODIUM_EXPORT -int crypto_auth_hmacsha512256(unsigned char *out, const unsigned char *in, - unsigned long long inlen,const unsigned char *k); +int crypto_auth_hmacsha512256(unsigned char *out, + const unsigned char *in, + unsigned long long inlen, + const unsigned char *k) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_auth_hmacsha512256_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); /* ------------------------------------------------------------------------- */ @@ -46,7 +48,7 @@ int crypto_auth_hmacsha512256_init(crypto_auth_hmacsha512256_state *state, SODIUM_EXPORT int crypto_auth_hmacsha512256_update(crypto_auth_hmacsha512256_state *state, const unsigned char *in, - unsigned long long inlen) __attribute__ ((nonnull)); + unsigned long long inlen) __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_auth_hmacsha512256_final(crypto_auth_hmacsha512256_state *state, diff --git a/src/libsodium/include/sodium/crypto_box.h b/src/libsodium/include/sodium/crypto_box.h index f6fe3ccb..e060dd29 100644 --- a/src/libsodium/include/sodium/crypto_box.h +++ b/src/libsodium/include/sodium/crypto_box.h @@ -61,7 +61,7 @@ SODIUM_EXPORT int crypto_box_easy(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *pk, const unsigned char *sk) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6))); SODIUM_EXPORT int crypto_box_open_easy(unsigned char *m, const unsigned char *c, @@ -74,7 +74,7 @@ int crypto_box_detached(unsigned char *c, unsigned char *mac, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *pk, const unsigned char *sk) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7))); SODIUM_EXPORT int crypto_box_open_detached(unsigned char *m, const unsigned char *c, @@ -99,7 +99,7 @@ int crypto_box_beforenm(unsigned char *k, const unsigned char *pk, SODIUM_EXPORT int crypto_box_easy_afternm(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, - const unsigned char *k) __attribute__ ((nonnull)); + const unsigned char *k) __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_box_open_easy_afternm(unsigned char *m, const unsigned char *c, @@ -111,7 +111,7 @@ SODIUM_EXPORT int crypto_box_detached_afternm(unsigned char *c, unsigned char *mac, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 2, 5, 6))); SODIUM_EXPORT int crypto_box_open_detached_afternm(unsigned char *m, const unsigned char *c, @@ -129,7 +129,7 @@ size_t crypto_box_sealbytes(void); SODIUM_EXPORT int crypto_box_seal(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *pk) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_box_seal_open(unsigned char *m, const unsigned char *c, @@ -151,7 +151,7 @@ SODIUM_EXPORT int crypto_box(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *pk, const unsigned char *sk) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6))); SODIUM_EXPORT int crypto_box_open(unsigned char *m, const unsigned char *c, @@ -162,7 +162,7 @@ int crypto_box_open(unsigned char *m, const unsigned char *c, SODIUM_EXPORT int crypto_box_afternm(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, - const unsigned char *k) __attribute__ ((nonnull)); + const unsigned char *k) __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_box_open_afternm(unsigned char *m, const unsigned char *c, diff --git a/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h b/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h index 0d3937a7..26a3d31e 100644 --- a/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h +++ b/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h @@ -60,7 +60,7 @@ int crypto_box_curve25519xchacha20poly1305_easy(unsigned char *c, const unsigned char *n, const unsigned char *pk, const unsigned char *sk) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6))); SODIUM_EXPORT int crypto_box_curve25519xchacha20poly1305_open_easy(unsigned char *m, @@ -79,7 +79,7 @@ int crypto_box_curve25519xchacha20poly1305_detached(unsigned char *c, const unsigned char *n, const unsigned char *pk, const unsigned char *sk) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 2, 5, 6, 7))); SODIUM_EXPORT int crypto_box_curve25519xchacha20poly1305_open_detached(unsigned char *m, @@ -105,7 +105,7 @@ int crypto_box_curve25519xchacha20poly1305_easy_afternm(unsigned char *c, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_box_curve25519xchacha20poly1305_open_easy_afternm(unsigned char *m, @@ -122,7 +122,7 @@ int crypto_box_curve25519xchacha20poly1305_detached_afternm(unsigned char *c, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 2, 5, 6))); SODIUM_EXPORT int crypto_box_curve25519xchacha20poly1305_open_detached_afternm(unsigned char *m, @@ -147,7 +147,7 @@ int crypto_box_curve25519xchacha20poly1305_seal(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *pk) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_box_curve25519xchacha20poly1305_seal_open(unsigned char *m, diff --git a/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h b/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h index f889430c..e733f499 100644 --- a/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +++ b/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h @@ -78,7 +78,7 @@ int crypto_box_curve25519xsalsa20poly1305(unsigned char *c, const unsigned char *n, const unsigned char *pk, const unsigned char *sk) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4, 5, 6))); SODIUM_EXPORT int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *m, @@ -95,7 +95,7 @@ int crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *m, diff --git a/src/libsodium/include/sodium/crypto_generichash.h b/src/libsodium/include/sodium/crypto_generichash.h index a5f313d7..d897e5d2 100644 --- a/src/libsodium/include/sodium/crypto_generichash.h +++ b/src/libsodium/include/sodium/crypto_generichash.h @@ -66,7 +66,7 @@ SODIUM_EXPORT int crypto_generichash_update(crypto_generichash_state *state, const unsigned char *in, unsigned long long inlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_generichash_final(crypto_generichash_state *state, diff --git a/src/libsodium/include/sodium/crypto_generichash_blake2b.h b/src/libsodium/include/sodium/crypto_generichash_blake2b.h index ecda3625..fee9d8ad 100644 --- a/src/libsodium/include/sodium/crypto_generichash_blake2b.h +++ b/src/libsodium/include/sodium/crypto_generichash_blake2b.h @@ -100,7 +100,7 @@ SODIUM_EXPORT int crypto_generichash_blake2b_update(crypto_generichash_blake2b_state *state, const unsigned char *in, unsigned long long inlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_generichash_blake2b_final(crypto_generichash_blake2b_state *state, diff --git a/src/libsodium/include/sodium/crypto_hash.h b/src/libsodium/include/sodium/crypto_hash.h index 4b16c477..8752f9ca 100644 --- a/src/libsodium/include/sodium/crypto_hash.h +++ b/src/libsodium/include/sodium/crypto_hash.h @@ -26,7 +26,7 @@ size_t crypto_hash_bytes(void); SODIUM_EXPORT int crypto_hash(unsigned char *out, const unsigned char *in, - unsigned long long inlen) __attribute__ ((nonnull)); + unsigned long long inlen) __attribute__ ((nonnull(1))); #define crypto_hash_PRIMITIVE "sha512" SODIUM_EXPORT diff --git a/src/libsodium/include/sodium/crypto_hash_sha256.h b/src/libsodium/include/sodium/crypto_hash_sha256.h index 306f1e93..b18217e1 100644 --- a/src/libsodium/include/sodium/crypto_hash_sha256.h +++ b/src/libsodium/include/sodium/crypto_hash_sha256.h @@ -36,7 +36,7 @@ size_t crypto_hash_sha256_bytes(void); SODIUM_EXPORT int crypto_hash_sha256(unsigned char *out, const unsigned char *in, - unsigned long long inlen) __attribute__ ((nonnull)); + unsigned long long inlen) __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_hash_sha256_init(crypto_hash_sha256_state *state) @@ -46,7 +46,7 @@ SODIUM_EXPORT int crypto_hash_sha256_update(crypto_hash_sha256_state *state, const unsigned char *in, unsigned long long inlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_hash_sha256_final(crypto_hash_sha256_state *state, diff --git a/src/libsodium/include/sodium/crypto_hash_sha512.h b/src/libsodium/include/sodium/crypto_hash_sha512.h index 7fb830c6..8efa7193 100644 --- a/src/libsodium/include/sodium/crypto_hash_sha512.h +++ b/src/libsodium/include/sodium/crypto_hash_sha512.h @@ -36,7 +36,7 @@ size_t crypto_hash_sha512_bytes(void); SODIUM_EXPORT int crypto_hash_sha512(unsigned char *out, const unsigned char *in, - unsigned long long inlen) __attribute__ ((nonnull)); + unsigned long long inlen) __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_hash_sha512_init(crypto_hash_sha512_state *state) @@ -46,7 +46,7 @@ SODIUM_EXPORT int crypto_hash_sha512_update(crypto_hash_sha512_state *state, const unsigned char *in, unsigned long long inlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_hash_sha512_final(crypto_hash_sha512_state *state, diff --git a/src/libsodium/include/sodium/crypto_onetimeauth.h b/src/libsodium/include/sodium/crypto_onetimeauth.h index 803dbac8..7cd7b070 100644 --- a/src/libsodium/include/sodium/crypto_onetimeauth.h +++ b/src/libsodium/include/sodium/crypto_onetimeauth.h @@ -33,12 +33,12 @@ const char *crypto_onetimeauth_primitive(void); SODIUM_EXPORT int crypto_onetimeauth(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_onetimeauth_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_onetimeauth_init(crypto_onetimeauth_state *state, @@ -48,7 +48,7 @@ SODIUM_EXPORT int crypto_onetimeauth_update(crypto_onetimeauth_state *state, const unsigned char *in, unsigned long long inlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_onetimeauth_final(crypto_onetimeauth_state *state, diff --git a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h index 516f7db3..f3e34d86 100644 --- a/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +++ b/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h @@ -36,14 +36,14 @@ int crypto_onetimeauth_poly1305(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_onetimeauth_poly1305_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_onetimeauth_poly1305_init(crypto_onetimeauth_poly1305_state *state, @@ -54,7 +54,7 @@ SODIUM_EXPORT int crypto_onetimeauth_poly1305_update(crypto_onetimeauth_poly1305_state *state, const unsigned char *in, unsigned long long inlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_onetimeauth_poly1305_final(crypto_onetimeauth_poly1305_state *state, diff --git a/src/libsodium/include/sodium/crypto_secretbox.h b/src/libsodium/include/sodium/crypto_secretbox.h index eae44877..1d3709db 100644 --- a/src/libsodium/include/sodium/crypto_secretbox.h +++ b/src/libsodium/include/sodium/crypto_secretbox.h @@ -36,7 +36,7 @@ size_t crypto_secretbox_messagebytes_max(void); SODIUM_EXPORT int crypto_secretbox_easy(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, - const unsigned char *k) __attribute__ ((nonnull)); + const unsigned char *k) __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c, @@ -50,7 +50,7 @@ int crypto_secretbox_detached(unsigned char *c, unsigned char *mac, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 2, 5, 6))); SODIUM_EXPORT int crypto_secretbox_open_detached(unsigned char *m, @@ -78,7 +78,7 @@ size_t crypto_secretbox_boxzerobytes(void); SODIUM_EXPORT int crypto_secretbox(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, - const unsigned char *k) __attribute__ ((nonnull)); + const unsigned char *k) __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_secretbox_open(unsigned char *m, const unsigned char *c, diff --git a/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h b/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h index e7948f2c..6ec674e3 100644 --- a/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h +++ b/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h @@ -35,7 +35,7 @@ int crypto_secretbox_xchacha20poly1305_easy(unsigned char *c, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_secretbox_xchacha20poly1305_open_easy(unsigned char *m, @@ -52,7 +52,7 @@ int crypto_secretbox_xchacha20poly1305_detached(unsigned char *c, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 2, 5, 6))); SODIUM_EXPORT int crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m, diff --git a/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h b/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h index 1c72d6c0..be0874cb 100644 --- a/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +++ b/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h @@ -36,7 +36,7 @@ int crypto_secretbox_xsalsa20poly1305(unsigned char *c, unsigned long long mlen, const unsigned char *n, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4, 5))); SODIUM_EXPORT int crypto_secretbox_xsalsa20poly1305_open(unsigned char *m, diff --git a/src/libsodium/include/sodium/crypto_shorthash.h b/src/libsodium/include/sodium/crypto_shorthash.h index dc8b2480..fecaa88b 100644 --- a/src/libsodium/include/sodium/crypto_shorthash.h +++ b/src/libsodium/include/sodium/crypto_shorthash.h @@ -28,7 +28,7 @@ const char *crypto_shorthash_primitive(void); SODIUM_EXPORT int crypto_shorthash(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT void crypto_shorthash_keygen(unsigned char k[crypto_shorthash_KEYBYTES]) diff --git a/src/libsodium/include/sodium/crypto_shorthash_siphash24.h b/src/libsodium/include/sodium/crypto_shorthash_siphash24.h index 912e9d8c..1e6f72a6 100644 --- a/src/libsodium/include/sodium/crypto_shorthash_siphash24.h +++ b/src/libsodium/include/sodium/crypto_shorthash_siphash24.h @@ -24,7 +24,7 @@ size_t crypto_shorthash_siphash24_keybytes(void); SODIUM_EXPORT int crypto_shorthash_siphash24(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); #ifndef SODIUM_LIBRARY_MINIMAL /* -- 128-bit output -- */ @@ -40,7 +40,7 @@ size_t crypto_shorthash_siphashx24_keybytes(void); SODIUM_EXPORT int crypto_shorthash_siphashx24(unsigned char *out, const unsigned char *in, unsigned long long inlen, const unsigned char *k) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 4))); #endif #ifdef __cplusplus diff --git a/src/libsodium/include/sodium/crypto_sign.h b/src/libsodium/include/sodium/crypto_sign.h index 3d31ab24..f5fafb12 100644 --- a/src/libsodium/include/sodium/crypto_sign.h +++ b/src/libsodium/include/sodium/crypto_sign.h @@ -61,7 +61,7 @@ int crypto_sign_keypair(unsigned char *pk, unsigned char *sk) SODIUM_EXPORT int crypto_sign(unsigned char *sm, unsigned long long *smlen_p, const unsigned char *m, unsigned long long mlen, - const unsigned char *sk) __attribute__ ((nonnull(1, 3, 5))); + const unsigned char *sk) __attribute__ ((nonnull(1, 5))); SODIUM_EXPORT int crypto_sign_open(unsigned char *m, unsigned long long *mlen_p, @@ -72,14 +72,14 @@ int crypto_sign_open(unsigned char *m, unsigned long long *mlen_p, SODIUM_EXPORT int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p, const unsigned char *m, unsigned long long mlen, - const unsigned char *sk) __attribute__ ((nonnull(1, 3, 5))); + const unsigned char *sk) __attribute__ ((nonnull(1, 5))); SODIUM_EXPORT int crypto_sign_verify_detached(const unsigned char *sig, const unsigned char *m, unsigned long long mlen, const unsigned char *pk) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_sign_init(crypto_sign_state *state); @@ -87,7 +87,7 @@ int crypto_sign_init(crypto_sign_state *state); SODIUM_EXPORT int crypto_sign_update(crypto_sign_state *state, const unsigned char *m, unsigned long long mlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_sign_final_create(crypto_sign_state *state, unsigned char *sig, diff --git a/src/libsodium/include/sodium/crypto_sign_ed25519.h b/src/libsodium/include/sodium/crypto_sign_ed25519.h index db978ea2..0fdac42d 100644 --- a/src/libsodium/include/sodium/crypto_sign_ed25519.h +++ b/src/libsodium/include/sodium/crypto_sign_ed25519.h @@ -43,7 +43,7 @@ SODIUM_EXPORT int crypto_sign_ed25519(unsigned char *sm, unsigned long long *smlen_p, const unsigned char *m, unsigned long long mlen, const unsigned char *sk) - __attribute__ ((nonnull(1, 3, 5))); + __attribute__ ((nonnull(1, 5))); SODIUM_EXPORT int crypto_sign_ed25519_open(unsigned char *m, unsigned long long *mlen_p, @@ -57,14 +57,14 @@ int crypto_sign_ed25519_detached(unsigned char *sig, const unsigned char *m, unsigned long long mlen, const unsigned char *sk) - __attribute__ ((nonnull(1, 3))); + __attribute__ ((nonnull(1, 5))); SODIUM_EXPORT int crypto_sign_ed25519_verify_detached(const unsigned char *sig, const unsigned char *m, unsigned long long mlen, const unsigned char *pk) - __attribute__ ((warn_unused_result)); + __attribute__ ((warn_unused_result)) __attribute__ ((nonnull(1, 4))); SODIUM_EXPORT int crypto_sign_ed25519_keypair(unsigned char *pk, unsigned char *sk) @@ -102,14 +102,14 @@ SODIUM_EXPORT int crypto_sign_ed25519ph_update(crypto_sign_ed25519ph_state *state, const unsigned char *m, unsigned long long mlen) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int crypto_sign_ed25519ph_final_create(crypto_sign_ed25519ph_state *state, unsigned char *sig, unsigned long long *siglen_p, const unsigned char *sk) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1, 2, 4))); SODIUM_EXPORT int crypto_sign_ed25519ph_final_verify(crypto_sign_ed25519ph_state *state, diff --git a/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h b/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h index e69339a4..eed158aa 100644 --- a/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +++ b/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h @@ -33,7 +33,7 @@ int crypto_sign_edwards25519sha512batch(unsigned char *sm, const unsigned char *m, unsigned long long mlen, const unsigned char *sk) - __attribute__ ((deprecated)) __attribute__ ((nonnull(1, 3, 5))); + __attribute__ ((deprecated)) __attribute__ ((nonnull(1, 5))); SODIUM_EXPORT int crypto_sign_edwards25519sha512batch_open(unsigned char *m, diff --git a/src/libsodium/include/sodium/utils.h b/src/libsodium/include/sodium/utils.h index 84feeea6..ac801512 100644 --- a/src/libsodium/include/sodium/utils.h +++ b/src/libsodium/include/sodium/utils.h @@ -19,7 +19,7 @@ extern "C" { #endif SODIUM_EXPORT -void sodium_memzero(void * const pnt, const size_t len) __attribute__ ((nonnull)); +void sodium_memzero(void * const pnt, const size_t len); SODIUM_EXPORT void sodium_stackzero(const size_t len); @@ -32,7 +32,7 @@ void sodium_stackzero(const size_t len); */ SODIUM_EXPORT int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + __attribute__ ((warn_unused_result)); /* * sodium_compare() returns -1 if b1_ < b2_, 1 if b1_ > b2_ and 0 if b1_ == b2_ @@ -42,8 +42,7 @@ int sodium_memcmp(const void * const b1_, const void * const b2_, size_t len) */ SODIUM_EXPORT int sodium_compare(const unsigned char *b1_, const unsigned char *b2_, - size_t len) - __attribute__ ((warn_unused_result)) __attribute__ ((nonnull)); + size_t len) __attribute__ ((warn_unused_result)); SODIUM_EXPORT int sodium_is_zero(const unsigned char *n, const size_t nlen); @@ -52,24 +51,22 @@ SODIUM_EXPORT void sodium_increment(unsigned char *n, const size_t nlen); SODIUM_EXPORT -void sodium_add(unsigned char *a, const unsigned char *b, const size_t len) - __attribute__ ((nonnull)); +void sodium_add(unsigned char *a, const unsigned char *b, const size_t len); SODIUM_EXPORT -void sodium_sub(unsigned char *a, const unsigned char *b, const size_t len) - __attribute__ ((nonnull)); +void sodium_sub(unsigned char *a, const unsigned char *b, const size_t len); SODIUM_EXPORT char *sodium_bin2hex(char * const hex, const size_t hex_maxlen, const unsigned char * const bin, const size_t bin_len) - __attribute__ ((nonnull)); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int sodium_hex2bin(unsigned char * const bin, const size_t bin_maxlen, const char * const hex, const size_t hex_len, const char * const ignore, size_t * const bin_len, const char ** const hex_end) - __attribute__ ((nonnull(1, 3))); + __attribute__ ((nonnull(1))); #define sodium_base64_VARIANT_ORIGINAL 1 #define sodium_base64_VARIANT_ORIGINAL_NO_PADDING 3 @@ -91,14 +88,14 @@ size_t sodium_base64_encoded_len(const size_t bin_len, const int variant); SODIUM_EXPORT char *sodium_bin2base64(char * const b64, const size_t b64_maxlen, const unsigned char * const bin, const size_t bin_len, - const int variant) __attribute__ ((nonnull)); + const int variant) __attribute__ ((nonnull(1))); SODIUM_EXPORT int sodium_base642bin(unsigned char * const bin, const size_t bin_maxlen, const char * const b64, const size_t b64_len, const char * const ignore, size_t * const bin_len, const char ** const b64_end, const int variant) - __attribute__ ((nonnull(1, 3))); + __attribute__ ((nonnull(1))); SODIUM_EXPORT int sodium_mlock(void * const addr, const size_t len) diff --git a/src/libsodium/sodium/utils.c b/src/libsodium/sodium/utils.c index d865eb90..0edb4e55 100644 --- a/src/libsodium/sodium/utils.c +++ b/src/libsodium/sodium/utils.c @@ -100,8 +100,11 @@ _sodium_dummy_symbol_to_prevent_memzero_lto(void *const pnt, /* LCOV_EXCL_STOP */ void -sodium_memzero(void *const pnt, const size_t len) +sodium_memzero(void * const pnt, const size_t len) { + if (len == 0) { + return; + } #ifdef _WIN32 SecureZeroMemory(pnt, len); #elif defined(HAVE_MEMSET_S) diff --git a/test/default/auth.c b/test/default/auth.c index 19af20d7..1f4553ca 100644 --- a/test/default/auth.c +++ b/test/default/auth.c @@ -14,12 +14,14 @@ static unsigned char key2[] = static unsigned char a[crypto_auth_BYTES]; static unsigned char a2[crypto_auth_hmacsha512_BYTES]; +static unsigned char a3[crypto_auth_hmacsha512_BYTES]; int main(void) { crypto_auth_hmacsha512_state st; crypto_auth_hmacsha256_state st256; + crypto_auth_hmacsha512256_state st512_256; size_t i; assert(crypto_auth_hmacsha512_statebytes() == @@ -65,6 +67,58 @@ main(void) printf("\n"); } + // Empty message tests: HMAC-SHA512 + memset(a2, 0, sizeof a2); + crypto_auth_hmacsha512_init(&st, key, sizeof key); + crypto_auth_hmacsha512_final(&st, a2); + + memset(a3, 0, sizeof a3); + crypto_auth_hmacsha512_init(&st, key, sizeof key); + crypto_auth_hmacsha512_update(&st, a2, 0U); + crypto_auth_hmacsha512_final(&st, a3); + assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + + memset(a3, 0, sizeof a3); + crypto_auth_hmacsha512_init(&st, key, sizeof key); + crypto_auth_hmacsha512_update(&st, NULL, 0U); + crypto_auth_hmacsha512_final(&st, a3); + assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + + // Empty message tests: HMAC-SHA512-256 + memset(a2, 0, sizeof a2); + crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key); + crypto_auth_hmacsha512256_final(&st512_256, a2); + + memset(a3, 0, sizeof a3); + crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key); + crypto_auth_hmacsha512256_update(&st512_256, a2, 0U); + crypto_auth_hmacsha512256_final(&st512_256, a3); + assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + + memset(a3, 0, sizeof a3); + crypto_auth_hmacsha512256_init(&st512_256, key, sizeof key); + crypto_auth_hmacsha512256_update(&st512_256, NULL, 0U); + crypto_auth_hmacsha512256_final(&st512_256, a3); + assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + + + // Empty message tests: HMAC-SHA256 + memset(a2, 0, sizeof a2); + crypto_auth_hmacsha256_init(&st256, key, sizeof key); + crypto_auth_hmacsha256_final(&st256, a2); + + memset(a3, 0, sizeof a3); + crypto_auth_hmacsha256_init(&st256, key, sizeof key); + crypto_auth_hmacsha256_update(&st256, a2, 0U); + crypto_auth_hmacsha256_final(&st256, a3); + assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + + memset(a3, 0, sizeof a3); + crypto_auth_hmacsha256_init(&st256, key, sizeof key); + crypto_auth_hmacsha256_update(&st256, NULL, 0U); + crypto_auth_hmacsha256_final(&st256, a3); + assert(sodium_memcmp(a2, a3, sizeof a2) == 0); + assert(crypto_auth_bytes() > 0U); assert(crypto_auth_keybytes() > 0U); assert(strcmp(crypto_auth_primitive(), "hmacsha512256") == 0); diff --git a/test/default/auth3.c b/test/default/auth3.c index ac686a1e..786f6f2e 100644 --- a/test/default/auth3.c +++ b/test/default/auth3.c @@ -25,7 +25,13 @@ static unsigned char a[32] = { 0x37, 0x2e, 0xfc, 0xf9, 0xb4, 0x0b, 0x35, 0xc2, int main(void) { + static unsigned char a2[crypto_auth_hmacsha256_BYTES]; + printf("%d\n", crypto_auth_hmacsha256_verify(a, c, sizeof c, key)); + // Test empty message with NULL pointer + crypto_auth_hmacsha256(a2, NULL, 0U, key); + assert(crypto_auth_hmacsha256_verify(a2, NULL, 0U, key) == 0); + return 0; } diff --git a/test/default/auth5.c b/test/default/auth5.c index 449314fe..5559ac51 100644 --- a/test/default/auth5.c +++ b/test/default/auth5.c @@ -32,5 +32,11 @@ main(void) } } } + + // Test empty message with NULL pointer + crypto_auth_keygen(key); + crypto_auth(a, NULL, 0U, key); + assert(crypto_auth_verify(a, NULL, 0U, key) == 0); + return 0; } diff --git a/test/default/auth7.c b/test/default/auth7.c index f6a8bfaa..71f97dff 100644 --- a/test/default/auth7.c +++ b/test/default/auth7.c @@ -32,5 +32,11 @@ main(void) } } } + + // Test empty message with NULL pointer + crypto_auth_keygen(key); + crypto_auth_hmacsha512(a, NULL, 0U, key); + assert(crypto_auth_hmacsha512_verify(a, NULL, 0U, key) == 0); + return 0; } diff --git a/test/default/box_easy.c b/test/default/box_easy.c index 9a336d3f..b7d0a028 100644 --- a/test/default/box_easy.c +++ b/test/default/box_easy.c @@ -50,12 +50,13 @@ main(void) /* Null message */ - ret = crypto_box_easy(c, c, 0, nonce, bobpk, alicesk); + ret = crypto_box_easy(c, NULL, 0, nonce, bobpk, alicesk); assert(ret == 0); for (i = 0; i < 1 + crypto_box_MACBYTES; ++i) { printf(",0x%02x", (unsigned int) c[i]); } printf("\n"); + ret = crypto_box_open_easy(c, c, crypto_box_MACBYTES, nonce, bobpk, alicesk); assert(ret == 0); diff --git a/test/default/codecs.c b/test/default/codecs.c index 711b4217..0ca7a49b 100644 --- a/test/default/codecs.c +++ b/test/default/codecs.c @@ -20,6 +20,11 @@ main(void) printf("%s\n", sodium_bin2hex(buf3, 33U, (const unsigned char *) "0123456789ABCDEF", 16U)); + printf("bin2hex(..., NULL, 0):%s\n", + sodium_bin2hex(buf4, sizeof(buf4), NULL, 0U)); + printf("bin2hex(..., \"\", 0):%s\n", + sodium_bin2hex(buf4, sizeof(buf4), (const unsigned char *) "", 0U)); + hex = "Cafe : 6942"; sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len, &hex_end); @@ -79,6 +84,12 @@ main(void) printf("sodium_hex2bin() with an extra character and no end pointer\n"); } + assert(sodium_hex2bin(buf4, sizeof(buf4), NULL, 0U, NULL, &bin_len, NULL) == 0); + assert(bin_len == 0); + + assert(sodium_hex2bin(buf4, sizeof(buf4), "", 0U, NULL, &bin_len, NULL) == 0); + assert(bin_len == 0); + printf("%s\n", sodium_bin2base64(buf3, 31U, (const unsigned char *) "\xfb\xf0\xf1" "0123456789ABCDEFab", 21U, sodium_base64_VARIANT_ORIGINAL)); @@ -94,6 +105,9 @@ main(void) printf("%s\n", sodium_bin2base64(buf3, 1U, guard_page, 0U, sodium_base64_VARIANT_ORIGINAL)); + printf("%s\n", + sodium_bin2base64(buf3, 1U, NULL, + 0U, sodium_base64_VARIANT_ORIGINAL)); printf("%s\n", sodium_bin2base64(buf3, 5U, (const unsigned char *) "a", 1U, sodium_base64_VARIANT_ORIGINAL)); @@ -201,6 +215,13 @@ main(void) assert(sodium_base642bin(buf1, sizeof buf1, "ka*w*=*", (size_t) 7U, "*~", NULL, NULL, sodium_base64_VARIANT_ORIGINAL) == 0); + assert(sodium_base642bin(buf1, sizeof buf1, "", 0U, NULL, &bin_len, NULL, + sodium_base64_VARIANT_ORIGINAL) == 0); + assert(bin_len == 0); + assert(sodium_base642bin(buf1, sizeof buf1, NULL, 0U, NULL, &bin_len, NULL, + sodium_base64_VARIANT_ORIGINAL) == 0); + assert(bin_len == 0); + for (i = 0; i < 1000; i++) { assert(sizeof buf1 >= 100); bin_len = (size_t) randombytes_uniform(100); diff --git a/test/default/codecs.exp b/test/default/codecs.exp index 863091be..748b1a18 100644 --- a/test/default/codecs.exp +++ b/test/default/codecs.exp @@ -1,4 +1,6 @@ 30313233343536373839414243444546 +bin2hex(..., NULL, 0): +bin2hex(..., "", 0): 4:cafe6942 dt1: 11 4:cafe6942 @@ -12,6 +14,7 @@ dt6: 11 -_DxMDEyMzQ1Njc4OUFCQ0RFRmFi -_DxMDEyMzQ1Njc4OUFCQ0RFRmFiYw + YQ== YWI= YWJj diff --git a/test/default/sodium_utils.c b/test/default/sodium_utils.c index 379518fc..8bd8509c 100644 --- a/test/default/sodium_utils.c +++ b/test/default/sodium_utils.c @@ -29,6 +29,10 @@ main(void) printf("%d\n", sodium_memcmp(buf1, buf2, 0U)); sodium_memzero(buf2, sizeof buf2 / 2); printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1)); + printf("%d\n", sodium_memcmp(buf1, NULL, 0U)); + printf("%d\n", sodium_memcmp(NULL, buf2, 0U)); + printf("%d\n", sodium_memcmp(NULL, NULL, 0U)); + sodium_memzero(NULL, 0U); memset(nonce, 0, sizeof nonce); sodium_increment(nonce, sizeof nonce); @@ -70,6 +74,8 @@ main(void) (unsigned int) bin_len); } } + printf("%d\n", sodium_compare(buf1, NULL, 0U)); + printf("%d\n", sodium_compare(NULL, buf1, 0U)); memset(buf1, 0, sizeof buf1); if (sodium_is_zero(buf1, sizeof buf1) != 1) { printf("sodium_is_zero() failed\n"); @@ -154,6 +160,21 @@ main(void) sodium_add(nonce, nonce, 24U); printf("%s\n", sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); + sodium_add(nonce, nonce, 0U); + printf("%s\n", + sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); + sodium_add(nonce, NULL, 0U); + printf("%s\n", + sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); + sodium_add(NULL, nonce, 0U); + + sodium_sub(nonce, nonce, 0U); + printf("%s\n", + sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); + sodium_sub(nonce, NULL, 0U); + printf("%s\n", + sodium_bin2hex(nonce_hex, sizeof nonce_hex, nonce, sizeof nonce)); + sodium_sub(NULL, nonce, 0U); randombytes_buf(buf1, 64U); randombytes_buf(buf2, 64U); diff --git a/test/default/sodium_utils.exp b/test/default/sodium_utils.exp index 84ec7fd5..c97a1db3 100644 --- a/test/default/sodium_utils.exp +++ b/test/default/sodium_utils.exp @@ -3,14 +3,23 @@ -1 0 0 +0 +0 +0 010000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000 010100000000000000000000000000000000000000000000 020000000000000000000000000000000000000000000000 0001ff000000000000000000000000000000000000000000 +0 +0 000000000000fffefefefefefefefefefefefefefefefefe 00000000000000000000fffefefefefefefefefefefefefe 00000000000000000000000000000000000000000000fffe fcfffffffffffbfdfefefefefefefefefefefefefefefefe fcfffffffffffffffffffbfdfefefefefefefefefefefefe fcfffffffffffffffffffffffffffffffffffffffffffbfd +fcfffffffffffffffffffffffffffffffffffffffffffbfd +fcfffffffffffffffffffffffffffffffffffffffffffbfd +fcfffffffffffffffffffffffffffffffffffffffffffbfd +fcfffffffffffffffffffffffffffffffffffffffffffbfd