config_os.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // config_os.h - written and placed in public domain by Jeffrey Walton
  2. // the bits that make up this source file are from the
  3. // library's monolithic config.h.
  4. /// \file config_os.h
  5. /// \brief Library configuration file
  6. /// \details <tt>config_os.h</tt> provides defines for platforms and operating
  7. /// systems.
  8. /// \details <tt>config.h</tt> was split into components in May 2019 to better
  9. /// integrate with Autoconf and its feature tests. The splitting occurred so
  10. /// users could continue to include <tt>config.h</tt> while allowing Autoconf
  11. /// to write new <tt>config_asm.h</tt> and new <tt>config_cxx.h</tt> using
  12. /// its feature tests.
  13. /// \note You should include <tt>config.h</tt> rather than <tt>config_os.h</tt>
  14. /// directly.
  15. /// \sa <A HREF="https://github.com/weidai11/cryptopp/issues/835">Issue 835,
  16. /// Make config.h more autoconf friendly</A>,
  17. /// <A HREF="https://www.cryptopp.com/wiki/Configure.sh">Configure.sh script</A>
  18. /// on the Crypto++ wiki
  19. /// \since Crypto++ 8.3
  20. #ifndef CRYPTOPP_CONFIG_OS_H
  21. #define CRYPTOPP_CONFIG_OS_H
  22. #include "config_ver.h"
  23. // It is OK to remove the hard stop below, but you are on your own.
  24. // After building the library be sure to run self tests described
  25. // https://www.cryptopp.com/wiki/Release_Process#Self_Tests
  26. // The problems with Clang pretending to be other compilers is
  27. // discussed at http://github.com/weidai11/cryptopp/issues/147.
  28. #if (defined(_MSC_VER) && defined(__clang__) && \
  29. !(defined( __clang_analyzer__)) && !defined(__INTEL_LLVM_COMPILER))
  30. # error: "Unsupported configuration"
  31. #endif
  32. // Windows platform
  33. #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
  34. #define CRYPTOPP_WIN32_AVAILABLE
  35. #endif
  36. // Unix and Linux platforms
  37. #if defined(__unix__) || defined(__MACH__) || defined(__NetBSD__) || defined(__sun)
  38. #define CRYPTOPP_UNIX_AVAILABLE
  39. #endif
  40. // BSD platforms
  41. #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
  42. #define CRYPTOPP_BSD_AVAILABLE
  43. #endif
  44. // Microsoft compilers
  45. #if defined(_MSC_VER) || defined(__fastcall)
  46. #define CRYPTOPP_FASTCALL __fastcall
  47. #else
  48. #define CRYPTOPP_FASTCALL
  49. #endif
  50. // Microsoft compilers
  51. #if defined(_MSC_VER)
  52. #define CRYPTOPP_NO_VTABLE __declspec(novtable)
  53. #else
  54. #define CRYPTOPP_NO_VTABLE
  55. #endif
  56. // Define this if you want to disable all OS-dependent features,
  57. // such as sockets and OS-provided random number generators
  58. // #define NO_OS_DEPENDENCE
  59. // Define this to use features provided by Microsoft's CryptoAPI.
  60. // Currently the only feature used is Windows random number generation.
  61. // This macro will be ignored if NO_OS_DEPENDENCE is defined.
  62. // #define USE_MS_CRYPTOAPI
  63. // Define this to use features provided by Microsoft's CryptoNG API.
  64. // CryptoNG API is available in Vista and above and its cross platform,
  65. // including desktop apps and store apps. Currently the only feature
  66. // used is Windows random number generation.
  67. // This macro will be ignored if NO_OS_DEPENDENCE is defined.
  68. // #define USE_MS_CNGAPI
  69. // If the user did not make a choice, then select CryptoNG if
  70. // targeting Windows 8 or above.
  71. #if !defined(USE_MS_CRYPTOAPI) && !defined(USE_MS_CNGAPI)
  72. # if !defined(_USING_V110_SDK71_) && ((WINVER >= 0x0602 /*_WIN32_WINNT_WIN8*/) || \
  73. (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/))
  74. # define USE_MS_CNGAPI
  75. # else
  76. # define USE_MS_CRYPTOAPI
  77. # endif
  78. #endif
  79. // Begin OS features, like init priorities and random numbers
  80. #ifndef NO_OS_DEPENDENCE
  81. // CRYPTOPP_INIT_PRIORITY attempts to manage initialization of C++ static objects.
  82. // Under GCC, the library uses init_priority attribute in the range
  83. // [CRYPTOPP_INIT_PRIORITY, CRYPTOPP_INIT_PRIORITY+100]. Under Windows,
  84. // CRYPTOPP_INIT_PRIORITY enlists "#pragma init_seg(lib)". The platforms
  85. // with gaps are Apple and Sun because they require linker scripts. Apple and
  86. // Sun will use the library's Singletons to initialize and acquire resources.
  87. // Also see http://cryptopp.com/wiki/Static_Initialization_Order_Fiasco
  88. #ifndef CRYPTOPP_INIT_PRIORITY
  89. # define CRYPTOPP_INIT_PRIORITY 250
  90. #endif
  91. // CRYPTOPP_USER_PRIORITY is for other libraries and user code that is using Crypto++
  92. // and managing C++ static object creation. It is guaranteed not to conflict with
  93. // values used by (or would be used by) the Crypto++ library.
  94. #ifndef CRYPTOPP_USER_PRIORITY
  95. # define CRYPTOPP_USER_PRIORITY (CRYPTOPP_INIT_PRIORITY+101)
  96. #endif
  97. // Most platforms allow us to specify when to create C++ objects. Apple and Sun do not.
  98. #if (CRYPTOPP_INIT_PRIORITY > 0) && !(defined(NO_OS_DEPENDENCE) || defined(__APPLE__) || defined(__sun__))
  99. # if (CRYPTOPP_GCC_VERSION >= 30000) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 800)
  100. # define HAVE_GCC_INIT_PRIORITY 1
  101. # elif (CRYPTOPP_MSC_VERSION >= 1310)
  102. # define HAVE_MSC_INIT_PRIORITY 1
  103. # elif defined(__xlc__) || defined(__xlC__) || defined(__ibmxl__)
  104. # define HAVE_XLC_INIT_PRIORITY 1
  105. # endif
  106. #endif // CRYPTOPP_INIT_PRIORITY, NO_OS_DEPENDENCE, Apple, Sun
  107. #if defined(CRYPTOPP_WIN32_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE)
  108. # define HIGHRES_TIMER_AVAILABLE
  109. #endif
  110. #ifdef CRYPTOPP_WIN32_AVAILABLE
  111. # if !defined(WINAPI_FAMILY)
  112. # define THREAD_TIMER_AVAILABLE
  113. # elif defined(WINAPI_FAMILY)
  114. # if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
  115. # define THREAD_TIMER_AVAILABLE
  116. # endif
  117. # endif
  118. #endif
  119. #if defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
  120. # define NONBLOCKING_RNG_AVAILABLE
  121. # define BLOCKING_RNG_AVAILABLE
  122. # define OS_RNG_AVAILABLE
  123. #endif
  124. // Cygwin/Newlib requires _XOPEN_SOURCE=600
  125. #if defined(CRYPTOPP_UNIX_AVAILABLE)
  126. # define UNIX_SIGNALS_AVAILABLE 1
  127. #endif
  128. #ifdef CRYPTOPP_WIN32_AVAILABLE
  129. # if !defined(WINAPI_FAMILY)
  130. # define NONBLOCKING_RNG_AVAILABLE
  131. # define OS_RNG_AVAILABLE
  132. # elif defined(WINAPI_FAMILY)
  133. # if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
  134. # define NONBLOCKING_RNG_AVAILABLE
  135. # define OS_RNG_AVAILABLE
  136. # elif !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
  137. # if ((WINVER >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/))
  138. # define NONBLOCKING_RNG_AVAILABLE
  139. # define OS_RNG_AVAILABLE
  140. # endif
  141. # endif
  142. # endif
  143. #endif
  144. #endif // NO_OS_DEPENDENCE
  145. #endif // CRYPTOPP_CONFIG_OS_H