lkml.org 
[lkml]   [2015]   [Jun]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2] tpm: introduce struct tpm_buf
Date
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?


Thanks,
Peter



\
 
 \ /
  Last update: 2015-06-08 23:21    [W:0.332 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site