diff options
| author | Felix Fietkau | 2024-03-26 18:40:51 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2024-03-26 18:40:58 +0000 |
| commit | 7621339d7694abef5da5e5353ac440f2d39dcecb (patch) | |
| tree | f4441f116666dc554c67a7396949157aa573b0f7 | |
| parent | 263b9a97cf7e1e2467319c23832b705fc01190b5 (diff) | |
mbedtls: fix build on non-linux systems
Deal with missing getrandom. Comment out linker flag.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | ustream-mbedtls.c | 12 |
2 files changed, 12 insertions, 4 deletions
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; } |