]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tpm2-util: add common array for TPM2 hash algorithms
authorLennart Poettering <lennart@poettering.net>
Mon, 23 Oct 2023 20:36:09 +0000 (22:36 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 Nov 2023 10:23:34 +0000 (11:23 +0100)
This is useful to enumerate all hash algorithms we want to predict
measurements for.

src/shared/tpm2-util.c
src/shared/tpm2-util.h

index 5373fa12a59a31f47966037b129c423c3022597f..bdb10cb4fb464d7054f76d5bbdc88c3c305c7eb9 100644 (file)
@@ -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;
 
index 20121222dd730eabe490f5b9a3e64e9adfee8b86..9969ba0981065a90beaaa5be026d9a0d478cab43 100644 (file)
@@ -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 <tss2/tss2_esys.h>
@@ -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;