linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: "Peter Hüwe" <PeterHuewe@gmx.de>
Cc: jgunthorpe@obsidianresearch.com, safford@us.ibm.com,
	Marcel Selhorst <tpmdd@selhorst.net>,
	"moderated list:TPM DEVICE DRIVER" 
	<tpmdd-devel@lists.sourceforge.net>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] tpm: introduce struct tpm_buf
Date: Tue, 9 Jun 2015 12:19:32 +0300	[thread overview]
Message-ID: <20150609091932.GC4968@jsakkine-mobl1> (raw)
In-Reply-To: <201506082239.33639.PeterHuewe@gmx.de>

On Mon, Jun 08, 2015 at 10:39:32PM +0200, Peter Hüwe wrote:
> Hi,
> 
> 
> Am Mittwoch, 3. Juni 2015, 18:39:14 schrieb Jarkko Sakkinen:
> > This patch introduces struct tpm_buf that provides a string buffer for
> > constructing TPM commands. This allows to construct variable sized TPM
> > commands. This feature is needed for TPM 2.0 commands in order to allow
> > policy authentication and algorithmic agility.
> > 
> > The commands in the tpm2-cmd.c have been updated to use struct tpm_buf.
> > Lots of awkward length calculations could be dropped because the buffer
> > knows its length.
> > 
> > The code is is along the lines of the string buffer code in
> > security/trusted/trusted.h.
> > 
> > Changes since v1:
> > 
> > - Fixed potential alignment issues in tpm_buf_tag().
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> 
> > +static inline void tpm_buf_append(struct tpm_buf *buf,
> > +				  const unsigned char *data,
> > +				  unsigned int len)
> > +{
> > +	struct tpm_input_header *head = (struct tpm_input_header *) buf->data;
> > +
> > +	BUG_ON((len + tpm_buf_length(buf)) > TPM_BUF_SIZE);
> > +
> > +	memcpy(&buf->data[tpm_buf_length(buf)], data, len);
> > +	head->length = cpu_to_be32(tpm_buf_length(buf) + len);
> > +}
> > +
> > +static inline void tpm_buf_store(struct tpm_buf *buf,
> > +				 unsigned int pos,
> > +				 const unsigned char *data,
> > +				 unsigned int len)
> > +{
> > +	BUG_ON((pos + len) > TPM_BUF_SIZE);
> > +
> > +	memcpy(&buf->data[pos], data, len);
> > +}
> 
> Don't you have to update the ->length here?

No. Store is for placing value in position, not appending to the end.

> Thanks,
> Peter

/Jarkko

  reply	other threads:[~2015-06-09  9:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-03 16:39 [PATCH v2] tpm: introduce struct tpm_buf Jarkko Sakkinen
2015-06-08 20:39 ` Peter Hüwe
2015-06-09  9:19   ` Jarkko Sakkinen [this message]
2015-06-09 10:32     ` [tpmdd-devel] " Peter Huewe
2015-06-09 11:39       ` Jarkko Sakkinen
2015-06-09 11:58         ` Peter Huewe
2015-06-09 12:05           ` 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=20150609091932.GC4968@jsakkine-mobl1 \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=PeterHuewe@gmx.de \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=safford@us.ibm.com \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=tpmdd@selhorst.net \
    /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).