Skip to content

Commit ec60d0f

Browse files
AnthonyGrondinAnthony Grondin
authored andcommitted
feat(bignum): Add initial bignum hardware acceleration
Libs need to be rebuilt: - cargo +stable xtask compile - cargo +stable xtask bindings Signed-off-by: Anthony Grondin <=>
1 parent fcc50ea commit ec60d0f

File tree

19 files changed

+1147
-166
lines changed

19 files changed

+1147
-166
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "mbedtls"]
22
path = mbedtls
3-
url = https://github.com/Mbed-TLS/mbedtls
3+
url = https://github.com/espressif/mbedtls

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ static_cell = { version = "=1.2", features = ["nightly"] }
7272

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

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

7779
[[example]]
7880
name = "async_client"

esp-mbedtls-sys/headers/esp32c3/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,6 +3609,8 @@
36093609
/* MPI / BIGNUM options */
36103610
//#define MBEDTLS_MPI_WINDOW_SIZE 2 /**< Maximum window size used. */
36113611
//#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
3612+
#define MBEDTLS_MPI_EXP_MOD_ALT
3613+
// #define MBEDTLS_MPI_MUL_MPI_ALT
36123614

36133615
/* CTR_DRBG options */
36143616
//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */

esp-mbedtls-sys/headers/esp32s3/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,6 +3609,9 @@
36093609
/* MPI / BIGNUM options */
36103610
//#define MBEDTLS_MPI_WINDOW_SIZE 2 /**< Maximum window size used. */
36113611
//#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
3612+
// #define MBEDTLS_BIGNUM_ALT
3613+
#define MBEDTLS_MPI_EXP_MOD_ALT
3614+
#define MBEDTLS_MPI_MUL_MPI_ALT
36123615

36133616
/* CTR_DRBG options */
36143617
//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */

