esp32 Hardware SHA256 function

For general Flowcode discussion that does not belong in the other sections.
Post Reply
mnfisher
Valued Contributor
Posts: 1024
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 107 times
Been thanked: 532 times

Flowcode v10 esp32 Hardware SHA256 function

Post 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 389 times
There are a host of other 'tools' in the mbedTLS folder (sha512, RSA etc) which look similar to use....

Martin

chipfryer27
Valued Contributor
Posts: 1207
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 293 times
Been thanked: 424 times

Re: esp32 Hardware SHA256 function

Post 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

MJU20
Posts: 250
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 52 times

Re: esp32 Hardware SHA256 function

Post 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!

Post Reply