You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
systemd/SOURCES/0633-tpm2-util-rename-tpm2_...

84 lines
4.3 KiB

From 0eb3ebe27c866b869d500733b82c7e5b3904a453 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Sat, 21 Oct 2023 16:17:39 +0200
Subject: [PATCH] =?UTF-8?q?tpm2-util:=20rename=20tpm2=5Fcalculate=5Fname()?=
=?UTF-8?q?=20=E2=86=92=20tpm2=5Fcalculate=5Fpubkey=5Fname()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We'll soon have a function for determining the name of an NV index,
hence let's rename the existing function for the same of a public key to
make clear it's about public keys only.
(cherry picked from commit b98c4f1d48124f7152a28cda4bfc9a9dd3136a65)
Related: RHEL-16182
---
src/shared/tpm2-util.c | 4 ++--
src/shared/tpm2-util.h | 2 +-
src/test/test-tpm2.c | 6 +++---
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c
index 5bce39a994..a16e611f27 100644
--- a/src/shared/tpm2-util.c
+++ b/src/shared/tpm2-util.c
@@ -3094,7 +3094,7 @@ static int find_signature(
*
* Since we (currently) hardcode to always using SHA256 for hashing, this returns an error if the public key
* nameAlg is not TPM2_ALG_SHA256. */
-int tpm2_calculate_name(const TPMT_PUBLIC *public, TPM2B_NAME *ret_name) {
+int tpm2_calculate_pubkey_name(const TPMT_PUBLIC *public, TPM2B_NAME *ret_name) {
TSS2_RC rc;
int r;
@@ -3358,7 +3358,7 @@ int tpm2_calculate_policy_authorize(
"Offset 0x%zx wrong after marshalling PolicyAuthorize command", offset);
TPM2B_NAME name = {};
- r = tpm2_calculate_name(&public->publicArea, &name);
+ r = tpm2_calculate_pubkey_name(&public->publicArea, &name);
if (r < 0)
return r;
diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h
index 959a428f08..c980567819 100644
--- a/src/shared/tpm2-util.h
+++ b/src/shared/tpm2-util.h
@@ -175,7 +175,7 @@ int tpm2_index_from_handle(Tpm2Context *c, const Tpm2Handle *handle, TPM2_HANDLE
int tpm2_pcr_read(Tpm2Context *c, const TPML_PCR_SELECTION *pcr_selection, Tpm2PCRValue **ret_pcr_values, size_t *ret_n_pcr_values);
int tpm2_pcr_read_missing_values(Tpm2Context *c, Tpm2PCRValue *pcr_values, size_t n_pcr_values);
-int tpm2_calculate_name(const TPMT_PUBLIC *public, TPM2B_NAME *ret_name);
+int tpm2_calculate_pubkey_name(const TPMT_PUBLIC *public, TPM2B_NAME *ret_name);
int tpm2_calculate_policy_auth_value(TPM2B_DIGEST *digest);
int tpm2_calculate_policy_authorize(const TPM2B_PUBLIC *public, const TPM2B_DIGEST *policy_ref, TPM2B_DIGEST *digest);
int tpm2_calculate_policy_pcr(const Tpm2PCRValue *pcr_values, size_t n_pcr_values, TPM2B_DIGEST *digest);
diff --git a/src/test/test-tpm2.c b/src/test/test-tpm2.c
index a4beb1ff8d..3df6258934 100644
--- a/src/test/test-tpm2.c
+++ b/src/test/test-tpm2.c
@@ -858,18 +858,18 @@ static void check_name(const TPM2B_NAME *name, const char *expect) {
assert_se(memcmp(name->name, e, e_len) == 0);
}
-TEST(calculate_name) {
+TEST(calculate_pubkey_name) {
TPM2B_PUBLIC public;
TPM2B_NAME name;
/* RSA */
tpm2b_public_rsa_init(&public, "9ec7341c52093ac40a1965a5df10432513c539adcf905e30577ab6ebc88ffe53cd08cef12ed9bec6125432f4fada3629b8b96d31b8f507aa35029188fe396da823fcb236027f7fbb01b0da3d87be7f999390449ced604bdf7e26c48657cc0671000f1147da195c3861c96642e54427cb7a11572e07567ec3fd6316978abc4bd92b27bb0a0e4958e599804eeb41d682b3b7fc1f960209f80a4fb8a1b64abfd96bf5d554e73cdd6ad1c8becb4fcf5e8f0c3e621d210e5e2f308f6520ad9a966779231b99f06c5989e5a23a9415c8808ab89ce81117632e2f8461cd4428bded40979236aeadafe8de3f51660a45e1dbc87694e6a36360201cca3ff9e7263e712727");
- assert_se(tpm2_calculate_name(&public.publicArea, &name) >= 0);
+ assert_se(tpm2_calculate_pubkey_name(&public.publicArea, &name) >= 0);
check_name(&name, "000be78f74a470dd92e979ca067cdb2293a35f075e8560b436bd2ccea5da21486a07");
/* ECC */
tpm2b_public_ecc_init(&public, TPM2_ECC_NIST_P256, "238e02ee4fd5598add6b502429f1815418515e4b0d6551c8e816b38cb15451d1", "70c2d491769775ec43ccd5a571c429233e9d30cf0f486c2e01acd6cb32ba93b6");
- assert_se(tpm2_calculate_name(&public.publicArea, &name) >= 0);
+ assert_se(tpm2_calculate_pubkey_name(&public.publicArea, &name) >= 0);
check_name(&name, "000b302787187ba19c82011c987bd2dcdbb652b3a543ccc5cb0b49c33d4caae604a6");
}