From d565cb612fec7c9c3aa1b7eb1999e7ed36a46eec Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Sat, 6 Jul 2024 15:58:11 +0000 Subject: [PATCH] fix: workaround missing SHA256 macros in MinGW-w64 (#14437) --- google/cloud/internal/sha256_hash.cc | 5 +++++ google/cloud/internal/sha256_hmac.cc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/google/cloud/internal/sha256_hash.cc b/google/cloud/internal/sha256_hash.cc index 1485c7ce45912..7b1bb32b9d4b6 100644 --- a/google/cloud/internal/sha256_hash.cc +++ b/google/cloud/internal/sha256_hash.cc @@ -30,6 +30,11 @@ namespace { Sha256Type Sha256Hash(void const* data, std::size_t count) { Sha256Type hash; #ifdef _WIN32 +// Workaround missing macros in MinGW-w64: +// https://github.com/mingw-w64/mingw-w64/issues/49 +#ifndef BCRYPT_SHA256_ALG_HANDLE +#define BCRYPT_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000041) +#endif BCryptHash(BCRYPT_SHA256_ALG_HANDLE, nullptr, 0, static_cast(const_cast(data)), static_cast(count), hash.data(), diff --git a/google/cloud/internal/sha256_hmac.cc b/google/cloud/internal/sha256_hmac.cc index 015649fa7465f..1dc968c54681f 100644 --- a/google/cloud/internal/sha256_hmac.cc +++ b/google/cloud/internal/sha256_hmac.cc @@ -38,6 +38,11 @@ Sha256Type Sha256HmacImpl(absl::Span key, unsigned char const* data, std::size_t count) { Sha256Type hash; #ifdef _WIN32 +// Workaround missing macros in MinGW-w64: +// https://github.com/mingw-w64/mingw-w64/issues/49 +#ifndef BCRYPT_HMAC_SHA256_ALG_HANDLE +#define BCRYPT_HMAC_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000000b1) +#endif BCryptHash(BCRYPT_HMAC_SHA256_ALG_HANDLE, reinterpret_cast(const_cast(key.data())), static_cast(key.size()), const_cast(data),