crypto_(secret)box_easy: check SIZE_MAX overflow only where needed
This commit is contained in:
parent
c54b05a1e5
commit
877bf76716
@ -1,4 +1,8 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user