Move size checks to the main chacha20 encryption function
This commit is contained in:
parent
1cd715eb5d
commit
2cbb5de483
@ -112,6 +112,9 @@ chacha_encrypt_bytes(chacha_ctx *ctx, const u8 *m, u8 *c, unsigned long long byt
|
|||||||
if (!bytes) {
|
if (!bytes) {
|
||||||
return; /* LCOV_EXCL_LINE */
|
return; /* LCOV_EXCL_LINE */
|
||||||
}
|
}
|
||||||
|
if (bytes > 64ULL * (1ULL << 32) - 64ULL) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
j0 = ctx->input[0];
|
j0 = ctx->input[0];
|
||||||
j1 = ctx->input[1];
|
j1 = ctx->input[1];
|
||||||
j2 = ctx->input[2];
|
j2 = ctx->input[2];
|
||||||
@ -267,9 +270,6 @@ stream_ietf_ref(unsigned char *c, unsigned long long clen,
|
|||||||
if (!clen) {
|
if (!clen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (clen > 64ULL * (1ULL << 32) - 64ULL) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]);
|
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]);
|
||||||
chacha_keysetup(&ctx, k);
|
chacha_keysetup(&ctx, k);
|
||||||
chacha_ietf_ivsetup(&ctx, n, NULL);
|
chacha_ietf_ivsetup(&ctx, n, NULL);
|
||||||
|
@ -137,6 +137,9 @@ chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *in, uint8_t *out,
|
|||||||
unsigned long long iters;
|
unsigned long long iters;
|
||||||
unsigned long long i;
|
unsigned long long i;
|
||||||
|
|
||||||
|
if (inlen > 64ULL * (1ULL << 32) - 64ULL) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
s0 = LOAD_ALIGNED(chacha_const);
|
s0 = LOAD_ALIGNED(chacha_const);
|
||||||
s1 = ctx->s1;
|
s1 = ctx->s1;
|
||||||
s2 = ctx->s2;
|
s2 = ctx->s2;
|
||||||
@ -234,7 +237,7 @@ chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *in, uint8_t *out,
|
|||||||
buf[0] = REVV_BE(v0 + s0);
|
buf[0] = REVV_BE(v0 + s0);
|
||||||
}
|
}
|
||||||
for (i = inlen & ~15ULL; i < inlen; i++) {
|
for (i = inlen & ~15ULL; i < inlen; i++) {
|
||||||
((char *)op)[i] = ((const char *)ip)[i] ^ ((char *)buf)[i];
|
((char *) op)[i] = ((const char *) ip)[i] ^ ((char *) buf)[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,9 +270,6 @@ stream_ietf_vec(unsigned char *c, unsigned long long clen,
|
|||||||
if (!clen) {
|
if (!clen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (clen > 64ULL * (1ULL << 32) - 64ULL) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]);
|
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES == 256 / 8 ? 1 : -1]);
|
||||||
chacha_keysetup(&ctx, k);
|
chacha_keysetup(&ctx, k);
|
||||||
chacha_ietf_ivsetup(&ctx, n, 0ULL);
|
chacha_ietf_ivsetup(&ctx, n, 0ULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user