ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
esp_crypto_hal.h File Reference

Single owner of the ESP32 RSA/MPI accelerator, by DIRECT register access - a self-contained HAL. More...

#include <stdint.h>
#include "sdkconfig.h"

Go to the source code of this file.

Detailed Description

Single owner of the ESP32 RSA/MPI accelerator, by DIRECT register access - a self-contained HAL.

A hardware-abstraction layer, deliberately outside crypto/ (very distinct, register-level code): the library's big-field crypto (the GF(2^255-19) layer in fe25519.h for X25519 / Ed25519 and the NIST P-256 field/scalar layer in ecdsa.cpp) drives ONE primitive on the RSA accelerator - a single-shot 256-bit modular multiply Z = X*Y mod M.

═══════════════════════════════════════════════════════════════════════════ SELF-CONTAINED - our own register map, no vendor headers or symbols ═══════════════════════════════════════════════════════════════════════════ The objective is a platform-agnostic library that reaches the silicon by DIRECT register access. So this HAL reproduces the accelerator's register map ITSELF (bases, offsets, clock/reset/power bits - values below, cross-checked against each die's TRM) and pokes it with PC_HW_REG. It includes NO soc/ header and references NO vendor symbol (no esp_mpi_* / mpi_hal_* / mpi_ll_*, no RSA_*_REG, no SYSTEM/ HP_SYS_CLKRST struct). An upstream rename or header reshuffle therefore cannot touch our crypto; only a genuine silicon change would, caught by the per-die #error. The one build dependency is sdkconfig.h, solely to learn which die we are compiling for (CONFIG_IDF_TARGET_*) - that is the build target, not a register.

Register generations: S3/S2 = "hw_ver1", ESP32-P4 and newer = "hw_ver3". The RSA block's own register offsets are identical across both; only the peripheral base and the clock/reset/power control registers differ. The classic ESP32 has no single-shot MODMULT, so it (and native builds) leave PC_RSA_MODMUL_HW undefined and callers use their software field layer.

═══════════════════════════════════════════════════════════════════════════ EXCLUSIVITY ═══════════════════════════════════════════════════════════════════════════ The accelerator is shared state. This HAL owns a single PC recursive mutex (see esp_crypto_hal.cpp) taken by pc_rsa_hw_acquire and dropped by pc_rsa_hw_release; a scalar-mult holds it across its whole run of multiplies.

Definition in file esp_crypto_hal.h.