From 6ac18dae429cf83e0ca79b1ed91ed1979f988160 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 29 Jul 2017 23:29:58 +0200 Subject: [PATCH] The MESSAGEBYTES_MAX constants are to be used with the libsodium API Projects using the legacy API are unlikely to use these new macros. OTOH, people using the Sodium API would be puzzled about the missing 16 bytes in the secretbox and box APIs. More importantly, these macros are designed for bindings. Having these bindings enforce proper limits (for the *_easy API that they all use) and yet have the underlying library call sodium_misuse() would be sad. --- .../crypto_box_curve25519xsalsa20poly1305.h | 41 ++++++++++--------- .../crypto_secretbox_xsalsa20poly1305.h | 3 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h b/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h index 4a0e1455..77c9e3af 100644 --- a/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +++ b/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h @@ -12,8 +12,6 @@ extern "C" { #endif -/* -- NaCl compatibility interface ; Requires padding -- */ - #define crypto_box_curve25519xsalsa20poly1305_SEEDBYTES 32U SODIUM_EXPORT size_t crypto_box_curve25519xsalsa20poly1305_seedbytes(void); @@ -38,6 +36,27 @@ size_t crypto_box_curve25519xsalsa20poly1305_noncebytes(void); SODIUM_EXPORT size_t crypto_box_curve25519xsalsa20poly1305_macbytes(void); +/* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */ +#define crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX \ + (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_box_curve25519xsalsa20poly1305_MACBYTES) + +SODIUM_EXPORT +int crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk, + unsigned char *sk, + const unsigned char *seed); + +SODIUM_EXPORT +int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk, + unsigned char *sk); + +SODIUM_EXPORT +int crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k, + const unsigned char *pk, + const unsigned char *sk) + __attribute__ ((warn_unused_result)); + +/* -- NaCl compatibility interface ; Requires padding -- */ + #define crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES 16U SODIUM_EXPORT size_t crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void); @@ -48,9 +67,6 @@ size_t crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void); SODIUM_EXPORT size_t crypto_box_curve25519xsalsa20poly1305_zerobytes(void); -#define crypto_box_curve25519xsalsa20poly1305_MESSAGEBYTES_MAX \ - (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_box_curve25519xsalsa20poly1305_ZEROBYTES) - SODIUM_EXPORT int crypto_box_curve25519xsalsa20poly1305(unsigned char *c, const unsigned char *m, @@ -69,21 +85,6 @@ int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *m, const unsigned char *sk) __attribute__ ((warn_unused_result)); -SODIUM_EXPORT -int crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk, - unsigned char *sk, - const unsigned char *seed); - -SODIUM_EXPORT -int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk, - unsigned char *sk); - -SODIUM_EXPORT -int crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k, - const unsigned char *pk, - const unsigned char *sk) - __attribute__ ((warn_unused_result)); - SODIUM_EXPORT int crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c, const unsigned char *m, diff --git a/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h b/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h index 04006a03..471271fd 100644 --- a/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +++ b/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h @@ -24,8 +24,9 @@ size_t crypto_secretbox_xsalsa20poly1305_noncebytes(void); SODIUM_EXPORT size_t crypto_secretbox_xsalsa20poly1305_macbytes(void); +/* Only for the libsodium API - The NaCl compatibility API would require BOXZEROBYTES extra bytes */ #define crypto_secretbox_xsalsa20poly1305_MESSAGEBYTES_MAX \ - (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_secretbox_xsalsa20poly1305_ZEROBYTES) + (crypto_stream_xsalsa20_MESSAGEBYTES_MAX - crypto_secretbox_xsalsa20poly1305_MACBYTES) SODIUM_EXPORT int crypto_secretbox_xsalsa20poly1305(unsigned char *c,