|
|
@ -1,4 +1,4 @@ |
|
|
|
/* $OpenBSD: arc4random.c,v 1.52 2015/01/16 16:48:51 deraadt Exp $ */ |
|
|
|
/* $OpenBSD: arc4random.c,v 1.53 2015/09/10 18:53:50 bcook Exp $ */ |
|
|
|
|
|
|
|
/* |
|
|
|
* Copyright (c) 1996, David Mazieres <dm@uun.org> |
|
|
@ -36,12 +36,13 @@ |
|
|
|
#define KEYSTREAM_ONLY |
|
|
|
#include "chacha_private.h" |
|
|
|
|
|
|
|
#define min(a, b) ((a) < (b) ? (a) : (b)) |
|
|
|
#ifdef __GNUC__ |
|
|
|
#define minimum(a, b) ((a) < (b) ? (a) : (b)) |
|
|
|
|
|
|
|
#if defined(__GNUC__) || defined(_MSC_VER) |
|
|
|
#define inline __inline |
|
|
|
#else /* !__GNUC__ */ |
|
|
|
#else /* __GNUC__ || _MSC_VER */ |
|
|
|
#define inline |
|
|
|
#endif /* !__GNUC__ */ |
|
|
|
#endif /* !__GNUC__ && !_MSC_VER */ |
|
|
|
|
|
|
|
#define KEYSZ 32 |
|
|
|
#define IVSZ 8 |
|
|
@ -127,7 +128,7 @@ _rs_rekey(u_char *dat, size_t datlen) |
|
|
|
if (dat) { |
|
|
|
size_t i, m; |
|
|
|
|
|
|
|
m = min(datlen, KEYSZ + IVSZ); |
|
|
|
m = minimum(datlen, KEYSZ + IVSZ); |
|
|
|
for (i = 0; i < m; i++) |
|
|
|
rsx->rs_buf[i] ^= dat[i]; |
|
|
|
} |
|
|
@ -147,7 +148,7 @@ _rs_random_buf(void *_buf, size_t n) |
|
|
|
_rs_stir_if_needed(n); |
|
|
|
while (n > 0) { |
|
|
|
if (rs->rs_have > 0) { |
|
|
|
m = min(n, rs->rs_have); |
|
|
|
m = minimum(n, rs->rs_have); |
|
|
|
keystream = rsx->rs_buf + sizeof(rsx->rs_buf) |
|
|
|
- rs->rs_have; |
|
|
|
memcpy(buf, keystream, m); |
|
|
|