cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect expected SHA-256 hash using STM32 Cryptographic Project file

stmmm
Associate II

I have configured the STM32CubeExpanision_Crypto_V4.0.1 folder using the STM32CubeIDE. Within the folder is a main.c file for a SHA256 digest located in ..STM32CubeExpansion_Crypto_V4.0.1\Projects\NUCLEO-L476RG\Applications\Hash\SHA2_Digest\Src. Within that file, there is a string of text for a message, and a string of text for the expected hash. However, I have typed in the text online in a sha-256 digest calculator and the generated hash value is not the same as the one in the main.c file. I have CRC enabled but I do not understand why the expected hash value in the main.c file is not correct.

Below is the string of text for the message and expected hash value.

0693W00000aHmLeQAK.pngBelow is the string of text for the message and expected hash value in raw form

0693W00000aHmNBQA0.png 

Msg = 6b918fb1a5ad1f9c5e5dbdf10a93a9c8f6bca89f37e79c9fe12a57227941b173ac79d8d440cde8c64c4ebc84a4c803d198a296f3de060900cc427f58ca6ec373084f95dd6c7c427ecfbf781f68be572a88dbcbb188581ab200bfb99a3a816407e7dd6dd21003554d4f7a99c93ebfce5c302ff0e11f26f83fe669acefb0c1bbb8b1e909bd14aa48ba3445c88b0e1190eef765ad898ab8ca2fe507015f1578f10dce3c11a55fb9434ee6e9ad6cc0fdc4684447a9b3b156b908646360f24fec2d8fa69e2c93db78708fcd2eef743dcb9353819b8d667c48ed54cd436fb1476598c4a1d7028e6f2ff50751db36ab6bc32435152a00abd3d58d9a8770d9a3e52d5a3628ae3c9e0325

MD = 46500b6ae1ab40bde097ef168b0f3199049b55545a1588792d39d594f493dca7

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

The readme.txt for that project says:

"@note NIST vectors examples for SHA2 are taken from:

"SHA Test Vectors for Hashing Byte-Oriented Messages"

Available at:

 https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/secure-hashing"

So look up the correct MD in the official source.

Probably, your "online in a sha-256 digest calculator" is broken or you used it the wrong way.

hth

KnarfB

View solution in original post

4 REPLIES 4
KnarfB
Principal III

The readme.txt for that project says:

"@note NIST vectors examples for SHA2 are taken from:

"SHA Test Vectors for Hashing Byte-Oriented Messages"

Available at:

 https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/secure-hashing"

So look up the correct MD in the official source.

Probably, your "online in a sha-256 digest calculator" is broken or you used it the wrong way.

hth

KnarfB

You are correct, I found the test vector file and the message and message digest match the one shown in the main.c file. However, I keep trying different online sha256 calculators and they all output the same result for the message digest: 1acbeb21ff834f222c8128c385b7b6dfbca315a47eb6f6d8c38a6f9eeb287f6e

I will continue to look into why this is, but thank you for clarifying where the test vectors came from.

The other checksum you got is when interpreting the message as text string of ASCII letters, but the const definition in the code uses hex bytes. Try https://emn178.github.io/online-tools/sha256.html and switch between text and hex

hth

KnarfB

That makes perfect sense now, thank you. I did not differentiate between text string and hex values.