From: Felix Fietkau Date: Tue, 26 Mar 2024 18:40:51 +0000 (+0100) Subject: mbedtls: fix build on non-linux systems X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=7621339d7694abef5da5e5353ac440f2d39dcecb;p=project%2Fustream-ssl.git mbedtls: fix build on non-linux systems Deal with missing getrandom. Comment out linker flag. Signed-off-by: Felix Fietkau --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f4dca0d..2e591ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,9 @@ ENDIF() 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) diff --git a/ustream-mbedtls.c b/ustream-mbedtls.c index 1c70cac..18ffe06 100644 --- a/ustream-mbedtls.c +++ b/ustream-mbedtls.c @@ -67,11 +67,17 @@ __hidden void ustream_set_io(struct ustream_ssl_ctx *ctx, void *ssl, struct ustr 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; }