esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
666 stars 188 forks source link

Allow creating multiple `SHA` instances and / or resume state. #842

Closed AnthonyGrondin closed 2 days ago

AnthonyGrondin commented 10 months ago

While implementing SHA hardware acceleration in https://github.com/esp-rs/esp-mbedtls/pull/19, we've struck on a tricky edge-case, where in a real utilization scenario, the MbedTLS library needs to be able to quickly switch between different SHA operations, and also to be able to clone a context, and resume work for it.

bjoernQ commented 10 months ago

Probably we should make this possible for all the crypto accelerators

AnthonyGrondin commented 10 months ago

Hi!

I'm currently blocked on this for https://github.com/esp-rs/esp-mbedtls/pull/19 but I don't really know what would be the best way to do it. If anyone wants to take care of it, I can then implement hardware accelerated SHA1, SHA256 and SHA512 for esp-mbedtls.

I haven't looked currently into AES and the other crypto accelerators, but I assume it would be the same thing.

bjoernQ commented 10 months ago

I hope I can take a swing on this but won't be able to get to this too soon. So, if someone else wants to work on this feel free to do so

My guess is that we need to save the current state after any operation and restore it before continuing an in-progress operation (see https://github.com/espressif/esp-idf/blob/8fc8f3f47997aadba21facabc66004c1d22de181/components/mbedtls/port/sha/block/sha.c#L19-L27 )

Will require API changes