static const char tau[16] = "expand 16-byte k";
static void
-chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
+chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits)
{
const char *constants;
}
static void
-chacha_ivsetup(chacha_ctx *x,const u8 *iv)
+chacha_ivsetup(chacha_ctx *x, const u8 *iv, const u8 *counter)
{
- x->input[12] = 0;
- x->input[13] = 0;
+ x->input[12] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 0);
+ x->input[13] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 4);
x->input[14] = U8TO32_LITTLE(iv + 0);
x->input[15] = U8TO32_LITTLE(iv + 4);
}
-/* $OpenBSD: rnd.c,v 1.175 2015/05/25 03:07:07 deraadt Exp $ */
+/* $OpenBSD: rnd.c,v 1.176 2015/10/27 11:13:06 mikeb Exp $ */
/*
* Copyright (c) 2011 Theo de Raadt.
_rs_init(u_char *buf, size_t n)
{
KASSERT(n >= KEYSZ + IVSZ);
- chacha_keysetup(&rs, buf, KEYSZ * 8, 0);
- chacha_ivsetup(&rs, buf + KEYSZ);
+ chacha_keysetup(&rs, buf, KEYSZ * 8);
+ chacha_ivsetup(&rs, buf + KEYSZ, NULL);
}
static void
buf = malloc(POOLBYTES, M_TEMP, M_WAITOK);
if (total > ARC4_MAIN_MAX_BYTES) {
arc4random_buf(lbuf, sizeof(lbuf));
- chacha_keysetup(&lctx, lbuf, KEYSZ * 8, 0);
- chacha_ivsetup(&lctx, lbuf + KEYSZ);
+ chacha_keysetup(&lctx, lbuf, KEYSZ * 8);
+ chacha_ivsetup(&lctx, lbuf + KEYSZ, NULL);
explicit_bzero(lbuf, sizeof(lbuf));
myctx = 1;
}