Use cryptobyte inside cryptobackend ASN.1 paths#2372
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR moves DER/ASN.1 parsing and encoding into the per-algorithm cryptobackend/* packages that actually need it (DSA/ECDSA/RSA), reducing adapter logic in the stdlib integration layer and avoiding callback-based parsing across the backend boundary. It also introduces an explicit golang.org/x/crypto dependency for cryptobyte, plus a go generate-driven sync check to keep that version aligned with go/src.
Changes:
- Shift DSA and ECDSA signature ASN.1 handling into
cryptobackend/dsa(Linux) andcryptobackend/ecdsa(Windows), and move Darwin RSA key marshaling intocryptobackend/rsa. - Add
golang.org/x/cryptotocryptobackend/go.mod(forcryptobyte) and record checksums incryptobackend/go.sum. - Add a
go generatehook + test to keepcryptobackend’sx/cryptoversion synced withgo/srcand to enforce a tidy module state.
Show a summary per file
| File | Description |
|---|---|
| patches/0002-Add-crypto-backends.patch | Updates stdlib integration to call backend ASN.1-aware APIs; also includes additional backend-related patch hunks. |
| patches/0001-Vendor-external-dependencies.patch | Updates vendored cryptobackend/* code used by go/src, including new cryptobyte usage paths. |
| cryptobackend/rsa/rsa_darwin.go | Implements RSA key DER parsing/encoding in the Darwin backend using cryptobyte. |
| cryptobackend/go.mod | Adds an explicit golang.org/x/crypto requirement for cryptobyte. |
| cryptobackend/go.sum | Adds checksums for the newly required golang.org/x/crypto version. |
| cryptobackend/dsa/dsa_linux.go | Hides OpenSSL’s DSA ASN.1 signature format behind backend parsing/encoding helpers. |
| cryptobackend/dsa/dsa_windows.go | Simplifies DSA backend API by removing callback-based ASN.1 plumbing. |
| cryptobackend/dsa/dsa_darwin.go | Keeps DSA stub backend signatures aligned with the updated API shape. |
| cryptobackend/dsa/nobackend.go | Updates no-backend stubs to match the simplified DSA API. |
| cryptobackend/ecdsa/ecdsa_windows.go | Implements ASN.1 signature encoding/decoding in the Windows ECDSA backend using cryptobyte. |
| cryptobackend/ecdsa/ecdsa_linux.go | Removes unsupported raw (r,s) ECDSA surface in favor of ASN.1 operations. |
| cryptobackend/ecdsa/ecdsa_darwin.go | Removes unsupported raw (r,s) ECDSA surface in favor of ASN.1 operations. |
| cryptobackend/ecdsa/nobackend.go | Updates no-backend stubs to expose only ASN.1 ECDSA operations. |
| cryptobackend/backend_test.go | Adds go generate + test enforcement for syncing and tidiness of the x/crypto dependency. |
Copilot's findings
- Files reviewed: 13/14 changed files
- Comments generated: 4
de0ebbb to
25357b0
Compare
25357b0 to
60b4f9b
Compare
gdams
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change moves DER/ASN.1 handling into the cryptobackend algorithm packages that actually need it, instead of keeping that parsing and encoding in the standard-library integration layer or passing parser callbacks across the backend boundary. RSA Darwin key marshaling now lives in
cryptobackend/rsa, Windows ECDSA signs and verifies ASN.1 signatures directly incryptobackend/ecdsa, and Linux DSA hides the OpenSSL ASN.1 signature format insidecryptobackend/dsa.This is also why
cryptobackendnow has an explicitgolang.org/x/cryptodependency pinned to the version recorded inpatches/0001-Vendor-external-dependencies.patch, which owns thego/src/go.moddependency hunk. The newgo generatehook incryptobackendreads that patch as the source of truth, runsgo mod tidy, and the matching test verifies that the generated module state is clean. Using the patch instead of the checked-outgosubmodule keeps the check working in CI jobs that do not initialize submodules.Why this is reasonable now: before the backend package was more monolithic, importing
cryptobytein the backend would have expanded the shared backend dependency surface. That would have meant algorithms that do not parse or emit DER, such as AES or hash backends, would still conceptually carry the ASN.1 helper dependency. The backend is now split into algorithm-specific packages, socryptobackend/dsa,cryptobackend/ecdsa, andcryptobackend/rsacan usecryptobytewithout pulling it into unrelated backend packages.The main benefit is a cleaner ownership boundary. Native backend packages now translate between native signature/key formats and Go's expected DER shapes themselves, so
crypto/dsa,crypto/ecdsa, andcrypto/rsado less backend-specific adapter work. This also removes the raw ECDSA backendSign/Verifysurface and letscrypto/ecdsacall the ASN.1 backend operations directly.