Module esp32c3_hal::rsa
source · Expand description
RSA Accelerator support.
Overview
The RSA
driver provides a set of functions to accelerate RSA (Rivest–Shamir–Adleman)
cryptographic operations on ESP chips. RSA
is a
widely used public-key
cryptographic algorithm that involves complex
mathematical computations, and the RSA
accelerator on ESP
chips is
designed to optimize these computations for faster performance.
Implementation details;
- The driver uses low-level peripheral access to read and write data
from/to the
RSA
peripheral. - The driver contains
unsafe
code blocks as it directly manipulates memory addresses for data transfer. - The driver supports different sizes of operands based on the generic types provided during instantiation.
- The nb crate is used to handle non-blocking operations.
- The driver provides a set of high-level abstractions to simplify
RSA
cryptographic operations onESP
chips, allowing developers to leverage theRSA accelerator
for improved performance.
Examples
Initialization
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let mut rsa = Rsa::new(peripherals.RSA);
Async (modular exponentiation)
#[embassy_executor::task]
async fn mod_exp_example(mut rsa: Rsa<'static>) {
let mut outbuf = [0_u8; U512::BYTES];
let mut mod_exp = RsaModularExponentiation::<operand_sizes::Op512>::new(
&mut rsa,
&BIGNUM_2.to_le_bytes(),
&BIGNUM_3.to_le_bytes(),
compute_mprime(&BIGNUM_3),
);
let r = compute_r(&BIGNUM_3).to_le_bytes();
let base = &BIGNUM_1.to_le_bytes();
mod_exp.exponentiation(&base, &r, &mut outbuf).await;
let residue_params = DynResidueParams::new(&BIGNUM_3);
let residue = DynResidue::new(&BIGNUM_1, residue_params);
let sw_out = residue.pow(&BIGNUM_2);
assert_eq!(U512::from_le_bytes(outbuf), sw_out.retrieve());
println!("modular exponentiation done");
}
This peripheral supports async
on every available chip except of esp32
(to be solved).
⚠️: The examples for RSA peripheral are quite extensive, so for a more detailed study of how to use this driver please visit the repository with corresponding example.
Modules
- Marker types for the operand sizes
Structs
- RSA peripheral container
- Support for RSA peripheral’s modular exponentiation feature that could be used to find the
(base ^ exponent) mod modulus
. - Support for RSA peripheral’s modular multiplication feature that could be used to find the
(operand a * operand b) mod modulus
. - Support for RSA peripheral’s large number multiplication feature that could be used to find the
operand a * operand b
.