aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows/win_rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/windows/win_rand.c')
-rw-r--r--src/platform/windows/win_rand.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/platform/windows/win_rand.c b/src/platform/windows/win_rand.c
index afe703ef..21568a81 100644
--- a/src/platform/windows/win_rand.c
+++ b/src/platform/windows/win_rand.c
@@ -1,5 +1,5 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -11,22 +11,24 @@
#ifdef NNG_PLATFORM_WINDOWS
+#ifndef _CRT_RAND_S
+#define _CRT_RAND_S
+#endif
+
#include <stdlib.h>
-void
-nni_plat_seed_prng(void *buf, size_t bufsz)
+uint32_t
+nni_random(void)
{
unsigned val;
- // The rand_s routine uses RtlGenRandom to get high quality
- // pseudo random numbers (i.e. numbers that should be good enough
- // for use with crypto keying.)
- while (bufsz > sizeof(val)) {
- rand_s(&val);
- memcpy(buf, &val, sizeof(val));
- buf = (((char *) buf) + sizeof(val));
- bufsz -= sizeof(val);
- }
+ // rand_s is claimed by Microsoft to generate cryptographically
+ // secure numbers. It also is claimed that this will only fail
+ // for EINVAL if val is NULL (not the case here). Other error
+ // conditions might be possible, but we have no way to tell.
+ // For now we just ignore that possibility.
+ rand_s(&val);
+ return ((uint32_t)val);
}
-#endif // NNG_PLATFORM_WINDOWS
+#endif // NNG_PLATFORM_WINDOWS \ No newline at end of file