8000 Upgrade to ring 0.17 by djc · Pull Request #1508 · rustls/rustls · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Upgrade to ring 0.17 #1508

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

Merged
merged 2 commits into from
Oct 6, 2023
Merged

Upgrade to ring 0.17 #1508

merged 2 commits into from
Oct 6, 2023

Conversation

djc
Copy link
Member
@djc djc commented Oct 2, 2023

Question: do we want to backport this to rustls 0.21? Would enable usage of rustls a on bunch more targets.

@djc djc requested review from cpu and ctz October 2, 2023 09:39
@codecov
Copy link
codecov bot commented Oct 2, 2023

Codecov Report

Merging #1508 (b6bf213) into main (47cae34) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1508   +/-   ##
=======================================
  Coverage   96.46%   96.46%           
=======================================
  Files          74       74           
  Lines       15111    15113    +2     
=======================================
+ Hits        14577    14579    +2     
  Misses        534      534           
Files Coverage Δ
rustls/src/crypto/ring/hash.rs 100.00% <100.00%> (ø)
rustls/src/crypto/ring/hmac.rs 100.00% <100.00%> (ø)
rustls/src/crypto/ring/kx.rs 97.05% <100.00%> (ø)
rustls/src/crypto/ring/sign.rs 96.03% <100.00%> (+0.03%) ⬆️
rustls/src/webpki/verify.rs 99.44% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@djc
Copy link
Member Author
djc commented Oct 2, 2023

@aochagavia the instruction count differences seem pretty worrying. Could you run time-based tests on your fancy new server for this PR?

Copy link
Member
@cpu cpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, just a couple nits/comments

@cpu cpu mentioned this pull request Oct 2, 2023
@aochagavia
Copy link
Contributor

@aochagavia the instruction count differences seem pretty worrying. Could you run time-based tests on your fancy new server for this PR?

I've been focusing on #1485, so we don't have automated time-based benchmarks at the moment. I could spend some time tomorrow to create a bunch of ad-hoc criterion benchmarks and run them manually. Would that help?

@ctz
Copy link
Member
ctz commented Oct 2, 2023

I could spend some time tomorrow to create a bunch of ad-hoc criterion benchmarks

I actually have some of these on the aws-lc-rs branch -- will extract them to merge separately.

@ctz ctz mentioned this pull request Oct 2, 2023
@ctz
Copy link
Member
ctz commented Oct 2, 2023

I could spend some time tomorrow to create a bunch of ad-hoc criterion benchmarks

I actually have some of these on the aws-lc-rs branch -- will extract them to merge separately.

That is #1511 -- local runs after merging that onto this gives:

 name                                                             main.txt ns/iter  ring17.txt ns/iter  diff ns/iter   diff %  speedup 
 bench_ewouldblock                                                11                11                             0    0.00%   x 1.00 
 crypto::ring::kx::benchmarks::bench_ecdh_p256                    52,784            51,970                      -814   -1.54%   x 1.02 
 crypto::ring::kx::benchmarks::bench_ecdh_p384                    769,208           765,313                   -3,895   -0.51%   x 1.01 
 crypto::ring::kx::benchmarks::bench_x25519                       54,136            75,106                    20,970   38.74%   x 0.72 ⬅
 crypto::ring::sign::benchmarks::bench_ecdsa_p256_sha256          16,739            16,540                      -199   -1.19%   x 1.01 
 crypto::ring::sign::benchmarks::bench_ecdsa_p384_sha384          415,218           411,350                   -3,868   -0.93%   x 1.01 
 crypto::ring::sign::benchmarks::bench_eddsa                      15,920            41,516                    25,596  160.78%   x 0.38 ⬅
 crypto::ring::sign::benchmarks::bench_load_and_validate_eddsa    15,033            40,857                    25,824  171.78%   x 0.37 ⬅
 crypto::ring::sign::benchmarks::bench_load_and_validate_p256     11,426            11,321                      -105   -0.92%   x 1.01 
 crypto::ring::sign::benchmarks::bench_load_and_validate_p384     385,406           384,189                   -1,217   -0.32%   x 1.00 
 crypto::ring::sign::benchmarks::bench_load_and_validate_rsa2048  21,941            21,666                      -275   -1.25%   x 1.01 
 crypto::ring::sign::benchmarks::bench_load_and_validate_rsa4096  80,350            77,442                    -2,908   -3.62%   x 1.04 
 crypto::ring::sign::benchmarks::bench_rsa2048_pkcs1_sha256       500,895           502,346                    1,451    0.29%   x 1.00 
 crypto::ring::sign::benchmarks::bench_rsa2048_pss_sha256         507,693           503,370                   -4,323   -0.85%   x 1.01 
 tls12::prf::benchmarks::bench_sha256                             2,436             2,370                        -66   -2.71%   x 1.03 
 tls13::key_schedule::benchmarks::bench_sha256                    10,269            10,030                      -239   -2.33%   x 1.02 

