-/* $OpenBSD: chacha.c,v 1.8 2019/01/22 00:59:21 dlg Exp $ */
+/* $OpenBSD: chacha.c,v 1.9 2022/08/20 18:44:58 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, size_t len)
{
unsigned char *k;
+ uint64_t n;
int i, l;
/* Consume remaining keystream, if any exists. */
len -= l;
}
- chacha_encrypt_bytes((chacha_ctx *)ctx, in, out, (uint32_t)len);
+ while (len > 0) {
+ if ((n = len) > UINT32_MAX)
+ n = UINT32_MAX;
+
+ chacha_encrypt_bytes((chacha_ctx *)ctx, in, out, (uint32_t)n);
+
+ in += n;
+ out += n;
+ len -= n;
+ }
}
void
const unsigned char key[32], const unsigned char iv[8], uint64_t counter)
{
struct chacha_ctx ctx;
+ uint64_t n;
/*
* chacha_ivsetup expects the counter to be in u8. Rather than
ctx.input[13] = (uint32_t)(counter >> 32);
}
- chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len);
+ while (len > 0) {
+ if ((n = len) > UINT32_MAX)
+ n = UINT32_MAX;
+
+ chacha_encrypt_bytes(&ctx, in, out, (uint32_t)n);
+
+ in += n;
+ out += n;
+ len -= n;
+ }
}
void