Skip to content

Commit

Permalink
tpm: seal/unseal for TPM 2.0
Browse files Browse the repository at this point in the history
Added tpm_trusted_seal() and tpm_trusted_unseal() API for sealing
trusted keys.

This patch implements basic sealing and unsealing functionality for
TPM 2.0:

* Seal with a parent key using a 20 byte auth value.
* Unseal with a parent key using a 20 byte auth value.

Signed-off-by: Jarkko Sakkinen <[email protected]>
Signed-off-by: Peter Huewe <[email protected]>
  • Loading branch information
Jarkko Sakkinen authored and PeterHuewe committed Oct 18, 2015
1 parent fe351e8 commit 954650e
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 3 deletions.
76 changes: 76 additions & 0 deletions drivers/char/tpm/tpm-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,30 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
return rc;
}

/**
* tpm_is_tpm2 - is the chip a TPM2 chip?
* @chip_num: tpm idx # or ANY
*
* Returns < 0 on error, and 1 or 0 on success depending whether the chip
* is a TPM2 chip.
*/
int tpm_is_tpm2(u32 chip_num)
{
struct tpm_chip *chip;
int rc;

chip = tpm_chip_find_get(chip_num);
if (chip == NULL)
return -ENODEV;

rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0;

tpm_chip_put(chip);

return rc;
}
EXPORT_SYMBOL_GPL(tpm_is_tpm2);

/**
* tpm_pcr_read - read a pcr value
* @chip_num: tpm idx # or ANY
Expand Down Expand Up @@ -1021,6 +1045,58 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)
}
EXPORT_SYMBOL_GPL(tpm_get_random);

/**
* tpm_seal_trusted() - seal a trusted key
* @chip_num: A specific chip number for the request or TPM_ANY_NUM
* @options: authentication values and other options
* @payload: the key data in clear and encrypted form
*
* Returns < 0 on error and 0 on success. At the moment, only TPM 2.0 chips
* are supported.
*/
int tpm_seal_trusted(u32 chip_num, struct trusted_key_payload *payload,
struct trusted_key_options *options)
{
struct tpm_chip *chip;
int rc;

chip = tpm_chip_find_get(chip_num);
if (chip == NULL || !(chip->flags & TPM_CHIP_FLAG_TPM2))
return -ENODEV;

rc = tpm2_seal_trusted(chip, payload, options);

tpm_chip_put(chip);
return rc;
}
EXPORT_SYMBOL_GPL(tpm_seal_trusted);

/**
* tpm_unseal_trusted() - unseal a trusted key
* @chip_num: A specific chip number for the request or TPM_ANY_NUM
* @options: authentication values and other options
* @payload: the key data in clear and encrypted form
*
* Returns < 0 on error and 0 on success. At the moment, only TPM 2.0 chips
* are supported.
*/
int tpm_unseal_trusted(u32 chip_num, struct trusted_key_payload *payload,
struct trusted_key_options *options)
{
struct tpm_chip *chip;
int rc;

chip = tpm_chip_find_get(chip_num);
if (chip == NULL || !(chip->flags & TPM_CHIP_FLAG_TPM2))
return -ENODEV;

rc = tpm2_unseal_trusted(chip, payload, options);

tpm_chip_put(chip);
return rc;
}
EXPORT_SYMBOL_GPL(tpm_unseal_trusted);

static int __init tpm_init(void)
{
int rc;
Expand Down
15 changes: 14 additions & 1 deletion drivers/char/tpm/tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ enum tpm2_return_codes {

enum tpm2_algorithms {
TPM2_ALG_SHA1 = 0x0004,
TPM2_ALG_KEYEDHASH = 0x0008,
TPM2_ALG_SHA256 = 0x000B,
TPM2_ALG_NULL = 0x0010
};

enum tpm2_command_codes {
TPM2_CC_FIRST = 0x011F,
TPM2_CC_SELF_TEST = 0x0143,
TPM2_CC_STARTUP = 0x0144,
TPM2_CC_SHUTDOWN = 0x0145,
TPM2_CC_CREATE = 0x0153,
TPM2_CC_LOAD = 0x0157,
TPM2_CC_UNSEAL = 0x015E,
TPM2_CC_FLUSH_CONTEXT = 0x0165,
TPM2_CC_GET_CAPABILITY = 0x017A,
TPM2_CC_GET_RANDOM = 0x017B,
TPM2_CC_PCR_READ = 0x017E,
Expand Down Expand Up @@ -407,7 +414,7 @@ struct tpm_buf {
u8 *data;
};

static inline void tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal)
static inline int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal)
{
struct tpm_input_header *head;

Expand Down Expand Up @@ -527,6 +534,12 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash);
int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max);
int tpm2_seal_trusted(struct tpm_chip *chip,
struct trusted_key_payload *payload,
struct trusted_key_options *options);
int tpm2_unseal_trusted(struct tpm_chip *chip,
struct trusted_key_payload *payload,
struct trusted_key_options *options);
ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
u32 *value, const char *desc);

Expand Down
Loading

0 comments on commit 954650e

Please sign in to comment.