@djc
Copy link
Member Author
djc commented Oct 2, 2023

@briansmith are these performance changes to be expected?

@briansmith
Copy link
Contributor

It looks like it is just Curve25519? The faster Curve25519 will come in ring 0.17.1. I will ping you with the PR when it is ready.

@briansmith
Copy link
Contributor

@ctz what is the exact hardware you are running on?

FWIW, I do think the Curve25519 regressions would be expected although I thought they would be smaller than that. There is a better-optimized Curve25519 that I brought into ring 0.17.0 as part of the BoringSSL merge but didn't enable because I wanted to do some additional review/testing.

In the case of RSA, it looks like the benchmarks are noisy since we wouldn't expect PSS vs PKCS#1 to make a difference. If you could clean up the noise it would be great. BoringSSL did make a change that might have negatively affected performance slightly, and my analogous change might have affected performance slightly more than that. If so, it can be fixed.

Similarly, some other algorithms will also get faster because I brought in new faster code, but didn't hook it up. However, unlike Curve25519, there weren't any major changes that would have regressed performance, at least intentionally, IIRC.

@briansmith
Copy link
Contributor

I would suggest waiting a bit before doing this, until more of the perf work in 0.17.1 is done, so that we can understand how that work affects the build requirements. It might require a newer GCC and/or clang than 0.17.0 requires right now, and I'd like to get that all clarified.

@briansmith
Copy link
Contributor

@ctz briansmith/ring#1688 is the PR for adding the new optimized Curve25519.

@ctz
Copy link
Member
ctz commented Oct 3, 2023

@ctz what is the exact hardware you are running on?

64-bit Linux on Intel Skylake -- specifically i7-7820X.

@djc
Copy link
Member Author
djc commented Oct 4, 2023

