Skip to content

Commit

Permalink
tpm2-util: rename tpm2_calculate_name() → tpm2_calculate_pubkey_name()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
poettering authored and bluca committed Oct 21, 2023
1 parent 242b4be commit b98c4f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/shared/tpm2-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3090,7 +3090,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;

Expand Down Expand Up @@ -3354,7 +3354,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;

Expand Down
2 changes: 1 addition & 1 deletion src/shared/tpm2-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int tpm2_read_public(Tpm2Context *c, const Tpm2Handle *session, const Tpm2Handle
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);
Expand Down
6 changes: 3 additions & 3 deletions src/test/test-tpm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,18 +859,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");
}

Expand Down

0 comments on commit b98c4f1

Please sign in to comment.