-
Notifications
You must be signed in to change notification settings - Fork 296
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
secp256k1: Add fixed-precision group order type. #2060
Conversation
0099740
to
5de2f48
Compare
Test coverage:
|
4834d4f
to
97b0625
Compare
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.
This was a doozy to review indeed :P
Only two small nits.
97b0625
to
9d41b55
Compare
5646278
to
2baa8f2
Compare
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.
Woot! 🎉
2baa8f2
to
406e4d3
Compare
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.
Wheew, looks good.
406e4d3
to
98b4c94
Compare
This introduces a specialized type for handling arithmetic modulo the group order which is significantly faster than using big integers from the standard library The implementation is also constant time, whereas big integers from the standard library are not, which helps protect against side channel attacks in certain scenarios. Comprehensive tests with 100% coverage and a full suite of benchmarks are included. Due to the fact the code relies on a lot of low-level bit manipulations to achieve the speed and constant time characteristics, it is not the easiest code to review for correctness, so significant effort has been put into attempting to clearly explain the details via comments to help with review. For now, this merely introduces the type without modifying any of the code to make use of it, and it also does not yet include the ability to perform inversions which will be required in order to switch over to it. That capability will be added in a future commit. The following benchmarks show a comparison between the new specialized type and generic big ints for various operations: benchmark old ns/op new ns/op delta ------------------------------------------------------------ BenchmarkModN 267 18.9 -92.92% BenchmarkZero 7.28 0.64 -91.25% BenchmarkIsZero 0.32 0.32 +0.00% BenchmarkEquals 9.14 5.58 -38.95% BenchmarkAddModN 305 23.8 -92.20% BenchmarkMulModN 457 237 -48.14% BenchmarkSquareModN 459 238 -48.15% BenchmarkNegateModN 295 9.82 -96.67% BenchmarkIsOverHalfOrder 9.25 8.55 -7.57% benchmark old allocs new allocs delta ------------------------------------------------------------ BenchmarkModN 2 0 -100.00% BenchmarkZero 0 0 +0.00% BenchmarkIsZero 0 0 +0.00% BenchmarkEquals 0 0 +0.00% BenchmarkAddModN 2 0 -100.00% BenchmarkMulModN 2 0 -100.00% BenchmarkSquareModN 2 0 -100.00% BenchmarkNegateModN 2 0 -100.00% BenchmarkIsOverHalfOrder 0 0 +0.00%
98b4c94
to
6889976
Compare
This requires #2059.
This introduces a specialized type for handling arithmetic modulo the group order which is significantly faster than using big integers from the standard library
The implementation is also constant time, whereas big integers from the standard library are not, which helps protect against side channel attacks in certain scenarios.
Comprehensive tests with 100% coverage and a full suite of benchmarks are included.
Due to the fact the code relies on a lot of low-level bit manipulations to achieve the speed and constant time characteristics, it is not the easiest code to review for correctness, so significant effort has been put into attempting to clearly explain the details via comments to help with review.
For now, this merely introduces the type without modifying any of the code to make use of it, and it also does not yet include the ability to perform inversions which will be required in order to switch over to it. That capability will be added in a future commit.
The following benchmarks show a comparison between the new specialized type and generic big ints for various operations: