Skip to contentSkip to conversation

KEYS: trusted: Expose common functionality

RFC In review Denis Kenzior 2 participants 3 messages Aug 2, 2018 – Aug 8, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC v3 7/13 KEYS: trusted: Expose common functionality

This patch exposes some common functionality needed to send TPM commands. The current approach is a complete hack and needs to be addressed properly. This commit just show-cases what functionality would need to be moved to a shared location or exposed in some other manner.

---
 crypto/asymmetric_keys/Kconfig |  1 +
 security/keys/trusted.c        | 12 ++++++++----
 security/keys/trusted.h        | 14 +++++++++++++-
 3 files changed, 22 insertions(+), 5 deletions(-)
crypto/asymmetric_keys/Kconfig +1 -0
index 88353a9ebc9b..be70ca6c85d3 100644
@@ -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
security/keys/trusted.c +8 -4
index b69d3b1777c2..1c025fdfe0e0 100644
@@ -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, ...)
 {
@@ -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,
@@ -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
@@ -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;
 
@@ -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.
@@ -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;
 
@@ -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];
security/keys/trusted.h +13 -1
index 8d5fe9eafb22..adbcb6817826 100644
@@ -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
@@ -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
Signature · 1 line
2.16.1
maintainer
#1 lore raw
Quoted 5 lines · Denis Kenzior

This patch exposes some common functionality needed to send TPM commands. The current approach is a complete hack and needs to be addressed properly. This commit just show-cases what functionality would need to be moved to a shared location or exposed in some other manner.

Consider adding the linux-integrity list to the cc line for these patches.

Signature · 2 lines
James Morris
<[email protected]>
#2 lore raw
In reply to Denis Kenzior

Hi James,

Quoted 10 lines · James Morris
Quoted 5 lines · Denis Kenzior

This patch exposes some common functionality needed to send TPM commands. The current approach is a complete hack and needs to be addressed properly. This commit just show-cases what functionality would need to be moved to a shared location or exposed in some other manner.

Consider adding the linux-integrity list to the cc line for these patches.

Will do.

And thanks for the Reviewed-bys. Any chance you can also take a look at patch 12. It is adding a tpm_sign primitive similar to other tpm primitives implemented in patches 8 & 9.

Regards,
-Denis