Skip to contentSkip to conversation

KEYS: trusted: Use ASN.1 encoded OID

PATCH Superseded Jarkko Sakkinen 1 participant 2 messages May 23, 2024

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 1/1 KEYS: trusted: Use ASN.1 encoded OID

There's no reason to encode OID_TPMSealedData at run-time, as it never changes.

Replace it with the encoded version, which has exactly the same size:

	67 81 05 0A 01 05

Include OBJECT IDENTIFIER (0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.

---
 include/linux/asn1_encoder.h              |  4 -
 lib/asn1_encoder.c                        | 91 -----------------------
 security/keys/trusted-keys/trusted_tpm2.c | 10 ++-
 3 files changed, 7 insertions(+), 98 deletions(-)
include/linux/asn1_encoder.h +0 -4
index 08cd0c2ad34f..afeefdfe2525 100644
@@ -8,14 +8,10 @@
 #include <linux/asn1_ber_bytecode.h>
 #include <linux/bug.h>
 
-#define asn1_oid_len(oid) (sizeof(oid)/sizeof(u32))
 unsigned char *
 asn1_encode_integer(unsigned char *data, const unsigned char *end_data,
 		    s64 integer);
 unsigned char *
-asn1_encode_oid(unsigned char *data, const unsigned char *end_data,
-		u32 oid[], int oid_len);
-unsigned char *
 asn1_encode_tag(unsigned char *data, const unsigned char *end_data,
 		u32 tag, const unsigned char *string, int len);
 unsigned char *
lib/asn1_encoder.c +0 -91

97 lines not on this page · raw message

security/keys/trusted-keys/trusted_tpm2.c +7 -3
index 8b7dd73d94c1..dadeed35627c 100644
@@ -26,7 +26,8 @@ static struct tpm2_hash tpm2_hash_map[] = {
 	{HASH_ALGO_SM3_256, TPM_ALG_SM3_256},
 };
 
-static u32 tpm2key_oid[] = { 2, 23, 133, 10, 1, 5 };
+/* Encoded OID_TPMSealedData. */
+static u8 OID_TPMSealedData_ASN1[] = {0x06, 0x06, 0x67, 0x81, 0x05, 0x0a, 0x01 0x05};
 
 static int tpm2_key_encode(struct trusted_key_payload *payload,
 			   struct trusted_key_options *options,
@@ -51,8 +52,8 @@ static int tpm2_key_encode(struct trusted_key_payload *payload,
 	if (!scratch)
 		return -ENOMEM;
 
-	work = asn1_encode_oid(work, end_work, tpm2key_oid,
-			       asn1_oid_len(tpm2key_oid));
+	work = memcpy(work, OID_TPMSealedData_ASN1, sizeof(OID_TPMSealedData_ASN1));
+	work += OID_TPMSealedData_ASN1;
 
 	if (options->blobauth_len == 0) {
 		unsigned char bool[3], *w = bool;
@@ -90,6 +91,9 @@ static int tpm2_key_encode(struct trusted_key_payload *payload,
 		goto err;
 	}
 
+	print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
+		       payload->blob, work1 - payload->blob, 0);
+
 	kfree(scratch);
 	return work1 - payload->blob;
 
Signature · 1 line
2.45.1
author maintainer
#1 lore raw
Quoted 11 lines · Jarkko Sakkinen

There's no reason to encode OID_TPMSealedData at run-time, as it never changes.

Replace it with the encoded version, which has exactly the same size:

	67 81 05 0A 01 05

Include OBJECT IDENTIFIER (0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.

Oops went out by mistake was going to have "--dry-run". I'll resend this one, sorry.

BR, Jarkko