Repository navigation
Conversation
AesGcm::encrypt and ChaCha20Poly1305::encrypt encrypt the concatenation of a list of slices into a separate output buffer, and AesGcmEncryptor::update_into encrypts the next piece of a stream from one buffer into another (#990). A TLS record layer is handed the plaintext in buffers it does not own, often in pieces, plus TLS 1.3's content-type byte, and must write the ciphertext to its own output: this is the API it needs, the one-call equivalent of aws-lc-rs's seal_out_of_place_scatter (which also takes several pieces). For now they gather the pieces into the output and encrypt it there with the in-place functions, on every architecture; the verified out-of-place functions (contracts in the Spec PR) replace that copy target by target without changing the API. Every length is checked before anything is written, and an output of the wrong length is InvalidOutputLength. Tests: every split of a message into pieces against in-place encryption, and the Wycheproof vectors in two pieces (and update_into). Benchmarks: out-of-place encryption of a TLS 1.3-shaped record (plaintext plus the content-type byte) against aws-lc-rs's seal_out_of_place_scatter and OpenSSL's EVP interface. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MmkzVkkRyGFLYBPdnXPeVb
Member
Author
|
Skip this, go directly to the efficient impl |
Member
Author
|
Closing as asked. The AES-GCM half of this API is now in #1228, on top of the verified out-of-place x86-64 functions ( Generated by Claude Code |
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #990. This is the Rust API a TLS record layer needs. The verified out-of-place assembly (contracts in #1209) will then replace its internal copy, one target at a time, without changing the API.
Rust only: no Lean, no assembly and no trust change. It is independent of #1209.
API
encryptencrypts the concatenation of the pieces intoout, which must be exactly as long as their total. Otherwise it returns the newError::InvalidOutputLength.update_intois the streaming form:output.len() == input.len(), and calls may be any length.This covers each case of rustls's
RecordEncrypter::encryptin one call:key.encrypt(&nonce, &aad, &[chunk…, &[typ]], &mut out[..n])out[..n][chunk…]into&mut out[8..8 + n]out[..8]This includes
OutboundPlain::Multiple, which aws-lc-rs'sseal_out_of_place_scattercan't take: its provider gathers intooutitself.Implementation, for now
The pieces are gathered into
out, which is then encrypted in place with the existing verified functions, on every architecture. That is what rustls-provider (#991) does by hand today, so there is no speedup yet.The speedup comes from the verified out-of-place functions specified in #1209:
vg_aes_gcm_seal_gather,vg_aes_gcm_stream_encrypt_toandvg_chacha20_poly1305_seal_gather. Their implementations follow in stacked PRs. The first is x86-64 AES-GCM's interleaved loops reading the plaintext from the input buffer. They will slot in behind this API.Tests and benchmarks
update_into.aes-128-gcm-encrypt-out-of-placeandchacha20poly1305-out-of-place. Each encrypts a TLS 1.3-shaped record (plaintext plus the content-type byte) out of place, against aws-lc-rs'sseal_out_of_place_scatter(the byte asextra_in) and OpenSSL's EVPCrypter.Checks
cargo fmt --checkpasses.cargo clippy --all-targets -- -D warningspasses (also inbench/).aes_gcmandchacha20poly1305unit tests and their Wycheproof tests pass.ci/check_arch_gates.py,ci/check_variants.pyandci/cpu_tests.py lintpass.🤖 Generated with Claude Code
https://claude.ai/code/session_01MmkzVkkRyGFLYBPdnXPeVb
Generated by Claude Code