wscript: enable bcrypt on Windows, add entropy generator that avoids usage of bcrypt for our 32-bit builds, allowing them to run on Windows XP

This commit is contained in:
Alibek Omarov
2026-06-07 06:30:01 +05:00
parent 85e5f032d8
commit e31c893852
5 changed files with 52 additions and 1 deletions

39
3rdparty/mbedtls/winxp_entropy.c vendored Normal file
View File

@@ -0,0 +1,39 @@
/*
winxp_entropy.c - platform entropy override for mbedTLS on 32-bit Windows
Copyright (C) 2026 Xash3D FWGS contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <windows.h>
#include <wincrypt.h>
#include "mbedtls/platform.h"
#include "psa/crypto.h"
int mbedtls_platform_get_entropy( psa_driver_get_entropy_flags_t flags, size_t *estimate_bits, unsigned char *output, size_t output_size )
{
if( flags != 0 )
return PSA_ERROR_NOT_SUPPORTED;
HCRYPTPROV prov;
if( !CryptAcquireContextW( &prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT ))
return PSA_ERROR_INSUFFICIENT_ENTROPY;
if( !CryptGenRandom( prov, output_size, output ))
{
CryptReleaseContext( prov, 0 );
return PSA_ERROR_INSUFFICIENT_ENTROPY;
}
CryptReleaseContext( prov, 0 );
*estimate_bits = 8 * output_size;
return 0;
}

View File

@@ -30,6 +30,9 @@ def build(bld):
'mbedtls/tf-psa-crypto/drivers/builtin/src/*.c',
])
if bld.env.DEST_OS == 'win32' and bld.env.DEST_SIZEOF_VOID_P == 4:
sources += ['winxp_entropy.c']
defines = [
'MBEDTLS_USER_CONFIG_FILE="xash_mbedtls_config.h"',
'TF_PSA_CRYPTO_USER_CONFIG_FILE="xash_psa_config.h"',

View File

@@ -1,6 +1,13 @@
#ifndef XASH_PSA_CONFIG_H
#define XASH_PSA_CONFIG_H
#if defined( _WIN32 ) && !defined( _WIN64 )
/* Upstream pulls BCryptGenRandom (Vista+); we still target XP on 32-bit.
winxp_entropy.c provides mbedtls_platform_get_entropy() via advapi32. */
#undef MBEDTLS_PSA_BUILTIN_GET_ENTROPY
#define MBEDTLS_PSA_DRIVER_GET_ENTROPY
#endif
#undef MBEDTLS_FS_IO
#undef MBEDTLS_PSA_ITS_FILE_C
#undef MBEDTLS_PSA_CRYPTO_STORAGE_C