This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377S: SHA-256 code for TI µc

Part Number: TMS320F28377S
Other Parts Discussed in Thread: SHA-256

Hi everyone, 

I found a SHA-256 code for TI microcontrollers at this link http://www.ti.com/tool/SHA-256 and I implemented it into my code for my TS320F28377S. However, when I compared its results to an online sha-256 algorithm, they don't match.

I don't understand why they don't give the same results, does the SHA-256 coded by TI have a particularity? 

The problem cannot come from my software because I also compared the results of the online SHA-256 with the the examples provided with the code by TI (expected hash are provided with the messages).

Thanks, 

Imen

  • Imen,

    Thanks for your interest in our products. To be clear, has your testing shown the TI SHA implementation does not match it's own example outputs provided in the TI code, or that the TI examples (and SHA implementation) does not match another implementation you found online? I think you are saying the latter, and if so, can you tell me which implementation online you are comparing it to? Thanks.

    Regards,

    Dave Foley

  • Hi again,
    You guessed in fact, it's the SHA implementation in the TI examples which don't match results with online solutions, here's some links to let you run some tests,
    emn178.github.io/.../sha256.html
    https://md5decrypt.net/Sha256/
    Imen
  • Hi, I have another question please, on which format does the SHA-256 treat the message to hash. I noticed that hashing 0xc98c8e55 doesn't give the same result as c98c8e55 so I'm a little confused, thanks
    Imen
  • Imen,
    This highlights the issue. The online calculators are looking for ASCII characters. You have to translate them to hex for the TI solution. So, if you plug the value 'a' (without the quotes) into the online calculators, you will get 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb'. If you translate 'a' to it's hex value, 0x61, and put it into a 32-bit big endian form in the code, you will use the statement 'message[0]=0x61000000;'. Then set bytes_to_be_hashed to 1 and run. You will get hash[0] = 0xCA978112, hash[1]=0xCA1BBDCA, ..., which matches the online calculator. Note, if you view the 32-bit hash variables in a memory window, the C28 core is little endian, meaning if the base address of hash is 0x8006 (i.e., hash[0]), then address 0x8006 will show 0x8112, address 0x8007 will show 0xCA97, address 0x8008 will show 0xBDCA, etc.

    Regards,
    Dave Foley
  • It's all clear, thank you very much
    Imen