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

btcec/v2: create new schnorr package for BIP-340, move existing ecdsa implementation into new ecdsa package #1777

Merged
merged 6 commits into from Feb 1, 2022

Commits on Jan 31, 2022

  1. btcec/v2: create new ecdsa package

    In this commit, we create a new package to house the ECDSA-specific
    logic in the new `btcec/v2` pacakge. Thsi c hange is meant to mirror the
    structure of the `dcrec` package, as we'll soon slot in our own custom
    BIP-340 implementation.
    Roasbeef committed Jan 31, 2022
    Copy the full SHA
    eb61742 View commit details
    Browse the repository at this point in the history
  2. chaincfg: add BIP-340 tagged hash implementation

    In this commit, we add an implementation of the BIP-340 tagged hash
    scheme. This initial version can be optimized quite a bit, for example,
    we can hard code the output of frequently used `sha256(tag)` values and
    save two `sha256` invocations.
    Roasbeef committed Jan 31, 2022
    Copy the full SHA
    3b3a6fc View commit details
    Browse the repository at this point in the history
  3. btcec/v2/schnorr: add initial BIP-340 schnorr sig implementation

    In this commit, we add an initial implementation of BIP-340. Mirroring
    the recently added `ecsda` package, we create a new `schnorr` package
    with a unique `Signature` type and `ParsePubkey` function. The new
    `Signature` type implements the fixed-sized 64-byte signatures, and the
    `ParsePubkey` method only accepts pubkeys that are 32-bytes in length,
    with an implicit sign byte.
    
    The signing implementation by default, deviates from BIP-340 as it opts
    to use rfc6979 deterministic signatures by default, which means callers
    don't need to always pass in their own `auxNonce` randomness. A set of
    functional arguments allows callers to pass in their own value, which is
    the way all the included test vectors function.
    
    The other optional functional argument added is the `FastSign` option
    that allows callers to skip the final step of verifying each signature
    they generate.
    Roasbeef committed Jan 31, 2022
    Copy the full SHA
    d6d38ad View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    0bbc831 View commit details
    Browse the repository at this point in the history
  5. btcec/schnorr: add benchmarks for sign/verify

    Benchmarks run w/o fast sign (always verify after you generate a sig):
    ```
    goos: darwin
    goarch: amd64
    pkg: github.com/btcsuite/btcd/btcec/v2/schnorr
    cpu: VirtualApple @ 2.50GHz
    BenchmarkSigVerify-8     	    8000	    152468 ns/op	     960 B/op	      16 allocs/op
    BenchmarkSign-8          	    4939	    215489 ns/op	    1408 B/op	      27 allocs/op
    BenchmarkSignRfc6979-8   	    5106	    217416 ns/op	    2129 B/op	      37 allocs/op
    PASS
    ok  	github.com/btcsuite/btcd/btcec/v2/schnorr	4.629s
    ```
    
    Benchmarks w/ fast sign:
    ```
    goos: darwin
    goarch: amd64
    pkg: github.com/btcsuite/btcd/btcec/v2/schnorr
    cpu: VirtualApple @ 2.50GHz
    BenchmarkSigVerify-8     	    7982	    142826 ns/op	     960 B/op	      16 allocs/op
    BenchmarkSign-8          	   18210	     65908 ns/op	     496 B/op	      12 allocs/op
    BenchmarkSignRfc6979-8   	   16537	     78161 ns/op	    1216 B/op	      22 allocs/op
    PASS
    ok  	github.com/btcsuite/btcd/btcec/v2/schnorr	5.418s
    ```
    Roasbeef committed Jan 31, 2022
    Copy the full SHA
    973fb37 View commit details
    Browse the repository at this point in the history
  6. btcec+chaincfg: use pre-computed tag hash values

    In this commit, we optimize our signature implementation slightly, by
    defining pre-computed sha256(tag) variables for the commonly used
    values.  If a tag matches this, then we'll use that hash value to avoid
    an extra round of hashing.
    Roasbeef committed Jan 31, 2022
    Copy the full SHA
    b7a4622 View commit details
    Browse the repository at this point in the history