Browse Source

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@
OPENBSD_5_9
bcook 8 years ago
parent
commit
2c1adf355f
1 changed files with 8 additions and 7 deletions
  1. +8
    -7
      src/lib/libc/crypt/arc4random.c

+ 8
- 7
src/lib/libc/crypt/arc4random.c 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))
#ifdef __GNUC__
#define minimum(a, b) ((a) < (b) ? (a) : (b))
#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
@ -127,7 +128,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];
} }
@ -147,7 +148,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);


Loading…
Cancel
Save