for (i = 0; i < chip->nr_allocated_banks; i++) if (ha->alg_id == chip->allocated_banks[i].alg_id)
digest_size = chip->allocated_banks[i].digest_size; /* should never happen */ if (!digest_size) return -EINVAL;
digest.alg_id = ha->alg_id;
rc = tpm_pcr_read(chip, ha->pcr, &digest); if (rc) return rc; for (i = 0; i < digest_size; i++)
str += sprintf(str, "%02X", digest.digest[i]);
str += sprintf(str, "\n");
return str - buf;
}
/* * The following set of defines represents all the magic to build * the per hash attribute groups for displaying each bank of PCRs. * The only slight problem with this approach is that every PCR is * hard coded to be present, so you don't know if an PCR is missing * until a cat of the file returns -EINVAL * * Also note you must ignore checkpatch warnings in this macro * code. This is deep macro magic that checkpatch.pl doesn't * understand.
*/
#define PCR_ATTR_BUILD(_alg, _hash) \
PCR_ATTRS(_alg, _hash) \
PCR_ATTR_GROUP_ARRAY(_alg, _hash); \
PCR_ATTR_GROUP(_alg, _hash) /* * End of macro structure to build an attribute group containing 24 * PCR value files for each supported hash algorithm
*/
/* * The next set of macros implements the cleverness for each hash to * build a static attribute group called pcr_group_<hash> which can be * added to chip->groups[]. * * The first argument is the TPM algorithm id and the second is the * hash used as both the suffix and the group name. Note: the group * name is a directory in the top level tpm class with the name * pcr-<hash>, so it must not clash with any other names already * in the sysfs directory.
*/
PCR_ATTR_BUILD(TPM_ALG_SHA1, sha1);
PCR_ATTR_BUILD(TPM_ALG_SHA256, sha256);
PCR_ATTR_BUILD(TPM_ALG_SHA384, sha384);
PCR_ATTR_BUILD(TPM_ALG_SHA512, sha512);
PCR_ATTR_BUILD(TPM_ALG_SM3_256, sm3);
void tpm_sysfs_add_device(struct tpm_chip *chip)
{ int i;
/* add one group for each bank hash */ for (i = 0; i < chip->nr_allocated_banks; i++) { switch (chip->allocated_banks[i].alg_id) { case TPM_ALG_SHA1:
chip->groups[chip->groups_cnt++] = &pcr_group_sha1; break; case TPM_ALG_SHA256:
chip->groups[chip->groups_cnt++] = &pcr_group_sha256; break; case TPM_ALG_SHA384:
chip->groups[chip->groups_cnt++] = &pcr_group_sha384; break; case TPM_ALG_SHA512:
chip->groups[chip->groups_cnt++] = &pcr_group_sha512; break; case TPM_ALG_SM3_256:
chip->groups[chip->groups_cnt++] = &pcr_group_sm3; break; default: /* * If triggers, send a patch to add both a * PCR_ATTR_BUILD() macro above for the * missing algorithm as well as an additional * case in this switch statement.
*/
dev_err(&chip->dev, "TPM with unsupported bank algorithm 0x%04x",
chip->allocated_banks[i].alg_id); break;
}
}
/* * This will only trigger if someone has added an additional * hash to the tpm_algorithms enum without incrementing * TPM_MAX_HASHES.
*/
WARN_ON(chip->groups_cnt > TPM_MAX_HASHES + 1);
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.