Page 1 of 1

esp32 Hardware SHA256 function

Posted: Wed Nov 01, 2023 6:50 pm
by mnfisher
I found the esp32 datasheet (at https://www.espressif.com/sites/default ... ual_en.pdf ) - which makes for interesting reading.
I managed to get the 'genuine' random number generator working easily but - as I need SHA256 function for a project - then tried to get that working by writing to registers / memory (it looks straightforward!)

This failed :-( - always returning 0.

So then - trawling through the espressif includes found mbedtls/sha256.h - which does exactly what's needed (other SHA schemes are also available!)

I wrote a simple program to test - and all seems well. It can probably be made into a component too. Here it does a very simple SHA256 calculation (4 bytes) - and I checked the result against https://xorbin.com/tools/sha256-hash-calculator (which doesn't need quotes)

Note that you can amend the mbedTLS config by using idf.py menuconfig (it's under component config).
SHA256_Update takes an array of bytes of any length and can also be called multiple times before calling SHA256_Finish.
I don't check the result bytes returned (0 is success)
SHA256.fcfx
(15.11 KiB) Downloaded 497 times
There are a host of other 'tools' in the mbedTLS folder (sha512, RSA etc) which look similar to use....

Martin

Re: esp32 Hardware SHA256 function

Posted: Thu Nov 02, 2023 5:13 am
by chipfryer27
Hi Martin

Although I've no need for that functionality just yet, it's always interesting to read your "how to" posts.

Regards

Re: esp32 Hardware SHA256 function

Posted: Tue Nov 07, 2023 10:53 pm
by MJU20
mnfisher wrote:
Wed Nov 01, 2023 6:50 pm
It can probably be made into a component too.
Thanks mnfisher!

Any component would be nice!
I look forward to it!