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 platform_config.hpp first so that windows.h is guaranteed to be not included
9 #include "platform_config.hpp"
10 
11 #include <boost/predef/os/windows.h>
12 #include <boost/predef/os/cygwin.h>
13 #if !BOOST_OS_WINDOWS && !BOOST_OS_CYGWIN
14 #error "This config test is for Windows only"
15 #endif
16 
17 #include <boost/winapi/config.hpp>
18 #include <boost/predef/platform.h>
19 #if !(BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 && BOOST_WINAPI_PARTITION_APP_SYSTEM)
20 #error "No BCrypt API"
21 #endif
22 
23 #include <cstddef>
24 #include <boost/winapi/basic_types.hpp>
25 #include <boost/winapi/bcrypt.hpp>
26 
main()27 int main()
28 {
29   unsigned char buf[16] = {};
30   boost::winapi::BCRYPT_ALG_HANDLE_ handle;
31   boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0);
32   status = boost::winapi::BCryptGenRandom(handle, reinterpret_cast<boost::winapi::PUCHAR_>(static_cast<unsigned char*>(buf)), static_cast<boost::winapi::ULONG_>(sizeof(buf)), 0);
33   boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
34 }
35