feat: add aws-lc-rs feature as alternative crypto backend (ring stays default)#134
Merged
Merged
Conversation
Add a new `aws-lc-rs` feature flag that allows users to opt-in to the AWS-LC crypto backend instead of ring. Ring remains the default via the `ring` feature in the default feature set. Changes: - Make `ring` dep optional, gated behind the new `ring` feature - Add `aws-lc-rs` optional dep - Add `ring` and `aws-lc-rs` features that propagate the backend choice to all sub-crates (quinn-jls, quinn-proto-jls, rustls-jls, iroh-quinn, iroh-quinn-proto, rustls, rcgen) - Replace hardcoded `ring::crypto` references in source with a feature-gated `crypto_provider` alias - Replace direct `ring::digest` SHA256 usage with feature-gated equivalent using `aws_lc_rs::digest` when aws-lc-rs is active This allows downstream crates (e.g. clash-rs) using aws-lc-rs as their primary crypto provider to avoid pulling in ring as a duplicate dependency, reducing binary size. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ibigbug
added a commit
to Watfaq/clash-rs
that referenced
this pull request
May 11, 2026
When aws-lc-rs is the active crypto backend, ring was still being pulled in as a duplicate dependency by three paths: 1. quinn (v0.11) - used feature = "rustls" which aliases to "rustls-ring". Removed "rustls" from static features; now routes via aws-lc-rs feature (quinn/rustls-aws-lc-rs) or ring feature (quinn/rustls-ring). 2. rcgen - used default features which include ring backend. Switched to default-features = false; crypto backend now selected via aws-lc-rs/ring features (rcgen/aws_lc_rs or rcgen/ring). 3. shadowquic - hardcoded ring throughout. Switched to the fork ibigbug/shadowquic@a6f3fde which adds an aws-lc-rs feature flag (see spongebob888/shadowquic#134). Added default-features = false on the dep and explicit feature routing in aws-lc-rs/ring clash-lib features. Result: cargo tree -p clash-lib -F aws-lc-rs,shadowquic -i ring returns empty — ring is completely absent from the aws-lc-rs path. Estimated binary size reduction: ~500KB-1MB stripped release. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ibigbug
added a commit
to Watfaq/clash-rs
that referenced
this pull request
May 12, 2026
…#1397) * fix: remove ring from aws-lc-rs code path When aws-lc-rs is the active crypto backend, ring was still being pulled in as a duplicate dependency by three paths: 1. quinn (v0.11) - used feature = "rustls" which aliases to "rustls-ring". Removed "rustls" from static features; now routes via aws-lc-rs feature (quinn/rustls-aws-lc-rs) or ring feature (quinn/rustls-ring). 2. rcgen - used default features which include ring backend. Switched to default-features = false; crypto backend now selected via aws-lc-rs/ring features (rcgen/aws_lc_rs or rcgen/ring). 3. shadowquic - hardcoded ring throughout. Switched to the fork ibigbug/shadowquic@a6f3fde which adds an aws-lc-rs feature flag (see spongebob888/shadowquic#134). Added default-features = false on the dep and explicit feature routing in aws-lc-rs/ring clash-lib features. Result: cargo tree -p clash-lib -F aws-lc-rs,shadowquic -i ring returns empty — ring is completely absent from the aws-lc-rs path. Estimated binary size reduction: ~500KB-1MB stripped release. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: remove unused imports in watfaq-dns handler test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: use ClashInstance RAII in anytls integration tests The anytls tests were using std::thread::spawn + start_clash without any cleanup mechanism. Threads kept running after each test completed, leaving ports 8902/9092 and 8998/9095 bound. The subsequent integration_test_anytls_udp test would then fail to bind port 8902 with 'Address already in use'. Replace both anytls tests with ClashInstance, which cancels the shutdown token on drop and waits for all ports to be released before returning — matching the pattern used throughout api_tests.rs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
spongebob888
approved these changes
May 12, 2026
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.
Summary
Add a new
aws-lc-rsCargo feature that lets downstream users swap the Ring crypto backend for AWS-LC. Ring remains the default — no breaking change.Motivation
Projects like clash-rs use
aws-lc-rsas their primary crypto provider across the whole binary. Without this feature,shadowquicunconditionally pulls inringas an additional crypto library, duplicating ~500KB–1MB of crypto code (AES, curve25519, P-256 assembly) in the final binary even though those primitives are already provided byaws-lc-rs.Changes
shadowquic/Cargo.tomlringdep optional, gated by the newringfeature (included indefault)aws-lc-rsas an optional depringandaws-lc-rsfeature flags that propagate the backend choice to all sub-crates:quinn-jls,quinn-proto-jls,rustls-jls,iroh-quinn,iroh-quinn-proto,rustls,rcgenrustls-ring/ringfrom depfeatureslistsSource files — replace
ring::with a feature-gatedcrypto_provideralias:src/shadowquic/quinn_wrapper/wrapper.rs— cipher suite selection + provider initsrc/sunnyquic/iroh_wrapper/wrapper.rs— samesrc/sunnyquic/dynamic_cert.rs—sign::any_supported_typesrc/sunnyquic/mod.rs— SHA256 hash viaring::digest/aws_lc_rs::digestUsage
Verification