Skip to content

Stop using linknames in the Windows ecdsa backend#2371

Merged
qmuntal merged 1 commit into
microsoft/mainfrom
dev/qmuntal/ecdsawin
Jun 16, 2026
Merged

Stop using linknames in the Windows ecdsa backend#2371
qmuntal merged 1 commit into
microsoft/mainfrom
dev/qmuntal/ecdsawin

Conversation

@qmuntal

@qmuntal qmuntal commented Jun 16, 2026

Copy link
Copy Markdown
Member

The CNG backend had to use linknames to encode/decode the ASN.1 DER ECDSA signature using the logic from crypto/ecdsa. Other backends don't have this problem because they support ASN.1 signatures natively.

This PR decouples the Windows backend from the crypto/ecdsa encoding implementation by removing the linknamed functions and adding a new backend API that returns the raw ECDSA signature components so that crypto/ecdsa can encode them appropriately, as it already does for the native FIPS 140 module.

Note that we could make the OpenSSL/Darwin backend to operate on raw signatures too, but that would make the backend implementation a bit more complex and less performance, given that those are their native signature representations.

Copilot AI review requested due to automatic review settings June 16, 2026 10:37
@qmuntal qmuntal requested a review from a team as a code owner June 16, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the Windows ECDSA backend’s dependency on //go:linkname for ASN.1 signature encoding/decoding by extending the ECDSA backend API to support (a) native ASN.1 signatures where available and (b) raw (r, s) signature components where needed, so crypto/ecdsa can perform encoding/decoding itself.

Changes:

  • Updated crypto/ecdsa’s GenerateKey, SignASN1, and VerifyASN1 systemcrypto fast paths to use the new cryptobackend/ecdsa APIs and to gate on SupportsCurve.
  • Extended the ECDSA backend surface to include Sign/Verify (raw components) alongside SignASN1/VerifyASN1 (DER), allowing Windows to avoid linknames.
  • Updated the vendored backend implementation in the vendor patch to match the new API shape.
Show a summary per file
File Description
patches/0002-Add-crypto-backends.patch Switch crypto/ecdsa to prefer backend ASN.1 signing/verification and fall back to raw (r,s) when ASN.1 isn’t supported (removes need for linknames).
patches/0001-Vendor-external-dependencies.patch Updates vendored cryptobackend/ecdsa implementations to the new API (adds raw/component + ASN.1 entrypoints).
cryptobackend/ecdsa/ecdsa_windows.go Removes linkname-based ASN.1 dependency by implementing raw Sign/Verify and returning ErrUnsupported for ASN.1 operations.
cryptobackend/ecdsa/ecdsa_linux.go Adds raw/component entrypoints as unsupported (since Linux backend uses ASN.1 natively) and exposes ASN.1 operations.
cryptobackend/ecdsa/ecdsa_darwin.go Adds raw/component entrypoints as unsupported (since Darwin backend uses ASN.1 natively) and exposes ASN.1 operations.
cryptobackend/ecdsa/nobackend.go Adds stubbed (panic) definitions for the expanded ECDSA backend API.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment thread patches/0002-Add-crypto-backends.patch
Comment thread patches/0002-Add-crypto-backends.patch
@qmuntal qmuntal merged commit 4a0c813 into microsoft/main Jun 16, 2026
57 checks passed
@qmuntal qmuntal deleted the dev/qmuntal/ecdsawin branch June 16, 2026 12:19
@qmuntal qmuntal linked an issue Jun 16, 2026 that may be closed by this pull request
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.

Clean up crypto backend patches

3 participants