-
-
Notifications
You must be signed in to change notification settings - Fork 742
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
Make CipherCtx::cipher_update
more flexible
#1733
Conversation
25260ae
to
e495400
Compare
Looks good to me other than the method naming! |
This change relaxes constraints on the output buffer size when it can be safely determined how many bytes will be put in the output buffer. For supported cryptographic backends (OpenSSL >= 1.1) the cipher's `num` parameter will be consulted for the number of bytes in the block cache. For unsupported backends the behavior will not change (the code will assume full block in the cache). For callers that do the check themselves and want to use other backends (e.g. BoringSSL or LibreSSL) and unsafe `cipher_update_unchecked` function is added. Additionally a `CipherCtx::minimal_output_size` function is added for letting the callers know how big should the output buffer be for the next `cipher_update` call. Fixes sfackler#1729. See: https://mta.openssl.org/pipermail/openssl-users/2022-November/015623.html
e495400
to
5ecff30
Compare
Rebased on top of Thanks for your reviews! I really appreciate it 🙏 🤔 It seems I missed a release with this PR... if you don't mind I'll file a couple of small documentation + example PRs. |
PRs are always welcome! |
I'm happy to cut a new release as well if you'd like. |
Thank you! I'll be back with one more documentation PR and then I'll kindly ask you for a new release (it will also look better on docs.rs). Thanks in advance, I'll be back :) |
Sadly the condition used to relax output buffer checks that depended on the `num` parameter does not really hold so this change effectively reverts PR sfackler#1733. As clarified on the OpenSSL mailing list [0] and during integration tests the `num` parameter does not reflect the internal buffer cache size thus one needs to pessimistically assume that each call to `cipher_update` will need sufficient size to contain one additional block. Streaming ciphers are not affected by this revert. [0]: https://mta.openssl.org/pipermail/openssl-users/2022-December/015727.html
Sadly the condition used to relax output buffer checks that depended on the `num` parameter does not really hold so this change effectively reverts PR sfackler#1733 without breaking the API. As clarified on the OpenSSL mailing list [0] and during integration tests the `num` parameter does not reflect the internal buffer cache size thus one needs to pessimistically assume that each call to `cipher_update` will need sufficient size to contain one additional block. Streaming ciphers are not affected by this revert. [0]: https://mta.openssl.org/pipermail/openssl-users/2022-December/015727.html
Sadly the condition used to relax output buffer checks that depended on the `num` parameter does not really hold so this change effectively reverts PR sfackler#1733. As clarified on the OpenSSL mailing list [0] and during integration tests the `num` parameter does not reflect the internal buffer cache size thus one needs to pessimistically assume that each call to `cipher_update` will need sufficient size to contain one additional block. Streaming ciphers are not affected by this revert. [0]: https://mta.openssl.org/pipermail/openssl-users/2022-December/015727.html
This change relaxes constraints on the output buffer size when it can be safely determined how many bytes will be put in the output buffer.
For supported cryptographic backends (OpenSSL >= 1.1) the cipher's
num
parameter will be consulted for the number of bytes in the block cache. For unsupported backends the behavior will not change (the code will assume full block in the cache).For callers that do the check themselves and want to use other backends (e.g. BoringSSL or LibreSSL) and unsafe
unchecked_cipher_update
function is added.Additionally a
CipherCtx::minimal_output_size
function is added for letting the callers know how big should the output buffer be for the nextcipher_update
call.Fixes #1729.
See: https://mta.openssl.org/pipermail/openssl-users/2022-November/015623.html