From 8c84bda1a438987a23527692744c8a1f68c64043 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 15 Feb 2026 04:47:53 +0300 Subject: [PATCH] Fix ecc_platform_specific.c: check Windows first, fix typo (| to ||), add stdint.h --- tinycrypt/lib/source/ecc_platform_specific.c | 51 ++++++++++---------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/tinycrypt/lib/source/ecc_platform_specific.c b/tinycrypt/lib/source/ecc_platform_specific.c index 97d2d201..93b7edbf 100644 --- a/tinycrypt/lib/source/ecc_platform_specific.c +++ b/tinycrypt/lib/source/ecc_platform_specific.c @@ -55,9 +55,33 @@ * uECC_platform_specific.c -- Implementation of platform specific functions */ +#include + +#if defined(_WIN32) +/* Windows implementation using CryptGenRandom */ +#include +#include + +int default_CSPRNG(uint8_t *dest, unsigned int size) { + /* input sanity check: */ + if (dest == (uint8_t *) 0 || (size <= 0)) + return 0; + + HCRYPTPROV hProvider = 0; + + if (!CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { + return 0; + } + + BOOL result = CryptGenRandom(hProvider, size, dest); + + CryptReleaseContext(hProvider, 0); + + return result ? 1 : 0; +} -#if defined(unix) || defined(__linux__) || defined(__unix__) || \ - defined(__unix) | (defined(__APPLE__) && defined(__MACH__)) || \ +#elif defined(unix) || defined(__linux__) || defined(__unix__) || \ + defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) || \ defined(uECC_POSIX) /* Some POSIX-like system with /dev/urandom or /dev/random. */ @@ -101,29 +125,6 @@ int default_CSPRNG(uint8_t *dest, unsigned int size) { return 1; } -#elif defined(_WIN32) -/* Windows implementation using CryptGenRandom */ -#include -#include - -int default_CSPRNG(uint8_t *dest, unsigned int size) { - /* input sanity check: */ - if (dest == (uint8_t *) 0 || (size <= 0)) - return 0; - - HCRYPTPROV hProvider = 0; - - if (!CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { - return 0; - } - - BOOL result = CryptGenRandom(hProvider, size, dest); - - CryptReleaseContext(hProvider, 0); - - return result ? 1 : 0; -} - #else /* No CSPRNG available - return error */ int default_CSPRNG(uint8_t *dest, unsigned int size) {