diff options
Diffstat (limited to 'thirdparty/mbedtls/include')
19 files changed, 271 insertions, 38 deletions
diff --git a/thirdparty/mbedtls/include/mbedtls/aria.h b/thirdparty/mbedtls/include/mbedtls/aria.h index 13763d4200..20f43f2256 100644 --- a/thirdparty/mbedtls/include/mbedtls/aria.h +++ b/thirdparty/mbedtls/include/mbedtls/aria.h @@ -88,14 +88,14 @@  /* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */  #define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED      -0x0058  /**< ARIA hardware accelerator failed. */ -#if !defined(MBEDTLS_ARIA_ALT) -// Regular implementation -// -  #ifdef __cplusplus  extern "C" {  #endif +#if !defined(MBEDTLS_ARIA_ALT) +// Regular implementation +// +  /**   * \brief The ARIA context-type definition.   */ diff --git a/thirdparty/mbedtls/include/mbedtls/bignum.h b/thirdparty/mbedtls/include/mbedtls/bignum.h index 4bb9fa3d43..4d04b336e7 100644 --- a/thirdparty/mbedtls/include/mbedtls/bignum.h +++ b/thirdparty/mbedtls/include/mbedtls/bignum.h @@ -88,12 +88,12 @@   * Maximum window size used for modular exponentiation. Default: 6   * Minimum value: 1. Maximum value: 6.   * - * Result is an array of ( 2 << MBEDTLS_MPI_WINDOW_SIZE ) MPIs used + * Result is an array of ( 2 ** MBEDTLS_MPI_WINDOW_SIZE ) MPIs used   * for the sliding window calculation. (So 64 by default)   *   * Reduction in size, reduces speed.   */ -#define MBEDTLS_MPI_WINDOW_SIZE                           6        /**< Maximum windows size used. */ +#define MBEDTLS_MPI_WINDOW_SIZE                           6        /**< Maximum window size used. */  #endif /* !MBEDTLS_MPI_WINDOW_SIZE */  #if !defined(MBEDTLS_MPI_MAX_SIZE) diff --git a/thirdparty/mbedtls/include/mbedtls/bn_mul.h b/thirdparty/mbedtls/include/mbedtls/bn_mul.h index 9615090f91..6f1201bf50 100644 --- a/thirdparty/mbedtls/include/mbedtls/bn_mul.h +++ b/thirdparty/mbedtls/include/mbedtls/bn_mul.h @@ -71,6 +71,46 @@  #include "bignum.h" + +/* + * Conversion macros for embedded constants: + * build lists of mbedtls_mpi_uint's from lists of unsigned char's grouped by 8, 4 or 2 + */ +#if defined(MBEDTLS_HAVE_INT32) + +#define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d )               \ +    ( (mbedtls_mpi_uint) (a) <<  0 ) |                        \ +    ( (mbedtls_mpi_uint) (b) <<  8 ) |                        \ +    ( (mbedtls_mpi_uint) (c) << 16 ) |                        \ +    ( (mbedtls_mpi_uint) (d) << 24 ) + +#define MBEDTLS_BYTES_TO_T_UINT_2( a, b )                   \ +    MBEDTLS_BYTES_TO_T_UINT_4( a, b, 0, 0 ) + +#define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \ +    MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ),                \ +    MBEDTLS_BYTES_TO_T_UINT_4( e, f, g, h ) + +#else /* 64-bits */ + +#define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h )   \ +    ( (mbedtls_mpi_uint) (a) <<  0 ) |                        \ +    ( (mbedtls_mpi_uint) (b) <<  8 ) |                        \ +    ( (mbedtls_mpi_uint) (c) << 16 ) |                        \ +    ( (mbedtls_mpi_uint) (d) << 24 ) |                        \ +    ( (mbedtls_mpi_uint) (e) << 32 ) |                        \ +    ( (mbedtls_mpi_uint) (f) << 40 ) |                        \ +    ( (mbedtls_mpi_uint) (g) << 48 ) |                        \ +    ( (mbedtls_mpi_uint) (h) << 56 ) + +#define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d )             \ +    MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, 0, 0, 0, 0 ) + +#define MBEDTLS_BYTES_TO_T_UINT_2( a, b )                   \ +    MBEDTLS_BYTES_TO_T_UINT_8( a, b, 0, 0, 0, 0, 0, 0 ) + +#endif /* bits in mbedtls_mpi_uint */ +  #if defined(MBEDTLS_HAVE_ASM)  #ifndef asm diff --git a/thirdparty/mbedtls/include/mbedtls/ccm.h b/thirdparty/mbedtls/include/mbedtls/ccm.h index 3dcdc91894..d50c6ec993 100644 --- a/thirdparty/mbedtls/include/mbedtls/ccm.h +++ b/thirdparty/mbedtls/include/mbedtls/ccm.h @@ -175,7 +175,7 @@ void mbedtls_ccm_free( mbedtls_ccm_context *ctx );   *                  than zero, \p output must be a writable buffer of at least   *                  that length.   * \param tag       The buffer holding the authentication field. This must be a - *                  readable buffer of at least \p tag_len Bytes. + *                  writable buffer of at least \p tag_len Bytes.   * \param tag_len   The length of the authentication field to generate in Bytes:   *                  4, 6, 8, 10, 12, 14 or 16.   * @@ -220,7 +220,7 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,   *                  than zero, \p output must be a writable buffer of at least   *                  that length.   * \param tag       The buffer holding the authentication field. This must be a - *                  readable buffer of at least \p tag_len Bytes. + *                  writable buffer of at least \p tag_len Bytes.   * \param tag_len   The length of the authentication field to generate in Bytes:   *                  0, 4, 6, 8, 10, 12, 14 or 16.   * diff --git a/thirdparty/mbedtls/include/mbedtls/config.h b/thirdparty/mbedtls/include/mbedtls/config.h index 217998a5eb..d53b457630 100644 --- a/thirdparty/mbedtls/include/mbedtls/config.h +++ b/thirdparty/mbedtls/include/mbedtls/config.h @@ -453,7 +453,7 @@   *       be overridden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt   *       must stay untouched.   * - * \note If you use the AES_xxx_ALT macros, then is is recommended to also set + * \note If you use the AES_xxx_ALT macros, then it is recommended to also set   *       MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES   *       tables.   * @@ -1747,6 +1747,23 @@  //#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT  /** + * \def MBEDTLS_TEST_HOOKS + * + * Enable features for invasive testing such as introspection functions and + * hooks for fault injection. This enables additional unit tests. + * + * Merely enabling this feature should not change the behavior of the product. + * It only adds new code, and new branching points where the default behavior + * is the same as when this feature is disabled. + * However, this feature increases the attack surface: there is an added + * risk of vulnerabilities, and more gadgets that can make exploits easier. + * Therefore this feature must never be enabled in production. + * + * Uncomment to enable invasive tests. + */ +//#define MBEDTLS_TEST_HOOKS + +/**   * \def MBEDTLS_THREADING_ALT   *   * Provide your own alternate threading implementation. @@ -3128,7 +3145,7 @@   */  /* MPI / BIGNUM options */ -//#define MBEDTLS_MPI_WINDOW_SIZE            6 /**< Maximum windows size used. */ +//#define MBEDTLS_MPI_WINDOW_SIZE            6 /**< Maximum window size used. */  //#define MBEDTLS_MPI_MAX_SIZE            1024 /**< Maximum number of bytes for usable MPIs. */  /* CTR_DRBG options */ diff --git a/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h b/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h index 7e5f2e5769..6c099adf4d 100644 --- a/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h +++ b/thirdparty/mbedtls/include/mbedtls/ctr_drbg.h @@ -214,6 +214,13 @@ typedef struct mbedtls_ctr_drbg_context      void *p_entropy;            /*!< The context for the entropy function. */  #if defined(MBEDTLS_THREADING_C) +    /* Invariant: the mutex is initialized if and only if f_entropy != NULL. +     * This means that the mutex is initialized during the initial seeding +     * in mbedtls_ctr_drbg_seed() and freed in mbedtls_ctr_drbg_free(). +     * +     * Note that this invariant may change without notice. Do not rely on it +     * and do not access the mutex directly in application code. +     */      mbedtls_threading_mutex_t mutex;  #endif  } @@ -224,6 +231,11 @@ mbedtls_ctr_drbg_context;   *                      and prepares it for mbedtls_ctr_drbg_seed()   *                      or mbedtls_ctr_drbg_free().   * + * \note                The reseed interval is + *                      #MBEDTLS_CTR_DRBG_RESEED_INTERVAL by default. + *                      You can override it by calling + *                      mbedtls_ctr_drbg_set_reseed_interval(). + *   * \param ctx           The CTR_DRBG context to initialize.   */  void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ); @@ -272,6 +284,15 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );   *                      device.   */  #endif +#if defined(MBEDTLS_THREADING_C) +/** + * \note                When Mbed TLS is built with threading support, + *                      after this function returns successfully, + *                      it is safe to call mbedtls_ctr_drbg_random() + *                      from multiple threads. Other operations, including + *                      reseeding, are not thread-safe. + */ +#endif /* MBEDTLS_THREADING_C */  /**   * \param ctx           The CTR_DRBG context to seed.   *                      It must have been initialized with @@ -281,6 +302,8 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );   *                      the same context unless you call   *                      mbedtls_ctr_drbg_free() and mbedtls_ctr_drbg_init()   *                      again first. + *                      After a failed call to mbedtls_ctr_drbg_seed(), + *                      you must call mbedtls_ctr_drbg_free().   * \param f_entropy     The entropy callback, taking as arguments the   *                      \p p_entropy context, the buffer to fill, and the   *                      length of the buffer. @@ -305,7 +328,8 @@ int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,                     size_t len );  /** - * \brief               This function clears CTR_CRBG context data. + * \brief               This function resets CTR_DRBG context to the state immediately + *                      after initial call of mbedtls_ctr_drbg_init().   *   * \param ctx           The CTR_DRBG context to clear.   */ @@ -371,6 +395,11 @@ void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,   * \brief               This function reseeds the CTR_DRBG context, that is   *                      extracts data from the entropy source.   * + * \note                This function is not thread-safe. It is not safe + *                      to call this function if another thread might be + *                      concurrently obtaining random numbers from the same + *                      context or updating or reseeding the same context. + *   * \param ctx           The CTR_DRBG context.   * \param additional    Additional data to add to the state. Can be \c NULL.   * \param len           The length of the additional data. @@ -388,6 +417,11 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,  /**   * \brief              This function updates the state of the CTR_DRBG context.   * + * \note               This function is not thread-safe. It is not safe + *                     to call this function if another thread might be + *                     concurrently obtaining random numbers from the same + *                     context or updating or reseeding the same context. + *   * \param ctx          The CTR_DRBG context.   * \param additional   The data to update the state with. This must not be   *                     \c NULL unless \p add_len is \c 0. @@ -411,6 +445,11 @@ int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx,   * This function automatically reseeds if the reseed counter is exceeded   * or prediction resistance is enabled.   * + * \note                This function is not thread-safe. It is not safe + *                      to call this function if another thread might be + *                      concurrently obtaining random numbers from the same + *                      context or updating or reseeding the same context. + *   * \param p_rng         The CTR_DRBG context. This must be a pointer to a   *                      #mbedtls_ctr_drbg_context structure.   * \param output        The buffer to fill. @@ -439,8 +478,16 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng,   *   * This function automatically reseeds if the reseed counter is exceeded   * or prediction resistance is enabled. - * - * + */ +#if defined(MBEDTLS_THREADING_C) +/** + * \note                When Mbed TLS is built with threading support, + *                      it is safe to call mbedtls_ctr_drbg_random() + *                      from multiple threads. Other operations, including + *                      reseeding, are not thread-safe. + */ +#endif /* MBEDTLS_THREADING_C */ +/**   * \param p_rng         The CTR_DRBG context. This must be a pointer to a   *                      #mbedtls_ctr_drbg_context structure.   * \param output        The buffer to fill. diff --git a/thirdparty/mbedtls/include/mbedtls/ecp.h b/thirdparty/mbedtls/include/mbedtls/ecp.h index bdc750eb24..e4a1ed81cf 100644 --- a/thirdparty/mbedtls/include/mbedtls/ecp.h +++ b/thirdparty/mbedtls/include/mbedtls/ecp.h @@ -154,6 +154,40 @@ typedef struct mbedtls_ecp_point  }  mbedtls_ecp_point; +/* Determine the minimum safe value of MBEDTLS_ECP_MAX_BITS. */ +#if !defined(MBEDTLS_ECP_C) +#define MBEDTLS_ECP_MAX_BITS_MIN 0 +/* Note: the curves must be listed in DECREASING size! */ +#elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 521 +#elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 512 +#elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 448 +#elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 384 +#elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 384 +#elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 256 +#elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 256 +#elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 256 +#elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 255 +#elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 225 // n is slightly above 2^224 +#elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 224 +#elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 192 +#elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) +#define MBEDTLS_ECP_MAX_BITS_MIN 192 +#else +#error "MBEDTLS_ECP_C enabled, but no curve?" +#endif +  #if !defined(MBEDTLS_ECP_ALT)  /*   * default mbed TLS elliptic curve arithmetic implementation @@ -228,7 +262,13 @@ mbedtls_ecp_group;   * \{   */ -#if !defined(MBEDTLS_ECP_MAX_BITS) +#if defined(MBEDTLS_ECP_MAX_BITS) + +#if MBEDTLS_ECP_MAX_BITS < MBEDTLS_ECP_MAX_BITS_MIN +#error "MBEDTLS_ECP_MAX_BITS is smaller than the largest supported curve" +#endif + +#else  /**   * The maximum size of the groups, that is, of \c N and \c P.   */ diff --git a/thirdparty/mbedtls/include/mbedtls/entropy.h b/thirdparty/mbedtls/include/mbedtls/entropy.h index 1e1d3f56ec..1d6e9b821b 100644 --- a/thirdparty/mbedtls/include/mbedtls/entropy.h +++ b/thirdparty/mbedtls/include/mbedtls/entropy.h @@ -147,13 +147,15 @@ mbedtls_entropy_source_state;   */  typedef struct mbedtls_entropy_context  { -    int accumulator_started; +    int accumulator_started; /* 0 after init. +                              * 1 after the first update. +                              * -1 after free. */  #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)      mbedtls_sha512_context  accumulator;  #else      mbedtls_sha256_context  accumulator;  #endif -    int             source_count; +    int             source_count; /* Number of entries used in source. */      mbedtls_entropy_source_state    source[MBEDTLS_ENTROPY_MAX_SOURCES];  #if defined(MBEDTLS_HAVEGE_C)      mbedtls_havege_state    havege_data; diff --git a/thirdparty/mbedtls/include/mbedtls/gcm.h b/thirdparty/mbedtls/include/mbedtls/gcm.h index 4e4434ed4d..1201fbd4f1 100644 --- a/thirdparty/mbedtls/include/mbedtls/gcm.h +++ b/thirdparty/mbedtls/include/mbedtls/gcm.h @@ -182,7 +182,7 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,   *                  than zero, this must be a writable buffer of at least that   *                  size in Bytes.   * \param tag_len   The length of the tag to generate. - * \param tag       The buffer for holding the tag. This must be a readable + * \param tag       The buffer for holding the tag. This must be a writable   *                  buffer of at least \p tag_len Bytes.   *   * \return          \c 0 if the encryption or decryption was performed @@ -310,7 +310,7 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx,   *                  tag. The tag can have a maximum length of 16 Bytes.   *   * \param ctx       The GCM context. This must be initialized. - * \param tag       The buffer for holding the tag. This must be a readable + * \param tag       The buffer for holding the tag. This must be a writable   *                  buffer of at least \p tag_len Bytes.   * \param tag_len   The length of the tag to generate. This must be at least   *                  four. diff --git a/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h b/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h index 6883678204..5718e187a9 100644 --- a/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h +++ b/thirdparty/mbedtls/include/mbedtls/hmac_drbg.h @@ -128,6 +128,14 @@ typedef struct mbedtls_hmac_drbg_context      void *p_entropy;            /*!< context for the entropy function        */  #if defined(MBEDTLS_THREADING_C) +    /* Invariant: the mutex is initialized if and only if +     * md_ctx->md_info != NULL. This means that the mutex is initialized +     * during the initial seeding in mbedtls_hmac_drbg_seed() or +     * mbedtls_hmac_drbg_seed_buf() and freed in mbedtls_ctr_drbg_free(). +     * +     * Note that this invariant may change without notice. Do not rely on it +     * and do not access the mutex directly in application code. +     */      mbedtls_threading_mutex_t mutex;  #endif  } mbedtls_hmac_drbg_context; @@ -138,6 +146,10 @@ typedef struct mbedtls_hmac_drbg_context   * This function makes the context ready for mbedtls_hmac_drbg_seed(),   * mbedtls_hmac_drbg_seed_buf() or mbedtls_hmac_drbg_free().   * + * \note                The reseed interval is #MBEDTLS_HMAC_DRBG_RESEED_INTERVAL + *                      by default. Override this value by calling + *                      mbedtls_hmac_drbg_set_reseed_interval(). + *   * \param ctx           HMAC_DRBG context to be initialized.   */  void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx ); @@ -173,7 +185,17 @@ void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );   * \note                During the initial seeding, this function calls   *                      the entropy source to obtain a nonce   *                      whose length is half the entropy length. - * + */ +#if defined(MBEDTLS_THREADING_C) +/** + * \note                When Mbed TLS is built with threading support, + *                      after this function returns successfully, + *                      it is safe to call mbedtls_hmac_drbg_random() + *                      from multiple threads. Other operations, including + *                      reseeding, are not thread-safe. + */ +#endif /* MBEDTLS_THREADING_C */ +/**   * \param ctx           HMAC_DRBG context to be seeded.   * \param md_info       MD algorithm to use for HMAC_DRBG.   * \param f_entropy     The entropy callback, taking as arguments the @@ -212,7 +234,17 @@ int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,   *   * This function is meant for use in algorithms that need a pseudorandom   * input such as deterministic ECDSA. - * + */ +#if defined(MBEDTLS_THREADING_C) +/** + * \note                When Mbed TLS is built with threading support, + *                      after this function returns successfully, + *                      it is safe to call mbedtls_hmac_drbg_random() + *                      from multiple threads. Other operations, including + *                      reseeding, are not thread-safe. + */ +#endif /* MBEDTLS_THREADING_C */ +/**   * \param ctx           HMAC_DRBG context to be initialised.   * \param md_info       MD algorithm to use for HMAC_DRBG.   * \param data          Concatenation of the initial entropy string and @@ -275,6 +307,11 @@ void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,  /**   * \brief               This function updates the state of the HMAC_DRBG context.   * + * \note                This function is not thread-safe. It is not safe + *                      to call this function if another thread might be + *                      concurrently obtaining random numbers from the same + *                      context or updating or reseeding the same context. + *   * \param ctx           The HMAC_DRBG context.   * \param additional    The data to update the state with.   *                      If this is \c NULL, there is no additional data. @@ -291,6 +328,11 @@ int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,   * \brief               This function reseeds the HMAC_DRBG context, that is   *                      extracts data from the entropy source.   * + * \note                This function is not thread-safe. It is not safe + *                      to call this function if another thread might be + *                      concurrently obtaining random numbers from the same + *                      context or updating or reseeding the same context. + *   * \param ctx           The HMAC_DRBG context.   * \param additional    Additional data to add to the state.   *                      If this is \c NULL, there is no additional data @@ -316,6 +358,11 @@ int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,   * This function automatically reseeds if the reseed counter is exceeded   * or prediction resistance is enabled.   * + * \note                This function is not thread-safe. It is not safe + *                      to call this function if another thread might be + *                      concurrently obtaining random numbers from the same + *                      context or updating or reseeding the same context. + *   * \param p_rng         The HMAC_DRBG context. This must be a pointer to a   *                      #mbedtls_hmac_drbg_context structure.   * \param output        The buffer to fill. @@ -345,7 +392,16 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng,   *   * This function automatically reseeds if the reseed counter is exceeded   * or prediction resistance is enabled. - * + */ +#if defined(MBEDTLS_THREADING_C) +/** + * \note                When Mbed TLS is built with threading support, + *                      it is safe to call mbedtls_ctr_drbg_random() + *                      from multiple threads. Other operations, including + *                      reseeding, are not thread-safe. + */ +#endif /* MBEDTLS_THREADING_C */ +/**   * \param p_rng         The HMAC_DRBG context. This must be a pointer to a   *                      #mbedtls_hmac_drbg_context structure.   * \param output        The buffer to fill. @@ -361,7 +417,8 @@ int mbedtls_hmac_drbg_random_with_add( void *p_rng,  int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );  /** - * \brief               Free an HMAC_DRBG context + * \brief               This function resets HMAC_DRBG context to the state immediately + *                      after initial call of mbedtls_hmac_drbg_init().   *   * \param ctx           The HMAC_DRBG context to free.   */ diff --git a/thirdparty/mbedtls/include/mbedtls/net_sockets.h b/thirdparty/mbedtls/include/mbedtls/net_sockets.h index 00fea7db19..c6e1a0270e 100644 --- a/thirdparty/mbedtls/include/mbedtls/net_sockets.h +++ b/thirdparty/mbedtls/include/mbedtls/net_sockets.h @@ -151,6 +151,7 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char   *   * \return         0 if successful, or one of:   *                      MBEDTLS_ERR_NET_SOCKET_FAILED, + *                      MBEDTLS_ERR_NET_UNKNOWN_HOST,   *                      MBEDTLS_ERR_NET_BIND_FAILED,   *                      MBEDTLS_ERR_NET_LISTEN_FAILED   * @@ -170,6 +171,8 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char   *                  can be NULL if client_ip is null   *   * \return          0 if successful, or + *                  MBEDTLS_ERR_NET_SOCKET_FAILED, + *                  MBEDTLS_ERR_NET_BIND_FAILED,   *                  MBEDTLS_ERR_NET_ACCEPT_FAILED, or   *                  MBEDTLS_ERR_NET_BUFFER_TOO_SMALL if buf_size is too small,   *                  MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to @@ -182,6 +185,10 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,  /**   * \brief          Check and wait for the context to be ready for read/write   * + * \note           The current implementation of this function uses + *                 select() and returns an error if the file descriptor + *                 is \c FD_SETSIZE or greater. + *   * \param ctx      Socket to check   * \param rw       Bitflag composed of MBEDTLS_NET_POLL_READ and   *                 MBEDTLS_NET_POLL_WRITE specifying the events @@ -263,16 +270,21 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );   *                 'timeout' seconds. If no error occurs, the actual amount   *                 read is returned.   * + * \note           The current implementation of this function uses + *                 select() and returns an error if the file descriptor + *                 is \c FD_SETSIZE or greater. + *   * \param ctx      Socket   * \param buf      The buffer to write to   * \param len      Maximum length of the buffer   * \param timeout  Maximum number of milliseconds to wait for data   *                 0 means no timeout (wait forever)   * - * \return         the number of bytes received, - *                 or a non-zero error code: - *                 MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out, + * \return         The number of bytes received if successful. + *                 MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out.   *                 MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal. + *                 Another negative error code (MBEDTLS_ERR_NET_xxx) + *                 for other failures.   *   * \note           This function will block (until data becomes available or   *                 timeout is reached) even if the socket is set to diff --git a/thirdparty/mbedtls/include/mbedtls/padlock.h b/thirdparty/mbedtls/include/mbedtls/padlock.h index d8246e2cd0..0e4a6bbf69 100644 --- a/thirdparty/mbedtls/include/mbedtls/padlock.h +++ b/thirdparty/mbedtls/include/mbedtls/padlock.h @@ -98,7 +98,7 @@ extern "C" {   *   * \param feature  The feature to detect   * - * \return         1 if CPU has support for the feature, 0 otherwise + * \return         non-zero if CPU has support for the feature, 0 otherwise   */  int mbedtls_padlock_has_support( int feature ); diff --git a/thirdparty/mbedtls/include/mbedtls/rsa.h b/thirdparty/mbedtls/include/mbedtls/rsa.h index 188c37cf3a..b2f65334fe 100644 --- a/thirdparty/mbedtls/include/mbedtls/rsa.h +++ b/thirdparty/mbedtls/include/mbedtls/rsa.h @@ -124,7 +124,10 @@ extern "C" {   */  typedef struct mbedtls_rsa_context  { -    int ver;                    /*!<  Always 0.*/ +    int ver;                    /*!<  Reserved for internal purposes. +                                 *    Do not set this field in application +                                 *    code. Its meaning might change without +                                 *    notice. */      size_t len;                 /*!<  The size of \p N in Bytes. */      mbedtls_mpi N;              /*!<  The public modulus. */ @@ -154,6 +157,7 @@ typedef struct mbedtls_rsa_context                                       mask generating function used in the                                       EME-OAEP and EMSA-PSS encodings. */  #if defined(MBEDTLS_THREADING_C) +    /* Invariant: the mutex is initialized iff ver != 0. */      mbedtls_threading_mutex_t mutex;    /*!<  Thread-safety mutex. */  #endif  } diff --git a/thirdparty/mbedtls/include/mbedtls/sha512.h b/thirdparty/mbedtls/include/mbedtls/sha512.h index 9ff78ecf41..5e5a15e000 100644 --- a/thirdparty/mbedtls/include/mbedtls/sha512.h +++ b/thirdparty/mbedtls/include/mbedtls/sha512.h @@ -152,8 +152,7 @@ int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,  /**   * \brief          This function finishes the SHA-512 operation, and writes - *                 the result to the output buffer. This function is for - *                 internal use only. + *                 the result to the output buffer.   *   * \param ctx      The SHA-512 context. This must be initialized   *                 and have a hash operation started. @@ -169,6 +168,7 @@ int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,  /**   * \brief          This function processes a single data block within   *                 the ongoing SHA-512 computation. + *                 This function is for internal use only.   *   * \param ctx      The SHA-512 context. This must be initialized.   * \param data     The buffer holding one block of data. This diff --git a/thirdparty/mbedtls/include/mbedtls/ssl.h b/thirdparty/mbedtls/include/mbedtls/ssl.h index d3ee3c4e6f..0abeb430e4 100644 --- a/thirdparty/mbedtls/include/mbedtls/ssl.h +++ b/thirdparty/mbedtls/include/mbedtls/ssl.h @@ -1409,7 +1409,7 @@ void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf,   * \note           For DTLS, you need to provide either a non-NULL   *                 f_recv_timeout callback, or a f_recv that doesn't block.   * - * \note           See the documentations of \c mbedtls_ssl_sent_t, + * \note           See the documentations of \c mbedtls_ssl_send_t,   *                 \c mbedtls_ssl_recv_t and \c mbedtls_ssl_recv_timeout_t for   *                 the conventions those callbacks must follow.   * @@ -2237,7 +2237,7 @@ void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,  #if defined(MBEDTLS_ECP_C)  /**   * \brief          Set the allowed curves in order of preference. - *                 (Default: all defined curves.) + *                 (Default: all defined curves in order of decreasing size.)   *   *                 On server: this only affects selection of the ECDHE curve;   *                 the curves used for ECDH and ECDSA are determined by the @@ -2269,7 +2269,9 @@ void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf,  #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)  /**   * \brief          Set the allowed hashes for signatures during the handshake. - *                 (Default: all available hashes except MD5.) + *                 (Default: all SHA-2 hashes, largest first. Also SHA-1 if + *                 the compile-time option + *                 `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE` is enabled.)   *   * \note           This only affects which hashes are offered and can be used   *                 for signatures during the handshake. Hashes for message diff --git a/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h b/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h index a10a434138..a83f5e6662 100644 --- a/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h +++ b/thirdparty/mbedtls/include/mbedtls/ssl_ticket.h @@ -124,7 +124,7 @@ void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );   *                  Recommended value: 86400 (one day).   *   * \note            It is highly recommended to select a cipher that is at - *                  least as strong as the the strongest ciphersuite + *                  least as strong as the strongest ciphersuite   *                  supported. Usually that means a 256-bit key.   *   * \note            The lifetime of the keys is twice the lifetime of tickets. diff --git a/thirdparty/mbedtls/include/mbedtls/threading.h b/thirdparty/mbedtls/include/mbedtls/threading.h index a8183a6ef4..45161ce467 100644 --- a/thirdparty/mbedtls/include/mbedtls/threading.h +++ b/thirdparty/mbedtls/include/mbedtls/threading.h @@ -73,6 +73,9 @@ extern "C" {  typedef struct mbedtls_threading_mutex_t  {      pthread_mutex_t mutex; +    /* is_valid is 0 after a failed init or a free, and nonzero after a +     * successful init. This field is not considered part of the public +     * API of Mbed TLS and may change without notice. */      char is_valid;  } mbedtls_threading_mutex_t;  #endif diff --git a/thirdparty/mbedtls/include/mbedtls/version.h b/thirdparty/mbedtls/include/mbedtls/version.h index d09b45002d..49cbeb003a 100644 --- a/thirdparty/mbedtls/include/mbedtls/version.h +++ b/thirdparty/mbedtls/include/mbedtls/version.h @@ -65,16 +65,16 @@   */  #define MBEDTLS_VERSION_MAJOR  2  #define MBEDTLS_VERSION_MINOR  16 -#define MBEDTLS_VERSION_PATCH  8 +#define MBEDTLS_VERSION_PATCH  11  /**   * The single version number has the following structure:   *    MMNNPP00   *    Major version | Minor version | Patch version   */ -#define MBEDTLS_VERSION_NUMBER         0x02100800 -#define MBEDTLS_VERSION_STRING         "2.16.8" -#define MBEDTLS_VERSION_STRING_FULL    "mbed TLS 2.16.8" +#define MBEDTLS_VERSION_NUMBER         0x02100B00 +#define MBEDTLS_VERSION_STRING         "2.16.11" +#define MBEDTLS_VERSION_STRING_FULL    "mbed TLS 2.16.11"  #if defined(MBEDTLS_VERSION_C) diff --git a/thirdparty/mbedtls/include/mbedtls/x509_crt.h b/thirdparty/mbedtls/include/mbedtls/x509_crt.h index c38e0c0556..30da1909b7 100644 --- a/thirdparty/mbedtls/include/mbedtls/x509_crt.h +++ b/thirdparty/mbedtls/include/mbedtls/x509_crt.h @@ -229,12 +229,21 @@ typedef void mbedtls_x509_crt_restart_ctx;  /**   * Default security profile. Should provide a good balance between security   * and compatibility with current deployments. + * + * This profile permits: + * - SHA2 hashes. + * - All supported elliptic curves. + * - RSA with 2048 bits and above. + * + * New minor versions of Mbed TLS may extend this profile, for example if + * new curves are added to the library. New minor versions of Mbed TLS will + * not reduce this profile unless serious security concerns require it.   */  extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;  /**   * Expected next default profile. Recommended for new deployments. - * Currently targets a 128-bit security level, except for RSA-2048. + * Currently targets a 128-bit security level, except for allowing RSA-2048.   */  extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;  |