[SLOF] [PATCH v3 6/7] tcgbios: Add test cases and test script to run them

Stefan Berger stefanb at linux.ibm.com
Sat Jul 10 00:46:34 AEST 2021


On 7/9/21 10:07 AM, Alexey Kardashevskiy wrote:
>
>
> On 09/07/2021 22:07, Stefan Berger wrote:
>> On 7/9/21 2:02 AM, Alexey Kardashevskiy wrote:
>>
>>>
>>>
>>> On 09/07/2021 12:53, Stefan Berger wrote:
>>>> From: Stefan Berger <stefanb at linux.ibm.com>
>>>>
>>>> Add test cases for sha1, sha256, sha384, and sha512 and a test script
>>>> to run the test cases.
>>>>
>>>> Signed-off-by: Stefan Berger <stefanb at linux.ibm.com>
>>>> ---
>>>>   lib/libtpm/sha.c      | 26 +++++++++++++++++++
>>>>   lib/libtpm/sha256.c   | 25 +++++++++++++++++++
>>>>   lib/libtpm/sha512.c   | 32 ++++++++++++++++++++++++
>>>>   lib/libtpm/sha_test.h | 58 
>>>> +++++++++++++++++++++++++++++++++++++++++++
>>>>   lib/libtpm/test.sh    | 29 ++++++++++++++++++++++
>>>>   5 files changed, 170 insertions(+)
>>>>   create mode 100644 lib/libtpm/sha_test.h
>>>>   create mode 100755 lib/libtpm/test.sh
>>>>
>>>> diff --git a/lib/libtpm/sha.c b/lib/libtpm/sha.c
>>>> index 43de658..6e8b19b 100644
>>>> --- a/lib/libtpm/sha.c
>>>> +++ b/lib/libtpm/sha.c
>>>> @@ -203,3 +203,29 @@ void sha1(const uint8_t *data, uint32_t 
>>>> length, uint8_t *hash)
>>>>       sha1_do(&ctx, data, length);
>>>>       memcpy(hash, &ctx.h[0], 20);
>>>>   }
>>>> +
>>>> +#ifdef MAIN
>>>> +
>>>> +#include "sha_test.h"
>>>> +
>>>> +int main(void)
>>>> +{
>>>> +    TESTVECTORS(data);
>>>> +    uint8_t hash[20];
>>>> +    char input[64];
>>>> +    int err = 0;
>>>> +    size_t i;
>>>> +
>>>> +    for (i = 0; data[i]; i++)
>>>> +        err |= test_hash(sha1, hash, sizeof(hash),
>>>> +                 data[i], strlen(data[i]),
>>>> +                 SHA1);
>>>> +
>>>> +    memset(input, 'a', sizeof(input));
>>>> +    for (i = 50; i < sizeof(input); i++)
>>>
>>>
>>> Why 50?
>>
>>
>> There's a critical point in the input size for sha1 at around 56 
>> bytes. I mainly wanted to cover that.
>
> This is fine but then it calls for a macro, something like 
> SHA1_CRIT_SIZE which you then use in sha.c and in the test. I never 
> ever wrote a single bit of sha so I really wish to have some clues here.


I now wrote a comment into the code explaining what the critical input 
size is and that we want to cover that along with some more tests around 
that size...



More information about the SLOF mailing list