config_os.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # error: "Unsupported configuration"
  30. #endif
  31. // Windows platform
  32. #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
  33. #define CRYPTOPP_WIN32_AVAILABLE
  34. #endif
  35. // Unix and Linux platforms
  36. #if defined(__unix__) || defined(__MACH__) || defined(__NetBSD__) || defined(__sun)
  37. #define CRYPTOPP_UNIX_AVAILABLE
  38. #endif
  39. // BSD platforms
  40. #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
  41. #define CRYPTOPP_BSD_AVAILABLE
  42. #endif
  43. // Microsoft compilers
  44. #if defined(CRYPTOPP_MSC_VERSION) || defined(__fastcall)
  45. #define CRYPTOPP_FASTCALL __fastcall
  46. #else
  47. #define CRYPTOPP_FASTCALL
  48. #endif
  49. // Microsoft compilers
  50. #if defined(CRYPTOPP_MSC_VERSION)
  51. #define CRYPTOPP_NO_VTABLE __declspec(novtable)
  52. #else
  53. #define CRYPTOPP_NO_VTABLE
  54. #endif
  55. // Define this if you want to disable all OS-dependent features,
  56. // such as sockets and OS-provided random number generators
  57. // #define NO_OS_DEPENDENCE
  58. // Define this to use features provided by Microsoft's CryptoAPI.
  59. // Currently the only feature used is Windows random number generation.
  60. // This macro will be ignored if NO_OS_DEPENDENCE is defined.
  61. // #define USE_MS_CRYPTOAPI
  62. // Define this to use features provided by Microsoft's CryptoNG API.
  63. // CryptoNG API is available in Vista and above and its cross platform,
  64. // including desktop apps and store apps. Currently the only feature
  65. // used is Windows random number generation.
  66. // This macro will be ignored if NO_OS_DEPENDENCE is defined.
  67. // #define USE_MS_CNGAPI
  68. // If the user did not make a choice, then select CryptoNG if
  69. // targeting Windows 8 or above.
  70. #if !defined(USE_MS_CRYPTOAPI) && !defined(USE_MS_CNGAPI)
  71. # if !defined(_USING_V110_SDK71_) && ((WINVER >= 0x0602 /*_WIN32_WINNT_WIN8*/) || \
  72. (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/))
  73. # define USE_MS_CNGAPI
  74. # else
  75. # define USE_MS_CRYPTOAPI
  76. # endif
  77. #endif
  78. // Begin OS features, like init priorities and random numbers
  79. #ifndef NO_OS_DEPENDENCE
  80. // CRYPTOPP_INIT_PRIORITY attempts to manage initialization of C++ static objects.
  81. // Under GCC, the library uses init_priority attribute in the range
  82. // [CRYPTOPP_INIT_PRIORITY, CRYPTOPP_INIT_PRIORITY+100]. Under Windows,
  83. // CRYPTOPP_INIT_PRIORITY enlists "#pragma init_seg(lib)". The platforms
  84. // with gaps are Apple and Sun because they require linker scripts. Apple and
  85. // Sun will use the library's Singletons to initialize and acquire resources.
  86. // Also see http://cryptopp.com/wiki/Static_Initialization_Order_Fiasco
  87. #ifndef CRYPTOPP_INIT_PRIORITY
  88. # define CRYPTOPP_INIT_PRIORITY 250
  89. #endif
  90. // CRYPTOPP_USER_PRIORITY is for other libraries and user code that is using Crypto++
  91. // and managing C++ static object creation. It is guaranteed not to conflict with
  92. // values used by (or would be used by) the Crypto++ library.
  93. #ifndef CRYPTOPP_USER_PRIORITY
  94. # define CRYPTOPP_USER_PRIORITY (CRYPTOPP_INIT_PRIORITY+101)
  95. #endif
  96. // Most platforms allow us to specify when to create C++ objects. Apple and Sun do not.
  97. #if (CRYPTOPP_INIT_PRIORITY > 0) && !(defined(NO_OS_DEPENDENCE) || defined(__APPLE__) || defined(__sun__))
  98. # if (CRYPTOPP_GCC_VERSION >= 30000) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 800)
  99. # define HAVE_GCC_INIT_PRIORITY 1
  100. # elif (CRYPTOPP_MSC_VERSION >= 1310)
  101. # define HAVE_MSC_INIT_PRIORITY 1
  102. # elif defined(__xlc__) || defined(__xlC__) || defined(__ibmxl__)
  103. # define HAVE_XLC_INIT_PRIORITY 1
  104. # endif
  105. #endif // CRYPTOPP_INIT_PRIORITY, NO_OS_DEPENDENCE, Apple, Sun
  106. #if defined(CRYPTOPP_WIN32_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE)
  107. # define HIGHRES_TIMER_AVAILABLE
  108. #endif
  109. #ifdef CRYPTOPP_WIN32_AVAILABLE
  110. # if !defined(WINAPI_FAMILY)
  111. # define THREAD_TIMER_AVAILABLE
  112. # elif defined(WINAPI_FAMILY)
  113. # if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
  114. # define THREAD_TIMER_AVAILABLE
  115. # endif
  116. # endif
  117. #endif
  118. #if defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
  119. # define NONBLOCKING_RNG_AVAILABLE
  120. # define BLOCKING_RNG_AVAILABLE
  121. # define OS_RNG_AVAILABLE
  122. #endif
  123. // Cygwin/Newlib requires _XOPEN_SOURCE=600
  124. #if defined(CRYPTOPP_UNIX_AVAILABLE)
  125. # define UNIX_SIGNALS_AVAILABLE 1
  126. #endif
  127. #ifdef CRYPTOPP_WIN32_AVAILABLE
  128. # if !defined(WINAPI_FAMILY)
  129. # define NONBLOCKING_RNG_AVAILABLE
  130. # define OS_RNG_AVAILABLE
  131. # elif defined(WINAPI_FAMILY)
  132. # if (WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
  133. # define NONBLOCKING_RNG_AVAILABLE
  134. # define OS_RNG_AVAILABLE
  135. # elif !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
  136. # if ((WINVER >= 0x0A00 /*_WIN32_WINNT_WIN10*/) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/))
  137. # define NONBLOCKING_RNG_AVAILABLE
  138. # define OS_RNG_AVAILABLE
  139. # endif
  140. # endif
  141. # endif
  142. #endif
  143. #endif // NO_OS_DEPENDENCE
  144. #endif // CRYPTOPP_CONFIG_OS_H