esp-mbedtls-sys/src/include/esp32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,6 +4808,7 @@ extern "C" {
48084808
/// buffer of length \p blen Bytes. It may be \c NULL if
48094809
/// \p blen is zero.
48104810
/// \param blen The length of \p buf in Bytes.
4811+
/// \param md_alg The hash algorithm used to hash the original data.
48114812
/// \param f_rng_blind The RNG function used for blinding. This must not be
48124813
/// \c NULL.
48134814
/// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be

esp-mbedtls-sys/src/include/esp32c3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4810,6 +4810,7 @@ extern "C" {
48104810
/// buffer of length \p blen Bytes. It may be \c NULL if
48114811
/// \p blen is zero.
48124812
/// \param blen The length of \p buf in Bytes.
4813+
/// \param md_alg The hash algorithm used to hash the original data.
48134814
/// \param f_rng_blind The RNG function used for blinding. This must not be
48144815
/// \c NULL.
48154816
/// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be

esp-mbedtls-sys/src/include/esp32s2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,6 +4808,7 @@ extern "C" {
48084808
/// buffer of length \p blen Bytes. It may be \c NULL if
48094809
/// \p blen is zero.
48104810
/// \param blen The length of \p buf in Bytes.
4811+
/// \param md_alg The hash algorithm used to hash the original data.
48114812
/// \param f_rng_blind The RNG function used for blinding. This must not be
48124813
/// \c NULL.
48134814
/// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be

esp-mbedtls-sys/src/include/esp32s3.rs

Lines changed: 21 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -206,125 +206,7 @@ pub const PSA_WANT_KEY_TYPE_DERIVE: u32 = 1;
206206
pub const PSA_WANT_KEY_TYPE_PASSWORD: u32 = 1;
207207
pub const PSA_WANT_KEY_TYPE_PASSWORD_HASH: u32 = 1;
208208
pub const PSA_WANT_KEY_TYPE_RAW_DATA: u32 = 1;
209-
pub const _LIBC_LIMITS_H_: u32 = 1;
210-
pub const __NEWLIB_H__: u32 = 1;
211-
pub const _NEWLIB_VERSION_H__: u32 = 1;
212-
pub const _NEWLIB_VERSION: &[u8; 6] = b"3.3.0\0";
213-
pub const __NEWLIB__: u32 = 3;
214-
pub const __NEWLIB_MINOR__: u32 = 3;
215-
pub const __NEWLIB_PATCHLEVEL__: u32 = 0;
216-
pub const _WANT_IO_C99_FORMATS: u32 = 1;
217-
pub const _WANT_IO_LONG_LONG: u32 = 1;
218-
pub const _WANT_IO_POS_ARGS: u32 = 1;
219-
pub const _WANT_REENT_SMALL: u32 = 1;
220-
pub const _REENT_CHECK_VERIFY: u32 = 1;
221-
pub const _MB_LEN_MAX: u32 = 1;
222-
pub const _ICONV_ENABLED: u32 = 1;
223-
pub const HAVE_INITFINI_ARRAY: u32 = 1;
224-
pub const _ATEXIT_DYNAMIC_ALLOC: u32 = 1;
225-
pub const _HAVE_LONG_DOUBLE: u32 = 1;
226-
pub const _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL: u32 = 1;
227-
pub const _LDBL_EQ_DBL: u32 = 1;
228-
pub const _FVWRITE_IN_STREAMIO: u32 = 1;
229-
pub const _FSEEK_OPTIMIZATION: u32 = 1;
230-
pub const _UNBUF_STREAM_OPT: u32 = 1;
231-
pub const _RETARGETABLE_LOCKING: u32 = 1;
232-
pub const _WANT_USE_LONG_TIME_T: u32 = 1;
233-
pub const _DEFAULT_SOURCE: u32 = 1;
234-
pub const _POSIX_SOURCE: u32 = 1;
235-
pub const _POSIX_C_SOURCE: u32 = 200809;
236-
pub const _ATFILE_SOURCE: u32 = 1;
237-
pub const __ATFILE_VISIBLE: u32 = 1;
238-
pub const __BSD_VISIBLE: u32 = 1;
239-
pub const __GNU_VISIBLE: u32 = 0;
240-
pub const __ISO_C_VISIBLE: u32 = 2011;
241-
pub const __LARGEFILE_VISIBLE: u32 = 0;
242-
pub const __MISC_VISIBLE: u32 = 1;
243-
pub const __POSIX_VISIBLE: u32 = 200809;
244-
pub const __SVID_VISIBLE: u32 = 1;
245-
pub const __XSI_VISIBLE: u32 = 0;
246-
pub const __SSP_FORTIFY_LEVEL: u32 = 0;
247-
pub const _POSIX_THREADS: u32 = 1;
248-
pub const _POSIX_TIMEOUTS: u32 = 1;
249-
pub const _POSIX_TIMERS: u32 = 1;
250-
pub const _POSIX_MONOTONIC_CLOCK: u32 = 200112;
251-
pub const _POSIX_CLOCK_SELECTION: u32 = 200112;
252-
pub const _UNIX98_THREAD_MUTEX_ATTRIBUTES: u32 = 1;
253-
pub const __have_longlong64: u32 = 1;
254-
pub const __have_long32: u32 = 1;
255-
pub const ___int8_t_defined: u32 = 1;
256-
pub const ___int16_t_defined: u32 = 1;
257-
pub const ___int32_t_defined: u32 = 1;
258-
pub const ___int64_t_defined: u32 = 1;
259-
pub const ___int_least8_t_defined: u32 = 1;
260-
pub const ___int_least16_t_defined: u32 = 1;
261-
pub const ___int_least32_t_defined: u32 = 1;
262-
pub const ___int_least64_t_defined: u32 = 1;
263-
pub const __GNUCLIKE_ASM: u32 = 3;
264-
pub const __GNUCLIKE___TYPEOF: u32 = 1;
265-
pub const __GNUCLIKE___OFFSETOF: u32 = 1;
266-
pub const __GNUCLIKE___SECTION: u32 = 1;
267-
pub const __GNUCLIKE_CTOR_SECTION_HANDLING: u32 = 1;
268-
pub const __GNUCLIKE_BUILTIN_CONSTANT_P: u32 = 1;
269-
pub const __GNUCLIKE_BUILTIN_VARARGS: u32 = 1;
270-
pub const __GNUCLIKE_BUILTIN_STDARG: u32 = 1;
271-
pub const __GNUCLIKE_BUILTIN_VAALIST: u32 = 1;
272-
pub const __GNUC_VA_LIST_COMPATIBILITY: u32 = 1;
273-
pub const __GNUCLIKE_BUILTIN_NEXT_ARG: u32 = 1;
274-
pub const __GNUCLIKE_BUILTIN_MEMCPY: u32 = 1;
275-
pub const __CC_SUPPORTS_INLINE: u32 = 1;
276-
pub const __CC_SUPPORTS___INLINE: u32 = 1;
277-
pub const __CC_SUPPORTS___INLINE__: u32 = 1;
278-
pub const __CC_SUPPORTS___FUNC__: u32 = 1;
279-
pub const __CC_SUPPORTS_WARNING: u32 = 1;
280-
pub const __CC_SUPPORTS_VARADIC_XXX: u32 = 1;
281-
pub const __CC_SUPPORTS_DYNAMIC_ARRAY_INIT: u32 = 1;
282-
pub const ARG_MAX: u32 = 4096;
283-
pub const CHILD_MAX: u32 = 40;
284-
pub const LINK_MAX: u32 = 32767;
285-
pub const MAX_CANON: u32 = 255;
286-
pub const MAX_INPUT: u32 = 255;
287-
pub const NAME_MAX: u32 = 255;
288-
pub const NGROUPS_MAX: u32 = 16;
289-
pub const OPEN_MAX: u32 = 64;
290-
pub const PATH_MAX: u32 = 1024;
291-
pub const PIPE_BUF: u32 = 512;
292-
pub const IOV_MAX: u32 = 1024;
293-
pub const BC_BASE_MAX: u32 = 99;
294-
pub const BC_DIM_MAX: u32 = 2048;
295-
pub const BC_SCALE_MAX: u32 = 99;
296-
pub const BC_STRING_MAX: u32 = 1000;
297-
pub const COLL_WEIGHTS_MAX: u32 = 0;
298-
pub const EXPR_NEST_MAX: u32 = 32;
299-
pub const LINE_MAX: u32 = 2048;
300-
pub const RE_DUP_MAX: u32 = 255;
301209
pub const MB_LEN_MAX: u32 = 1;
302-
pub const NL_ARGMAX: u32 = 32;
303-
pub const _POSIX2_RE_DUP_MAX: u32 = 255;
304-
pub const __int20: u32 = 2;
305-
pub const __int20__: u32 = 2;
306-
pub const __INT8: &[u8; 3] = b"hh\0";
307-
pub const __INT16: &[u8; 2] = b"h\0";
308-
pub const __INT64: &[u8; 3] = b"ll\0";
309-
pub const __FAST8: &[u8; 3] = b"hh\0";
310-
pub const __FAST16: &[u8; 2] = b"h\0";
311-
pub const __FAST64: &[u8; 3] = b"ll\0";
312-
pub const __LEAST8: &[u8; 3] = b"hh\0";
313-
pub const __LEAST16: &[u8; 2] = b"h\0";
314-
pub const __LEAST64: &[u8; 3] = b"ll\0";
315-
pub const __int8_t_defined: u32 = 1;
316-
pub const __int16_t_defined: u32 = 1;
317-
pub const __int32_t_defined: u32 = 1;
318-
pub const __int64_t_defined: u32 = 1;
319-
pub const __int_least8_t_defined: u32 = 1;
320-
pub const __int_least16_t_defined: u32 = 1;
321-
pub const __int_least32_t_defined: u32 = 1;
322-
pub const __int_least64_t_defined: u32 = 1;
323-
pub const __int_fast8_t_defined: u32 = 1;
324-
pub const __int_fast16_t_defined: u32 = 1;
325-
pub const __int_fast32_t_defined: u32 = 1;
326-
pub const __int_fast64_t_defined: u32 = 1;
327-
pub const WINT_MIN: u32 = 0;
328210
pub const MBEDTLS_ERR_MPI_FILE_IO_ERROR: i32 = -2;
329211
pub const MBEDTLS_ERR_MPI_BAD_INPUT_DATA: i32 = -4;
330212
pub const MBEDTLS_ERR_MPI_INVALID_CHARACTER: i32 = -6;
@@ -1067,52 +949,32 @@ pub const MBEDTLS_CTR_DRBG_MAX_SEED_INPUT: u32 = 384;
1067949
pub const MBEDTLS_CTR_DRBG_PR_OFF: u32 = 0;
1068950
pub const MBEDTLS_CTR_DRBG_PR_ON: u32 = 1;
1069951
pub const MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN: u32 = 0;
1070-
pub type __int8_t = crate::c_types::c_schar;
1071-
pub type __uint8_t = crate::c_types::c_uchar;
1072-
pub type __int16_t = crate::c_types::c_short;
1073-
pub type __uint16_t = crate::c_types::c_ushort;
1074-
pub type __int32_t = crate::c_types::c_int;
1075-
pub type __uint32_t = crate::c_types::c_uint;
1076-
pub type __int64_t = crate::c_types::c_longlong;
1077-
pub type __uint64_t = crate::c_types::c_ulonglong;
1078-
pub type __int_least8_t = crate::c_types::c_schar;
1079-
pub type __uint_least8_t = crate::c_types::c_uchar;
1080-
pub type __int_least16_t = crate::c_types::c_short;
1081-
pub type __uint_least16_t = crate::c_types::c_ushort;
1082-
pub type __int_least32_t = crate::c_types::c_int;
1083-
pub type __uint_least32_t = crate::c_types::c_uint;
1084-
pub type __int_least64_t = crate::c_types::c_longlong;
1085-
pub type __uint_least64_t = crate::c_types::c_ulonglong;
1086-
pub type __intmax_t = crate::c_types::c_longlong;
1087-
pub type __uintmax_t = crate::c_types::c_ulonglong;
1088-
pub type __intptr_t = crate::c_types::c_int;
1089-
pub type __uintptr_t = crate::c_types::c_uint;
1090-
pub type wchar_t = crate::c_types::c_uchar;
952+
pub type int_least64_t = i64;
953+
pub type uint_least64_t = u64;
954+
pub type int_fast64_t = i64;
955+
pub type uint_fast64_t = u64;
956+
pub type int_least32_t = i32;
957+
pub type uint_least32_t = u32;
958+
pub type int_fast32_t = i32;
959+
pub type uint_fast32_t = u32;
960+
pub type int_least16_t = i16;
961+
pub type uint_least16_t = u16;
962+
pub type int_fast16_t = i16;
963+
pub type uint_fast16_t = u16;
964+
pub type int_least8_t = i8;
965+
pub type uint_least8_t = u8;
966+
pub type int_fast8_t = i8;
967+
pub type uint_fast8_t = u8;
968+
pub type intmax_t = crate::c_types::c_longlong;
969+
pub type uintmax_t = crate::c_types::c_ulonglong;
970+
pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int;
971+
pub type wchar_t = crate::c_types::c_int;
1091972
#[repr(C)]
1092973
#[derive(Copy, Clone)]
1093974
pub struct max_align_t {
1094975
pub __clang_max_align_nonce1: crate::c_types::c_longlong,
1095976
pub __clang_max_align_nonce2: f64,
1096977
}
1097-
pub type intmax_t = __intmax_t;
1098-
pub type uintmax_t = __uintmax_t;
1099-
pub type int_least8_t = __int_least8_t;
1100-
pub type uint_least8_t = __uint_least8_t;
1101-
pub type int_least16_t = __int_least16_t;
1102-
pub type uint_least16_t = __uint_least16_t;
1103-
pub type int_least32_t = __int_least32_t;
1104-
pub type uint_least32_t = __uint_least32_t;
1105-
pub type int_least64_t = __int_least64_t;
1106-
pub type uint_least64_t = __uint_least64_t;
1107-
pub type int_fast8_t = crate::c_types::c_schar;
1108-
pub type uint_fast8_t = crate::c_types::c_uchar;
1109-
pub type int_fast16_t = crate::c_types::c_short;
1110-
pub type uint_fast16_t = crate::c_types::c_ushort;
1111-
pub type int_fast32_t = crate::c_types::c_int;
1112-
pub type uint_fast32_t = crate::c_types::c_uint;
1113-
pub type int_fast64_t = crate::c_types::c_longlong;
1114-
pub type uint_fast64_t = crate::c_types::c_ulonglong;
1115-
pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int;
1116978
extern "C" {
1117979
/// \brief Securely zeroize a buffer
1118980
///
@@ -4808,6 +4670,7 @@ extern "C" {
48084670
/// buffer of length \p blen Bytes. It may be \c NULL if
48094671
/// \p blen is zero.
48104672
/// \param blen The length of \p buf in Bytes.
4673+
/// \param md_alg The hash algorithm used to hash the original data.
48114674
/// \param f_rng_blind The RNG function used for blinding. This must not be
48124675
/// \c NULL.
48134676
/// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be

esp-mbedtls/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ esp-mbedtls-sys = { path = "../esp-mbedtls-sys" }
88
log = "0.4.17"
99
embedded-io = { version = "0.6.1" }
1010
embedded-io-async = { version = "0.6.0", optional = true }
11+
crypto-bigint = { version = "0.5.3", default-features = false, features = ["extra-sizes"] }
1112
esp32-hal = { version = "0.16.0", optional = true }
1213
esp32c3-hal = { version = "0.13.0", optional = true }
1314
esp32s2-hal = { version = "0.13.0", optional = true }
1415
esp32s3-hal = { version = "0.13.0", optional = true }
16+
cfg-if = "1.0.0"
1517

1618
[features]
1719
async = ["dep:embedded-io-async"]

0 commit comments

Comments
 (0)