From 325ce093f9e80900e560fd1cadecad3c63408d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 22 Feb 2016 10:33:34 +0100 Subject: [PATCH] Give better error messages for semi-portable parts Previously it was failing with errors about headers not found, which is suboptimal in terms of clarity. Now give a clean error with pointer to the documentation. Do the checks in the .c files rather than check_config.h as it keeps them closer to the platform-specific implementations. --- include/mbedtls/config.h | 17 ++++++++++++++--- library/entropy_poll.c | 6 ++++++ library/net.c | 5 +++++ library/timing.c | 5 +++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h index d1db0d825..c69ba1bcb 100644 --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h @@ -1897,11 +1897,15 @@ /** * \def MBEDTLS_NET_C * - * Enable the TCP/IP networking routines. + * Enable the TCP and UDP over IPv6/IPv4 networking routines. + * + * \note This module only works on Unix (including Linux, BSD and OS X) and + * Windows. For other platforms, you'll want to disable it, and write your + * own networking callbacks to be passed to \c mbedtls_ssl_set_bio(). * * Module: library/net.c * - * This module provides TCP/IP networking routines. + * This module provides networking routines. */ #define MBEDTLS_NET_C @@ -2264,7 +2268,14 @@ /** * \def MBEDTLS_TIMING_C * - * Enable the portable timing interface. + * Enable the semi-portable timing interface. + * + * \note The provided implementation only works on Unix (including Linux, BSD + * and OS X) and Windows. On other platforms, you can either disable that + * module and provide your own implementations of the callbacks needed by + * \c mbedtls_ssl_set_timer_cb() for DTLS, or leave it enabled and provide + * your own implementation of the whole module by setting + * \c MBEDTLS_TIMING_ALT in the current file. * * Module: library/timing.c * Caller: library/havege.c diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 25a27bef3..972ad2aea 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -39,6 +39,12 @@ #endif #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) + +#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \ + !defined(__APPLE__) && !defined(_WIN32) +#error "Platform entropy sources only work on Unix and Windows, see MBEDTLS_NO_PLATFORM_ENTROPY in config.h" +#endif + #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #if !defined(_WIN32_WINNT) diff --git a/library/net.c b/library/net.c index a77268c55..3b78b6b15 100644 --- a/library/net.c +++ b/library/net.c @@ -27,6 +27,11 @@ #if defined(MBEDTLS_NET_C) +#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \ + !defined(__APPLE__) && !defined(_WIN32) +#error "This module only works on Unix and Windows, see MBEDTLS_NET_C in config.h" +#endif + #include "mbedtls/net.h" #include diff --git a/library/timing.c b/library/timing.c index 5d8b25b99..a7c7ff027 100644 --- a/library/timing.c +++ b/library/timing.c @@ -38,6 +38,11 @@ #if !defined(MBEDTLS_TIMING_ALT) +#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \ + !defined(__APPLE__) && !defined(_WIN32) +#error "This module only works on Unix and Windows, see MBEDTLS_TIMING_C in config.h" +#endif + #ifndef asm #define asm __asm #endif