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;
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;
}
}
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;
}
}
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;
}