Skip to content

tpm2: fix selector checks in union accessors - #451

Merged
chrisfenner merged 1 commit into
google:mainfrom
protonnegativo:fix/389-union-selectors
Oct 27, 2026
Merged

chrisfenner merged 1 commit into
google:mainfrom
protonnegativo:fix/389-union-selectors

Conversation

@protonnegativo

Copy link
Copy Markdown
Contributor

Fixes #389.

TPMUAsymScheme.ECDH() compared the selector against TPMAlgRSASSA. The same copy-paste mistake is in four more union accessors in tpm2/structures.go, so this fixes them together:

  • TPMUCapabilities.ACTData() checked TPMCapAuthPolicies instead of TPMCapACT
  • TPMUKDFScheme.KDF1SP80056A(), KDF2() and KDF1SP800108() checked TPMAlgMGF1
  • TPMUAsymScheme.ECDH() checked TPMAlgRSASSA

Each of them returned an error for the member it is named after, and panicked on the type assertion when the selector was the wrong constant (for example KDF2() on an MGF1 scheme). The error messages of KDF2(), ECDSA() and ECDAA() also named another member (mgf1, rsassa); those are fixed too. OAEP() is not touched.

TestUnionAccessors in the new tpm2/structures_test.go builds each union with its own selector and calls the accessor; all five cases fail on main, and the WrongMember case panics there. go test ./..., go vet ./tpm2/ and gofmt pass.

ACTData, KDF1SP80056A, KDF2, KDF1SP800108 and TPMUAsymScheme.ECDH
compared the union selector against the wrong constant, so they
returned an error for the member they are named after (and could
panic on the type assertion when the selector matched the wrong
constant). Also fix the error messages of KDF2, ECDSA and ECDAA,
which named another member.

Fixes google#389
@protonnegativo
protonnegativo requested review from a team and jkl73 as code owners October 27, 2026 04:51

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

Thank you for this fix!

@chrisfenner
chrisfenner merged commit 6c18a16 into google:main Oct 27, 2026
12 checks passed
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.

Possible Typo in TPMUAsymScheme Method?

2 participants