Good C/Cpp/Arduino lib for esp32s3 Hashing

Just need to bring arbitrary data into fixed len 64bit words.
Anything better than md5 will be fine.
Doesn’t seem to be heaps of consensus on a lib.
What do you use?

1 Like

Im a little confused.
You have data that you want to load into an array of 64bit words? Or you have some data to hash?

Im not sure how you can get better then md5 and fit into a 64bit word?

If you need a 64bit hash from a stream of bytes, how secure does it need to be?
Eg you couls do a sha256 then just grab 8 bytes from the result.

2 Likes

Maybe a code example would help.

#include "aSuggestionFromTheCrowd.h"

uint64_t  hashMe(*char s) { //todo! }

String someStr = "blah blah blah";
String someLongStr = "artneynddiaitnvorahtorasotnariestorakvkaoekvearkveoathrskvaov"

uint64_t hash;
hash = hashMe(someStr);
hash = hashMe(someLongStr);

I mean at that point I’d be happy with just using SHA256.
I just haven’t found a decent Lib for Sha256.

Yeah, I sure there would be something.
There is like a big crypto using in many micro projects mbedtls, but it could be an over kill if you only need one hash.
Keep in mind that sha256 is 32 Bytes long, uint64_t is 8 bytes long.
So if you only want 8 Bytes then you also need to “extract bits/bytes from it”

I have not look at the code, but these things tend to work. You may just need to tweak to your use case… e.g. you want to hash a string not a file.

If you like, give me some time and Im sure I can get the C code to work as needed for you use case.

1 Like

That’d work. I’ll start here
I surprised there is no Arduino Core Sha256 or similar but I suppose it would not be that common a requirement.

1 Like

Without digging too deep, There should be something in the core ESP32 code as sha256 would be needed for some SSL (https) checks, So if you have HTTPD (or any other SSL running, then the code will already be somewhere to call.

Edit:

have a gloss over this

2 Likes

OK, after some reading and playing, looks like the ESP32 IDF (and I saw a referece to arduino as well) is using the mbedtls for SSL opterations. In that there is hashing options with one being SHA256.

I found this code worked for me in the idf (as a quick hard coded example) and a nice write up as well…

2 Likes