[SLOF] [PATCH 05/16] Extend internal firmware API
Nikunj A Dadhania
nikunj at linux.vnet.ibm.com
Wed Nov 11 04:39:11 AEDT 2015
Stefan Berger <stefanb at linux.vnet.ibm.com> writes:
> On 11/09/2015 03:56 AM, Nikunj A Dadhania wrote:
>> Stefan Berger <stefanb at linux.vnet.ibm.com> writes:
>>
>>> Extend the internal API of the TPM firmware support with additional
>>> functions for hashing data, extending the TPM's platform configuration
>>> registers with a hash, and appending to the log that is recording
>>> what was hashed.
>>>
>>> Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
>>> ---
>>> lib/libtpm/tcgbios.c | 276 +++++++++++++++++++++++++++++++++++++++++++++++
>>> lib/libtpm/tcgbios_int.h | 1 +
>>> 2 files changed, 277 insertions(+)
>>>
>>> diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
>>> index afbaede..072ed4d 100644
>>> --- a/lib/libtpm/tcgbios.c
>>> +++ b/lib/libtpm/tcgbios.c
>>> @@ -24,6 +24,9 @@
>>> #include "tcgbios.h"
>>> #include "tcgbios_int.h"
>>> #include "stdio.h"
>>> +#include "sha1.h"
>>> +#include "stddef.h"
>>> +#include "helpers.h"
>>>
>>> #define DEBUG 0
>>> #define dprintf(_x ...) do { \
>>> @@ -79,6 +82,8 @@ extern struct tpm_driver tpm_drivers[];
>>>
>>> static void *log_base;
>>> static uint32_t log_area_size;
>>> +/* next log entry goes here */
>>> +static void *log_area_address_next;
>>>
>>> /********************************************************
>>> Extensions for TCG-enabled BIOS
>>> @@ -89,6 +94,7 @@ void tpm_set_log_parameters(void *addr, unsigned int size)
>>> dprintf("Log is at 0x%llx; size is %u bytes\n",
>>> (uint64_t)addr, size);
>>> log_base = addr;
>>> + log_area_address_next = addr;
>>> log_area_size = size;
>>> }
>>>
>>> @@ -399,3 +405,273 @@ err_exit:
>>> return rc;
>>> return TCGBIOS_COMMAND_ERROR;
>>> }
>>> +
>>> +static void set_log_area_address_next(void *next)
>>> +{
>>> + log_area_address_next = next;
>>> +}
>> Where do you verify that next address is not more than log-area-size ?
>
> This is verified when the blob is appended to the log. If it doesn't
> fit, this function will not be called.
>
>
>>
>>> +
>>> +static void *get_log_area_address_next(void)
>>> +{
>>> + return log_area_address_next;
>>> +}
>>> +
>>> +static uint32_t tpm_sha1_calc(const uint8_t *data, uint32_t length,
>>> + uint8_t *hash)
>>> +{
>>> + uint32_t rc;
>>> + uint32_t returnCode;
>>> + struct tpm_res_sha1start start;
>>> + struct tpm_res_sha1complete complete;
>>> + uint32_t blocks = length / 64;
>>> + uint32_t rest = length & 0x3f;
>> Better like this:
>>
>> #define BLK_SIZE 64
>>
>> uint32_t blocks = length / BLK_SIZE;
>> uint32_t rest = length & (BLK_SIZE - 1);
>>
>>
>>> + uint32_t numbytes, numbytes_no;
>> Bit confusing names :-)
>
> _no stands for network (byte) order. Do you have a better suggestion for
> the name ?
numbytes_nw_order ?
More information about the SLOF
mailing list