1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

tpm2: add tpm2_hash_alg_to_size()

Add function to get the hash size for a hash algorithm
This commit is contained in:
Dan Streetman 2023-07-11 11:11:59 -04:00
parent 240774f5ce
commit c9df1fb119
2 changed files with 14 additions and 0 deletions

View File

@ -4239,6 +4239,18 @@ int tpm2_parse_luks2_json(
return 0;
}
int tpm2_hash_alg_to_size(uint16_t alg) {
if (alg == TPM2_ALG_SHA1)
return 20;
if (alg == TPM2_ALG_SHA256)
return 32;
if (alg == TPM2_ALG_SHA384)
return 48;
if (alg == TPM2_ALG_SHA512)
return 64;
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown hash algorithm id 0x%" PRIx16, alg);
}
const char *tpm2_hash_alg_to_string(uint16_t alg) {
if (alg == TPM2_ALG_SHA1)
return "sha1";

View File

@ -164,6 +164,8 @@ int tpm2_parse_luks2_json(JsonVariant *v, int *ret_keyslot, uint32_t *ret_hash_p
#define TPM2_ALG_RSA 0x1
#endif
int tpm2_hash_alg_to_size(uint16_t alg);
const char *tpm2_hash_alg_to_string(uint16_t alg);
int tpm2_hash_alg_from_string(const char *alg);