-
Notifications
You must be signed in to change notification settings - Fork 56
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
feat: add AEAD seal_in_place_scatter method #206
Conversation
aws-lc-rs/src/aead/aes_gcm.rs
Outdated
if 1 != EVP_AEAD_CTX_seal_scatter( | ||
aead_ctx, | ||
in_out.as_mut_ptr(), | ||
extra_out_and_tag.as_mut_ptr().cast(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: The cast()
here is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
aws-lc-rs/src/aead.rs
Outdated
/// | ||
#[inline] | ||
#[allow(clippy::needless_pass_by_value)] | ||
pub fn seal_in_place_scatter<A>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had an offline conversation with Justin, so will summarize it here so that we can get this closed out. Let's remove SealingKey::seal_in_place_scatter
, and only have support for this feature on LessSafeKey
. With that small modification we are open to accepting this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me!
Description of changes:
The current AEAD encrypt API takes a
in_out: &mut [u8]
, which forces callers to copy all of the cleartext into a single slice. This shouldn't be needed since encrypting a payload is copying the data since it has to XOR it with the cipher stream.Luckily, AWS-LC already provides a EVP API to account for this: EVP_AEAD_CTX_seal_scatter. This allows the caller to pass a
extra_in
, which is encrypted into thetag_out
buffer.In transport protocols like TLS and QUIC, where the bulk of the data being encrypted is separate from the framing header, using this API can yield large wins. In the case of s2n-quic, we see a reduction in 8% of CPU by avoiding the copy.
Call-outs:
API ergonomics
This new API isn't the most straightforward interface to use. You have to make sure to split the slices up in the correct order and account for the tag size. If we want to limit its use, we can add a feature flag stating that it's somewhat advanced.
API naming
I'm not sure if this is the best name, but it's what I came up with. Let me know if there's something better.
Testing:
I've updated the AEAD tests to check the new API matches the existing ones. I'm using part of the key bytes to pick an arbitrary split point in the input for the
extra_in
parameter. This will make the tests deterministic for a given key but still be somewhat "random" in how thein_out
is split from theextra_in
.s2n-quic without this change
Throughput is ~20Gbps. You can see the
memcpy
taking about 8% of CPU cycles in the flamegraph:s2n-quic with this change
Throughput is ~21Gbps. You can see in the flamegraph that the
memcpy
is gone:By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.