8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 22:43:03 +01:00

Fix #8187 - Performance regression in generating of UUID values after introducing GUID-v7 (#8188)

Replacing deprecated win32 crypto functions.
This commit is contained in:
Adriano dos Santos Fernandes 2024-08-01 07:40:42 -03:00 committed by GitHub
parent a62ac95ee5
commit 43e4088685
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 29 deletions

View File

@ -34,7 +34,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile> <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<AdditionalDependencies>psapi.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>bcrypt.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>../../../extern/re2/builds/$(PlatformName)/$(Configuration)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>../../../extern/re2/builds/$(PlatformName)/$(Configuration)</AdditionalLibraryDirectories>
</Link> </Link>
<Bscmake> <Bscmake>

View File

@ -32,7 +32,7 @@
#endif #endif
#include <windows.h> #include <windows.h>
#include <wincrypt.h> #include <bcrypt.h>
#include <objbase.h> #include <objbase.h>
#include <stdio.h> #include <stdio.h>
@ -45,33 +45,8 @@ namespace Firebird {
void GenerateRandomBytes(void* buffer, FB_SIZE_T size) void GenerateRandomBytes(void* buffer, FB_SIZE_T size)
{ {
HCRYPTPROV hProv; if (BCryptGenRandom(nullptr, static_cast<UCHAR*>(buffer), size, BCRYPT_USE_SYSTEM_PREFERRED_RNG) != S_OK)
Firebird::system_call_failed::raise("BCryptGenRandom");
// Acquire crypto-provider context handle.
if (! CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
if (GetLastError() == NTE_BAD_KEYSET)
{
// A common cause of this error is that the key container does not exist.
// To create a key container, call CryptAcquireContext
// using the CRYPT_NEWKEYSET flag.
if (! CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET))
{
Firebird::system_call_failed::raise("CryptAcquireContext");
}
}
else
{
Firebird::system_call_failed::raise("CryptAcquireContext");
}
}
if (! CryptGenRandom(hProv, size, static_cast<UCHAR*>(buffer)))
{
Firebird::system_call_failed::raise("CryptGenRandom");
}
CryptReleaseContext(hProv, 0);
} }
void GenerateGuid(UUID* guid) void GenerateGuid(UUID* guid)