Skip to content

Commit

Permalink
feat: Use hardware acceleration for exponent mpi.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyGrondin committed Feb 21, 2024
1 parent c1aeff8 commit 0914830
Show file tree
Hide file tree
Showing 27 changed files with 665 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ build-std = ["core"]

[alias]
xtask = "run --manifest-path ./xtask/Cargo.toml --"


# Alias' for quickly building for different chips or running examples
# By default we enable
# - `default` HAL features to set up basic chip specific settings
esp32 = "run --features esp32 --target xtensa-esp32-none-elf --features esp32-hal/default"
esp32s2 = "run --features esp32s2 --target xtensa-esp32s2-none-elf --features esp32s2-hal/default"
esp32s3 = "run --features esp32s3 --target xtensa-esp32s3-none-elf --features esp32s3-hal/default"
esp32c3 = "run --features esp32c3 --target riscv32imc-unknown-none-elf --features esp32c3-hal/default"
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ static_cell = { version = "=1.2", features = ["nightly"] }

esp-mbedtls = { path = "./esp-mbedtls" }

[target.xtensa-esp32s3-none-elf.dependencies]
[[example]]
name = "crypto_self_test"
required-features = ["esp-wifi/wifi-logs"]

[[example]]
name = "async_client"
Expand Down
1 change: 1 addition & 0 deletions esp-mbedtls-sys/headers/esp32c3/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
//#define MBEDTLS_ECJPAKE_ALT
//#define MBEDTLS_GCM_ALT
//#define MBEDTLS_NIST_KW_ALT
#define MBEDTLS_MPI_EXP_MOD_ALT_FALLBACK
//#define MBEDTLS_MD5_ALT
//#define MBEDTLS_POLY1305_ALT
//#define MBEDTLS_RIPEMD160_ALT
Expand Down
1 change: 1 addition & 0 deletions esp-mbedtls-sys/headers/esp32s2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
//#define MBEDTLS_ECJPAKE_ALT
//#define MBEDTLS_GCM_ALT
//#define MBEDTLS_NIST_KW_ALT
#define MBEDTLS_MPI_EXP_MOD_ALT_FALLBACK
//#define MBEDTLS_MD5_ALT
//#define MBEDTLS_POLY1305_ALT
//#define MBEDTLS_RIPEMD160_ALT
Expand Down
1 change: 1 addition & 0 deletions esp-mbedtls-sys/headers/esp32s3/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
//#define MBEDTLS_ECJPAKE_ALT
//#define MBEDTLS_GCM_ALT
//#define MBEDTLS_NIST_KW_ALT
#define MBEDTLS_MPI_EXP_MOD_ALT_FALLBACK
//#define MBEDTLS_MD5_ALT
//#define MBEDTLS_POLY1305_ALT
//#define MBEDTLS_RIPEMD160_ALT
Expand Down
7 changes: 7 additions & 0 deletions esp-mbedtls-sys/include/include.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
#include "mbedtls/debug.h"
#include "mbedtls/ctr_drbg.h"
#include "psa/crypto_values.h"

// Provides a function prototype to generate bindings for mbedtls_mpi_exp_mod_soft()
#if defined(MBEDTLS_MPI_EXP_MOD_ALT_FALLBACK)
int mbedtls_mpi_exp_mod_soft(mbedtls_mpi *X, const mbedtls_mpi *A,
const mbedtls_mpi *E, const mbedtls_mpi *N,
mbedtls_mpi *prec_RR);
#endif
9 changes: 9 additions & 0 deletions esp-mbedtls-sys/src/include/esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22495,3 +22495,12 @@ extern "C" {
/// \return \c 1 on failure.
pub fn mbedtls_ctr_drbg_self_test(verbose: crate::c_types::c_int) -> crate::c_types::c_int;
}
extern "C" {
pub fn mbedtls_mpi_exp_mod_soft(
X: *mut mbedtls_mpi,
A: *const mbedtls_mpi,
E: *const mbedtls_mpi,
N: *const mbedtls_mpi,
prec_RR: *mut mbedtls_mpi,
) -> crate::c_types::c_int;
}
9 changes: 9 additions & 0 deletions esp-mbedtls-sys/src/include/esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22492,3 +22492,12 @@ extern "C" {
/// \return \c 1 on failure.
pub fn mbedtls_ctr_drbg_self_test(verbose: crate::c_types::c_int) -> crate::c_types::c_int;
}
extern "C" {
pub fn mbedtls_mpi_exp_mod_soft(
X: *mut mbedtls_mpi,
A: *const mbedtls_mpi,
E: *const mbedtls_mpi,
N: *const mbedtls_mpi,
prec_RR: *mut mbedtls_mpi,
) -> crate::c_types::c_int;
}
9 changes: 9 additions & 0 deletions esp-mbedtls-sys/src/include/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22492,3 +22492,12 @@ extern "C" {
/// \return \c 1 on failure.
pub fn mbedtls_ctr_drbg_self_test(verbose: crate::c_types::c_int) -> crate::c_types::c_int;
}
extern "C" {
pub fn mbedtls_mpi_exp_mod_soft(
X: *mut mbedtls_mpi,
A: *const mbedtls_mpi,
E: *const mbedtls_mpi,
N: *const mbedtls_mpi,
prec_RR: *mut mbedtls_mpi,
) -> crate::c_types::c_int;
}
2 changes: 2 additions & 0 deletions esp-mbedtls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ esp-mbedtls-sys = { path = "../esp-mbedtls-sys" }
log = "0.4.17"
embedded-io = { version = "0.6.1" }
embedded-io-async = { version = "0.6.0", optional = true }
crypto-bigint = { version = "0.5.3", default-features = false, features = ["extra-sizes"] }
esp32-hal = { version = "0.18.0", optional = true }
esp32c3-hal = { version = "0.15.0", optional = true }
esp32s2-hal = { version = "0.15.0", optional = true }
esp32s3-hal = { version = "0.15.0", optional = true }
cfg-if = "1.0.0"

[features]
async = ["dep:embedded-io-async"]
Expand Down
Loading

0 comments on commit 0914830

Please sign in to comment.