tpm2-util: make tpm2_pcr_bank_from_string() case-insensitive
This way we can use it directly in measure.c, and thus remove a bit of redundant code. OpenSSL prefers uppercasing the MD names, others don't hence let's be lenient here.
This commit is contained in:
committed by
Yu Watanabe
parent
e7f64b8962
commit
f92ebc86dd
+3
-19
@@ -531,22 +531,6 @@ static int verb_calculate(int argc, char *argv[], void *userdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static TPM2_ALG_ID convert_evp_md_name_to_tpm2_alg(const EVP_MD *md) {
|
||||
const char *mdname;
|
||||
|
||||
mdname = EVP_MD_name(md);
|
||||
if (strcaseeq(mdname, "sha1"))
|
||||
return TPM2_ALG_SHA1;
|
||||
if (strcaseeq(mdname, "sha256"))
|
||||
return TPM2_ALG_SHA256;
|
||||
if (strcaseeq(mdname, "sha384"))
|
||||
return TPM2_ALG_SHA384;
|
||||
if (strcaseeq(mdname, "sha512"))
|
||||
return TPM2_ALG_SHA512;
|
||||
|
||||
return TPM2_ALG_ERROR;
|
||||
}
|
||||
|
||||
static int verb_sign(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(pcr_state_free_all) PcrState *pcr_states = NULL;
|
||||
@@ -637,9 +621,9 @@ static int verb_sign(int argc, char *argv[], void *userdata) {
|
||||
assert(sizeof(intermediate_digest.buffer) >= SHA256_DIGEST_SIZE);
|
||||
sha256_direct(p->value, p->value_size, intermediate_digest.buffer);
|
||||
|
||||
TPM2_ALG_ID tpmalg = convert_evp_md_name_to_tpm2_alg(p->md);
|
||||
if (tpmalg == TPM2_ALG_ERROR) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Unsupported PCR bank");
|
||||
int tpmalg = tpm2_pcr_bank_from_string(EVP_MD_name(p->md));
|
||||
if (tpmalg < 0) {
|
||||
log_error_errno(tpmalg, "Unsupported PCR bank");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
||||
@@ -2048,13 +2048,13 @@ const char *tpm2_pcr_bank_to_string(uint16_t bank) {
|
||||
}
|
||||
|
||||
int tpm2_pcr_bank_from_string(const char *bank) {
|
||||
if (streq_ptr(bank, "sha1"))
|
||||
if (strcaseeq_ptr(bank, "sha1"))
|
||||
return TPM2_ALG_SHA1;
|
||||
if (streq_ptr(bank, "sha256"))
|
||||
if (strcaseeq_ptr(bank, "sha256"))
|
||||
return TPM2_ALG_SHA256;
|
||||
if (streq_ptr(bank, "sha384"))
|
||||
if (strcaseeq_ptr(bank, "sha384"))
|
||||
return TPM2_ALG_SHA384;
|
||||
if (streq_ptr(bank, "sha512"))
|
||||
if (strcaseeq_ptr(bank, "sha512"))
|
||||
return TPM2_ALG_SHA512;
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -2068,9 +2068,9 @@ const char *tpm2_primary_alg_to_string(uint16_t alg) {
|
||||
}
|
||||
|
||||
int tpm2_primary_alg_from_string(const char *alg) {
|
||||
if (streq_ptr(alg, "ecc"))
|
||||
if (strcaseeq_ptr(alg, "ecc"))
|
||||
return TPM2_ALG_ECC;
|
||||
if (streq_ptr(alg, "rsa"))
|
||||
if (strcaseeq_ptr(alg, "rsa"))
|
||||
return TPM2_ALG_RSA;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user