Skip to content

Update to Go 1.26#42

Merged
turbolent merged 6 commits into
mainfrom
bastian/go-1.26
Jun 23, 2026
Merged

Update to Go 1.26#42
turbolent merged 6 commits into
mainfrom
bastian/go-1.26

Conversation

@turbolent

@turbolent turbolent commented Jun 17, 2026

Copy link
Copy Markdown
Member

Update to Go 1.26. Go 1.25 will be EOL around August.

There were two problems:

  • Since Go 1.26, (*ecdsa.PrivateKey).ECDH serializes via Bytes(), which reads X/Y and panics on the nil coordinates.

    goecdsaPrivateKey called priv.ECDH() to derive the public point from the scalar, but the public affine coordinates X/Y are not set at that point.

    Fixed by building the ecdh.PrivateKey directly from the scalar bytes instead, which avoids reading X/Y. Behavior is unchanged and compatible with Go 1.20+.

  • Go 1.26 deprecated direct access to the raw crypto/ecdsa key fields (PrivateKey.D, PublicKey.X/Y).

    The replacement API only works for NIST curves, not the secp256k1 this package supports via btcec — so the fields can't be fully removed without a risky rewrite.

    Fixed by suppressing in .golangci.yml for now, refactoring is out of scope.

@janezpodhostnik

Copy link
Copy Markdown
Contributor

I don't know enough about this to review it. Does this change reference any existing code/docs I could get a link to.

@turbolent

Copy link
Copy Markdown
Member Author

Comment thread ecdsa.go
Comment thread ecdsa.go
@turbolent turbolent changed the title Fix ECDSA P-256 private key construction panic on Go 1.26 Update to Go 1.26 Jun 22, 2026

@zhangchiqing zhangchiqing 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.

Looks good

@turbolent

Copy link
Copy Markdown
Member Author

Created https://github.com/onflow/flow-okrs/issues/239 to track the work for replacing the usage of the APIs which were deprecated in Go 1.26 and we just ignore for now

@turbolent turbolent merged commit b566d9b into main Jun 23, 2026
3 checks passed
@turbolent turbolent deleted the bastian/go-1.26 branch June 23, 2026 14:56
Comment thread ecdsa.go
Comment on lines -226 to +238
// use crypto/ecdh implementation to perform base scalar multiplication
// of an ECDH private key, because crypto/elliptic deprecated `ScalarBaseMult`
ecdhPriv, err := priv.ECDH()
// Perform the base scalar multiplication using crypto/ecdh,
// because crypto/elliptic deprecated `ScalarBaseMult`.
//
// We build the ecdh.PrivateKey directly from the scalar bytes
// instead of going through `priv.ECDH()`: since Go 1.26,
// ecdsa's `(*PrivateKey).ECDH` serializes the key via `(*PrivateKey).Bytes`,
// which reads the public affine coordinates `X`/`Y`.
// Those are not set yet at this point (we are computing them),
// so that path dereferences nil and panics.
// Constructing the ecdh key from the scalar avoids reading `X`/`Y`
// and works across Go versions.
scalarLen := bitsToBytes(curve.Params().N.BitLen())
ecdhPriv, err := ecdh.P256().NewPrivateKey(d.FillBytes(make([]byte, scalarLen)))

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.

In my review, I focused on scrutinizing the correctness of this line. To the best of my understanding everything is good

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.

5 participants