upstream OpenBSD: arc4random: Add support for building arc4random with MSVC.

By default, MSVC's stdlib.h defines min(), so we need to spell out something
less common to avoid picking it up.

ok deraadt@ beck@ miod@
This commit is contained in:
bcook 2015-09-10 18:53:50 +00:00 committed by Corinna Vinschen
parent 783133b753
commit ef76759d7f
1 changed files with 8 additions and 7 deletions

View File

@ -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> * Copyright (c) 1996, David Mazieres <dm@uun.org>
@ -36,12 +36,13 @@
#define KEYSTREAM_ONLY #define KEYSTREAM_ONLY
#include "chacha_private.h" #include "chacha_private.h"
#define min(a, b) ((a) < (b) ? (a) : (b)) #define minimum(a, b) ((a) < (b) ? (a) : (b))
#ifdef __GNUC__
#if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline #define inline __inline
#else /* !__GNUC__ */ #else /* __GNUC__ || _MSC_VER */
#define inline #define inline
#endif /* !__GNUC__ */ #endif /* !__GNUC__ && !_MSC_VER */
#define KEYSZ 32 #define KEYSZ 32
#define IVSZ 8 #define IVSZ 8
@ -130,7 +131,7 @@ _rs_rekey(u_char *dat, size_t datlen)
if (dat) { if (dat) {
size_t i, m; size_t i, m;
m = min(datlen, KEYSZ + IVSZ); m = minimum(datlen, KEYSZ + IVSZ);
for (i = 0; i < m; i++) for (i = 0; i < m; i++)
rsx->rs_buf[i] ^= dat[i]; rsx->rs_buf[i] ^= dat[i];
} }
@ -150,7 +151,7 @@ _rs_random_buf(void *_buf, size_t n)
_rs_stir_if_needed(n); _rs_stir_if_needed(n);
while (n > 0) { while (n > 0) {
if (rs->rs_have > 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) keystream = rsx->rs_buf + sizeof(rsx->rs_buf)
- rs->rs_have; - rs->rs_have;
memcpy(buf, keystream, m); memcpy(buf, keystream, m);