Skip to content
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 field func to determine when >= P-N. #2093

Merged
merged 1 commit into from
Feb 20, 2020

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Feb 19, 2020

This is rebased on #2087.

This introduces the ability to determine if a specialized field value is greater than or equal to the field prime minus the group order in constant time. It is also significantly faster than performing the calculation via big integers since it would require a conversion from the specialized type in practice.

Comprehensive tests with 100% coverage and benchmarks are included.

For now, this merely introduces the method without modifying any of the code to make use of it, but it will be useful when working with signatures and public key recovery in the future.

The following benchmark shows a comparison between determining the condition via the new specialized method and via generic big ints:

benchmark                          old ns/op    new ns/op    delta
--------------------------------------------------------------------
BenchmarkIsGtOrEqPrimeMinusOrder   123          10.6         -91.38%

benchmark                          old allocs   new allocs   delta
--------------------------------------------------------------------
BenchmarkIsGtOrEqPrimeMinusOrder   2            0            -100.00%

benchmark                          old bytes    new bytes    delta
--------------------------------------------------------------------
BenchmarkIsGtOrEqPrimeMinusOrder   96           0            -100.00%

@davecgh davecgh added this to the 1.6.0 milestone Feb 19, 2020
@davecgh davecgh force-pushed the secp256k1_add_field_gte_p_minus_n branch from d5bcfd8 to cd5db9f Compare February 19, 2020 05:44
This introduces the ability to determine if a specialized field value is
greater than or equal to the field prime minus the group order in
constant time.  It is also significantly faster than performing the
calculation via big integers since it would require a conversion from
the specialized type in practice.

Comprehensive tests with 100% coverage and benchmarks are included.

For now, this merely introduces the method without modifying any of the
code to make use of it, but it will be useful when working with
signatures and public key recovery in the future.

The following benchmark shows a comparison between determining the
condition via the new specialized method and via generic big ints:

benchmark                          old ns/op    new ns/op    delta
--------------------------------------------------------------------
BenchmarkIsGtOrEqPrimeMinusOrder   123          10.6         -91.38%

benchmark                          old allocs   new allocs   delta
--------------------------------------------------------------------
BenchmarkIsGtOrEqPrimeMinusOrder   2            0            -100.00%

benchmark                          old bytes    new bytes    delta
--------------------------------------------------------------------
BenchmarkIsGtOrEqPrimeMinusOrder   96           0            -100.00%
@davecgh davecgh force-pushed the secp256k1_add_field_gte_p_minus_n branch from cd5db9f to cd441ba Compare February 20, 2020 17:36
@davecgh davecgh merged commit cd441ba into decred:master Feb 20, 2020
@davecgh davecgh deleted the secp256k1_add_field_gte_p_minus_n branch February 20, 2020 18:07
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.

None yet

4 participants