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
+2 -5
View File
@@ -444,8 +444,7 @@ static void digest_init(TPM2B_DIGEST *digest, const char *hash) {
/* Make sure the length matches a known hash algorithm */
assert_se(IN_SET(s, TPM2_SHA1_DIGEST_SIZE, TPM2_SHA256_DIGEST_SIZE, TPM2_SHA384_DIGEST_SIZE, TPM2_SHA512_DIGEST_SIZE));
memcpy_safe(digest->buffer, h, s);
digest->size = s;
*digest = TPM2B_DIGEST_MAKE(h, s);
assert_se(digest_check(digest, hash));
}
@@ -726,9 +725,7 @@ static void tpm2b_public_init(TPM2B_PUBLIC *public) {
_cleanup_free_ void *mem = NULL;
size_t len = 0;
assert_se(unhexmem(key, strlen(key), &mem, &len) == 0);
assert_se(len <= sizeof(tpmt.unique.rsa.buffer));
memcpy_safe(tpmt.unique.rsa.buffer, mem, len);
tpmt.unique.rsa.size = len;
tpmt.unique.rsa = TPM2B_PUBLIC_KEY_RSA_MAKE(mem, len);
public->publicArea = tpmt;
}