ggentropy

A string formatting library for C++
Log | Files | Refs | README

commit e9f417c6067dfa9f1d7ea59ec6c8a8081fd241df
parent 1a7397812634c1b01c46f1d7bc2ff34f26f34d20
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu,  9 Jul 2020 12:37:36 +0300

FreeBSD/NetBSD/Solaris support

Diffstat:
MREADME.md | 3++-
Mggentropy.cpp | 17++++++++++++-----
2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md @@ -4,7 +4,8 @@ ggentropy is a liberally licensed, cross platform, entropy library for C++. You can use it to generate cryptographically secure random numbers, safe for use as nonces and keys in cryptographic operations. -ggentropy supports Windows, MacOS, Linux and OpenBSD. +ggentropy supports Windows, MacOS, Linux, FreeBSD, OpenBSD, NetBSD and +Solaris. ## Usage diff --git a/ggentropy.cpp b/ggentropy.cpp @@ -20,17 +20,24 @@ # define PLATFORM_WINDOWS 1 #elif defined( __linux__ ) # define PLATFORM_LINUX 1 +# define PLATFORM_HAS_URANDOM 1 #elif defined( __APPLE__ ) -# define PLATFORM_MACOS 1 +# define PLATFORM_HAS_URANDOM 1 +#elif defined( __FreeBSD__ ) +# define PLATFORM_HAS_ARC4RANDOM 1 #elif defined( __OpenBSD__ ) -# define PLATFORM_OPENBSD 1 +# define PLATFORM_HAS_ARC4RANDOM 1 +#elif defined( __NetBSD__ ) +# define PLATFORM_HAS_ARC4RANDOM 1 +#elif defined( __sun ) +# define PLATFORM_HAS_URANDOM 1 #else # error new platform #endif #include <assert.h> -#if PLATFORM_LINUX || PLATFORM_MACOS +#if PLATFORM_HAS_URANDOM #include <stdio.h> @@ -90,14 +97,14 @@ bool ggentropy( void * buf, size_t n ) { return try_urandom( buf, n ); } -#elif PLATFORM_MACOS +#elif PLATFORM_HAS_URANDOM bool ggentropy( void * buf, size_t n ) { assert( n <= 256 ); return try_urandom( buf, n ); } -#elif PLATFORM_OPENBSD +#elif PLATFORM_HAS_ARC4RANDOM #include <stdlib.h>