ADD_DEFINITIONS(-Wno-unused-parameter -Wmissing-declarations)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
-SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
+IF (NOT APPLE)
+ SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
+ENDIF()
IF(MBEDTLS)
ADD_DEFINITIONS(-DHAVE_MBEDTLS)
static int _random(void *ctx, unsigned char *out, size_t len)
{
- ssize_t ret;
+#ifdef linux
+ if (getrandom(out, len, 0) != (ssize_t) len)
+ return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
+#else
+ static FILE *f;
- ret = getrandom(out, len, 0);
- if (ret < 0 || (size_t)ret != len)
+ if (!f)
+ f = fopen("/dev/urandom", "r");
+ if (fread(out, len, 1, f) != 1)
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
+#endif
return 0;
}