Skip to content

Go 1.26 support - #44

Merged
turbolent merged 23 commits into
mainfrom
tarak/go1.26-cgo-only
Aug 11, 2026
Merged

Go 1.26 support#44
turbolent merged 23 commits into
mainfrom
tarak/go1.26-cgo-only

Conversation

@tarakby

@tarakby tarakby commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

closes #40

  • ECDSA on P-256 is based on Go crypto standard lib implements (no changes)
  • ECDSA on SECp256k1 is based on go-etehereum/crypto/secp256k1
    • this requires cgo, CGO_ENABLED=1, in the past version SECp256k1 did not use cgo
    • signatures generation is now based on RFC6979. The signatures are therefore deterministic. Moreover they are always normalized with a lower S. These are not required or guaranteed by the crypto package, and the signature determinism may change in future updates of the package. Therefore, applications must not make assumptions about the signatures determinism.
    • verification still accepts both low S and high S versions of the valid signature. Although the underlying go-ethereum verification enforces non-malleability (low S only), signatures in this package are still malleable (no change compared to prior versions).

This PR also removes the non-cgo build mode, which is used to build the library without cgo (CGO_ENABLED=0) while disabling BLS. Now that ECDSA secp256k1 also uses cgo, the non-cgo mode has very limited utility and is discontinued.

Bench of ECDSA secp256k1 before this update:

cpu: Apple M3
BenchmarkECDSASecp256k1Sign/Single_sign_ECDSA_secp256k1-8                  35007             33050 ns/op
BenchmarkECDSASecp256k1Verify/verify_ECDSA_secp256k1-8                      7588            143643 ns/op

Bench of ECDSA secp256k1 after this update:

cpu: Apple M3
BenchmarkECDSASecp256k1Sign/Single_sign_ECDSA_secp256k1-8                  79647             14783 ns/op
BenchmarkECDSASecp256k1Verify/verify_ECDSA_secp256k1-8                     73384             16207 ns/op

@tarakby
tarakby marked this pull request as ready for review August 6, 2026 19:42

@turbolent turbolent left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the code from a Go-perspective, but I don't have the expertise to review the crypto changes

Comment thread ecdsa_test.go
Comment thread ecdsa_secp256k1.go Outdated
@turbolent

Copy link
Copy Markdown
Member

Could you please improve the PR title?

Comment thread ecdsa_p256.go Outdated
Comment thread ecdsa_secp256k1.go
Comment thread ecdsa.go Outdated
Comment thread ecdsa.go Outdated
Comment thread ecdsa_secp256k1.go
@tarakby tarakby changed the title Tarak/go1.26 cgo only Go 1.26 support Aug 7, 2026
@tarakby
tarakby requested a review from turbolent August 7, 2026 20:56
Comment thread ecdsa_secp256k1.go
- return untyped nil interfaces on key decoding errors
- return false instead of panicking in Equals(nil)
- reject hashers whose computed hash is shorter than their declared size
- clip the capacity of secp256k1 signatures sliced from the [R||S||V] buffer
- make lazy PublicKey() construction safe for concurrent use
- derive (N-1)/2 from N and cross-check the secp256k1 constants
  against go-ethereum at initialization
- restore the P-256 public key length check
- add tests: RFC 6979 known-answer vectors, concurrent PublicKey,
  nil inputs, dishonest hasher, compressed edge points
- build the public key eagerly at private key construction
  instead of lazily in PublicKey(), which removes the concurrency guards
- read the secp256k1 curve constants from go-ethereum
  instead of hardcoding them and cross-checking
- check the hasher output in bytes only, based on len(h),
  and drop the redundant hasher.Size() check
- drop the P-256 public key length check,
  already covered by ParseUncompressedPublicKey
- return the untyped nil once after the switch in the decoding functions
- move the nil-input checks to sign_test_utils.go so they cover all algos,
  and extend them to DecodePublicKeyCompressed
- document that the RFC 6979 vectors only test the current implementation,
  not a property the package guarantees
- drop the concurrent PublicKey and compressed edge point tests
Comment thread ecdsa.go
Comment thread ecdsa_secp256k1.go
Comment thread ecdsa.go Outdated
Comment thread ecdsa.go Outdated
Comment thread ecdsa.go Outdated
Comment thread ecdsa.go Outdated
Comment thread ecdsa_secp256k1.go Outdated
@janezpodhostnik

Copy link
Copy Markdown
Contributor

I see that pretty much all of my comments a re covered in #46. I wish I saw that sooner :). I'll resolve my comments

@turbolent
turbolent merged commit 84252ae into main Aug 11, 2026
3 checks passed
@turbolent
turbolent deleted the tarak/go1.26-cgo-only branch August 11, 2026 20:17
@zhangchiqing
zhangchiqing restored the tarak/go1.26-cgo-only branch August 12, 2026 03:27
@zhangchiqing
zhangchiqing deleted the tarak/go1.26-cgo-only branch August 12, 2026 03:28
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.

update to go1.26

3 participants