Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce helper for formatting PCR selection bitmasks #345

Merged
merged 3 commits into from
Sep 14, 2023

Conversation

chrisfenner
Copy link
Member

This change introduces PCClientCompatible.PCRs(), a function that converts a variadic list of PCR indices (as ints) into a PCR selection bitmask. Because of the vagaries of TPM:

  1. That the minimum size of a PCR selection bitmask is not 0, but related to the minimum number of PCRs specified by the profile
  2. That the PC Client Platform TPM Profile specification mandates a minimum but not a maximum number of implementation PCR,

this change creates an interface that could be implemented for other TPM profiles that specify different amounts of PCRs. The vast majority of on-market TPMs will just work with PCClientCompatible.PCRs, even if they implement more than 24 PCRs.

PCRs() can panic if given invalid values; this is to allow it to be inlined into the definition of a structure that needs a PCR selection.

This change introduces PCClientCompatible.PCRs(), a function that
converts a variadic list of PCR indices (as ints) into a PCR selection
bitmask. Because of the vagaries of TPM:

1. That the minimum size of a PCR selection bitmask is not 0, but
   related to the minimum number of PCRs specified by the profile
2. That the PC Client Platform TPM Profile specification mandates a
   minimum but not a maximum number of implementation PCR,

this change creates an interface that could be implemented for other TPM
profiles that specify different amounts of PCRs. The vast majority of
on-market TPMs will just work with PCClientCompatible.PCRs, even if they
implement more than 24 PCRs.

PCRs() can panic if given invalid values; this is to allow it to be
inlined into the definition of a structure that needs a PCR selection.
Copy link
Contributor

@alexmwu alexmwu left a comment

Choose a reason for hiding this comment

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

Great quality-of-life improvement!

tpm2/pcrs.go Outdated
selection := make([]byte, selectionSize)
for _, pcr := range pcrs {
// Panic if negative PCRs are selected.
if pcr < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could pcr be a uint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I had initially used int since functions like len return int but I think uint is way better (no panics now)!

@chrisfenner chrisfenner merged commit ee6cbcd into google:main Sep 14, 2023
4 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.

2 participants