Topic: SHA384 Determinism

I'm testing wc_InitSha384, wc_Sha384Update and wc_Sha384Final and I'm finding that my final hashed value is different every time I make a call. I'm hashing a byte array of 255, 255, 255 into a byte array of length 48 and it has different values every time. What gives?

Share

Re: SHA384 Determinism

Hi Bryce,

That is strange, I would definitely expect the same input to create the same output from SHA384.  Please share your code.

We don't have a SHA384 example but we do have a SHA512 example, does your code follow the same general flow?  https://github.com/wolfSSL/wolfssl-exam … 512-hash.c

Thanks,
Kareem

Share

Re: SHA384 Determinism

I probably don't understand how this works but my code is as follows:

byte input[] = {255};
byte hash[48];
wc_Sha384 sha384;
wc_InitSha384(&sha);
wc_Sha384Update(&sha384, input, sizeof(data));
wc_Sha384Final(&sha384, hash);

and then I'm checking the first 3 indices of hash against some hardcoded values.

Share

Re: SHA384 Determinism

Hi Bryce,

Thanks for the followup.  Looks like you are initializing a different variable "sha" here: wc_InitSha384(&sha);
sha384 must be initialized before you can use it, please try replacing this line with: wc_InitSha384(&sha384);

Thanks,
Kareem

Share

Re: SHA384 Determinism

Sorry that was just a typo by me. I am actually using sha384 as the variable used in init.

Share

Re: SHA384 Determinism

And just to confirm you are calling wc_InitSha384 after each wc_Sha384Update + wc_Sha384Final, correct?
I'm also assuming the sizeof(data) here is actually sizeof(input): wc_Sha384Update(&sha384, input, sizeof(data));

Are you using any kind of hardware acceleration for SHA384?  Can you share your version and build settings?

Share

Re: SHA384 Determinism

I call wc_InitSha384 before update and final every time I perform a hash.

Yes you are correct sizeof(input); is correct

No hardware acceleration. I'm using wolfssl-5.7.4-gplv3-fips-ready with the fipsv5 user_settings.h

Share

Re: SHA384 Determinism

5.7.4 is outdated, please try upgrading to 5.8.0 and let me know if it helps.

Here is a full code sample which should work:

int main(void) {
    int i;
    int j;
    byte input[] = {255};
    byte hash[48];
    wc_Sha384 sha384;
    for (j = 0; j < 10; j++) {
        wc_InitSha384(&sha384);
        wc_Sha384Update(&sha384, input, sizeof(input));
        wc_Sha384Final(&sha384, hash);
        printf("Buffer: \n");
        for (i = 0; i < 48; i++)
            printf("%02x ", hash[i]);
        printf("\n");
    }
    return 0; 
}

Share