All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "James Bottomley" <James.Bottomley@HansenPartnership.com>,
	<linux-integrity@vger.kernel.org>
Cc: <keyrings@vger.kernel.org>, "David Howells" <dhowells@redhat.com>
Subject: Re: [PATCH 2/3] KEYS: trusted: use encode_OID for OID encoding
Date: Fri, 24 May 2024 16:35:56 +0300	[thread overview]
Message-ID: <D1HWXUV6417K.2OLSXFURG1G3Y@kernel.org> (raw)
In-Reply-To: <20240524125955.20739-3-James.Bottomley@HansenPartnership.com>

On Fri May 24, 2024 at 3:59 PM EEST, James Bottomley wrote:
> The new routine takes the OID enum instead of needing the u32 OID
> array explicitly which reduces duplication and the potential for
> mistakes.
>
> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
> ---
>  security/keys/trusted-keys/trusted_tpm2.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c
> index 9c7ac2e423d3..b6f34ff0ca5c 100644
> --- a/security/keys/trusted-keys/trusted_tpm2.c
> +++ b/security/keys/trusted-keys/trusted_tpm2.c
> @@ -19,8 +19,6 @@
>  #include "tpm2key.asn1.h"
>  #include "tpm2-policy.h"
>  
> -static u32 tpm2key_oid[] = { 2, 23, 133, 10, 1, 5 };
> -
>  static int tpm2_key_encode(struct trusted_key_payload *payload,
>  			   struct trusted_key_options *options,
>  			   u8 *src, u32 len)
> @@ -31,6 +29,7 @@ static int tpm2_key_encode(struct trusted_key_payload *payload,
>  	u8 *end_work = scratch + SCRATCH_SIZE;
>  	u8 *priv, *pub;
>  	u16 priv_len, pub_len;
> +	int ret;
>  
>  	priv_len = get_unaligned_be16(src) + 2;
>  	priv = src;
> @@ -43,8 +42,10 @@ 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));
> +	ret = encode_OID(OID_TPMSealedData, work, end_work - work);
> +	if (ret < 0)
> +		return ret;
> +	work += ret;
>  
>  	if (options->blobauth_len == 0) {
>  		unsigned char bool[3], *w = bool;

Yupe, it's better this way.

BR, Jarkko

  reply	other threads:[~2024-05-24 13:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24 12:59 [PATCH 0/3] replace asn1_encode_oid with encode_OID James Bottomley
2024-05-24 12:59 ` [PATCH 1/3] lib/oid_registry: add ability to ASN.1 encode OIDs James Bottomley
2024-05-24 13:34   ` Jarkko Sakkinen
2024-05-24 14:02     ` James Bottomley
2024-05-24 14:26       ` Jarkko Sakkinen
2024-05-24 14:28         ` Jarkko Sakkinen
2024-05-27  3:49   ` Ben Boeckel
2024-05-24 12:59 ` [PATCH 2/3] KEYS: trusted: use encode_OID for OID encoding James Bottomley
2024-05-24 13:35   ` Jarkko Sakkinen [this message]
2024-05-24 12:59 ` [PATCH 3/3] lib: asn1_encode: remove obsolete asn1_encode_oid James Bottomley
2024-05-24 13:36   ` Jarkko Sakkinen

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=D1HWXUV6417K.2OLSXFURG1G3Y@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=dhowells@redhat.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.