mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
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:
39
3rdparty/mbedtls/winxp_entropy.c
vendored
Normal file
39
3rdparty/mbedtls/winxp_entropy.c
vendored
Normal 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;
|
||||||
|
}
|
||||||
3
3rdparty/mbedtls/wscript
vendored
3
3rdparty/mbedtls/wscript
vendored
@@ -30,6 +30,9 @@ def build(bld):
|
|||||||
'mbedtls/tf-psa-crypto/drivers/builtin/src/*.c',
|
'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 = [
|
defines = [
|
||||||
'MBEDTLS_USER_CONFIG_FILE="xash_mbedtls_config.h"',
|
'MBEDTLS_USER_CONFIG_FILE="xash_mbedtls_config.h"',
|
||||||
'TF_PSA_CRYPTO_USER_CONFIG_FILE="xash_psa_config.h"',
|
'TF_PSA_CRYPTO_USER_CONFIG_FILE="xash_psa_config.h"',
|
||||||
|
|||||||
7
3rdparty/mbedtls/xash_psa_config.h
vendored
7
3rdparty/mbedtls/xash_psa_config.h
vendored
@@ -1,6 +1,13 @@
|
|||||||
#ifndef XASH_PSA_CONFIG_H
|
#ifndef XASH_PSA_CONFIG_H
|
||||||
#define 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_FS_IO
|
||||||
#undef MBEDTLS_PSA_ITS_FILE_C
|
#undef MBEDTLS_PSA_ITS_FILE_C
|
||||||
#undef MBEDTLS_PSA_CRYPTO_STORAGE_C
|
#undef MBEDTLS_PSA_CRYPTO_STORAGE_C
|
||||||
|
|||||||
@@ -191,6 +191,8 @@ def build(bld):
|
|||||||
|
|
||||||
if bld.env.DEST_OS == 'win32':
|
if bld.env.DEST_OS == 'win32':
|
||||||
libs += ['USER32', 'SHELL32', 'GDI32', 'ADVAPI32', 'DBGHELP', 'PSAPI', 'WS2_32']
|
libs += ['USER32', 'SHELL32', 'GDI32', 'ADVAPI32', 'DBGHELP', 'PSAPI', 'WS2_32']
|
||||||
|
if bld.env.DEST_SIZEOF_VOID_P > 4:
|
||||||
|
libs += ['BCRYPT']
|
||||||
elif bld.env.DEST_OS == 'nswitch':
|
elif bld.env.DEST_OS == 'nswitch':
|
||||||
libs += ['SOLDER']
|
libs += ['SOLDER']
|
||||||
# HACK: link in the entirety of libstdc++ so that dynamic libs could use all of it without manual exporting
|
# HACK: link in the entirety of libstdc++ so that dynamic libs could use all of it without manual exporting
|
||||||
|
|||||||
2
wscript
2
wscript
@@ -471,7 +471,7 @@ def configure(conf):
|
|||||||
# Don't check them more than once, to save time
|
# Don't check them more than once, to save time
|
||||||
# Usually, they are always available
|
# Usually, they are always available
|
||||||
# but we need them in uselib
|
# but we need them in uselib
|
||||||
a = [ 'user32', 'shell32', 'gdi32', 'advapi32', 'dbghelp', 'psapi', 'ws2_32' ]
|
a = [ 'user32', 'shell32', 'gdi32', 'advapi32', 'dbghelp', 'psapi', 'ws2_32', 'bcrypt' ]
|
||||||
if conf.env.COMPILER_CC == 'msvc':
|
if conf.env.COMPILER_CC == 'msvc':
|
||||||
for i in a:
|
for i in a:
|
||||||
conf.start_msg('Checking for MSVC library')
|
conf.start_msg('Checking for MSVC library')
|
||||||
|
|||||||
Reference in New Issue
Block a user