diff --git a/src/libsodium/crypto_box/crypto_box_easy.c b/src/libsodium/crypto_box/crypto_box_easy.c index 7224f241..7f39e220 100644 --- a/src/libsodium/crypto_box/crypto_box_easy.c +++ b/src/libsodium/crypto_box/crypto_box_easy.c @@ -1,4 +1,8 @@ +#include +#include +#include + #include "crypto_box.h" #include "crypto_secretbox.h" #include "utils.h" @@ -26,6 +30,9 @@ 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) { + if (mlen > SIZE_MAX - crypto_box_MACBYTES) { + return -1; + } return crypto_box_detached(c + crypto_box_MACBYTES, c, m, mlen, n, pk, sk); } diff --git a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c index 08de0961..5000a057 100644 --- a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +++ b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c @@ -27,9 +27,6 @@ crypto_secretbox_detached(unsigned char *c, unsigned char *mac, unsigned long long i; unsigned long long mlen0; - if (mlen > SIZE_MAX - crypto_secretbox_MACBYTES) { - return -1; - } crypto_core_hsalsa20(subkey, n, k, sigma); memset(block0, 0U, crypto_secretbox_ZEROBYTES); @@ -68,6 +65,9 @@ crypto_secretbox_easy(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *k) { + if (mlen > SIZE_MAX - crypto_secretbox_MACBYTES) { + return -1; + } return crypto_secretbox_detached(c + crypto_secretbox_MACBYTES, c, m, mlen, n, k); }