Should we hold off on merging this until the performance regresssion is dealt with? Should we hold off on releasing a 0.21.x release with this until the performance regression is dealt with? (I'm thinking maybe not and yes.)

@ctz
Copy link
Member
ctz commented Oct 5, 2023

do we want to backport this to rustls 0.21?

I would think probably not? I feel rustls 0.21 and rustls-webpki 0.101 should be maintenance/serious bug fixes only at this point.

Should we hold off on merging this until the performance regresssion is dealt with? Should we hold off on releasing a 0.21.x release with this until the performance regression is dealt with? (I'm thinking maybe not and yes.)

I'd agree with that assessment. I don't see an eventuality where the first 0.22.x release goes out with ring 0.16.

This PR probably also depends on (or could incorporate) taking rustls-webpki==0.102.0-alpha.4 -- see eg fb8ee75

@djc
Copy link
Member Author
djc commented Oct 5, 2023

Hmm, I think I disagree. Clearly there's a lot of excitement about ring 0.17 (given the amount of issues opened and the number of issues/PRs linking to this PR), probably because of the massively increased portability? The point of not having ring appear in the public API means that we can bump ring without this being externally visible. rustls 0.22 is probably at least a week from being released and even when we release it, it will take the ecosystem a while to update dependencies -- that means that, for the time being, downstreams might be likely to pull two versions of ring into their dependency graphs when there's really no good reason to do that. So I think we should have ring 0.17 backports for webpki 0.101 and rustls 0.21 and release them as soon as we think it's ready, but maybe after the worst of the performance regressions has been addressed.

Or do you see serious risks for rustls 0.21 from our upgrade to ring 0.17 (I don't really). Plus, once we release rustls 0.22 we're on the hook to provide rustls 0.21 maintenance for a year longer -- that can be quite limited but it might still be nice if they are both on the latest ring release.

@ctz
Copy link
Member
ctz commented Oct 5, 2023

The point of not having ring appear in the public API means that we can bump ring without this being externally visible.

I'm not sure we have anything that validates we've achieved this though. I just went to check 0.21 and rustls::cipher_suite::TLS13_AES_256_GCM_SHA384.hash_algorithm() is pub and leaks a ring type. Are there downstream callers of that? Probably not. If there is maybe they will accept "we wrote that pub before pub(crate) existed, and it should've been pub(crate) all along".

I guess it would be interesting if cargo-semver-checks catches that detail if we do the backport.

Or do you see serious risks for rustls 0.21 from our upgrade to ring 0.17 (I don't really).

I don't see this as about risk, more about the extent to which previous release branches are active vs just maintained.

@djc
Copy link
Member Author
djc commented Oct 5, 2023

The point of not having ring appear in the public API means that we can bump ring without this being externally visible.

I'm not sure we have anything that validates we've achieved this though. I just went to check 0.21 and rustls::cipher_suite::TLS13_AES_256_GCM_SHA384.hash_algorithm() is pub and leaks a ring type. Are there downstream callers of that? Probably not. If there is maybe they will accept "we wrote that pub before pub(crate) existed, and it should've been pub(crate) all along".

Hmm, that's fair. Well, if we expose that probably one reason to not backport to 0.21.

I guess it would be interesting if cargo-semver-checks catches that detail if we do the backport.

That would be a really interesting test -- I suppose it would?

Or do you see serious risks for rustls 0.21 from our upgrade to ring 0.17 (I don't really).

I don't see this as about risk, more about the extent to which previous release branches are active vs just maintained.

That's fair. I would be inclined to say that the 0.21 branch should definitely be perceived as "active" since it's what ~everyone is using right now. That doesn't mean that we backport every feature and refactoring, but for something like this which (a) should be (mostly) semver-compatible and (b) makes downstream users` life better with broader compatibility and (c) low risk, I like the cost-benefit of backporting.

It's also really nice to stick with up-to-date dependencies to avoid having duplicates in dependency graphs...

@cpu
Copy link
Member
cpu commented Oct 6, 2023

I like the cost-benefit of backporting.

fwiw, I agree. I don't think it's something we should necessarily do for every dependency but I think for this case it makes sense.

@ctz ctz force-pushed the ring-0.17 branch 2 times, most recently from 5305a96 to c4a38d6 Compare October 6, 2023 14:54
@cpu cpu added this pull request to the merge queue Oct 6, 2023
Merged via the queue into main with commit 092a6af Oct 6, 2023
@cpu cpu deleted the ring-0.17 branch October 6, 2023 15:31
@cpu cpu mentioned this pull request Oct 6, 2023
4 tasks
@cpu
Copy link
Member
cpu commented Oct 6, 2023

Started a 0.21.x backport in #1525

@briansmith
Copy link
Contributor

0.17.1 was released with the performance improvement to Ed25519.

@briansmith
Copy link
Contributor

More of the performance optimizations added in recent BoringSSL changes will appear in upcoming 0.17.x releases. We are trying a new QA process for enabling these.

@djc
Copy link
Member Author
djc commented Oct 9, 2023

I bumped the lockfile to 0.17.2 in #1528, but it didn't seem to help much with the performance regressions seen here.

@briansmith
Copy link
Contributor

Here are the latest benchmarks: briansmith/ring#1688 (comment). The fastest combination is ring 0.17 using Clang 17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0