esp-rs / esp-mbedtls

mbedtls for ESP32 bare-metal
Apache License 2.0
17 stars 7 forks source link

feat(bignum): Add initial bignum hardware acceleration #20

Open AnthonyGrondin opened 10 months ago

AnthonyGrondin commented 10 months ago

Description

This is still work in progress.

I've tried to port over most of the code from https://github.com/espressif/esp-idf/blob/b4268c874a4cf8fcf7c0c4153cffb76ad2ddda4e/components/mbedtls/port/bignum/esp_bignum.c

Using espressif's port of mbedtls, we can provide custom implementation for mpi operations, using the RSA hardware accelerator.

I've only made it work for esp32s3 with the examples crypto_self_test and sync_server so far. I will fix the compilation for async and other targets and examples when I get this working.

What works:

What doesn't work:

Building and running

Libraries need to be need to be rebuilt, and the submodule refreshed on existing clones, since I've changed it to use espressif's custom fork.

cargo +stable xtask compile
cargo +stable xtask bindings
AnthonyGrondin commented 9 months ago

I've switched over to try to implement the modular exponentiation, and I've managed to get it work on the esp32s3 for all self_tests, and sync_server. I did some limited benchmarks and it's slightly faster than using the software implementation. There might still be ways to tweak it and make it faster.

There are still safety issues, because it seems to fail when using it in async and sometimes the verification fails.

I still have to figure out how to use Generics for RSA to reduce code duplication, as we need to provide a generic from a non-const value at runtime (max operand size). The current architecture of the RSA module makes it tricky.