I found an implementation of SHA256 on the net. It consists of a single file sha256.c
, I've tested the function successfully on Linux.
Here's the link for the file: http://bradconte.com/sha256_c
When I try to use it in contiki, the output is not right.
Here's a piece of the code :
unsigned char text1[]={"sallam"}, hash[32];
int idx;
SHA256_CTX ctx;
sha256_init(&ctx);
sha256_update(&ctx, text1, strlen(text1));
sha256_final(&ctx, hash);
print_hash(hash);
Here's the function I use to print the hash:
void print_hash(unsigned char hash[])
{
int idx;
for (idx=0; idx < 32; idx++)
printf("%02x",hash[idx]);
printf("\n");
}
I've already tried to change the format ouptut to %x
but it didn't help.
I think it has something to do with little-endian vs big-endian (endianness) issues.