diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-01-01 17:57:12 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-01-01 17:57:12 -0800 |
| commit | 11985f8c59cccc0364bde7dd314e246ea53cff90 (patch) | |
| tree | c75c15db75b297817c10c9f2f6188aa767cbfa82 /src/platform/windows | |
| parent | ec7de57627a2bba8fadfb34d118ac478fbc351aa (diff) | |
| download | nng-11985f8c59cccc0364bde7dd314e246ea53cff90.tar.gz nng-11985f8c59cccc0364bde7dd314e246ea53cff90.tar.bz2 nng-11985f8c59cccc0364bde7dd314e246ea53cff90.zip | |
fixes #1083 Random number improvements
Diffstat (limited to 'src/platform/windows')
| -rw-r--r-- | src/platform/windows/win_rand.c | 28 |
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 |
