crypt.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2014 Antony Polukhin
  3. * Copyright 2015 Andrey Semashev
  4. *
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * See http://www.boost.org/LICENSE_1_0.txt
  7. */
  8. #ifndef BOOST_WINAPI_CRYPT_HPP_INCLUDED_
  9. #define BOOST_WINAPI_CRYPT_HPP_INCLUDED_
  10. #include <boost/winapi/basic_types.hpp>
  11. #if defined( BOOST_USE_WINDOWS_H )
  12. // This header is not always included as part of windows.h
  13. #include <wincrypt.h>
  14. #endif
  15. #include <boost/winapi/detail/header.hpp>
  16. #ifdef BOOST_HAS_PRAGMA_ONCE
  17. #pragma once
  18. #endif
  19. #if !defined( BOOST_USE_WINDOWS_H )
  20. namespace boost { namespace winapi {
  21. typedef ULONG_PTR_ HCRYPTPROV_;
  22. }}
  23. extern "C" {
  24. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  25. #if !defined( BOOST_NO_ANSI_APIS )
  26. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  27. CryptEnumProvidersA(
  28. boost::winapi::DWORD_ dwIndex,
  29. boost::winapi::DWORD_ *pdwReserved,
  30. boost::winapi::DWORD_ dwFlags,
  31. boost::winapi::DWORD_ *pdwProvType,
  32. boost::winapi::LPSTR_ szProvName,
  33. boost::winapi::DWORD_ *pcbProvName);
  34. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  35. CryptAcquireContextA(
  36. boost::winapi::HCRYPTPROV_ *phProv,
  37. boost::winapi::LPCSTR_ pszContainer,
  38. boost::winapi::LPCSTR_ pszProvider,
  39. boost::winapi::DWORD_ dwProvType,
  40. boost::winapi::DWORD_ dwFlags);
  41. #endif // !defined( BOOST_NO_ANSI_APIS )
  42. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  43. CryptEnumProvidersW(
  44. boost::winapi::DWORD_ dwIndex,
  45. boost::winapi::DWORD_ *pdwReserved,
  46. boost::winapi::DWORD_ dwFlags,
  47. boost::winapi::DWORD_ *pdwProvType,
  48. boost::winapi::LPWSTR_ szProvName,
  49. boost::winapi::DWORD_ *pcbProvName);
  50. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  51. CryptAcquireContextW(
  52. boost::winapi::HCRYPTPROV_ *phProv,
  53. boost::winapi::LPCWSTR_ szContainer,
  54. boost::winapi::LPCWSTR_ szProvider,
  55. boost::winapi::DWORD_ dwProvType,
  56. boost::winapi::DWORD_ dwFlags);
  57. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  58. CryptGenRandom(
  59. boost::winapi::HCRYPTPROV_ hProv,
  60. boost::winapi::DWORD_ dwLen,
  61. boost::winapi::BYTE_ *pbBuffer);
  62. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  63. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  64. #if defined(_MSC_VER) && (_MSC_VER+0) >= 1500 && (_MSC_VER+0) < 1900 && BOOST_USE_NTDDI_VERSION < BOOST_WINAPI_NTDDI_WINXP
  65. // Standalone MS Windows SDK 6.0A and later until 10.0 provide a different declaration of CryptReleaseContext for Windows 2000 and older.
  66. // This is not the case for (a) MinGW and MinGW-w64, (b) MSVC 7.1 and 8, which are shipped with their own Windows SDK,
  67. // and (c) MSVC 14.0 and later, which are used with Windows SDK 10.
  68. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  69. CryptReleaseContext(
  70. boost::winapi::HCRYPTPROV_ hProv,
  71. boost::winapi::ULONG_PTR_ dwFlags);
  72. #else
  73. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  74. CryptReleaseContext(
  75. boost::winapi::HCRYPTPROV_ hProv,
  76. boost::winapi::DWORD_ dwFlags);
  77. #endif
  78. #endif // BOOST_WINAPI_PARTITION_APP_SYSTEM
  79. }
  80. #endif // !defined( BOOST_USE_WINDOWS_H )
  81. namespace boost {
  82. namespace winapi {
  83. #if defined( BOOST_USE_WINDOWS_H )
  84. typedef ::HCRYPTPROV HCRYPTPROV_;
  85. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  86. BOOST_CONSTEXPR_OR_CONST DWORD_ PROV_RSA_FULL_ = PROV_RSA_FULL;
  87. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_VERIFYCONTEXT_ = CRYPT_VERIFYCONTEXT;
  88. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_NEWKEYSET_ = CRYPT_NEWKEYSET;
  89. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_DELETEKEYSET_ = CRYPT_DELETEKEYSET;
  90. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_MACHINE_KEYSET_ = CRYPT_MACHINE_KEYSET;
  91. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_SILENT_ = CRYPT_SILENT;
  92. #endif
  93. #else
  94. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  95. BOOST_CONSTEXPR_OR_CONST DWORD_ PROV_RSA_FULL_ = 1;
  96. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_VERIFYCONTEXT_ = 0xF0000000;
  97. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_NEWKEYSET_ = 8;
  98. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_DELETEKEYSET_ = 16;
  99. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_MACHINE_KEYSET_ = 32;
  100. BOOST_CONSTEXPR_OR_CONST DWORD_ CRYPT_SILENT_ = 64;
  101. #endif
  102. #endif
  103. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  104. #if !defined( BOOST_NO_ANSI_APIS )
  105. using ::CryptEnumProvidersA;
  106. using ::CryptAcquireContextA;
  107. #endif
  108. using ::CryptEnumProvidersW;
  109. using ::CryptAcquireContextW;
  110. using ::CryptGenRandom;
  111. #if !defined( BOOST_NO_ANSI_APIS )
  112. BOOST_FORCEINLINE BOOL_ crypt_enum_providers(
  113. DWORD_ dwIndex,
  114. DWORD_ *pdwReserved,
  115. DWORD_ dwFlags,
  116. DWORD_ *pdwProvType,
  117. LPSTR_ szProvName,
  118. DWORD_ *pcbProvName)
  119. {
  120. return ::CryptEnumProvidersA(dwIndex, pdwReserved, dwFlags, pdwProvType, szProvName, pcbProvName);
  121. }
  122. BOOST_FORCEINLINE BOOL_ crypt_acquire_context(
  123. HCRYPTPROV_ *phProv,
  124. LPCSTR_ pszContainer,
  125. LPCSTR_ pszProvider,
  126. DWORD_ dwProvType,
  127. DWORD_ dwFlags)
  128. {
  129. return ::CryptAcquireContextA(phProv, pszContainer, pszProvider, dwProvType, dwFlags);
  130. }
  131. #endif
  132. BOOST_FORCEINLINE BOOL_ crypt_enum_providers(
  133. DWORD_ dwIndex,
  134. DWORD_ *pdwReserved,
  135. DWORD_ dwFlags,
  136. DWORD_ *pdwProvType,
  137. LPWSTR_ szProvName,
  138. DWORD_ *pcbProvName)
  139. {
  140. return ::CryptEnumProvidersW(dwIndex, pdwReserved, dwFlags, pdwProvType, szProvName, pcbProvName);
  141. }
  142. BOOST_FORCEINLINE BOOL_ crypt_acquire_context(
  143. HCRYPTPROV_ *phProv,
  144. LPCWSTR_ szContainer,
  145. LPCWSTR_ szProvider,
  146. DWORD_ dwProvType,
  147. DWORD_ dwFlags)
  148. {
  149. return ::CryptAcquireContextW(phProv, szContainer, szProvider, dwProvType, dwFlags);
  150. }
  151. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  152. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  153. BOOST_FORCEINLINE BOOL_ CryptReleaseContext(HCRYPTPROV_ hProv, DWORD_ dwFlags)
  154. {
  155. return ::CryptReleaseContext(hProv, dwFlags);
  156. }
  157. #endif
  158. }
  159. }
  160. #include <boost/winapi/detail/footer.hpp>
  161. #endif // BOOST_WINAPI_CRYPT_HPP_INCLUDED_