Fix ecc_platform_specific.c: check Windows first, fix typo (| to ||), add stdint.h
This commit is contained in:
1 parent
560e121d4c
commit
8c84bda1a4
1 file changed
+26
-25
@@ -55,9 +55,33 @@
|
||||
* uECC_platform_specific.c -- Implementation of platform specific functions
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(unix) || defined(__linux__) || defined(__unix__) || \
|
||||
defined(__unix) | (defined(__APPLE__) && defined(__MACH__)) || \
|
||||
#if 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;
|
||||
}
|
||||
|
||||
#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 <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) {
|
||||
|
||||
Reference in new issue
Block a user