Repository navigation
secp256k1: Introduce internal arith package. - #3752
Merged
Merged
Conversation
jholdstock
reviewed
Jul 27, 2026
davecgh
force-pushed
the
secp256k1_internal_arith
branch
4 times, most recently
from
July 27, 2026 07:22
95157e6 to
309029b
Compare
jholdstock
approved these changes
Jul 28, 2026
davecgh
force-pushed
the
secp256k1_internal_arith
branch
from
July 29, 2026 00:25
309029b to
d74c9d5
Compare
The package currently defines several generic constant time helpers in the main package despite them not being specific to any particular type or algorithm. They are instead arithmetic primitives that are shared by multiple implementations. Notably, the helpers used by the field implementations that will be split into separate packages in future commits to prepare for architecture-specific backend selection. In order to smooth that transition, this moves the helpers into a new internal arith package and updates all call sites to use them. No functional changes are intended. The move is purely organizational and preserves the existing constant time semantics.
This adds dedicated tests for the constant time helpers in the new internal arith package. While the helpers are already well exercised by the upper layers that use them, testing the primitives directly helps ensure their correctness in isolation.
The package currently defines modulus-agnostic 512-bit multiplication and squaring primitives as part of the 64-bit field implementation despite them also being used by the scalar implementation. They are also shared by the field implementations that will be split into separate packages in future commits to prepare for architecture-specific backend selection. In order to smooth that transition, this moves the primitives into the internal arith package and updates all call sites to use them. No functional changes are intended. The move is purely organizational and preserves the existing arithmetic.
This adds dedicated tests for the 512-bit multiplication in the new internal arith package. While it is already already well exercised by the upper layers that use it, testing primitives directly helps ensure correctness in isolation.
This adds dedicated tests for the 512-bit squaring in the new internal arith package. While it is already already well exercised by the upper layers that use it, testing primitives directly helps ensure correctness in isolation.
davecgh
force-pushed
the
secp256k1_internal_arith
branch
from
November 20, 2026 07:10
d74c9d5 to
49e52a7
Compare
dcr-approvals-proxy
approved these changes
Nov 20, 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.
This is rebased on #3731.
The package currently defines several generic constant time helpers and modulus-agnostic 512-bit multiplication and squaring in the main package and are shared by the scalar implementation and both field implementations.
The field implementations will eventually be split into separate packages in the future to prepare for architecture-specific backend selection.
In order to smooth that transition, this moves the aforementioned helpers and modulus-agnostic code into an internal
arithpackage and updates all call sites to use them.While the helpers and arithmetic are already well exercised by the upper layers that use them, testing the primitives directly helps ensure their correctness in isolation, so this also adds dedicated tests for all functions moved to the new internal package.
No functional changes are intended. The move is purely organizational and preserves the existing constant time semantics as well as the existing arithmetic.
It is implemented via a series of commits to ease the review process. See the individual commit descriptions for details.