• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright 2020 Andrey Semashev
2 
3 //  Distributed under the Boost Software License, Version 1.0.
4 //  See http://www.boost.org/LICENSE_1_0.txt
5 
6 //  See library home page at http://www.boost.org/libs/filesystem
7 
8 // Include Boost.Predef first so that windows.h is guaranteed to be not included
9 #include <boost/predef/os/windows.h>
10 #include <boost/predef/os/cygwin.h>
11 #if !BOOST_OS_WINDOWS && !BOOST_OS_CYGWIN
12 #error "This config test is for Windows only"
13 #endif
14 
15 #include <boost/winapi/config.hpp>
16 #include <boost/predef/platform.h>
17 #if !(BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 && BOOST_WINAPI_PARTITION_APP_SYSTEM)
18 #error "No BCrypt API"
19 #endif
20 
21 #include <cstddef>
22 #include <boost/winapi/basic_types.hpp>
23 #include <boost/winapi/bcrypt.hpp>
24 
main()25 int main()
26 {
27   unsigned char buf[16] = {};
28   boost::winapi::BCRYPT_ALG_HANDLE_ handle;
29   boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0);
30   status = boost::winapi::BCryptGenRandom(handle, reinterpret_cast<boost::winapi::PUCHAR_>(static_cast<unsigned char*>(buf)), static_cast<boost::winapi::ULONG_>(sizeof(buf)), 0);
31   boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
32 }
33