Skip to main content
Visitor
October 2, 2026
Question

HAL2 Hash issue when handling incomplete bytes

  • October 2, 2026
  • 0 replies
  • 12 views

I believe I’ve encountered an Issue with the current version of the STM32 HAL2 and wanted to raise an issue, but I’m not sure where best to raise the issue.

The one of the new features in the new HAL2 hash is that HAL_HASH_Update can handle input sizes that don’t perfectly line up with the block size, using HASH_SaveRemainingBytes to save any excess bytes at the end of a call and then calling HASH_AppendLastIncompleteWord at the next call to write those excess bytes to peripheral along with using some bytes from the new buffer to bulk it up to 4.
 

This means that I can write something like: (where the buffer is 163 bytes long)

HAL_HASH_Update(&hhash, &u8InputBuffer[0], 10,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[10], 10,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[20], 1,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[21], 62,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[83], 7,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[90], 73,0xFFFF);

This correctly computes the correct HASH. If however I do:

HAL_HASH_Update(&hhash, &u8InputBuffer[0], 10,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[10], 10,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[20], 1,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[21], 1,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[22], 1,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[23], 1,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[24], 1,0xFFFF);
HAL_HASH_Update(&hhash, &u8InputBuffer[25], 138,0xFFFF);

This fails to calculate the correct Hash. I’ve investigated and the issue looks to be in HASH_AppendLastIncompleteWord. The problem is that HASH_AppendLastIncompleteWord doesn’t check the number of bytes that have come in, it just assumes that there will be at least 4 bytes in the buffer.

Please let me know where I can raise this so that it can be fixed.