[solved] SHA256 generates "wrong" hash on PowerPC (MPC5567) ? Endianness issue?

Hello Mbed forum,

I’m working on an embedded application, for a MPC5567 target, that shall verify a signature generated on an Intel x64 PC. Part of the verification process is to hash a large constant buffer, with SHA256.
In order to test my application, I’m generating the SHA256 hash (on the same constant buffer) on both the MPC5567 and the development PC. And I get different hashes.

The hash generated on PC is correct: I got the exact same results from online SHA256 generators and from a homemade python application using pica/Cryptography, and a homemade C application that uses MBEDTLS. So it seems that the hash generated on the MPC5567 is incorrect.

I’m suspecting an endianness issue: the MPC5567 is ‘big endian’ and the PC is ‘little endian’.

Has anyone came accross such issue where the same hash generation yields different results on different platforms?

Thanks for your help.

fab

Hi fab,
It is very much likely an Endianness issue, as Mbed TLS is tested on little Endian architectures. However, it should support BE platforms as well.
Is the hash similar but in BE format, or is it entirely different?

Regards,
Mbed TLS Team member
Ron

Hi Ron,
The hashes were completely different. It turns out that I was not computing them over the exact same data, on PC and on the target.
After fixing my bug, I was able to verify that SHA256 gives the same result on little-endian CPU and big-endian CPU.
So there is no endianness issue.
Thanks for your support.
Regards,
fab