From 7b7e223d39aeb6909a4f1de4b23820e3e78765ff Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 13 Jun 2014 17:15:34 -0700 Subject: [PATCH] Do not allocate more memory than needed in the easy interfaces. And compute m_boxed_len as (ZEROBYTES || message len) to match the way the documentation describes the output. --- src/libsodium/crypto_box/crypto_box_easy.c | 2 +- src/libsodium/crypto_secretbox/crypto_secretbox_easy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsodium/crypto_box/crypto_box_easy.c b/src/libsodium/crypto_box/crypto_box_easy.c index c03c8ebf..ecc33b66 100644 --- a/src/libsodium/crypto_box/crypto_box_easy.c +++ b/src/libsodium/crypto_box/crypto_box_easy.c @@ -72,7 +72,7 @@ crypto_box_open_easy(unsigned char *m, const unsigned char *c, } memset(c_boxed, 0, crypto_box_BOXZEROBYTES); memcpy(c_boxed + crypto_box_BOXZEROBYTES, c, clen); - m_boxed_len = c_boxed_len + crypto_box_MACBYTES; + m_boxed_len = crypto_box_ZEROBYTES + (clen - crypto_box_MACBYTES); if ((m_boxed = (unsigned char *) malloc(m_boxed_len)) == NULL) { free(c_boxed); return -1; diff --git a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c index fd6508df..883fca88 100644 --- a/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +++ b/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c @@ -74,7 +74,7 @@ crypto_secretbox_open_easy(unsigned char *m, const unsigned char *c, } memset(c_boxed, 0, crypto_secretbox_BOXZEROBYTES); memcpy(c_boxed + crypto_secretbox_BOXZEROBYTES, c, clen); - m_boxed_len = c_boxed_len + crypto_secretbox_MACBYTES; + m_boxed_len = crypto_secretbox_ZEROBYTES + (clen - crypto_secretbox_MACBYTES); if ((m_boxed = (unsigned char *) malloc(m_boxed_len)) == NULL) { free(c_boxed); return -1;