Skip to content

Commit

Permalink
Fix Mbed TLS compilation on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Jan 12, 2025
1 parent caf4a4f commit ef8a7a1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/mbedtls/library/entropy_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@
#include <bcrypt.h>
#include <intsafe.h>

#if defined(__MINGW32__)
// MINGW
int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,
size_t *olen)
{
HCRYPTPROV provider;
((void) data);
*olen = 0;

if (CryptAcquireContext(&provider, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE ) {
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
}

if (CryptGenRandom(provider, (DWORD) len, output) == FALSE ) {
CryptReleaseContext( provider, 0 );
return(MBEDTLS_ERR_ENTROPY_SOURCE_FAILED);
}

CryptReleaseContext(provider, 0);
*olen = len;

return 0;
}
#else
int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,
size_t *olen)
{
Expand All @@ -68,6 +93,7 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,

return 0;
}
#endif
#else /* _WIN32 && !EFIX64 && !EFI32 */

/*
Expand Down

0 comments on commit ef8a7a1

Please sign in to comment.