summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libc/crypt/arc4random.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c
index 75cdff3bc4..5afc6a15ab 100644
--- a/src/lib/libc/crypt/arc4random.c
+++ b/src/lib/libc/crypt/arc4random.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: arc4random.c,v 1.52 2015/01/16 16:48:51 deraadt Exp $ */ 1/* $OpenBSD: arc4random.c,v 1.53 2015/09/10 18:53:50 bcook Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, David Mazieres <dm@uun.org> 4 * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -36,12 +36,13 @@
36#define KEYSTREAM_ONLY 36#define KEYSTREAM_ONLY
37#include "chacha_private.h" 37#include "chacha_private.h"
38 38
39#define min(a, b) ((a) < (b) ? (a) : (b)) 39#define minimum(a, b) ((a) < (b) ? (a) : (b))
40#ifdef __GNUC__ 40
41#if defined(__GNUC__) || defined(_MSC_VER)
41#define inline __inline 42#define inline __inline
42#else /* !__GNUC__ */ 43#else /* __GNUC__ || _MSC_VER */
43#define inline 44#define inline
44#endif /* !__GNUC__ */ 45#endif /* !__GNUC__ && !_MSC_VER */
45 46
46#define KEYSZ 32 47#define KEYSZ 32
47#define IVSZ 8 48#define IVSZ 8
@@ -127,7 +128,7 @@ _rs_rekey(u_char *dat, size_t datlen)
127 if (dat) { 128 if (dat) {
128 size_t i, m; 129 size_t i, m;
129 130
130 m = min(datlen, KEYSZ + IVSZ); 131 m = minimum(datlen, KEYSZ + IVSZ);
131 for (i = 0; i < m; i++) 132 for (i = 0; i < m; i++)
132 rsx->rs_buf[i] ^= dat[i]; 133 rsx->rs_buf[i] ^= dat[i];
133 } 134 }
@@ -147,7 +148,7 @@ _rs_random_buf(void *_buf, size_t n)
147 _rs_stir_if_needed(n); 148 _rs_stir_if_needed(n);
148 while (n > 0) { 149 while (n > 0) {
149 if (rs->rs_have > 0) { 150 if (rs->rs_have > 0) {
150 m = min(n, rs->rs_have); 151 m = minimum(n, rs->rs_have);
151 keystream = rsx->rs_buf + sizeof(rsx->rs_buf) 152 keystream = rsx->rs_buf + sizeof(rsx->rs_buf)
152 - rs->rs_have; 153 - rs->rs_have;
153 memcpy(buf, keystream, m); 154 memcpy(buf, keystream, m);