Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:31

0001 //
0002 // Copyright (c) 2017 James E. King III
0003 //
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // (See accompanying file LICENSE_1_0.txt or copy at
0006 //   https://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // Platform-specific random entropy provider platform detection
0009 //
0010 
0011 #ifndef BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP
0012 #define BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP
0013 
0014 #include <boost/predef/library/c/cloudabi.h>
0015 #include <boost/predef/library/c/gnu.h>
0016 #include <boost/predef/os/bsd/open.h>
0017 #include <boost/predef/os/windows.h>
0018 
0019 // Note: Don't use Boost.Predef to detect Linux and Android as it may give different results depending on header inclusion order.
0020 // https://github.com/boostorg/predef/issues/81#issuecomment-413329061
0021 #if (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
0022 #include <sys/syscall.h>
0023 #if defined(SYS_getrandom)
0024 #define BOOST_UUID_RANDOM_PROVIDER_HAS_GETRANDOM
0025 #endif // defined(SYS_getrandom)
0026 #endif
0027 
0028 // On Linux, getentropy is implemented via getrandom. If we know that getrandom is not supported by the kernel, getentropy
0029 // will certainly not work, even if libc provides a wrapper function for it. There is no reason, ever, to use getentropy on that platform.
0030 #if !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY) && (defined(__linux__) || defined(__linux) || defined(linux) || defined(__ANDROID__))
0031 #define BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY
0032 #endif
0033 
0034 //
0035 // Platform Detection - will load in the correct header and
0036 // will define the class <tt>random_provider_base</tt>.
0037 //
0038 
0039 #if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || BOOST_LIB_C_CLOUDABI
0040 # define BOOST_UUID_RANDOM_PROVIDER_ARC4RANDOM
0041 # define BOOST_UUID_RANDOM_PROVIDER_NAME arc4random
0042 
0043 #elif BOOST_OS_WINDOWS
0044 # include <boost/winapi/config.hpp>
0045 # if BOOST_WINAPI_PARTITION_APP_SYSTEM && \
0046      !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT) && \
0047      !defined(_WIN32_WCE) && \
0048      (BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6)
0049 #  define BOOST_UUID_RANDOM_PROVIDER_BCRYPT
0050 #  define BOOST_UUID_RANDOM_PROVIDER_NAME bcrypt
0051 
0052 # elif BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
0053 #  define BOOST_UUID_RANDOM_PROVIDER_WINCRYPT
0054 #  define BOOST_UUID_RANDOM_PROVIDER_NAME wincrypt
0055 # else
0056 #  error Unable to find a suitable windows entropy provider
0057 # endif
0058 
0059 #elif defined(BOOST_UUID_RANDOM_PROVIDER_HAS_GETRANDOM) && !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX) && !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETRANDOM)
0060 # define BOOST_UUID_RANDOM_PROVIDER_GETRANDOM
0061 # define BOOST_UUID_RANDOM_PROVIDER_NAME getrandom
0062 
0063 #elif BOOST_LIB_C_GNU >= BOOST_VERSION_NUMBER(2, 25, 0) && !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX) && !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY)
0064 # define BOOST_UUID_RANDOM_PROVIDER_GETENTROPY
0065 # define BOOST_UUID_RANDOM_PROVIDER_NAME getentropy
0066 
0067 #else
0068 # define BOOST_UUID_RANDOM_PROVIDER_POSIX
0069 # define BOOST_UUID_RANDOM_PROVIDER_NAME posix
0070 
0071 #endif
0072 
0073 #define BOOST_UUID_RANDOM_PROVIDER_STRINGIFY2(X) #X
0074 #define BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(X) BOOST_UUID_RANDOM_PROVIDER_STRINGIFY2(X)
0075 
0076 #if defined(BOOST_UUID_RANDOM_PROVIDER_SHOW)
0077 #pragma message("BOOST_UUID_RANDOM_PROVIDER_NAME " BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(BOOST_UUID_RANDOM_PROVIDER_NAME))
0078 #endif
0079 
0080 #endif // BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP