-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Hello,
Thank you for maintaining mbedTLS and providing a high-performance, lightweight TLS library.
I am currently rewriting a private C++ web server/framework for public release, leveraging Linux io_uring and KTLS to enable zero-copy send and receive operations. While mbedTLS’s read/write callbacks integrate well with registered buffers, filling the fields in KTLS tls12_crypto_info_* requires additional steps, some of which currently rely on internal helpers.
For TLS 1.2, the key and IV/salt can be derived using the public mbedtls_ssl_tls_prf function, which is straightforward. TLS 1.3, however, provides no public API to derive record keys from the application traffic secret. In my prototype, I had to rely on the internal mbedtls_ssl_tls13_make_traffic_keys function, declared extern, to obtain the AEAD key and IV required by the kernel.
Using mbedtls_ssl_tls13_make_traffic_keys also requires calling mbedtls_md_psa_alg_from_type and populating an mbedtls_ssl_key_set structure. While these obstacles can be worked around, obtaining the correct sequence numbers for TX and RX is more complex. For TX, the outgoing sequence can be read from mbedtls_ssl_context::cur_out_ctr (if I am not mistaken). For RX, I have not explored the sources in depth, but it appears to reside in mbedtls_ssl_transform.
While it is possible to invoke private/internal helpers for TLS 1.3 and compute sequence numbers inside the read/write callbacks, doing so makes the code fragile and difficult to maintain, and risks compatibility or licensing problems.
mbedTLS could be made KTLS-friendly by leveraging the existing functions: with a simple wrapper around mbedtls_ssl_tls13_make_traffic_keys and mbedtls_ssl_key_set, and a getter for the TX/RX sequence numbers, the hand-off to the kernel can be performed at any time — even if the kernel reads data frames after the handshake. This scenario occurs, for example, with an HTTP GET request, in which case I use the mbedTLS read function to drain the buffer before enabling KTLS.
Thank you for considering this enhancement.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status