tpm2: add TPM2B_*_MAKE(), TPM2B_*_CHECK_SIZE() macros

The tpm2-tss library has many structs with only an array and size; these macros
make it easy to assign to these structs.
This commit is contained in:
Dan Streetman
2023-08-04 10:57:07 -04:00
parent 07c0406117
commit 53b91e1981
4 changed files with 72 additions and 23 deletions
+4 -11
View File
@@ -831,18 +831,11 @@ static int verb_sign(int argc, char *argv[], void *userdata) {
if (tpmalg < 0)
return log_error_errno(tpmalg, "Unsupported PCR bank");
TPM2B_DIGEST pcr_digest = {
.size = p->value_size,
};
assert(sizeof(pcr_digest.buffer) >= p->value_size);
memcpy_safe(pcr_digest.buffer, p->value, p->value_size);
Tpm2PCRValue pcr_value = TPM2_PCR_VALUE_MAKE(TPM_PCR_INDEX_KERNEL_IMAGE,
tpmalg,
TPM2B_DIGEST_MAKE(p->value, p->value_size));
Tpm2PCRValue pcr_value = TPM2_PCR_VALUE_MAKE(TPM_PCR_INDEX_KERNEL_IMAGE, tpmalg, pcr_digest);
TPM2B_DIGEST pcr_policy_digest;
r = tpm2_digest_init(TPM2_ALG_SHA256, &pcr_policy_digest);
if (r < 0)
return r;
TPM2B_DIGEST pcr_policy_digest = TPM2B_DIGEST_MAKE(NULL, TPM2_SHA256_DIGEST_SIZE);
r = tpm2_calculate_policy_pcr(&pcr_value, 1, &pcr_policy_digest);
if (r < 0)