KEYS: trusted: Use ASN.1 encoded OID
Subsystems (5)
Jarkko Sakkinen
maintainerPATCH v2 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.
---
v2:
* Not my day I guess. This one has print_hex_dump() taken away. Apologies for spamming. The patch is however tested properly with run-tests.sh in https://gitlab.com/jarkkojs/linux-tpmdd-test.
--- include/linux/asn1_encoder.h | 4 - lib/asn1_encoder.c | 91 ----------------------- security/keys/trusted-keys/trusted_tpm2.c | 7 +- 3 files changed, 4 insertions(+), 98 deletions(-)
include/linux/asn1_encoder.h +0 -4
@@ -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 +4 -3
@@ -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 +=sizeof (OID_TPMSealedData_ASN1);if (options->blobauth_len ==0 ) {unsigned char bool[3 ], *w = bool;
Signature · 1 line
2.45.1
David Howells
maintainerQuoted 9 lines · Jarkko Sakkinen
There's no reason to encode
OID_TPMSealedDataat run-time, as it never changes.Replace it with the encoded version, which has exactly the same size:
67 81 05 0A 01 05Include OBJECT IDENTIFIER (
0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.
This seems reasonable. We have a limited set of OIDs we can generate (currently 1). Better to store the BER-encoded form and copy that in rather than trying to turn a pretty-printed OID into the BER encoding unless we absolutely have to.
David
Jarkko Sakkinen
maintainerQuoted 9 lines · David Howells
Quoted 7 lines · Jarkko Sakkinen
There's no reason to encode
OID_TPMSealedDataat run-time, as it never changes.Replace it with the encoded version, which has exactly the same size:
67 81 05 0A 01 05
Quoted 7 lines
Quoted 2 lines
Include OBJECT IDENTIFIER (
0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.This seems reasonable. We have a limited set of OIDs we can generate (currently 1). Better to store the BER-encoded form and copy that in rather than trying to turn a pretty-printed OID into the BER encoding unless we absolutely have to.
Yup, I crafted a plan in response to James about possibility to generate all from a CSV file (oid_registry.gen.[sh] and oid_registry.h incldues oid_registry.gen.h for compat).
No bandwidth to work in it, but happy to review it.
Quoted 2 lines
David
BR, Jarkko
Quoted 11 lines · Jarkko Sakkinen
There's no reason to encode
OID_TPMSealedDataat run-time, as it never changes.Replace it with the encoded version, which has exactly the same size:
67 81 05 0A 01 05Include OBJECT IDENTIFIER (
0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.Signed-off-by Jarkko Sakkinen <[email protected]>
Jarkko Sakkinen
maintainerQuoted 7 lines · David Howells
Quoted 5 lines · Jarkko Sakkinen
There's no reason to encode
OID_TPMSealedDataat run-time, as it never changes.Replace it with the encoded version, which has exactly the same size:
Quoted 8 lines
Quoted 6 lines
67 81 05 0A 01 05Include OBJECT IDENTIFIER (
0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.Signed-off-by Jarkko Sakkinen <[email protected]>Reviewed-by David Howells <[email protected]>
Thanks!
BR, Jarkko
Quoted 6 lines · Jarkko Sakkinen
There's no reason to encode
OID_TPMSealedDataat run-time, as it never changes.Replace it with the encoded version, which has exactly the same size:
67 81 05 0A 01 05
Is it the same size? It looks considerably smaller to me (6*4 bytes versus 8 bytes).
Quoted 2 lines
Include OBJECT IDENTIFIER (
0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.
An "epilogue" occurs at the end, but it seems to be at the beginning here (that would be a "prologue").
security/keys/trusted-keys/trusted_tpm2.c static struct tpm2_hash tpm2_hash_map[] = { · line 30
Quoted 3 lines
security/keys/trusted-keys/trusted_tpm2.c +2
-1-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 };
I'd say that a comment of what it encodes would be good to have for context, but the source tree has OID_TPMSealedData in a header with the value in a comment there, so that seems good enough to me.
Quoted 1 line
as it never changes.
Should it, perhaps be const too?
--Ben
Jarkko Sakkinen
maintainerQuoted 10 lines · Ben Boeckel
Quoted 6 lines · Jarkko Sakkinen
There's no reason to encode
OID_TPMSealedDataat run-time, as it never changes.Replace it with the encoded version, which has exactly the same size:
67 81 05 0A 01 05Is it the same size? It looks considerably smaller to me (6*4 bytes versus 8 bytes).
Not in that sense but in practice the old array stored byte values. Forgot for that reason that it was actually u32 array.
I can change it to "same number of elements".
Quoted 6 lines
Quoted 3 lines
Include OBJECT IDENTIFIER (
0x06) tag and length as the epilogue so that the OID can be simply copied to the blob.An "epilogue" occurs at the end, but it seems to be at the beginning here (that would be a "prologue").
Yup, typo.
Quoted 7 lines
security/keys/trusted-keys/trusted_tpm2.c static struct tpm2_hash tpm2_hash_map[] = { · line 30
Quoted 3 lines
security/keys/trusted-keys/trusted_tpm2.c +2
-1-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 };I'd say that a comment of what it encodes would be good to have for context, but the source tree has
OID_TPMSealedDatain a header with the value in a comment there, so that seems good enough to me.
OK. I named it this way to promote generation these from CSV file (see my other response to James).
Quoted 4 lines
Quoted 2 lines
as it never changes.
Should it, perhaps be
consttoo?
Yup.
Quoted 2 lines
--Ben
Thanks for the remarks!
BR, Jarkko