Openssl EVP_DigestUpdate endianess

In <openssl/evp.h> there is this function:

EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt)

Is the code supposed to account for endianess for the argument d?

In my mips vm this:

char[] test =  "Hello World\n" ;
EVP_DigestUpdate(mdctx, test, strlen(test));

works fine and is consistent with my x86 pc, but this:

uint64_t test = 1ULL;
EVP_DigestUpdate(mdctx, &test, sizeof(test));

produces inconsistent results with my x86 pc.

1 Like

This is a possible workaround:

uint64_t test = 1ULL;

#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
test = __builtin_bswap64(test);
#endif

EVP_DigestUpdate(mdctx, &test, sizeof(test));

I am not sure if it’s a proper solution.

1 Like

In short, no.

You’re hashing raw bytes of opaque data, not doing math with numbers. What’s expected is a pointer to a piece of memory - if this were c++ instead of a void* and size_t you’d probably get at least one overload taking something likeconst std::vector<std::byte>& data.

1 Like

I completely forgot about this thread. Yes it is as you say.
I did eventually read some parts of the OpenSSL source code. It is macro definitions of macro definitions all the way down, and for a newbie like me it was kind of hard to untangle.