crypto-algorithms icon indicating copy to clipboard operation
crypto-algorithms copied to clipboard

Fix undefined behaviour in SHA-256 byte-loading by casting to WORD be…

Open 0300dbdd1b opened this issue 7 months ago • 0 comments

Clang’s UndefinedBehaviorSanitizer reports:

  runtime error: left shift of 255 by 24 places cannot be represented in type 'int'

Because each data byte (0–255) is promoted to a signed int before shifting, `255 << 24` overflows a 32-bit signed range.  

Cast input bytes to WORD before shifting to prevent signed-integer overflow UB.

0300dbdd1b avatar May 01 '25 13:05 0300dbdd1b