]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tpm2-util: expose more hash algorithms
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Aug 2022 15:30:29 +0000 (17:30 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 19 Aug 2022 19:12:49 +0000 (20:12 +0100)
swtpm supports them, hence maybe support them in our codebase, too

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

index 9bbd5fb27cb593aef184bc499e0098d2ac9618cb..e1a519089366f79790f0daa2d02608780faf5408 100644 (file)
@@ -1443,20 +1443,26 @@ int tpm2_make_luks2_json(
 }
 
 const char *tpm2_pcr_bank_to_string(uint16_t bank) {
-        /* For now, let's officially only support these two. We can extend this later on, should the need
-         * arise. */
-        if (bank == TPM2_ALG_SHA256)
-                return "sha256";
         if (bank == TPM2_ALG_SHA1)
                 return "sha1";
+        if (bank == TPM2_ALG_SHA256)
+                return "sha256";
+        if (bank == TPM2_ALG_SHA384)
+                return "sha384";
+        if (bank == TPM2_ALG_SHA512)
+                return "sha512";
         return NULL;
 }
 
 int tpm2_pcr_bank_from_string(const char *bank) {
-        if (streq_ptr(bank, "sha256"))
-                return TPM2_ALG_SHA256;
         if (streq_ptr(bank, "sha1"))
                 return TPM2_ALG_SHA1;
+        if (streq_ptr(bank, "sha256"))
+                return TPM2_ALG_SHA256;
+        if (streq_ptr(bank, "sha384"))
+                return TPM2_ALG_SHA384;
+        if (streq_ptr(bank, "sha512"))
+                return TPM2_ALG_SHA512;
         return -EINVAL;
 }
 
index ed6a5d1ca2ce3e0650fb112d702cea29c3ae40ac..220eb341ecf49fca99c60faafc60d84bb47cf90d 100644 (file)
@@ -67,12 +67,20 @@ static inline bool TPM2_PCR_MASK_VALID(uint64_t pcr_mask) {
 
 /* We want the helpers below to work also if TPM2 libs are not available, hence define these four defines if
  * they are missing. */
+#ifndef TPM2_ALG_SHA1
+#define TPM2_ALG_SHA1 0x4
+#endif
+
 #ifndef TPM2_ALG_SHA256
 #define TPM2_ALG_SHA256 0xB
 #endif
 
-#ifndef TPM2_ALG_SHA1
-#define TPM2_ALG_SHA1 0x4
+#ifndef TPM2_ALG_SHA384
+#define TPM2_ALG_SHA384 0xC
+#endif
+
+#ifndef TPM2_ALG_SHA512
+#define TPM2_ALG_SHA512 0xD
 #endif
 
 #ifndef TPM2_ALG_ECC