-
Notifications
You must be signed in to change notification settings - Fork 477
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
Please add a "non inplace" protect and unprotect API #569
Comments
If protect/unprotect were not in-place, wouldn't there just be a copy going on internal to the protect/unprotect call instead of at the application layer? |
It depends on the underliyng crypto primitive implementation. |
Fair point. You would at least have to copy the header over, since that's not touched by the crypto. |
You want libsrtp to allocate memory and copy the packet data? That strikes me as less desirable than doing that in your code since you could, at the very least, create a static buffer to avoid reallocating memory repeatedly. |
No, I think the request is to allow the application to provide separate input and output buffers. So the application would continue to own the memory. |
OK. Then how is that different from: memcpy(srtp_buffer, input_buffer, sizeof(input_buffer));
srtp_protect(srtp_buffer); Just the desire of libsrtp to do the memcpy? |
No, the point is that you can do encryption without any memcpy. Consider the following cases:
When doing an out-of-place encryption, case 3 seems pretty clearly more efficient than case 2. In case 3, you only write once to each memory location in |
All that said, this would be a pretty invasive change. We would need to plumb this all the way through from the SRTP-level interface to the low-level crypto interfaces. We could probably minimize the pain by having the in-place SRTP protect call through to an out-of-place version, so that at least we would have one behavior throughout the @ydroneaud have you done any experimentation to measure the potential benefit here? Even a quick experiment comparing in-place to out-of-place would be helpful in justifying this. You could probably modify the timing tests in |
Yeah, SRTP's AES implementation will use the plaintext input as the state table array and operate on it in-place. So, I guess that's the issue here? It would be trivial enough to copy that before operating on it, but either way it results in a copy. I'm not sure that we'd be saving any copying at the end of the day. The state table must get loaded and then the output stored. Using that input as the state table saves that copy. (I'm guessing it's not much savings, honestly. It would be interesting to measure. I think most of the computation is going to be related to sbox lookup, column mixing, etc. Anyway, perhaps I'm still missing the point, but I assume the ask is for srtp_aes_encrypt(), for example, to first copy the input block and then output that once all the operations are complete into a separate output buffer. |
Perhaps more to the point (since I expect the internal AES-CTR impl doesn't get much use), the OpenSSL implementation of AES-CTR does exactly case 3 in my taxonomy above:
It would be a trivial change for the internal impl to work this way, assuming the API passed in separate input and output buffers. You would just change this line to the above form instead of using So if we had an out-of-place API, there would be no |
Yeah, something like that'll work. I had my head one-level down further in the AES code itself. That doesn't matter: this code matters. |
Hello, I also have the same request. Has there been any progress on this suggestion? |
This is now supported |
In my use case, due to the inplace protect/unprotect API, RTP/RTCP packets have to be duplicated before being protected/unprotected.
I believe some memory bandwidth could be saved if libsrtp exposed an API that doesn't process data inplace.
I would imagine the API would be used this way
The text was updated successfully, but these errors were encountered: