From: Lennart Poettering Date: Mon, 23 Oct 2023 20:36:09 +0000 (+0200) Subject: tpm2-util: add common array for TPM2 hash algorithms X-Git-Tag: v255-rc1~27^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b52e9505983760628d73e6d87ce5d6393c260827;p=thirdparty%2Fsystemd.git tpm2-util: add common array for TPM2 hash algorithms This is useful to enumerate all hash algorithms we want to predict measurements for. --- diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 5373fa12a59..bdb10cb4fb4 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -5419,6 +5419,16 @@ int tpm2_extend_bytes( } #endif +const uint16_t tpm2_hash_algorithms[] = { + TPM2_ALG_SHA1, + TPM2_ALG_SHA256, + TPM2_ALG_SHA384, + TPM2_ALG_SHA512, + 0, +}; + +assert_cc(ELEMENTSOF(tpm2_hash_algorithms) == TPM2_N_HASH_ALGORITHMS + 1); + char *tpm2_pcr_mask_to_string(uint32_t mask) { _cleanup_free_ char *s = NULL; diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index 20121222dd7..9969ba09810 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -37,6 +37,8 @@ static inline bool TPM2_PCR_MASK_VALID(uint32_t pcr_mask) { #define FOREACH_PCR_IN_MASK(pcr, mask) BIT_FOREACH(pcr, mask) +#define TPM2_N_HASH_ALGORITHMS 4U + #if HAVE_TPM2 #include @@ -353,6 +355,8 @@ int tpm2_asym_alg_from_string(const char *alg) _pure_; char *tpm2_pcr_mask_to_string(uint32_t mask); +extern const uint16_t tpm2_hash_algorithms[]; + typedef struct { uint32_t search_pcr_mask; const char *device;