Browse Source

Fix ecc_platform_specific.c: check Windows first, fix typo (| to ||), add stdint.h

nodeinfo-routing-update
Evgeny 8 months ago
parent
commit
8c84bda1a4
  1. 51
      tinycrypt/lib/source/ecc_platform_specific.c

51
tinycrypt/lib/source/ecc_platform_specific.c

@ -55,9 +55,33 @@
* uECC_platform_specific.c -- Implementation of platform specific functions
*/
#include <stdint.h>
#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;
}
#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 <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) {

Loading…
Cancel
Save