Wrong SHA256 hash value from hashcrypt

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Wrong SHA256 hash value from hashcrypt

Jump to solution
1,004 Views
TestNXP
Contributor II
Hello,
 
when I am calculating a SHA256 hash via hashcrypt functions for messages longer than 120000 Bytes I get wrong hash results (see screenshot). You can see the python results on the left and the NXP MCU calculated values on the right. 
 
image.png


I am caluclating the hash for byte arrays filled with "0xAB". 
Is there some limitation to the message size that can be hashed by the hashcrypt periphery?
 
I am using a LPC55S28 MCU. I am testing this with following function based on the hashcrypt example:

 

void TestSha256(void)
{
static uint8_t message[MESSAGE_SIZE];

for (int i = 0; i < MESSAGE_SIZE; i++)
{
message[i] = 0xab;
}

    status_t status;
    size_t outLength;
    unsigned int length;
    unsigned char output[32];


    length    = sizeof(message);
    outLength = sizeof(output);
    memset(&output, 0, outLength);

    /************************ SHA-256 **************************/
    status = HASHCRYPT_SHA(HASHCRYPT, kHASHCRYPT_Sha256, message, 100000, output, &outLength);
    TEST_ASSERT(kStatus_Success == status);
    TEST_ASSERT(outLength == 32u);
    PRINTF("100kiB: ");
    for (int i = 0; i < 32; i++)
    {
    PRINTF("%x", output[i]);
    }
    PRINTF("\n");
    status = HASHCRYPT_SHA(HASHCRYPT, kHASHCRYPT_Sha256, message, 120000, output, &outLength);
    TEST_ASSERT(kStatus_Success == status);
    TEST_ASSERT(outLength == 32u);
    PRINTF("120kiB: ");
    for (int i = 0; i < 32; i++)
    {
    PRINTF("%x", output[i]);
    }
    PRINTF("\n");
    status = HASHCRYPT_SHA(HASHCRYPT, kHASHCRYPT_Sha256, message, 130000, output, &outLength);
    TEST_ASSERT(kStatus_Success == status);
    TEST_ASSERT(outLength == 32u);
    PRINTF("130kiB: ");
    for (int i = 0; i < 32; i++)
    {
    PRINTF("%x", output[i]);
    }
    PRINTF("\n");
    status = HASHCRYPT_SHA(HASHCRYPT, kHASHCRYPT_Sha256, message, 140000, output, &outLength);
    TEST_ASSERT(kStatus_Success == status);
    TEST_ASSERT(outLength == 32u);
    PRINTF("140kiB: ");
    for (int i = 0; i < 32; i++)
    {
    PRINTF("%x", output[i]);
    }
    PRINTF("\n");
    status = HASHCRYPT_SHA(HASHCRYPT, kHASHCRYPT_Sha256, message, 150000, output, &outLength);
    TEST_ASSERT(kStatus_Success == status);
    TEST_ASSERT(outLength == 32u);
    PRINTF("150kiB: ");
    for (int i = 0; i < 32; i++)
    {
    PRINTF("%x", output[i]);
    }
    PRINTF("\n");
}

 

 

 

Labels (1)
Tags (2)
0 Kudos
Reply
1 Solution
970 Views
TestNXP
Contributor II

Hello @Alice_Yang 

is there a difference according this problem between v2.13.0 and v.2.14.0. ? 

 

I did also get the information that hardware hashing is limited to 2047 blocks each 512 Bit which does indeed result to ~130000 Bytes. Thats also the point where hashcrypt generates wrong hash values for me. (See screenshot from LPC55xx user guide)

 TestNXP_0-1697785079343.png

Can you tell me where this limitation comes from? From my understanding hashing should be possible for as big data as you want.

View solution in original post

0 Kudos
Reply
2 Replies
977 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @TestNXP 

Please use latest  version SDK v2.14.0.

 

BR

Alice

0 Kudos
Reply
971 Views
TestNXP
Contributor II

Hello @Alice_Yang 

is there a difference according this problem between v2.13.0 and v.2.14.0. ? 

 

I did also get the information that hardware hashing is limited to 2047 blocks each 512 Bit which does indeed result to ~130000 Bytes. Thats also the point where hashcrypt generates wrong hash values for me. (See screenshot from LPC55xx user guide)

 TestNXP_0-1697785079343.png

Can you tell me where this limitation comes from? From my understanding hashing should be possible for as big data as you want.

0 Kudos
Reply