Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL read interface with less data copies #514

Open
attilamolnar opened this issue Jun 20, 2016 · 2 comments
Open

SSL read interface with less data copies #514

attilamolnar opened this issue Jun 20, 2016 · 2 comments

Comments

@attilamolnar
Copy link
Contributor

mbedtls_ssl_read() contains a call to memcpy() which copies the data from the internal mbedtls_ssl_context buffer to the user supplied buffer. This copy is not necessary and could be avoided by having a different interface for SSL reads. To achieve this, the basic idea is that the application gets a pointer to the internal mbedTLS buffer and the number of available bytes, accesses the data directly and then calls an mbedTLS function to let the library know it finished processing the data.

With this functionality, applications could avoid a copy entirely if the incoming data can be processed in-place. It also allows them to inspect the data first in case they do need to copy it, letting them decide which part of the data to copy (e.g. some non-fixed size message headers may not need to be copied, only the body which begins at an offset only known after looking at the headers).

From a quick look this can be implemented in mbedTLS relatively simply because of the way mbedtls_ssl_read() is structured: first it does some work independently of the values of buf and len, then it calls memcpy() and then it alters the internal state in light of the number of bytes consumed. This means splitting up mbedtls_ssl_read() into smaller functions would probably accomplish most of the work required to implement this.

GnuTLS has similar functionality from version 3.3.5, see gnutls_record_recv_packet, in http://gnutls.org/manual/html_node/Core-TLS-API.html#Core-TLS-API.

Let me know if you are interested in this and I'll be glad to work on it.

@ciarmcom
Copy link

ARM Internal Ref: IOTSSL-818

@pjbakker
Copy link
Contributor

If splitting mbedtls_ssl_read() into smaller functions in a clean way, while keeping the mbedtls_ssl_read() 'wrapper' in place and with identical behaviour, provides this capability, we would be interested.

iameli pushed a commit to livepeer/mbedtls that referenced this issue Dec 5, 2023
Fix gcc11 warning by defining output length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants