Skip to content

Commit

Permalink
KEYS: trusted: Expose common functionality [ver analogdevicesinc#2]
Browse files Browse the repository at this point in the history
This patch exposes some common functionality needed to send TPM commands.
Several functions from keys/trusted.c are exposed for use by the new tpm
key subtype and a module dependency is introduced.

In the future, common functionality between the trusted key type and the
asym_tpm subtype should be factored out into a common utility library.

Signed-off-by: Denis Kenzior <[email protected]>
Signed-off-by: David Howells <[email protected]>
Tested-by: Marcel Holtmann <[email protected]>
Reviewed-by: Marcel Holtmann <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
denkenz authored and James Morris committed Oct 26, 2018
1 parent ad4b1eb commit e1ea9f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions crypto/asymmetric_keys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
config ASYMMETRIC_TPM_KEY_SUBTYPE
tristate "Asymmetric TPM backed private key subtype"
depends on TCG_TPM
depends on TRUSTED_KEYS
select CRYPTO_HMAC
select CRYPTO_SHA1
select CRYPTO_HASH_INFO
Expand Down
12 changes: 8 additions & 4 deletions security/keys/trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
/*
* calculate authorization info fields to send to TPM
*/
static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
unsigned char *h2, unsigned char h3, ...)
{
Expand Down Expand Up @@ -168,11 +168,12 @@ static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
kzfree(sdesc);
return ret;
}
EXPORT_SYMBOL_GPL(TSS_authhmac);

/*
* verify the AUTH1_COMMAND (Seal) result from TPM
*/
static int TSS_checkhmac1(unsigned char *buffer,
int TSS_checkhmac1(unsigned char *buffer,
const uint32_t command,
const unsigned char *ononce,
const unsigned char *key,
Expand Down Expand Up @@ -249,6 +250,7 @@ static int TSS_checkhmac1(unsigned char *buffer,
kzfree(sdesc);
return ret;
}
EXPORT_SYMBOL_GPL(TSS_checkhmac1);

/*
* verify the AUTH2_COMMAND (unseal) result from TPM
Expand Down Expand Up @@ -355,7 +357,7 @@ static int TSS_checkhmac2(unsigned char *buffer,
* For key specific tpm requests, we will generate and send our
* own TPM command packets using the drivers send function.
*/
static int trusted_tpm_send(unsigned char *cmd, size_t buflen)
int trusted_tpm_send(unsigned char *cmd, size_t buflen)
{
int rc;

Expand All @@ -367,6 +369,7 @@ static int trusted_tpm_send(unsigned char *cmd, size_t buflen)
rc = -EPERM;
return rc;
}
EXPORT_SYMBOL_GPL(trusted_tpm_send);

/*
* Lock a trusted key, by extending a selected PCR.
Expand Down Expand Up @@ -425,7 +428,7 @@ static int osap(struct tpm_buf *tb, struct osapsess *s,
/*
* Create an object independent authorisation protocol (oiap) session
*/
static int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
{
int ret;

Expand All @@ -442,6 +445,7 @@ static int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce)
TPM_NONCE_SIZE);
return 0;
}
EXPORT_SYMBOL_GPL(oiap);

struct tpm_digests {
unsigned char encauth[SHA1_DIGEST_SIZE];
Expand Down
14 changes: 13 additions & 1 deletion security/keys/trusted.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define __TRUSTED_KEY_H

/* implementation specific TPM constants */
#define MAX_BUF_SIZE 512
#define MAX_BUF_SIZE 1024
#define TPM_GETRANDOM_SIZE 14
#define TPM_OSAP_SIZE 36
#define TPM_OIAP_SIZE 10
Expand Down Expand Up @@ -36,6 +36,18 @@ enum {
SRK_keytype = 4
};

int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
unsigned char *h2, unsigned char h3, ...);
int TSS_checkhmac1(unsigned char *buffer,
const uint32_t command,
const unsigned char *ononce,
const unsigned char *key,
unsigned int keylen, ...);

int trusted_tpm_send(unsigned char *cmd, size_t buflen);
int oiap(struct tpm_buf *tb, uint32_t *handle, unsigned char *nonce);

#define TPM_DEBUG 0

#if TPM_DEBUG
Expand Down

0 comments on commit e1ea9f8

Please sign in to comment.