Fix Windows build: add default_CSPRNG and improve build.sh error handling
- Add Windows implementation of default_CSPRNG() using CryptGenRandom - Add fallback stub for platforms without CSPRNG support - Fix build.sh to properly detect build failures (use PIPESTATUS) - Show proper error message instead of "Build completed successfully" on failure
This commit is contained in:
1 parent
27f2edca40
commit
f5faa7c834
16 files changed
+83
-252
No files matched your search
@@ -101,5 +101,36 @@ int default_CSPRNG(uint8_t *dest, unsigned int size) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
/* Windows implementation using CryptGenRandom */
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
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) {
|
||||
(void)dest;
|
||||
(void)size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* platform */
|
||||
|
||||
Reference in new issue
Block a user