linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: openssl-tpm2-engine@groups.io
Cc: linux-integrity@vger.kernel.org, Jarkko Sakkinen <jarkko@kernel.org>
Subject: [PATCH 3/8] libcommon: add bin2hex and tmp2_get_hexname
Date: Fri,  2 Aug 2024 16:26:01 -0400	[thread overview]
Message-ID: <20240802202606.12767-4-James.Bottomley@HansenPartnership.com> (raw)
In-Reply-To: <20240802202606.12767-1-James.Bottomley@HansenPartnership.com>

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 src/include/tpm2-common.h   |  5 +++++
 src/libcommon/tpm2-common.c | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/include/tpm2-common.h b/src/include/tpm2-common.h
index 97b60f2..0e0f28a 100644
--- a/src/include/tpm2-common.h
+++ b/src/include/tpm2-common.h
@@ -9,6 +9,9 @@
  * not a TPM error, so don't process the rc as one */
 #define NOT_TPM_ERROR (0xffffffff)
 
+/* maximum space for a sha256 name in ascii */
+#define MAX_HEXNAME 132
+
 extern TPM_ALG_ID name_alg;
 
 struct policy_command {
@@ -141,4 +144,6 @@ int tpm2_rsa_decrypt(const struct app_data *ad, PUBLIC_KEY_RSA_2B *cipherText,
 		     char *srk_auth);
 int tpm2_rm_signed_policy(char *tpmkey, int rmnum);
 int tpm2_get_signed_policy(char *tpmkey, STACK_OF(TSSAUTHPOLICY) **sk);
+void bin2hex(char *dst, const unsigned char *src, size_t count);
+void tpm2_get_hexname(char hexname[MAX_HEXNAME], TPM2B_PUBLIC *pub);
 #endif
diff --git a/src/libcommon/tpm2-common.c b/src/libcommon/tpm2-common.c
index b70ac27..3ffa773 100644
--- a/src/libcommon/tpm2-common.c
+++ b/src/libcommon/tpm2-common.c
@@ -2320,6 +2320,14 @@ int hex2bin(unsigned char *dst, const char *src, size_t count)
 	return 0;
 }
 
+void bin2hex(char *dst, const unsigned char *src, size_t count)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		sprintf(&dst[i<<1], "%02x", src[i]);
+}
+
 TPM_RC tpm2_parse_policy_file(const char *policy_file,
 			      STACK_OF(TSSOPTPOLICY) *sk,
 			      char *auth, TPMT_HA *digest)
@@ -3376,6 +3384,14 @@ openssl_print_errors()
 	ERR_print_errors_fp(stderr);
 }
 
+void tpm2_get_hexname(char hexname[MAX_HEXNAME], TPM2B_PUBLIC *pub)
+{
+	NAME_2B n;
+
+	tpm2_ObjectPublic_GetName(&n, &pub->publicArea);
+	bin2hex(hexname, (unsigned char *)n.name, n.size);
+}
+
 IMPLEMENT_ASN1_FUNCTIONS(TSSOPTPOLICY)
 IMPLEMENT_ASN1_FUNCTIONS(TSSAUTHPOLICY)
 IMPLEMENT_ASN1_FUNCTIONS(TSSLOADABLE)
-- 
2.35.3


  parent reply	other threads:[~2024-08-02 20:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-02 20:25 [PATCH 0/8] openssl_tpm2_engine: Add attestation functions for primary keys James Bottomley
2024-08-02 20:25 ` [PATCH 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss James Bottomley
2024-08-03 17:08   ` Jarkko Sakkinen
2024-08-03 17:51     ` James Bottomley
2024-08-03 19:31       ` Jarkko Sakkinen
2024-08-03 19:47         ` James Bottomley
2024-08-03 20:43           ` Jarkko Sakkinen
2024-08-04 13:42             ` [PATCH v2 " James Bottomley
2024-08-04 15:37               ` [openssl-tpm2-engine] " James Bottomley
2024-08-04 21:28               ` Jarkko Sakkinen
2024-08-05  2:48                 ` [openssl-tpm2-engine] " James Bottomley
2024-08-05 11:54                   ` Jarkko Sakkinen
2024-08-02 20:26 ` [PATCH 2/8] libcommon: add ability to create a signing primary key James Bottomley
2024-08-02 20:26 ` James Bottomley [this message]
2024-08-03 17:21   ` [PATCH 3/8] libcommon: add bin2hex and tmp2_get_hexname Jarkko Sakkinen
2024-08-02 20:26 ` [PATCH 4/8] libcommon: add primary creation from template James Bottomley
2024-08-02 20:26 ` [PATCH 5/8] tss: add tpm2_Certify, tpm2_ActivateCredential and tpm2_PolicyOR James Bottomley
2024-08-02 20:26 ` [PATCH 6/8] tools: add new attest_tpm2_primary command James Bottomley
2024-08-02 20:26 ` [PATCH 7/8] attest_tpm2_primary: add man page James Bottomley
2024-08-02 20:26 ` [PATCH 8/8] tests: add tests for attest_tpm2_primary James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240802202606.12767-4-James.Bottomley@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=jarkko@kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=openssl-tpm2-engine@groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).