From 69477b5706449dd025874852e864edd05c4c418c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 13 Jan 2022 01:01:45 +0100 Subject: [PATCH] Add a field for application data to TLS structures In structure types that are passed to user callbacks, add a field that the library won't ever care about. The application can use this field to either identify an instance of the structure with a handle, or store a pointer to extra data. Signed-off-by: Gilles Peskine --- ChangeLog.d/ssl_context-user_data.txt | 3 +++ include/mbedtls/ssl.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 ChangeLog.d/ssl_context-user_data.txt diff --git a/ChangeLog.d/ssl_context-user_data.txt b/ChangeLog.d/ssl_context-user_data.txt new file mode 100644 index 0000000000..81df94aa63 --- /dev/null +++ b/ChangeLog.d/ssl_context-user_data.txt @@ -0,0 +1,3 @@ +Features + * The structures mbedtls_ssl_config and mbedtls_ssl_context have an + extra field user_data which is reserved for the application. diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h index 7e5fb199c8..afbebfea12 100644 --- a/include/mbedtls/ssl.h +++ b/include/mbedtls/ssl.h @@ -1448,6 +1448,13 @@ struct mbedtls_ssl_config #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C) unsigned int MBEDTLS_PRIVATE(dhm_min_bitlen); /*!< min. bit length of the DHM prime */ #endif + + /** User data pointer or handle. + * + * The library sets this to \p 0 when creating a context and does not + * access it afterwards. + */ + uintptr_t user_data; }; struct mbedtls_ssl_context @@ -1669,6 +1676,13 @@ struct mbedtls_ssl_context /** Callback to export key block and master secret */ mbedtls_ssl_export_keys_t *MBEDTLS_PRIVATE(f_export_keys); void *MBEDTLS_PRIVATE(p_export_keys); /*!< context for key export callback */ + + /** User data pointer or handle. + * + * The library sets this to \p 0 when creating a context and does not + * access it afterwards. + */ + uintptr_t user_data; }; /**