Skip to content

secp256k1: Introduce internal arith package. - #3752

Merged
davecgh merged 6 commits into
decred:masterfrom
davecgh:secp256k1_internal_arith
Nov 20, 2026
Merged

davecgh merged 6 commits into
decred:masterfrom
davecgh:secp256k1_internal_arith

Conversation

@davecgh

@davecgh davecgh commented Jul 26, 2026

Copy link
Copy Markdown
Member

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 arith package 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.

@davecgh davecgh added this to the 2.2.0 milestone Jul 26, 2026
Comment thread dcrec/secp256k1/curve.go Resolved
Comment thread dcrec/secp256k1/curve_test.go Resolved
@davecgh
davecgh force-pushed the secp256k1_internal_arith branch 4 times, most recently from 95157e6 to 309029b Compare July 27, 2026 07:22
@davecgh
davecgh force-pushed the secp256k1_internal_arith branch from 309029b to d74c9d5 Compare July 29, 2026 00:25
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
davecgh force-pushed the secp256k1_internal_arith branch from d74c9d5 to 49e52a7 Compare November 20, 2026 07:10
@davecgh
davecgh merged commit 49e52a7 into decred:master Nov 20, 2026
32 checks passed
@davecgh
davecgh deleted the secp256k1_internal_arith branch November 20, 2026 07:13
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.

3 participants