51 #pragma comment(lib, "bcrypt.lib") // link against the bcrypt library
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
55 #include <openssl/sha.h>
56 #pragma GCC diagnostic pop
59 #include <pvsutil/Assert.h>
60 #include <pvsutil/Logger.h>
62 #include "SkelCL/detail/Util.h"
67 BCRYPT_ALG_HANDLE createAlgoritmProvider() {
68 BCRYPT_ALG_HANDLE alg;
69 auto result = ::BCryptOpenAlgorithmProvider(
71 BCRYPT_SHA1_ALGORITHM,
79 std::vector<BYTE> createHashBuffer(BCRYPT_ALG_HANDLE alg) {
83 NTSTATUS result = ::BCryptGetProperty(
86 reinterpret_cast<BYTE *>(&propertyValue),
87 sizeof(propertyValue),
92 return std::vector<BYTE>(propertyValue);
95 BCRYPT_HASH_HANDLE createHash(BCRYPT_ALG_HANDLE alg,
96 std::vector<BYTE>& hashBuffer) {
97 BCRYPT_HASH_HANDLE hash;
98 auto result = ::BCryptCreateHash(
112 void SHA1(
const std::string&
string, BYTE* buffer) {
113 auto alg = createAlgoritmProvider();
115 auto hashBuffer = createHashBuffer(alg);
117 auto hash = createHash(alg, hashBuffer);
119 const void* data =
static_cast<const void*
>(
string.data());
120 auto result = ::BCryptHashData(
122 static_cast<UCHAR *>(const_cast<void *>(data)),
128 result = ::BCryptFinishHash(
136 ::BCryptDestroyHash(hash);
137 ::BCryptCloseAlgorithmProvider(alg, 0);
149 std::string envVarValue(
const std::string& envVar)
151 char* envValue = std::getenv(envVar.c_str());
152 if (envValue != NULL) {
159 std::string hash(
const std::string&
string)
165 unsigned char raw[20];
166 const char* c_str =
string.c_str();
167 #pragma GCC diagnostic push
168 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
169 SHA1(reinterpret_cast<const unsigned char*>(c_str),
string.length(), raw);
170 #pragma GCC diagnostic pop
172 std::ostringstream buffer;
173 for (
int i = 0; i < 20; ++i) {
177 <<
static_cast<int>( raw[i] );
182 size_t devideAndRoundUp(
size_t i,
size_t j)
191 size_t devideAndAlign(
size_t i,
size_t j,
size_t a)
202 size_t ceilToMultipleOf(
size_t i,
size_t j)
204 if (i == 0)
return j;
212 bool isPowerOfTwo(
size_t n)
214 return ((n & (n - 1)) == 0);
220 frexp(static_cast<float>(n), &exp);
221 return 1 << (exp - 1);
227 frexp(static_cast<float>(n), &exp);