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.
This commit is contained in:
Frank Denis 2014-06-13 17:15:34 -07:00
parent 6aacecac60
commit 7b7e223d39
2 changed files with 2 additions and 2 deletions

View File

@ -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;

View File

@ -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;