Move size checks to the main chacha20 encryption function

This commit is contained in:
Frank Denis 2015-11-26 12:34:49 +01:00
parent 1cd715eb5d
commit 2cbb5de483
2 changed files with 7 additions and 7 deletions

View File

@ -112,6 +112,9 @@ chacha_encrypt_bytes(chacha_ctx *ctx, const u8 *m, u8 *c, unsigned long long byt
if (!bytes) {
return; /* LCOV_EXCL_LINE */
}
if (bytes > 64ULL * (1ULL << 32) - 64ULL) {
abort();
}
j0 = ctx->input[0];
j1 = ctx->input[1];
j2 = ctx->input[2];
@ -267,9 +270,6 @@ stream_ietf_ref(unsigned char *c, unsigned long long clen,
if (!clen) {
return 0;
}
if (clen > 64ULL * (1ULL << 32) - 64ULL) {
abort();
}
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]);
chacha_keysetup(&ctx, k);
chacha_ietf_ivsetup(&ctx, n, NULL);

View File

@ -137,6 +137,9 @@ chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *in, uint8_t *out,
unsigned long long iters;
unsigned long long i;
if (inlen > 64ULL * (1ULL << 32) - 64ULL) {
abort();
}
s0 = LOAD_ALIGNED(chacha_const);
s1 = ctx->s1;
s2 = ctx->s2;
@ -267,9 +270,6 @@ stream_ietf_vec(unsigned char *c, unsigned long long clen,
if (!clen) {
return 0;
}
if (clen > 64ULL * (1ULL << 32) - 64ULL) {
abort();
}
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]);
chacha_keysetup(&ctx, k);
chacha_ietf_ivsetup(&ctx, n, 0ULL);