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: Optimize field inverse calc. #3421

Merged
merged 2 commits into from
Aug 12, 2024

Commits on Aug 12, 2024

  1. Configuration menu
    Copy the full SHA
    2a7dfaf View commit details
    Browse the repository at this point in the history
  2. secp256k1: Optimize field inverse calc.

    This optimizes the field multiplicative inverse calculation to use a
    more optimal addition chain which reduces the number of field squarings
    from 258 to 255 and the number field multiplications from 33 to 15.
    
    This calculation is primarily involved when converting back to affine
    space which is done for various things such as:
    
    - Calculating public keys
    - ECDSA signing
    - Generating shared secrets via ECDHE
    - Public key recovery from a compact signature
    - Schnorr signing and signature verification
    - Calculating hierarchical deterministic extended keys
    
    The following benchmarks show a before and after comparison of field
    inversion as well as how it that translates to public key calculation,
    schnorr signature verification, and recovery from compact signatures:
    
    name               old time/op   new time/op   delta
    ------------------------------------------------------------------------
    FieldInverse       12.0µs ± 0%   10.9µs ± 1%   -8.96%  (p=0.008 n=10+10)
    PrivateKeyPubKey   35.0µs ± 1%   33.9µs ± 2%   -3.18%  (p=0.008 n=10+10)
    SchnorrSigVerify    122µs ± 1%    121µs ± 1%   -0.82%  (p=0.015 n=10+10)
    RecoverCompact      137µs ± 1%    135µs ± 1%   -1.35%  (p=0.002 n=10+10)
    davecgh committed Aug 12, 2024
    Configuration menu
    Copy the full SHA
    9aba0ce View commit details
    Browse the repository at this point in the history