diff --git a/.cargo/config.toml b/.cargo/config.toml index e3b94db..de0842a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -24,7 +24,6 @@ runner = "espflash flash --monitor --baud 921600" rustflags = [ #"-C", "linker=rust-lld", - "-C", "link-arg=-Tlinkall.x", "-C", "link-arg=-Trom_functions.x", ] @@ -43,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" diff --git a/.gitmodules b/.gitmodules index f1b208d..a939eb3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "mbedtls"] path = mbedtls - url = https://github.com/Mbed-TLS/mbedtls + url = https://github.com/espressif/mbedtls diff --git a/Cargo.toml b/Cargo.toml index 0786d51..438b76d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["bjoernQ "] edition = "2021" license = "MIT OR Apache-2.0" +rust-version = "1.75" [profile.release] debug = true @@ -33,8 +34,6 @@ esp-println = { version = "0.9.0", features = ["log"] } embassy-time = { version = "0.3.0", optional = true } embassy-executor = { version = "0.5.0", package = "embassy-executor", features = [ "nightly", - "executor-thread", - "integrated-timers", ], optional = true } embassy-net = { version = "0.4.0", features = [ "tcp", @@ -69,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" diff --git a/cfg.toml b/cfg.toml index 6be17f2..506cbed 100644 --- a/cfg.toml +++ b/cfg.toml @@ -1,3 +1,3 @@ [esp-wifi] heap_size = 112640 # use 110k by default -# heap_size = 73728 # uncomment this to use 72k for esp32-s2/c2 \ No newline at end of file +# heap_size = 73728 # uncomment this to use 72k for esp32-s2/c2 diff --git a/esp-mbedtls-sys/headers/esp32c3/config.h b/esp-mbedtls-sys/headers/esp32c3/config.h index 7eb82a8..de28467 100644 --- a/esp-mbedtls-sys/headers/esp32c3/config.h +++ b/esp-mbedtls-sys/headers/esp32c3/config.h @@ -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 diff --git a/esp-mbedtls-sys/headers/esp32s2/config.h b/esp-mbedtls-sys/headers/esp32s2/config.h index 1f366db..72e4bba 100644 --- a/esp-mbedtls-sys/headers/esp32s2/config.h +++ b/esp-mbedtls-sys/headers/esp32s2/config.h @@ -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 diff --git a/esp-mbedtls-sys/headers/esp32s3/config.h b/esp-mbedtls-sys/headers/esp32s3/config.h index 1f366db..72e4bba 100644 --- a/esp-mbedtls-sys/headers/esp32s3/config.h +++ b/esp-mbedtls-sys/headers/esp32s3/config.h @@ -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 diff --git a/esp-mbedtls-sys/include/include.h b/esp-mbedtls-sys/include/include.h index 5355552..3dd7dde 100644 --- a/esp-mbedtls-sys/include/include.h +++ b/esp-mbedtls-sys/include/include.h @@ -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 diff --git a/esp-mbedtls-sys/src/include/esp32.rs b/esp-mbedtls-sys/src/include/esp32.rs index 34a5e23..b0f8ec8 100644 --- a/esp-mbedtls-sys/src/include/esp32.rs +++ b/esp-mbedtls-sys/src/include/esp32.rs @@ -206,125 +206,7 @@ pub const PSA_WANT_KEY_TYPE_DERIVE: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD_HASH: u32 = 1; pub const PSA_WANT_KEY_TYPE_RAW_DATA: u32 = 1; -pub const _LIBC_LIMITS_H_: u32 = 1; -pub const __NEWLIB_H__: u32 = 1; -pub const _NEWLIB_VERSION_H__: u32 = 1; -pub const _NEWLIB_VERSION: &[u8; 6] = b"3.3.0\0"; -pub const __NEWLIB__: u32 = 3; -pub const __NEWLIB_MINOR__: u32 = 3; -pub const __NEWLIB_PATCHLEVEL__: u32 = 0; -pub const _WANT_IO_C99_FORMATS: u32 = 1; -pub const _WANT_IO_LONG_LONG: u32 = 1; -pub const _WANT_IO_POS_ARGS: u32 = 1; -pub const _WANT_REENT_SMALL: u32 = 1; -pub const _REENT_CHECK_VERIFY: u32 = 1; -pub const _MB_LEN_MAX: u32 = 1; -pub const _ICONV_ENABLED: u32 = 1; -pub const HAVE_INITFINI_ARRAY: u32 = 1; -pub const _ATEXIT_DYNAMIC_ALLOC: u32 = 1; -pub const _HAVE_LONG_DOUBLE: u32 = 1; -pub const _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL: u32 = 1; -pub const _LDBL_EQ_DBL: u32 = 1; -pub const _FVWRITE_IN_STREAMIO: u32 = 1; -pub const _FSEEK_OPTIMIZATION: u32 = 1; -pub const _UNBUF_STREAM_OPT: u32 = 1; -pub const _RETARGETABLE_LOCKING: u32 = 1; -pub const _WANT_USE_LONG_TIME_T: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __ATFILE_VISIBLE: u32 = 1; -pub const __BSD_VISIBLE: u32 = 1; -pub const __GNU_VISIBLE: u32 = 0; -pub const __ISO_C_VISIBLE: u32 = 2011; -pub const __LARGEFILE_VISIBLE: u32 = 0; -pub const __MISC_VISIBLE: u32 = 1; -pub const __POSIX_VISIBLE: u32 = 200809; -pub const __SVID_VISIBLE: u32 = 1; -pub const __XSI_VISIBLE: u32 = 0; -pub const __SSP_FORTIFY_LEVEL: u32 = 0; -pub const _POSIX_THREADS: u32 = 1; -pub const _POSIX_TIMEOUTS: u32 = 1; -pub const _POSIX_TIMERS: u32 = 1; -pub const _POSIX_MONOTONIC_CLOCK: u32 = 200112; -pub const _POSIX_CLOCK_SELECTION: u32 = 200112; -pub const _UNIX98_THREAD_MUTEX_ATTRIBUTES: u32 = 1; -pub const __have_longlong64: u32 = 1; -pub const __have_long32: u32 = 1; -pub const ___int8_t_defined: u32 = 1; -pub const ___int16_t_defined: u32 = 1; -pub const ___int32_t_defined: u32 = 1; -pub const ___int64_t_defined: u32 = 1; -pub const ___int_least8_t_defined: u32 = 1; -pub const ___int_least16_t_defined: u32 = 1; -pub const ___int_least32_t_defined: u32 = 1; -pub const ___int_least64_t_defined: u32 = 1; -pub const __GNUCLIKE_ASM: u32 = 3; -pub const __GNUCLIKE___TYPEOF: u32 = 1; -pub const __GNUCLIKE___OFFSETOF: u32 = 1; -pub const __GNUCLIKE___SECTION: u32 = 1; -pub const __GNUCLIKE_CTOR_SECTION_HANDLING: u32 = 1; -pub const __GNUCLIKE_BUILTIN_CONSTANT_P: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VARARGS: u32 = 1; -pub const __GNUCLIKE_BUILTIN_STDARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VAALIST: u32 = 1; -pub const __GNUC_VA_LIST_COMPATIBILITY: u32 = 1; -pub const __GNUCLIKE_BUILTIN_NEXT_ARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_MEMCPY: u32 = 1; -pub const __CC_SUPPORTS_INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE__: u32 = 1; -pub const __CC_SUPPORTS___FUNC__: u32 = 1; -pub const __CC_SUPPORTS_WARNING: u32 = 1; -pub const __CC_SUPPORTS_VARADIC_XXX: u32 = 1; -pub const __CC_SUPPORTS_DYNAMIC_ARRAY_INIT: u32 = 1; -pub const ARG_MAX: u32 = 4096; -pub const CHILD_MAX: u32 = 40; -pub const LINK_MAX: u32 = 32767; -pub const MAX_CANON: u32 = 255; -pub const MAX_INPUT: u32 = 255; -pub const NAME_MAX: u32 = 255; -pub const NGROUPS_MAX: u32 = 16; -pub const OPEN_MAX: u32 = 64; -pub const PATH_MAX: u32 = 1024; -pub const PIPE_BUF: u32 = 512; -pub const IOV_MAX: u32 = 1024; -pub const BC_BASE_MAX: u32 = 99; -pub const BC_DIM_MAX: u32 = 2048; -pub const BC_SCALE_MAX: u32 = 99; -pub const BC_STRING_MAX: u32 = 1000; -pub const COLL_WEIGHTS_MAX: u32 = 0; -pub const EXPR_NEST_MAX: u32 = 32; -pub const LINE_MAX: u32 = 2048; -pub const RE_DUP_MAX: u32 = 255; pub const MB_LEN_MAX: u32 = 1; -pub const NL_ARGMAX: u32 = 32; -pub const _POSIX2_RE_DUP_MAX: u32 = 255; -pub const __int20: u32 = 2; -pub const __int20__: u32 = 2; -pub const __INT8: &[u8; 3] = b"hh\0"; -pub const __INT16: &[u8; 2] = b"h\0"; -pub const __INT64: &[u8; 3] = b"ll\0"; -pub const __FAST8: &[u8; 3] = b"hh\0"; -pub const __FAST16: &[u8; 2] = b"h\0"; -pub const __FAST64: &[u8; 3] = b"ll\0"; -pub const __LEAST8: &[u8; 3] = b"hh\0"; -pub const __LEAST16: &[u8; 2] = b"h\0"; -pub const __LEAST64: &[u8; 3] = b"ll\0"; -pub const __int8_t_defined: u32 = 1; -pub const __int16_t_defined: u32 = 1; -pub const __int32_t_defined: u32 = 1; -pub const __int64_t_defined: u32 = 1; -pub const __int_least8_t_defined: u32 = 1; -pub const __int_least16_t_defined: u32 = 1; -pub const __int_least32_t_defined: u32 = 1; -pub const __int_least64_t_defined: u32 = 1; -pub const __int_fast8_t_defined: u32 = 1; -pub const __int_fast16_t_defined: u32 = 1; -pub const __int_fast32_t_defined: u32 = 1; -pub const __int_fast64_t_defined: u32 = 1; -pub const WINT_MIN: u32 = 0; pub const MBEDTLS_ERR_MPI_FILE_IO_ERROR: i32 = -2; pub const MBEDTLS_ERR_MPI_BAD_INPUT_DATA: i32 = -4; pub const MBEDTLS_ERR_MPI_INVALID_CHARACTER: i32 = -6; @@ -1067,52 +949,32 @@ pub const MBEDTLS_CTR_DRBG_MAX_SEED_INPUT: u32 = 384; pub const MBEDTLS_CTR_DRBG_PR_OFF: u32 = 0; pub const MBEDTLS_CTR_DRBG_PR_ON: u32 = 1; pub const MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN: u32 = 0; -pub type __int8_t = crate::c_types::c_schar; -pub type __uint8_t = crate::c_types::c_uchar; -pub type __int16_t = crate::c_types::c_short; -pub type __uint16_t = crate::c_types::c_ushort; -pub type __int32_t = crate::c_types::c_int; -pub type __uint32_t = crate::c_types::c_uint; -pub type __int64_t = crate::c_types::c_longlong; -pub type __uint64_t = crate::c_types::c_ulonglong; -pub type __int_least8_t = crate::c_types::c_schar; -pub type __uint_least8_t = crate::c_types::c_uchar; -pub type __int_least16_t = crate::c_types::c_short; -pub type __uint_least16_t = crate::c_types::c_ushort; -pub type __int_least32_t = crate::c_types::c_int; -pub type __uint_least32_t = crate::c_types::c_uint; -pub type __int_least64_t = crate::c_types::c_longlong; -pub type __uint_least64_t = crate::c_types::c_ulonglong; -pub type __intmax_t = crate::c_types::c_longlong; -pub type __uintmax_t = crate::c_types::c_ulonglong; -pub type __intptr_t = crate::c_types::c_int; -pub type __uintptr_t = crate::c_types::c_uint; -pub type wchar_t = crate::c_types::c_uchar; +pub type int_least64_t = i64; +pub type uint_least64_t = u64; +pub type int_fast64_t = i64; +pub type uint_fast64_t = u64; +pub type int_least32_t = i32; +pub type uint_least32_t = u32; +pub type int_fast32_t = i32; +pub type uint_fast32_t = u32; +pub type int_least16_t = i16; +pub type uint_least16_t = u16; +pub type int_fast16_t = i16; +pub type uint_fast16_t = u16; +pub type int_least8_t = i8; +pub type uint_least8_t = u8; +pub type int_fast8_t = i8; +pub type uint_fast8_t = u8; +pub type intmax_t = crate::c_types::c_longlong; +pub type uintmax_t = crate::c_types::c_ulonglong; +pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; +pub type wchar_t = crate::c_types::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct max_align_t { pub __clang_max_align_nonce1: crate::c_types::c_longlong, pub __clang_max_align_nonce2: f64, } -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; -pub type int_least8_t = __int_least8_t; -pub type uint_least8_t = __uint_least8_t; -pub type int_least16_t = __int_least16_t; -pub type uint_least16_t = __uint_least16_t; -pub type int_least32_t = __int_least32_t; -pub type uint_least32_t = __uint_least32_t; -pub type int_least64_t = __int_least64_t; -pub type uint_least64_t = __uint_least64_t; -pub type int_fast8_t = crate::c_types::c_schar; -pub type uint_fast8_t = crate::c_types::c_uchar; -pub type int_fast16_t = crate::c_types::c_short; -pub type uint_fast16_t = crate::c_types::c_ushort; -pub type int_fast32_t = crate::c_types::c_int; -pub type uint_fast32_t = crate::c_types::c_uint; -pub type int_fast64_t = crate::c_types::c_longlong; -pub type uint_fast64_t = crate::c_types::c_ulonglong; -pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; extern "C" { /// \brief Securely zeroize a buffer /// @@ -4808,6 +4670,7 @@ extern "C" { /// buffer of length \p blen Bytes. It may be \c NULL if /// \p blen is zero. /// \param blen The length of \p buf in Bytes. + /// \param md_alg The hash algorithm used to hash the original data. /// \param f_rng_blind The RNG function used for blinding. This must not be /// \c NULL. /// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be diff --git a/esp-mbedtls-sys/src/include/esp32c3.rs b/esp-mbedtls-sys/src/include/esp32c3.rs index 02e7202..622cadf 100644 --- a/esp-mbedtls-sys/src/include/esp32c3.rs +++ b/esp-mbedtls-sys/src/include/esp32c3.rs @@ -206,125 +206,8 @@ pub const PSA_WANT_KEY_TYPE_DERIVE: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD_HASH: u32 = 1; pub const PSA_WANT_KEY_TYPE_RAW_DATA: u32 = 1; -pub const _LIBC_LIMITS_H_: u32 = 1; -pub const __NEWLIB_H__: u32 = 1; -pub const _NEWLIB_VERSION_H__: u32 = 1; -pub const _NEWLIB_VERSION: &[u8; 6] = b"3.3.0\0"; -pub const __NEWLIB__: u32 = 3; -pub const __NEWLIB_MINOR__: u32 = 3; -pub const __NEWLIB_PATCHLEVEL__: u32 = 0; -pub const _WANT_IO_C99_FORMATS: u32 = 1; -pub const _WANT_IO_LONG_LONG: u32 = 1; -pub const _WANT_IO_POS_ARGS: u32 = 1; -pub const _WANT_REENT_SMALL: u32 = 1; -pub const _REENT_CHECK_VERIFY: u32 = 1; -pub const _MB_LEN_MAX: u32 = 1; -pub const _ICONV_ENABLED: u32 = 1; -pub const HAVE_INITFINI_ARRAY: u32 = 1; -pub const _ATEXIT_DYNAMIC_ALLOC: u32 = 1; -pub const _HAVE_LONG_DOUBLE: u32 = 1; -pub const _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL: u32 = 1; -pub const _FVWRITE_IN_STREAMIO: u32 = 1; -pub const _FSEEK_OPTIMIZATION: u32 = 1; -pub const _UNBUF_STREAM_OPT: u32 = 1; -pub const _RETARGETABLE_LOCKING: u32 = 1; -pub const _WANT_USE_LONG_TIME_T: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __ATFILE_VISIBLE: u32 = 1; -pub const __BSD_VISIBLE: u32 = 1; -pub const __GNU_VISIBLE: u32 = 0; -pub const __ISO_C_VISIBLE: u32 = 2011; -pub const __LARGEFILE_VISIBLE: u32 = 0; -pub const __MISC_VISIBLE: u32 = 1; -pub const __POSIX_VISIBLE: u32 = 200809; -pub const __SVID_VISIBLE: u32 = 1; -pub const __XSI_VISIBLE: u32 = 0; -pub const __SSP_FORTIFY_LEVEL: u32 = 0; -pub const _POSIX_THREADS: u32 = 1; -pub const _POSIX_TIMEOUTS: u32 = 1; -pub const _POSIX_TIMERS: u32 = 1; -pub const _POSIX_MONOTONIC_CLOCK: u32 = 200112; -pub const _POSIX_CLOCK_SELECTION: u32 = 200112; -pub const _UNIX98_THREAD_MUTEX_ATTRIBUTES: u32 = 1; -pub const __have_longlong64: u32 = 1; -pub const __have_long32: u32 = 1; -pub const ___int8_t_defined: u32 = 1; -pub const ___int16_t_defined: u32 = 1; -pub const ___int32_t_defined: u32 = 1; -pub const ___int64_t_defined: u32 = 1; -pub const ___int_least8_t_defined: u32 = 1; -pub const ___int_least16_t_defined: u32 = 1; -pub const ___int_least32_t_defined: u32 = 1; -pub const ___int_least64_t_defined: u32 = 1; -pub const __GNUCLIKE_ASM: u32 = 3; -pub const __GNUCLIKE___TYPEOF: u32 = 1; -pub const __GNUCLIKE___OFFSETOF: u32 = 1; -pub const __GNUCLIKE___SECTION: u32 = 1; -pub const __GNUCLIKE_CTOR_SECTION_HANDLING: u32 = 1; -pub const __GNUCLIKE_BUILTIN_CONSTANT_P: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VARARGS: u32 = 1; -pub const __GNUCLIKE_BUILTIN_STDARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VAALIST: u32 = 1; -pub const __GNUC_VA_LIST_COMPATIBILITY: u32 = 1; -pub const __GNUCLIKE_BUILTIN_NEXT_ARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_MEMCPY: u32 = 1; -pub const __CC_SUPPORTS_INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE__: u32 = 1; -pub const __CC_SUPPORTS___FUNC__: u32 = 1; -pub const __CC_SUPPORTS_WARNING: u32 = 1; -pub const __CC_SUPPORTS_VARADIC_XXX: u32 = 1; -pub const __CC_SUPPORTS_DYNAMIC_ARRAY_INIT: u32 = 1; -pub const ARG_MAX: u32 = 4096; -pub const CHILD_MAX: u32 = 40; -pub const LINK_MAX: u32 = 32767; -pub const MAX_CANON: u32 = 255; -pub const MAX_INPUT: u32 = 255; -pub const NAME_MAX: u32 = 255; -pub const NGROUPS_MAX: u32 = 16; -pub const OPEN_MAX: u32 = 64; -pub const PATH_MAX: u32 = 1024; -pub const PIPE_BUF: u32 = 512; -pub const IOV_MAX: u32 = 1024; -pub const BC_BASE_MAX: u32 = 99; -pub const BC_DIM_MAX: u32 = 2048; -pub const BC_SCALE_MAX: u32 = 99; -pub const BC_STRING_MAX: u32 = 1000; -pub const COLL_WEIGHTS_MAX: u32 = 0; -pub const EXPR_NEST_MAX: u32 = 32; -pub const LINE_MAX: u32 = 2048; -pub const RE_DUP_MAX: u32 = 255; pub const MB_LEN_MAX: u32 = 1; -pub const NL_ARGMAX: u32 = 32; -pub const _POSIX2_RE_DUP_MAX: u32 = 255; pub const CHAR_MIN: u32 = 0; -pub const __int20: u32 = 2; -pub const __int20__: u32 = 2; -pub const __INT8: &[u8; 3] = b"hh\0"; -pub const __INT16: &[u8; 2] = b"h\0"; -pub const __INT64: &[u8; 3] = b"ll\0"; -pub const __FAST8: &[u8; 3] = b"hh\0"; -pub const __FAST16: &[u8; 2] = b"h\0"; -pub const __FAST64: &[u8; 3] = b"ll\0"; -pub const __LEAST8: &[u8; 3] = b"hh\0"; -pub const __LEAST16: &[u8; 2] = b"h\0"; -pub const __LEAST64: &[u8; 3] = b"ll\0"; -pub const __int8_t_defined: u32 = 1; -pub const __int16_t_defined: u32 = 1; -pub const __int32_t_defined: u32 = 1; -pub const __int64_t_defined: u32 = 1; -pub const __int_least8_t_defined: u32 = 1; -pub const __int_least16_t_defined: u32 = 1; -pub const __int_least32_t_defined: u32 = 1; -pub const __int_least64_t_defined: u32 = 1; -pub const __int_fast8_t_defined: u32 = 1; -pub const __int_fast16_t_defined: u32 = 1; -pub const __int_fast32_t_defined: u32 = 1; -pub const __int_fast64_t_defined: u32 = 1; -pub const WINT_MIN: u32 = 0; pub const MBEDTLS_ERR_MPI_FILE_IO_ERROR: i32 = -2; pub const MBEDTLS_ERR_MPI_BAD_INPUT_DATA: i32 = -4; pub const MBEDTLS_ERR_MPI_INVALID_CHARACTER: i32 = -6; @@ -1067,26 +950,25 @@ pub const MBEDTLS_CTR_DRBG_MAX_SEED_INPUT: u32 = 384; pub const MBEDTLS_CTR_DRBG_PR_OFF: u32 = 0; pub const MBEDTLS_CTR_DRBG_PR_ON: u32 = 1; pub const MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN: u32 = 0; -pub type __int8_t = crate::c_types::c_schar; -pub type __uint8_t = crate::c_types::c_uchar; -pub type __int16_t = crate::c_types::c_short; -pub type __uint16_t = crate::c_types::c_ushort; -pub type __int32_t = crate::c_types::c_int; -pub type __uint32_t = crate::c_types::c_uint; -pub type __int64_t = crate::c_types::c_longlong; -pub type __uint64_t = crate::c_types::c_ulonglong; -pub type __int_least8_t = crate::c_types::c_schar; -pub type __uint_least8_t = crate::c_types::c_uchar; -pub type __int_least16_t = crate::c_types::c_short; -pub type __uint_least16_t = crate::c_types::c_ushort; -pub type __int_least32_t = crate::c_types::c_int; -pub type __uint_least32_t = crate::c_types::c_uint; -pub type __int_least64_t = crate::c_types::c_longlong; -pub type __uint_least64_t = crate::c_types::c_ulonglong; -pub type __intmax_t = crate::c_types::c_longlong; -pub type __uintmax_t = crate::c_types::c_ulonglong; -pub type __intptr_t = crate::c_types::c_int; -pub type __uintptr_t = crate::c_types::c_uint; +pub type int_least64_t = i64; +pub type uint_least64_t = u64; +pub type int_fast64_t = i64; +pub type uint_fast64_t = u64; +pub type int_least32_t = i32; +pub type uint_least32_t = u32; +pub type int_fast32_t = i32; +pub type uint_fast32_t = u32; +pub type int_least16_t = i16; +pub type uint_least16_t = u16; +pub type int_fast16_t = i16; +pub type uint_fast16_t = u16; +pub type int_least8_t = i8; +pub type uint_least8_t = u8; +pub type int_fast8_t = i8; +pub type uint_fast8_t = u8; +pub type intmax_t = crate::c_types::c_longlong; +pub type uintmax_t = crate::c_types::c_ulonglong; +pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; pub type wchar_t = crate::c_types::c_int; #[repr(C)] #[repr(align(16))] @@ -1096,25 +978,6 @@ pub struct max_align_t { pub __bindgen_padding_0: u64, pub __clang_max_align_nonce2: u128, } -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; -pub type int_least8_t = __int_least8_t; -pub type uint_least8_t = __uint_least8_t; -pub type int_least16_t = __int_least16_t; -pub type uint_least16_t = __uint_least16_t; -pub type int_least32_t = __int_least32_t; -pub type uint_least32_t = __uint_least32_t; -pub type int_least64_t = __int_least64_t; -pub type uint_least64_t = __uint_least64_t; -pub type int_fast8_t = crate::c_types::c_schar; -pub type uint_fast8_t = crate::c_types::c_uchar; -pub type int_fast16_t = crate::c_types::c_short; -pub type uint_fast16_t = crate::c_types::c_ushort; -pub type int_fast32_t = crate::c_types::c_int; -pub type uint_fast32_t = crate::c_types::c_uint; -pub type int_fast64_t = crate::c_types::c_longlong; -pub type uint_fast64_t = crate::c_types::c_ulonglong; -pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; extern "C" { /// \brief Securely zeroize a buffer /// @@ -4810,6 +4673,7 @@ extern "C" { /// buffer of length \p blen Bytes. It may be \c NULL if /// \p blen is zero. /// \param blen The length of \p buf in Bytes. + /// \param md_alg The hash algorithm used to hash the original data. /// \param f_rng_blind The RNG function used for blinding. This must not be /// \c NULL. /// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be @@ -22631,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; +} diff --git a/esp-mbedtls-sys/src/include/esp32s2.rs b/esp-mbedtls-sys/src/include/esp32s2.rs index 34a5e23..c22260b 100644 --- a/esp-mbedtls-sys/src/include/esp32s2.rs +++ b/esp-mbedtls-sys/src/include/esp32s2.rs @@ -206,125 +206,7 @@ pub const PSA_WANT_KEY_TYPE_DERIVE: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD_HASH: u32 = 1; pub const PSA_WANT_KEY_TYPE_RAW_DATA: u32 = 1; -pub const _LIBC_LIMITS_H_: u32 = 1; -pub const __NEWLIB_H__: u32 = 1; -pub const _NEWLIB_VERSION_H__: u32 = 1; -pub const _NEWLIB_VERSION: &[u8; 6] = b"3.3.0\0"; -pub const __NEWLIB__: u32 = 3; -pub const __NEWLIB_MINOR__: u32 = 3; -pub const __NEWLIB_PATCHLEVEL__: u32 = 0; -pub const _WANT_IO_C99_FORMATS: u32 = 1; -pub const _WANT_IO_LONG_LONG: u32 = 1; -pub const _WANT_IO_POS_ARGS: u32 = 1; -pub const _WANT_REENT_SMALL: u32 = 1; -pub const _REENT_CHECK_VERIFY: u32 = 1; -pub const _MB_LEN_MAX: u32 = 1; -pub const _ICONV_ENABLED: u32 = 1; -pub const HAVE_INITFINI_ARRAY: u32 = 1; -pub const _ATEXIT_DYNAMIC_ALLOC: u32 = 1; -pub const _HAVE_LONG_DOUBLE: u32 = 1; -pub const _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL: u32 = 1; -pub const _LDBL_EQ_DBL: u32 = 1; -pub const _FVWRITE_IN_STREAMIO: u32 = 1; -pub const _FSEEK_OPTIMIZATION: u32 = 1; -pub const _UNBUF_STREAM_OPT: u32 = 1; -pub const _RETARGETABLE_LOCKING: u32 = 1; -pub const _WANT_USE_LONG_TIME_T: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __ATFILE_VISIBLE: u32 = 1; -pub const __BSD_VISIBLE: u32 = 1; -pub const __GNU_VISIBLE: u32 = 0; -pub const __ISO_C_VISIBLE: u32 = 2011; -pub const __LARGEFILE_VISIBLE: u32 = 0; -pub const __MISC_VISIBLE: u32 = 1; -pub const __POSIX_VISIBLE: u32 = 200809; -pub const __SVID_VISIBLE: u32 = 1; -pub const __XSI_VISIBLE: u32 = 0; -pub const __SSP_FORTIFY_LEVEL: u32 = 0; -pub const _POSIX_THREADS: u32 = 1; -pub const _POSIX_TIMEOUTS: u32 = 1; -pub const _POSIX_TIMERS: u32 = 1; -pub const _POSIX_MONOTONIC_CLOCK: u32 = 200112; -pub const _POSIX_CLOCK_SELECTION: u32 = 200112; -pub const _UNIX98_THREAD_MUTEX_ATTRIBUTES: u32 = 1; -pub const __have_longlong64: u32 = 1; -pub const __have_long32: u32 = 1; -pub const ___int8_t_defined: u32 = 1; -pub const ___int16_t_defined: u32 = 1; -pub const ___int32_t_defined: u32 = 1; -pub const ___int64_t_defined: u32 = 1; -pub const ___int_least8_t_defined: u32 = 1; -pub const ___int_least16_t_defined: u32 = 1; -pub const ___int_least32_t_defined: u32 = 1; -pub const ___int_least64_t_defined: u32 = 1; -pub const __GNUCLIKE_ASM: u32 = 3; -pub const __GNUCLIKE___TYPEOF: u32 = 1; -pub const __GNUCLIKE___OFFSETOF: u32 = 1; -pub const __GNUCLIKE___SECTION: u32 = 1; -pub const __GNUCLIKE_CTOR_SECTION_HANDLING: u32 = 1; -pub const __GNUCLIKE_BUILTIN_CONSTANT_P: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VARARGS: u32 = 1; -pub const __GNUCLIKE_BUILTIN_STDARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VAALIST: u32 = 1; -pub const __GNUC_VA_LIST_COMPATIBILITY: u32 = 1; -pub const __GNUCLIKE_BUILTIN_NEXT_ARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_MEMCPY: u32 = 1; -pub const __CC_SUPPORTS_INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE__: u32 = 1; -pub const __CC_SUPPORTS___FUNC__: u32 = 1; -pub const __CC_SUPPORTS_WARNING: u32 = 1; -pub const __CC_SUPPORTS_VARADIC_XXX: u32 = 1; -pub const __CC_SUPPORTS_DYNAMIC_ARRAY_INIT: u32 = 1; -pub const ARG_MAX: u32 = 4096; -pub const CHILD_MAX: u32 = 40; -pub const LINK_MAX: u32 = 32767; -pub const MAX_CANON: u32 = 255; -pub const MAX_INPUT: u32 = 255; -pub const NAME_MAX: u32 = 255; -pub const NGROUPS_MAX: u32 = 16; -pub const OPEN_MAX: u32 = 64; -pub const PATH_MAX: u32 = 1024; -pub const PIPE_BUF: u32 = 512; -pub const IOV_MAX: u32 = 1024; -pub const BC_BASE_MAX: u32 = 99; -pub const BC_DIM_MAX: u32 = 2048; -pub const BC_SCALE_MAX: u32 = 99; -pub const BC_STRING_MAX: u32 = 1000; -pub const COLL_WEIGHTS_MAX: u32 = 0; -pub const EXPR_NEST_MAX: u32 = 32; -pub const LINE_MAX: u32 = 2048; -pub const RE_DUP_MAX: u32 = 255; pub const MB_LEN_MAX: u32 = 1; -pub const NL_ARGMAX: u32 = 32; -pub const _POSIX2_RE_DUP_MAX: u32 = 255; -pub const __int20: u32 = 2; -pub const __int20__: u32 = 2; -pub const __INT8: &[u8; 3] = b"hh\0"; -pub const __INT16: &[u8; 2] = b"h\0"; -pub const __INT64: &[u8; 3] = b"ll\0"; -pub const __FAST8: &[u8; 3] = b"hh\0"; -pub const __FAST16: &[u8; 2] = b"h\0"; -pub const __FAST64: &[u8; 3] = b"ll\0"; -pub const __LEAST8: &[u8; 3] = b"hh\0"; -pub const __LEAST16: &[u8; 2] = b"h\0"; -pub const __LEAST64: &[u8; 3] = b"ll\0"; -pub const __int8_t_defined: u32 = 1; -pub const __int16_t_defined: u32 = 1; -pub const __int32_t_defined: u32 = 1; -pub const __int64_t_defined: u32 = 1; -pub const __int_least8_t_defined: u32 = 1; -pub const __int_least16_t_defined: u32 = 1; -pub const __int_least32_t_defined: u32 = 1; -pub const __int_least64_t_defined: u32 = 1; -pub const __int_fast8_t_defined: u32 = 1; -pub const __int_fast16_t_defined: u32 = 1; -pub const __int_fast32_t_defined: u32 = 1; -pub const __int_fast64_t_defined: u32 = 1; -pub const WINT_MIN: u32 = 0; pub const MBEDTLS_ERR_MPI_FILE_IO_ERROR: i32 = -2; pub const MBEDTLS_ERR_MPI_BAD_INPUT_DATA: i32 = -4; pub const MBEDTLS_ERR_MPI_INVALID_CHARACTER: i32 = -6; @@ -1067,52 +949,32 @@ pub const MBEDTLS_CTR_DRBG_MAX_SEED_INPUT: u32 = 384; pub const MBEDTLS_CTR_DRBG_PR_OFF: u32 = 0; pub const MBEDTLS_CTR_DRBG_PR_ON: u32 = 1; pub const MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN: u32 = 0; -pub type __int8_t = crate::c_types::c_schar; -pub type __uint8_t = crate::c_types::c_uchar; -pub type __int16_t = crate::c_types::c_short; -pub type __uint16_t = crate::c_types::c_ushort; -pub type __int32_t = crate::c_types::c_int; -pub type __uint32_t = crate::c_types::c_uint; -pub type __int64_t = crate::c_types::c_longlong; -pub type __uint64_t = crate::c_types::c_ulonglong; -pub type __int_least8_t = crate::c_types::c_schar; -pub type __uint_least8_t = crate::c_types::c_uchar; -pub type __int_least16_t = crate::c_types::c_short; -pub type __uint_least16_t = crate::c_types::c_ushort; -pub type __int_least32_t = crate::c_types::c_int; -pub type __uint_least32_t = crate::c_types::c_uint; -pub type __int_least64_t = crate::c_types::c_longlong; -pub type __uint_least64_t = crate::c_types::c_ulonglong; -pub type __intmax_t = crate::c_types::c_longlong; -pub type __uintmax_t = crate::c_types::c_ulonglong; -pub type __intptr_t = crate::c_types::c_int; -pub type __uintptr_t = crate::c_types::c_uint; -pub type wchar_t = crate::c_types::c_uchar; +pub type int_least64_t = i64; +pub type uint_least64_t = u64; +pub type int_fast64_t = i64; +pub type uint_fast64_t = u64; +pub type int_least32_t = i32; +pub type uint_least32_t = u32; +pub type int_fast32_t = i32; +pub type uint_fast32_t = u32; +pub type int_least16_t = i16; +pub type uint_least16_t = u16; +pub type int_fast16_t = i16; +pub type uint_fast16_t = u16; +pub type int_least8_t = i8; +pub type uint_least8_t = u8; +pub type int_fast8_t = i8; +pub type uint_fast8_t = u8; +pub type intmax_t = crate::c_types::c_longlong; +pub type uintmax_t = crate::c_types::c_ulonglong; +pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; +pub type wchar_t = crate::c_types::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct max_align_t { pub __clang_max_align_nonce1: crate::c_types::c_longlong, pub __clang_max_align_nonce2: f64, } -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; -pub type int_least8_t = __int_least8_t; -pub type uint_least8_t = __uint_least8_t; -pub type int_least16_t = __int_least16_t; -pub type uint_least16_t = __uint_least16_t; -pub type int_least32_t = __int_least32_t; -pub type uint_least32_t = __uint_least32_t; -pub type int_least64_t = __int_least64_t; -pub type uint_least64_t = __uint_least64_t; -pub type int_fast8_t = crate::c_types::c_schar; -pub type uint_fast8_t = crate::c_types::c_uchar; -pub type int_fast16_t = crate::c_types::c_short; -pub type uint_fast16_t = crate::c_types::c_ushort; -pub type int_fast32_t = crate::c_types::c_int; -pub type uint_fast32_t = crate::c_types::c_uint; -pub type int_fast64_t = crate::c_types::c_longlong; -pub type uint_fast64_t = crate::c_types::c_ulonglong; -pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; extern "C" { /// \brief Securely zeroize a buffer /// @@ -4808,6 +4670,7 @@ extern "C" { /// buffer of length \p blen Bytes. It may be \c NULL if /// \p blen is zero. /// \param blen The length of \p buf in Bytes. + /// \param md_alg The hash algorithm used to hash the original data. /// \param f_rng_blind The RNG function used for blinding. This must not be /// \c NULL. /// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be @@ -22629,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; +} diff --git a/esp-mbedtls-sys/src/include/esp32s3.rs b/esp-mbedtls-sys/src/include/esp32s3.rs index 34a5e23..c22260b 100644 --- a/esp-mbedtls-sys/src/include/esp32s3.rs +++ b/esp-mbedtls-sys/src/include/esp32s3.rs @@ -206,125 +206,7 @@ pub const PSA_WANT_KEY_TYPE_DERIVE: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD: u32 = 1; pub const PSA_WANT_KEY_TYPE_PASSWORD_HASH: u32 = 1; pub const PSA_WANT_KEY_TYPE_RAW_DATA: u32 = 1; -pub const _LIBC_LIMITS_H_: u32 = 1; -pub const __NEWLIB_H__: u32 = 1; -pub const _NEWLIB_VERSION_H__: u32 = 1; -pub const _NEWLIB_VERSION: &[u8; 6] = b"3.3.0\0"; -pub const __NEWLIB__: u32 = 3; -pub const __NEWLIB_MINOR__: u32 = 3; -pub const __NEWLIB_PATCHLEVEL__: u32 = 0; -pub const _WANT_IO_C99_FORMATS: u32 = 1; -pub const _WANT_IO_LONG_LONG: u32 = 1; -pub const _WANT_IO_POS_ARGS: u32 = 1; -pub const _WANT_REENT_SMALL: u32 = 1; -pub const _REENT_CHECK_VERIFY: u32 = 1; -pub const _MB_LEN_MAX: u32 = 1; -pub const _ICONV_ENABLED: u32 = 1; -pub const HAVE_INITFINI_ARRAY: u32 = 1; -pub const _ATEXIT_DYNAMIC_ALLOC: u32 = 1; -pub const _HAVE_LONG_DOUBLE: u32 = 1; -pub const _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL: u32 = 1; -pub const _LDBL_EQ_DBL: u32 = 1; -pub const _FVWRITE_IN_STREAMIO: u32 = 1; -pub const _FSEEK_OPTIMIZATION: u32 = 1; -pub const _UNBUF_STREAM_OPT: u32 = 1; -pub const _RETARGETABLE_LOCKING: u32 = 1; -pub const _WANT_USE_LONG_TIME_T: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __ATFILE_VISIBLE: u32 = 1; -pub const __BSD_VISIBLE: u32 = 1; -pub const __GNU_VISIBLE: u32 = 0; -pub const __ISO_C_VISIBLE: u32 = 2011; -pub const __LARGEFILE_VISIBLE: u32 = 0; -pub const __MISC_VISIBLE: u32 = 1; -pub const __POSIX_VISIBLE: u32 = 200809; -pub const __SVID_VISIBLE: u32 = 1; -pub const __XSI_VISIBLE: u32 = 0; -pub const __SSP_FORTIFY_LEVEL: u32 = 0; -pub const _POSIX_THREADS: u32 = 1; -pub const _POSIX_TIMEOUTS: u32 = 1; -pub const _POSIX_TIMERS: u32 = 1; -pub const _POSIX_MONOTONIC_CLOCK: u32 = 200112; -pub const _POSIX_CLOCK_SELECTION: u32 = 200112; -pub const _UNIX98_THREAD_MUTEX_ATTRIBUTES: u32 = 1; -pub const __have_longlong64: u32 = 1; -pub const __have_long32: u32 = 1; -pub const ___int8_t_defined: u32 = 1; -pub const ___int16_t_defined: u32 = 1; -pub const ___int32_t_defined: u32 = 1; -pub const ___int64_t_defined: u32 = 1; -pub const ___int_least8_t_defined: u32 = 1; -pub const ___int_least16_t_defined: u32 = 1; -pub const ___int_least32_t_defined: u32 = 1; -pub const ___int_least64_t_defined: u32 = 1; -pub const __GNUCLIKE_ASM: u32 = 3; -pub const __GNUCLIKE___TYPEOF: u32 = 1; -pub const __GNUCLIKE___OFFSETOF: u32 = 1; -pub const __GNUCLIKE___SECTION: u32 = 1; -pub const __GNUCLIKE_CTOR_SECTION_HANDLING: u32 = 1; -pub const __GNUCLIKE_BUILTIN_CONSTANT_P: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VARARGS: u32 = 1; -pub const __GNUCLIKE_BUILTIN_STDARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_VAALIST: u32 = 1; -pub const __GNUC_VA_LIST_COMPATIBILITY: u32 = 1; -pub const __GNUCLIKE_BUILTIN_NEXT_ARG: u32 = 1; -pub const __GNUCLIKE_BUILTIN_MEMCPY: u32 = 1; -pub const __CC_SUPPORTS_INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE: u32 = 1; -pub const __CC_SUPPORTS___INLINE__: u32 = 1; -pub const __CC_SUPPORTS___FUNC__: u32 = 1; -pub const __CC_SUPPORTS_WARNING: u32 = 1; -pub const __CC_SUPPORTS_VARADIC_XXX: u32 = 1; -pub const __CC_SUPPORTS_DYNAMIC_ARRAY_INIT: u32 = 1; -pub const ARG_MAX: u32 = 4096; -pub const CHILD_MAX: u32 = 40; -pub const LINK_MAX: u32 = 32767; -pub const MAX_CANON: u32 = 255; -pub const MAX_INPUT: u32 = 255; -pub const NAME_MAX: u32 = 255; -pub const NGROUPS_MAX: u32 = 16; -pub const OPEN_MAX: u32 = 64; -pub const PATH_MAX: u32 = 1024; -pub const PIPE_BUF: u32 = 512; -pub const IOV_MAX: u32 = 1024; -pub const BC_BASE_MAX: u32 = 99; -pub const BC_DIM_MAX: u32 = 2048; -pub const BC_SCALE_MAX: u32 = 99; -pub const BC_STRING_MAX: u32 = 1000; -pub const COLL_WEIGHTS_MAX: u32 = 0; -pub const EXPR_NEST_MAX: u32 = 32; -pub const LINE_MAX: u32 = 2048; -pub const RE_DUP_MAX: u32 = 255; pub const MB_LEN_MAX: u32 = 1; -pub const NL_ARGMAX: u32 = 32; -pub const _POSIX2_RE_DUP_MAX: u32 = 255; -pub const __int20: u32 = 2; -pub const __int20__: u32 = 2; -pub const __INT8: &[u8; 3] = b"hh\0"; -pub const __INT16: &[u8; 2] = b"h\0"; -pub const __INT64: &[u8; 3] = b"ll\0"; -pub const __FAST8: &[u8; 3] = b"hh\0"; -pub const __FAST16: &[u8; 2] = b"h\0"; -pub const __FAST64: &[u8; 3] = b"ll\0"; -pub const __LEAST8: &[u8; 3] = b"hh\0"; -pub const __LEAST16: &[u8; 2] = b"h\0"; -pub const __LEAST64: &[u8; 3] = b"ll\0"; -pub const __int8_t_defined: u32 = 1; -pub const __int16_t_defined: u32 = 1; -pub const __int32_t_defined: u32 = 1; -pub const __int64_t_defined: u32 = 1; -pub const __int_least8_t_defined: u32 = 1; -pub const __int_least16_t_defined: u32 = 1; -pub const __int_least32_t_defined: u32 = 1; -pub const __int_least64_t_defined: u32 = 1; -pub const __int_fast8_t_defined: u32 = 1; -pub const __int_fast16_t_defined: u32 = 1; -pub const __int_fast32_t_defined: u32 = 1; -pub const __int_fast64_t_defined: u32 = 1; -pub const WINT_MIN: u32 = 0; pub const MBEDTLS_ERR_MPI_FILE_IO_ERROR: i32 = -2; pub const MBEDTLS_ERR_MPI_BAD_INPUT_DATA: i32 = -4; pub const MBEDTLS_ERR_MPI_INVALID_CHARACTER: i32 = -6; @@ -1067,52 +949,32 @@ pub const MBEDTLS_CTR_DRBG_MAX_SEED_INPUT: u32 = 384; pub const MBEDTLS_CTR_DRBG_PR_OFF: u32 = 0; pub const MBEDTLS_CTR_DRBG_PR_ON: u32 = 1; pub const MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN: u32 = 0; -pub type __int8_t = crate::c_types::c_schar; -pub type __uint8_t = crate::c_types::c_uchar; -pub type __int16_t = crate::c_types::c_short; -pub type __uint16_t = crate::c_types::c_ushort; -pub type __int32_t = crate::c_types::c_int; -pub type __uint32_t = crate::c_types::c_uint; -pub type __int64_t = crate::c_types::c_longlong; -pub type __uint64_t = crate::c_types::c_ulonglong; -pub type __int_least8_t = crate::c_types::c_schar; -pub type __uint_least8_t = crate::c_types::c_uchar; -pub type __int_least16_t = crate::c_types::c_short; -pub type __uint_least16_t = crate::c_types::c_ushort; -pub type __int_least32_t = crate::c_types::c_int; -pub type __uint_least32_t = crate::c_types::c_uint; -pub type __int_least64_t = crate::c_types::c_longlong; -pub type __uint_least64_t = crate::c_types::c_ulonglong; -pub type __intmax_t = crate::c_types::c_longlong; -pub type __uintmax_t = crate::c_types::c_ulonglong; -pub type __intptr_t = crate::c_types::c_int; -pub type __uintptr_t = crate::c_types::c_uint; -pub type wchar_t = crate::c_types::c_uchar; +pub type int_least64_t = i64; +pub type uint_least64_t = u64; +pub type int_fast64_t = i64; +pub type uint_fast64_t = u64; +pub type int_least32_t = i32; +pub type uint_least32_t = u32; +pub type int_fast32_t = i32; +pub type uint_fast32_t = u32; +pub type int_least16_t = i16; +pub type uint_least16_t = u16; +pub type int_fast16_t = i16; +pub type uint_fast16_t = u16; +pub type int_least8_t = i8; +pub type uint_least8_t = u8; +pub type int_fast8_t = i8; +pub type uint_fast8_t = u8; +pub type intmax_t = crate::c_types::c_longlong; +pub type uintmax_t = crate::c_types::c_ulonglong; +pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; +pub type wchar_t = crate::c_types::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct max_align_t { pub __clang_max_align_nonce1: crate::c_types::c_longlong, pub __clang_max_align_nonce2: f64, } -pub type intmax_t = __intmax_t; -pub type uintmax_t = __uintmax_t; -pub type int_least8_t = __int_least8_t; -pub type uint_least8_t = __uint_least8_t; -pub type int_least16_t = __int_least16_t; -pub type uint_least16_t = __uint_least16_t; -pub type int_least32_t = __int_least32_t; -pub type uint_least32_t = __uint_least32_t; -pub type int_least64_t = __int_least64_t; -pub type uint_least64_t = __uint_least64_t; -pub type int_fast8_t = crate::c_types::c_schar; -pub type uint_fast8_t = crate::c_types::c_uchar; -pub type int_fast16_t = crate::c_types::c_short; -pub type uint_fast16_t = crate::c_types::c_ushort; -pub type int_fast32_t = crate::c_types::c_int; -pub type uint_fast32_t = crate::c_types::c_uint; -pub type int_fast64_t = crate::c_types::c_longlong; -pub type uint_fast64_t = crate::c_types::c_ulonglong; -pub type mbedtls_iso_c_forbids_empty_translation_units = crate::c_types::c_int; extern "C" { /// \brief Securely zeroize a buffer /// @@ -4808,6 +4670,7 @@ extern "C" { /// buffer of length \p blen Bytes. It may be \c NULL if /// \p blen is zero. /// \param blen The length of \p buf in Bytes. + /// \param md_alg The hash algorithm used to hash the original data. /// \param f_rng_blind The RNG function used for blinding. This must not be /// \c NULL. /// \param p_rng_blind The RNG context to be passed to \p f_rng. This may be @@ -22629,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; +} diff --git a/esp-mbedtls/Cargo.toml b/esp-mbedtls/Cargo.toml index f11f1ce..e865779 100644 --- a/esp-mbedtls/Cargo.toml +++ b/esp-mbedtls/Cargo.toml @@ -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"] diff --git a/esp-mbedtls/src/bignum.rs b/esp-mbedtls/src/bignum.rs new file mode 100644 index 0000000..84923ad --- /dev/null +++ b/esp-mbedtls/src/bignum.rs @@ -0,0 +1,354 @@ +#![allow(non_snake_case)] + +use crate::hal::prelude::nb; +use crate::hal::rsa::{operand_sizes, RsaModularExponentiation}; + +use crypto_bigint::*; + +use esp_mbedtls_sys::bindings::*; +use esp_mbedtls_sys::c_types::*; + +macro_rules! error_checked { + ($block:expr) => {{ + let res = $block; + if res != 0 { + panic!("Non zero error {:?}", res); + } else { + // Do nothing for now + } + }}; +} + +#[cfg(feature = "esp32")] +const SOC_RSA_MAX_BIT_LEN: usize = 4096; +#[cfg(feature = "esp32c3")] +const SOC_RSA_MAX_BIT_LEN: usize = 3072; +#[cfg(feature = "esp32s2")] +const SOC_RSA_MAX_BIT_LEN: usize = 4096; +#[cfg(feature = "esp32s3")] +const SOC_RSA_MAX_BIT_LEN: usize = 4096; + +/// Bad input parameters to function. +const MBEDTLS_ERR_MPI_BAD_INPUT_DATA: c_int = -0x0004; + +/// Calculate the number of words used for a hardware operation. +/// +/// For every chip except `esp32`, this will return `words` +/// For `esp32`, this will return the number of words rounded up to the 512 block count. +const fn calculate_hw_words(words: usize) -> usize { + // Round up number of words to nearest + // 512 bit (16 word) block count. + #[cfg(feature = "esp32")] + return (words + 0xF) & !0xF; + #[cfg(not(feature = "esp32"))] + words +} + +/// Return the number of words actually used to represent an mpi number. +fn mpi_words(X: &mbedtls_mpi) -> usize { + for i in (0..=X.private_n).rev() { + if unsafe { X.private_p.add(i - 1).read() } != 0 { + return i; + } + } + 0 +} + +#[inline] +fn copy_bytes(src: *const T, dst: *mut T, count: usize) +where + T: Copy, +{ + unsafe { core::ptr::copy_nonoverlapping(src, dst, count) }; +} + +fn compute_mprime(M: &mbedtls_mpi) -> u32 { + let mut t: u64 = 1; + let mut two_2_i_minus_1: u64 = 2; // 2^(i-1) + let mut two_2_i: u64 = 4; // 2^i + let n = unsafe { M.private_p.read() } as u64; + + for _ in 2..=32 { + if n * t % two_2_i >= two_2_i_minus_1 { + t += two_2_i_minus_1; + } + + two_2_i_minus_1 <<= 1; + two_2_i <<= 1; + } + + (u32::MAX as u64 - t + 1) as u32 +} + +/// Calculate Rinv = RR^2 mod M, where: +/// +/// R = b^n where b = 2^32, n=num_words, +/// R = 2^N (where N=num_bits) +/// RR = R^2 = 2^(2*N) (where N=num_bits=num_words*32) +/// +/// This calculation is computationally expensive (mbedtls_mpi_mod_mpi) +/// so caller should cache the result where possible. +/// +/// DO NOT call this function while holding esp_mpi_enable_hardware_hw_op(). +fn calculate_rinv(prec_RR: &mut mbedtls_mpi, M: &mbedtls_mpi, num_words: usize) -> c_int { + let ret = 0; + let num_bits = num_words * 32; + let mut RR = mbedtls_mpi { + private_s: 0, + private_n: 0, + private_p: core::ptr::null_mut(), + }; + + unsafe { + mbedtls_mpi_init(&mut RR); + error_checked!(mbedtls_mpi_set_bit(&mut RR, num_bits * 2, 1)); + error_checked!(mbedtls_mpi_mod_mpi(prec_RR, &RR, M)); + mbedtls_mpi_free(&mut RR); + } + + ret +} + +/// Z = X ^ Y mod M +#[no_mangle] +pub unsafe extern "C" fn mbedtls_mpi_exp_mod( + Z: *mut mbedtls_mpi, + X: &mbedtls_mpi, + Y: &mbedtls_mpi, + M: &mbedtls_mpi, + prec_RR: *mut mbedtls_mpi, +) -> c_int { + match crate::RSA_REF { + None => return unsafe { mbedtls_mpi_exp_mod_soft(Z, X, Y, M, prec_RR) }, + Some(ref mut rsa) => { + let x_words = mpi_words(X); + let y_words = mpi_words(Y); + let m_words = mpi_words(M); + + // All numbers must be the lame length, so choose longest number as + // cardinal length of operation + let num_words = + calculate_hw_words(core::cmp::max(m_words, core::cmp::max(x_words, y_words))); + + if num_words * 32 > SOC_RSA_MAX_BIT_LEN { + return unsafe { mbedtls_mpi_exp_mod_soft(Z, X, Y, M, prec_RR) }; + } + + if M.private_p.is_null() { + todo!("Handle this null"); + } + unsafe { + if mbedtls_mpi_cmp_int(M, 0) <= 0 || M.private_p.read() & 1 == 0 { + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; + } + + if mbedtls_mpi_cmp_int(Y, 0) < 0 { + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; + } + + if mbedtls_mpi_cmp_int(Y, 0) == 0 { + return mbedtls_mpi_lset(Z, 1); + } + } + + let mut rinv_new = mbedtls_mpi { + private_s: 0, + private_n: 0, + private_p: core::ptr::null_mut(), + }; + + // Determine RR pointer, either _RR for cached value or local RR_new + let rinv: &mut mbedtls_mpi = if prec_RR.is_null() { + unsafe { mbedtls_mpi_init(&mut rinv_new) }; + &mut rinv_new + } else { + // This is safe since we check above if pointer is not null + unsafe { &mut *prec_RR } + }; + + if rinv.private_p.is_null() { + calculate_rinv(rinv, M, num_words); + } + + unsafe { + error_checked!(mbedtls_mpi_grow(Z, m_words)); + } + + nb::block!(rsa.ready()).unwrap(); + rsa.enable_disable_constant_time_acceleration(true); + rsa.enable_disable_search_acceleration(true); + unsafe { + match num_words { + U256::LIMBS => { + const OP_SIZE: usize = U256::LIMBS; + let mut base = [0u32; OP_SIZE]; + let mut exponent = [0u32; OP_SIZE]; + let mut modulus = [0u32; OP_SIZE]; + let mut r = [0u32; OP_SIZE]; + copy_bytes(X.private_p, base.as_mut_ptr(), x_words); + copy_bytes(Y.private_p, exponent.as_mut_ptr(), y_words); + copy_bytes(M.private_p, modulus.as_mut_ptr(), m_words); + copy_bytes(rinv.private_p, r.as_mut_ptr(), mpi_words(rinv)); + let mut mod_exp = RsaModularExponentiation::::new( + rsa, + &exponent, // exponent (Y) Y_MEM + &modulus, // modulus (M) M_MEM + compute_mprime(M), // mprime + ); + let mut out = [0u32; OP_SIZE]; + mod_exp.start_exponentiation( + &base, // X_MEM + &r, // Z_MEM + ); + + mod_exp.read_results(&mut out); + copy_bytes(out.as_ptr(), (*Z).private_p, m_words); + } + U384::LIMBS => { + const OP_SIZE: usize = U384::LIMBS; + let mut base = [0u32; OP_SIZE]; + let mut exponent = [0u32; OP_SIZE]; + let mut modulus = [0u32; OP_SIZE]; + let mut r = [0u32; OP_SIZE]; + copy_bytes(X.private_p, base.as_mut_ptr(), x_words); + copy_bytes(Y.private_p, exponent.as_mut_ptr(), y_words); + copy_bytes(M.private_p, modulus.as_mut_ptr(), m_words); + copy_bytes(rinv.private_p, r.as_mut_ptr(), mpi_words(rinv)); + let mut mod_exp = RsaModularExponentiation::::new( + rsa, + &exponent, // exponent (Y) Y_MEM + &modulus, // modulus (M) M_MEM + compute_mprime(M), // mprime + ); + let mut out = [0u32; OP_SIZE]; + mod_exp.start_exponentiation( + &base, // X_MEM + &r, // Z_MEM + ); + + mod_exp.read_results(&mut out); + copy_bytes(out.as_ptr(), (*Z).private_p, m_words); + } + U512::LIMBS => { + const OP_SIZE: usize = U512::LIMBS; + let mut base = [0u32; OP_SIZE]; + let mut exponent = [0u32; OP_SIZE]; + let mut modulus = [0u32; OP_SIZE]; + let mut r = [0u32; OP_SIZE]; + copy_bytes(X.private_p, base.as_mut_ptr(), x_words); + copy_bytes(Y.private_p, exponent.as_mut_ptr(), y_words); + copy_bytes(M.private_p, modulus.as_mut_ptr(), m_words); + copy_bytes(rinv.private_p, r.as_mut_ptr(), mpi_words(rinv)); + let mut mod_exp = RsaModularExponentiation::::new( + rsa, + &exponent, // exponent (Y) Y_MEM + &modulus, // modulus (M) M_MEM + compute_mprime(M), // mprime + ); + let mut out = [0u32; OP_SIZE]; + mod_exp.start_exponentiation( + &base, // X_MEM + &r, // Z_MEM + ); + + mod_exp.read_results(&mut out); + copy_bytes(out.as_ptr(), (*Z).private_p, m_words); + } + U1024::LIMBS => { + const OP_SIZE: usize = U1024::LIMBS; + let mut base = [0u32; OP_SIZE]; + let mut exponent = [0u32; OP_SIZE]; + let mut modulus = [0u32; OP_SIZE]; + let mut r = [0u32; OP_SIZE]; + copy_bytes(X.private_p, base.as_mut_ptr(), x_words); + copy_bytes(Y.private_p, exponent.as_mut_ptr(), y_words); + copy_bytes(M.private_p, modulus.as_mut_ptr(), m_words); + copy_bytes(rinv.private_p, r.as_mut_ptr(), mpi_words(rinv)); + let mut mod_exp = RsaModularExponentiation::::new( + rsa, + &exponent, // exponent (Y) Y_MEM + &modulus, // modulus (M) M_MEM + compute_mprime(M), // mprime + ); + let mut out = [0u32; OP_SIZE]; + mod_exp.start_exponentiation( + &base, // X_MEM + &r, // Z_MEM + ); + + mod_exp.read_results(&mut out); + copy_bytes(out.as_ptr(), (*Z).private_p, m_words); + } + U2048::LIMBS => { + const OP_SIZE: usize = U2048::LIMBS; + let mut base = [0u32; OP_SIZE]; + let mut exponent = [0u32; OP_SIZE]; + let mut modulus = [0u32; OP_SIZE]; + let mut r = [0u32; OP_SIZE]; + copy_bytes(X.private_p, base.as_mut_ptr(), x_words); + copy_bytes(Y.private_p, exponent.as_mut_ptr(), y_words); + copy_bytes(M.private_p, modulus.as_mut_ptr(), m_words); + copy_bytes(rinv.private_p, r.as_mut_ptr(), mpi_words(rinv)); + let mut mod_exp = RsaModularExponentiation::::new( + rsa, + &exponent, // exponent (Y) Y_MEM + &modulus, // modulus (M) M_MEM + compute_mprime(M), // mprime + ); + let mut out = [0u32; OP_SIZE]; + mod_exp.start_exponentiation( + &base, // X_MEM + &r, // Z_MEM + ); + + mod_exp.read_results(&mut out); + copy_bytes(out.as_ptr(), (*Z).private_p, m_words); + } + #[cfg(not(feature = "esp32c3"))] + U4096::LIMBS => { + const OP_SIZE: usize = U4096::LIMBS; + let mut base = [0u32; OP_SIZE]; + let mut exponent = [0u32; OP_SIZE]; + let mut modulus = [0u32; OP_SIZE]; + let mut r = [0u32; OP_SIZE]; + copy_bytes(X.private_p, base.as_mut_ptr(), x_words); + copy_bytes(Y.private_p, exponent.as_mut_ptr(), y_words); + copy_bytes(M.private_p, modulus.as_mut_ptr(), m_words); + copy_bytes(rinv.private_p, r.as_mut_ptr(), mpi_words(rinv)); + let mut mod_exp = RsaModularExponentiation::::new( + rsa, + &exponent, // exponent (Y) Y_MEM + &modulus, // modulus (M) M_MEM + compute_mprime(M), // mprime + ); + let mut out = [0u32; OP_SIZE]; + mod_exp.start_exponentiation( + &base, // X_MEM + &r, // Z_MEM + ); + + mod_exp.read_results(&mut out); + copy_bytes(out.as_ptr(), (*Z).private_p, m_words); + } + op => { + todo!("Implement operand: {}", op); + } + } + } + + assert_eq!(X.private_s, 1); + // Compensate for negative X + if X.private_s == -1 && unsafe { Y.private_p.read() & 1 } != 0 { + unsafe { (*Z).private_s = -1 }; + unsafe { error_checked!(mbedtls_mpi_add_mpi(Z, M, Z)) }; + } else { + unsafe { (*Z).private_s = 1 }; + } + + if prec_RR.is_null() { + unsafe { mbedtls_mpi_free(&mut rinv_new) }; + } + 0 + } + } +} diff --git a/esp-mbedtls/src/compat.rs b/esp-mbedtls/src/compat.rs index 249bf17..77aed29 100644 --- a/esp-mbedtls/src/compat.rs +++ b/esp-mbedtls/src/compat.rs @@ -115,8 +115,8 @@ extern "C" fn vsnprintf( } #[no_mangle] -extern "C" fn rand() { - todo!() +extern "C" fn rand() -> crate::c_ulong { + unsafe { crate::random() } } pub struct StrBuf { diff --git a/esp-mbedtls/src/lib.rs b/esp-mbedtls/src/lib.rs index 64a2240..2be2a37 100644 --- a/esp-mbedtls/src/lib.rs +++ b/esp-mbedtls/src/lib.rs @@ -16,8 +16,13 @@ pub use esp32s2_hal as hal; #[cfg(feature = "esp32s3")] pub use esp32s3_hal as hal; +use crate::hal::rsa::Rsa; + mod compat; +#[cfg(any(feature = "esp32c3", feature = "esp32s2", feature = "esp32s3"))] +mod bignum; + use core::ffi::CStr; use core::mem::size_of; @@ -25,8 +30,18 @@ use compat::StrBuf; use embedded_io::Read; use embedded_io::Write; use esp_mbedtls_sys::bindings::*; +/// Re-export self-tests +pub use esp_mbedtls_sys::bindings::{ + // Bignum + mbedtls_mpi_self_test, + // RSA + mbedtls_rsa_self_test, +}; use esp_mbedtls_sys::c_types::*; +/// Hold the RSA peripheral for cryptographic operations. +static mut RSA_REF: Option<&mut Rsa> = None; + // these will come from esp-wifi (i.e. this can only be used together with esp-wifi) extern "C" { fn free(ptr: *const u8); @@ -384,15 +399,36 @@ pub struct Session { } impl Session { + /// Create a session for a TLS stream. + /// + /// # Arguments + /// + /// * `stream` - The stream for the connection. + /// * `servername` - The hostname to check against the received server certificate. It sets the ServerName TLS extension, too, if that extension is enabled. (client-side only) + /// * `mode` - Use [Mode::Client] if you are running a client. [Mode::Server] if you are + /// running a server. + /// * `min_version` - The minimum TLS version for the connection, that will be accepted. + /// * `certificates` - Certificate chain for the connection. Will play a different role + /// depending on if running as client or server. See [Certificates] for more information. + /// * `rsa` - Optionally take an RSA driver instance. This session will use the hardware rsa crypto + /// accelerators for the session. Passing None will use the software implementation of RSA which is slower. + /// + /// # Errors + /// + /// This will return a [TlsError] if there were an error during the initialization of the + /// session. This can happen if there is not enough memory of if the certificates are in an + /// invalid format. pub fn new( stream: T, servername: &str, mode: Mode, min_version: TlsVersion, certificates: Certificates, + rsa: Option<&mut Rsa>, ) -> Result { let (ssl_context, ssl_config, crt, client_crt, private_key) = certificates.init_ssl(servername, mode, min_version)?; + unsafe { RSA_REF = core::mem::transmute(rsa) } return Ok(Self { stream, ssl_context, @@ -589,15 +625,36 @@ pub mod asynch { } impl Session { + /// Create a session for a TLS stream. + /// + /// # Arguments + /// + /// * `stream` - The stream for the connection. + /// * `servername` - The hostname to check against the received server certificate. It sets the ServerName TLS extension, too, if that extension is enabled. (client-side only) + /// * `mode` - Use [Mode::Client] if you are running a client. [Mode::Server] if you are + /// running a server. + /// * `min_version` - The minimum TLS version for the connection, that will be accepted. + /// * `certificates` - Certificate chain for the connection. Will play a different role + /// depending on if running as client or server. See [Certificates] for more information. + /// * `rsa` - Optionally take an RSA driver instance. This session will use the hardware rsa crypto + /// accelerators for the session. Passing None will use the software implementation of RSA which is slower. + /// + /// # Errors + /// + /// This will return a [TlsError] if there were an error during the initialization of the + /// session. This can happen if there is not enough memory of if the certificates are in an + /// invalid format. pub fn new( stream: T, servername: &str, mode: Mode, min_version: TlsVersion, certificates: Certificates, + rsa: Option<&mut Rsa>, ) -> Result { let (ssl_context, ssl_config, crt, client_crt, private_key) = certificates.init_ssl(servername, mode, min_version)?; + unsafe { RSA_REF = core::mem::transmute(rsa) } return Ok(Self { stream, ssl_context, diff --git a/examples/async_client.rs b/examples/async_client.rs index 29c21cf..6fb917b 100644 --- a/examples/async_client.rs +++ b/examples/async_client.rs @@ -34,7 +34,7 @@ use esp_wifi::wifi::{ use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; use hal::Rng; -use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; +use hal::{embassy, peripherals::Peripherals, prelude::*, rsa::Rsa, timer::TimerGroup}; use static_cell::make_static; const SSID: &str = env!("SSID"); @@ -116,6 +116,8 @@ async fn main(spawner: Spawner) -> ! { set_debug(0); + let mut rsa = Rsa::new(peripherals.RSA); + let tls: Session<_, 4096> = Session::new( &mut socket, "www.google.com", @@ -128,6 +130,7 @@ async fn main(spawner: Spawner) -> ! { .ok(), ..Default::default() }, + Some(&mut rsa), ) .unwrap(); diff --git a/examples/async_client_mTLS.rs b/examples/async_client_mTLS.rs index 4b15fda..6c46bb8 100644 --- a/examples/async_client_mTLS.rs +++ b/examples/async_client_mTLS.rs @@ -34,7 +34,7 @@ use esp_wifi::wifi::{ use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; use hal::Rng; -use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; +use hal::{embassy, peripherals::Peripherals, prelude::*, rsa::Rsa, timer::TimerGroup}; use static_cell::make_static; const SSID: &str = env!("SSID"); @@ -116,6 +116,8 @@ async fn main(spawner: Spawner) -> ! { set_debug(0); + let mut rsa = Rsa::new(peripherals.RSA); + let certificates = Certificates { ca_chain: X509::pem( concat!(include_str!("./certs/certauth.cryptomix.com.pem"), "\0").as_bytes(), @@ -134,6 +136,7 @@ async fn main(spawner: Spawner) -> ! { Mode::Client, TlsVersion::Tls1_3, certificates, + Some(&mut rsa), ) .unwrap(); diff --git a/examples/async_server.rs b/examples/async_server.rs index 808414d..47306f4 100644 --- a/examples/async_server.rs +++ b/examples/async_server.rs @@ -21,7 +21,7 @@ pub use esp32s2_hal as hal; pub use esp32s3_hal as hal; use embassy_net::tcp::TcpSocket; -use embassy_net::{Config, Stack, StackResources}; +use embassy_net::{Config, IpListenEndpoint, Stack, StackResources}; use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; @@ -37,8 +37,7 @@ use esp_wifi::wifi::{ use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; use hal::Rng; -use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use smoltcp::wire::IpListenEndpoint; +use hal::{embassy, peripherals::Peripherals, prelude::*, rsa::Rsa, timer::TimerGroup}; use static_cell::make_static; const SSID: &str = env!("SSID"); @@ -111,6 +110,7 @@ async fn main(spawner: Spawner) -> ! { } let mut socket = TcpSocket::new(&stack, &mut rx_buffer, &mut tx_buffer); + let mut rsa = Rsa::new(peripherals.RSA); socket.set_timeout(Some(Duration::from_secs(10))); loop { println!("Waiting for connection..."); @@ -150,6 +150,7 @@ async fn main(spawner: Spawner) -> ! { .ok(), ..Default::default() }, + Some(&mut rsa), ) .unwrap(); diff --git a/examples/async_server_mTLS.rs b/examples/async_server_mTLS.rs index f9f9f3f..1e0134f 100644 --- a/examples/async_server_mTLS.rs +++ b/examples/async_server_mTLS.rs @@ -38,7 +38,7 @@ pub use esp32s2_hal as hal; pub use esp32s3_hal as hal; use embassy_net::tcp::TcpSocket; -use embassy_net::{Config, Stack, StackResources}; +use embassy_net::{Config, IpListenEndpoint, Stack, StackResources}; use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; @@ -54,8 +54,7 @@ use esp_wifi::wifi::{ use esp_wifi::{initialize, EspWifiInitFor}; use hal::clock::ClockControl; use hal::Rng; -use hal::{embassy, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use smoltcp::wire::IpListenEndpoint; +use hal::{embassy, peripherals::Peripherals, prelude::*, rsa::Rsa, timer::TimerGroup}; use static_cell::make_static; const SSID: &str = env!("SSID"); @@ -128,6 +127,7 @@ async fn main(spawner: Spawner) -> ! { } let mut socket = TcpSocket::new(&stack, &mut rx_buffer, &mut tx_buffer); + let mut rsa = Rsa::new(peripherals.RSA); socket.set_timeout(Some(Duration::from_secs(10))); loop { println!("Waiting for connection..."); @@ -169,6 +169,7 @@ async fn main(spawner: Spawner) -> ! { .ok(), ..Default::default() }, + Some(&mut rsa), ) .unwrap(); diff --git a/examples/crypto_self_test.rs b/examples/crypto_self_test.rs new file mode 100644 index 0000000..849227d --- /dev/null +++ b/examples/crypto_self_test.rs @@ -0,0 +1,146 @@ +//! Run crypto self tests to ensure their functionnality +#![no_std] +#![no_main] + +#[doc(hidden)] +#[cfg(feature = "esp32")] +pub use esp32_hal as hal; +#[doc(hidden)] +#[cfg(feature = "esp32c3")] +pub use esp32c3_hal as hal; +#[doc(hidden)] +#[cfg(feature = "esp32s2")] +pub use esp32s2_hal as hal; +#[doc(hidden)] +#[cfg(feature = "esp32s3")] +pub use esp32s3_hal as hal; + +use esp_backtrace as _; +use esp_mbedtls::set_debug; +use esp_println::{logger::init_logger, println}; + +/// Only used for ROM functions +#[allow(unused_imports)] +use esp_wifi::{initialize, EspWifiInitFor}; +use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, systimer::SystemTimer, Rng}; + +#[entry] +fn main() -> ! { + init_logger(log::LevelFilter::Info); + + // Init ESP-WIFI heap for malloc + let peripherals = Peripherals::take(); + #[cfg(feature = "esp32")] + let mut system = peripherals.DPORT.split(); + #[cfg(not(feature = "esp32"))] + #[allow(unused_mut)] + let mut system = peripherals.SYSTEM.split(); + let clocks = ClockControl::max(system.clock_control).freeze(); + + #[cfg(feature = "esp32c3")] + let timer = hal::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0; + #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] + let timer = hal::timer::TimerGroup::new(peripherals.TIMG1, &clocks).timer0; + let _ = initialize( + EspWifiInitFor::Wifi, + timer, + Rng::new(peripherals.RNG), + system.radio_clock_control, + &clocks, + ) + .unwrap(); + + set_debug(1); + + // println!("Testing AES"); + // unsafe { + // esp_mbedtls::mbedtls_aes_self_test(1i32); + // } + // println!("Testing MD5"); + // unsafe { + // esp_mbedtls::mbedtls_md5_self_test(1i32); + // } + println!("Testing RSA"); + unsafe { + esp_mbedtls::mbedtls_rsa_self_test(1i32); + } + // println!("Testing SHA"); + unsafe { + // esp_mbedtls::mbedtls_sha1_self_test(1i32); + // #[cfg(not(feature = "esp32"))] + // esp_mbedtls::mbedtls_sha224_self_test(1i32); + // esp_mbedtls::mbedtls_sha256_self_test(1i32); + // esp_mbedtls::mbedtls_sha384_self_test(1i32); + // esp_mbedtls::mbedtls_sha512_self_test(1i32); + + // HW Crypto: + // Testing RSA + // INFO - RSA key validation: + // INFO - passed + // PKCS#1 encryption : + // INFO - passed + // PKCS#1 decryption : + // INFO - passed + // INFO - PKCS#1 data sign : + // INFO - passed + // PKCS#1 sig. verify: + // INFO - passed + // INFO - 10 + // INFO - pre_cal 16377170 + // INFO - MPI test #1 (mul_mpi): + // INFO - passed + // INFO - MPI test #2 (div_mpi): + // INFO - passed + // INFO - MPI test #3 (exp_mod): + // INFO - passed + // INFO - MPI test #4 (inv_mod): + // INFO - passed + // INFO - MPI test #5 (simple gcd): + // INFO - passed + // INFO - 10 + // INFO - post_cal 17338357 + // Took 961187 cycles + // Done + + // SW Crypto: + // Testing RSA + // INFO - RSA key validation: + // INFO - passed + // PKCS#1 encryption : + // INFO - passed + // PKCS#1 decryption : + // INFO - passed + // INFO - PKCS#1 data sign : + // INFO - passed + // PKCS#1 sig. verify: + // INFO - passed + // INFO - 10 + // INFO - pre_cal 19067376 + // INFO - MPI test #1 (mul_mpi): + // INFO - passed + // INFO - MPI test #2 (div_mpi): + // INFO - passed + // INFO - MPI test #3 (exp_mod): + // INFO - passed + // INFO - MPI test #4 (inv_mod): + // INFO - passed + // INFO - MPI test #5 (simple gcd): + // INFO - passed + // INFO - 10 + // INFO - post_cal 20393146 + // Took 1325770 cycles + // Done + + let pre_calc = SystemTimer::now(); + log::info!("pre_cal {}", pre_calc); + esp_mbedtls::mbedtls_mpi_self_test(1i32); + let post_calc = SystemTimer::now(); + let hw_time = post_calc - pre_calc; + log::info!("post_cal {}", post_calc); + println!("Took {} cycles", hw_time); + } + + println!("Done"); + + loop {} +} diff --git a/examples/sync_client.rs b/examples/sync_client.rs index 531133e..e26753a 100644 --- a/examples/sync_client.rs +++ b/examples/sync_client.rs @@ -27,7 +27,7 @@ use esp_wifi::{ wifi_interface::WifiStack, EspWifiInitFor, }; -use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; +use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rsa::Rsa, Rng}; use smoltcp::{iface::SocketStorage, wire::IpAddress}; const SSID: &str = env!("SSID"); @@ -112,6 +112,8 @@ fn main() -> ! { set_debug(0); + let mut rsa = Rsa::new(peripherals.RSA); + let tls = Session::new( &mut socket, "www.google.com", @@ -124,6 +126,7 @@ fn main() -> ! { .ok(), ..Default::default() }, + Some(&mut rsa), ) .unwrap(); diff --git a/examples/sync_client_mTLS.rs b/examples/sync_client_mTLS.rs index d91de79..117230f 100644 --- a/examples/sync_client_mTLS.rs +++ b/examples/sync_client_mTLS.rs @@ -27,7 +27,7 @@ use esp_wifi::{ wifi_interface::WifiStack, EspWifiInitFor, }; -use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; +use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rsa::Rsa, Rng}; use smoltcp::{iface::SocketStorage, wire::IpAddress}; const SSID: &str = env!("SSID"); @@ -112,6 +112,8 @@ fn main() -> ! { set_debug(0); + let mut rsa = Rsa::new(peripherals.RSA); + let certificates = Certificates { ca_chain: X509::pem( concat!(include_str!("./certs/certauth.cryptomix.com.pem"), "\0").as_bytes(), @@ -130,6 +132,7 @@ fn main() -> ! { Mode::Client, TlsVersion::Tls1_3, certificates, + Some(&mut rsa), ) .unwrap(); diff --git a/examples/sync_server.rs b/examples/sync_server.rs index e607d7b..a6756ae 100644 --- a/examples/sync_server.rs +++ b/examples/sync_server.rs @@ -30,7 +30,7 @@ use esp_wifi::{ wifi_interface::WifiStack, EspWifiInitFor, }; -use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; +use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rsa::Rsa, Rng}; use smoltcp::iface::SocketStorage; const SSID: &str = env!("SSID"); @@ -112,6 +112,9 @@ fn main() -> ! { socket.listen(443).unwrap(); set_debug(0); + + let mut rsa = Rsa::new(peripherals.RSA); + loop { socket.work(); @@ -144,6 +147,7 @@ fn main() -> ! { .ok(), ..Default::default() }, + Some(&mut rsa), ) .unwrap(); match tls.connect() { diff --git a/examples/sync_server_mTLS.rs b/examples/sync_server_mTLS.rs index 21848b6..bb04e47 100644 --- a/examples/sync_server_mTLS.rs +++ b/examples/sync_server_mTLS.rs @@ -47,7 +47,7 @@ use esp_wifi::{ wifi_interface::WifiStack, EspWifiInitFor, }; -use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; +use hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rsa::Rsa, Rng}; use smoltcp::iface::SocketStorage; const SSID: &str = env!("SSID"); @@ -129,6 +129,9 @@ fn main() -> ! { socket.listen(443).unwrap(); set_debug(0); + + let mut rsa = Rsa::new(peripherals.RSA); + loop { socket.work(); @@ -165,6 +168,7 @@ fn main() -> ! { .ok(), ..Default::default() }, + Some(&mut rsa), ) .unwrap(); match tls.connect() { diff --git a/libs/riscv32imc-unknown-none-elf/libmbedcrypto.a b/libs/riscv32imc-unknown-none-elf/libmbedcrypto.a index 3959f1c..70b8d81 100644 Binary files a/libs/riscv32imc-unknown-none-elf/libmbedcrypto.a and b/libs/riscv32imc-unknown-none-elf/libmbedcrypto.a differ diff --git a/libs/riscv32imc-unknown-none-elf/libmbedtls.a b/libs/riscv32imc-unknown-none-elf/libmbedtls.a index 386d96f..f660cc6 100644 Binary files a/libs/riscv32imc-unknown-none-elf/libmbedtls.a and b/libs/riscv32imc-unknown-none-elf/libmbedtls.a differ diff --git a/libs/riscv32imc-unknown-none-elf/libmbedx509.a b/libs/riscv32imc-unknown-none-elf/libmbedx509.a index 386589a..23d95ea 100644 Binary files a/libs/riscv32imc-unknown-none-elf/libmbedx509.a and b/libs/riscv32imc-unknown-none-elf/libmbedx509.a differ diff --git a/libs/xtensa-esp32-none-elf/libmbedcrypto.a b/libs/xtensa-esp32-none-elf/libmbedcrypto.a index 248fbd8..34b2959 100644 Binary files a/libs/xtensa-esp32-none-elf/libmbedcrypto.a and b/libs/xtensa-esp32-none-elf/libmbedcrypto.a differ diff --git a/libs/xtensa-esp32-none-elf/libmbedtls.a b/libs/xtensa-esp32-none-elf/libmbedtls.a index 0e8d78c..e442ec1 100644 Binary files a/libs/xtensa-esp32-none-elf/libmbedtls.a and b/libs/xtensa-esp32-none-elf/libmbedtls.a differ diff --git a/libs/xtensa-esp32-none-elf/libmbedx509.a b/libs/xtensa-esp32-none-elf/libmbedx509.a index 6ee249a..55f258b 100644 Binary files a/libs/xtensa-esp32-none-elf/libmbedx509.a and b/libs/xtensa-esp32-none-elf/libmbedx509.a differ diff --git a/libs/xtensa-esp32s2-none-elf/libmbedcrypto.a b/libs/xtensa-esp32s2-none-elf/libmbedcrypto.a index 14c6f34..ff878b4 100644 Binary files a/libs/xtensa-esp32s2-none-elf/libmbedcrypto.a and b/libs/xtensa-esp32s2-none-elf/libmbedcrypto.a differ diff --git a/libs/xtensa-esp32s2-none-elf/libmbedtls.a b/libs/xtensa-esp32s2-none-elf/libmbedtls.a index 13b0b16..e442ec1 100644 Binary files a/libs/xtensa-esp32s2-none-elf/libmbedtls.a and b/libs/xtensa-esp32s2-none-elf/libmbedtls.a differ diff --git a/libs/xtensa-esp32s2-none-elf/libmbedx509.a b/libs/xtensa-esp32s2-none-elf/libmbedx509.a index b4b166f..55f258b 100644 Binary files a/libs/xtensa-esp32s2-none-elf/libmbedx509.a and b/libs/xtensa-esp32s2-none-elf/libmbedx509.a differ diff --git a/libs/xtensa-esp32s3-none-elf/libmbedcrypto.a b/libs/xtensa-esp32s3-none-elf/libmbedcrypto.a index 248fbd8..ff878b4 100644 Binary files a/libs/xtensa-esp32s3-none-elf/libmbedcrypto.a and b/libs/xtensa-esp32s3-none-elf/libmbedcrypto.a differ diff --git a/libs/xtensa-esp32s3-none-elf/libmbedtls.a b/libs/xtensa-esp32s3-none-elf/libmbedtls.a index 0e8d78c..e442ec1 100644 Binary files a/libs/xtensa-esp32s3-none-elf/libmbedtls.a and b/libs/xtensa-esp32s3-none-elf/libmbedtls.a differ diff --git a/libs/xtensa-esp32s3-none-elf/libmbedx509.a b/libs/xtensa-esp32s3-none-elf/libmbedx509.a index 6ee249a..55f258b 100644 Binary files a/libs/xtensa-esp32s3-none-elf/libmbedx509.a and b/libs/xtensa-esp32s3-none-elf/libmbedx509.a differ diff --git a/mbedtls b/mbedtls index 1873d3b..cadbbd9 160000 --- a/mbedtls +++ b/mbedtls @@ -1 +1 @@ -Subproject commit 1873d3bfc2da771672bd8e7e8f41f57e0af77f33 +Subproject commit cadbbd91bb15c64e7bd4e8490010ddb78eed2121 diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 881e596..91c7916 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -106,7 +106,7 @@ fn main() -> Result<()> { arch: Arch::Xtensa, target: "xtensa-esp32-none-elf", toolchain_file: workspace - .join("xtask/toolchains/toolchain-esp32.cmake") + .join("xtask/toolchains/toolchain-clang-esp32.cmake") .canonicalize() .unwrap(), compile_include_path: workspace.join("esp-mbedtls-sys").join("headers/esp32/"), @@ -119,7 +119,7 @@ fn main() -> Result<()> { arch: Arch::RiscV, target: "riscv32imc-unknown-none-elf", toolchain_file: workspace - .join("xtask/toolchains/toolchain-esp32c3.cmake") + .join("xtask/toolchains/toolchain-clang-esp32c3.cmake") .canonicalize() .unwrap(), compile_include_path: workspace.join("esp-mbedtls-sys").join("headers/esp32c3/"), @@ -131,7 +131,7 @@ fn main() -> Result<()> { arch: Arch::Xtensa, target: "xtensa-esp32s2-none-elf", toolchain_file: workspace - .join("xtask/toolchains/toolchain-esp32s2.cmake") + .join("xtask/toolchains/toolchain-clang-esp32s2.cmake") .canonicalize() .unwrap(), compile_include_path: workspace.join("esp-mbedtls-sys").join("headers/esp32s2/"), @@ -144,7 +144,7 @@ fn main() -> Result<()> { arch: Arch::Xtensa, target: "xtensa-esp32s3-none-elf", toolchain_file: workspace - .join("xtask/toolchains/toolchain-esp32s3.cmake") + .join("xtask/toolchains/toolchain-clang-esp32s3.cmake") .canonicalize() .unwrap(), compile_include_path: workspace.join("esp-mbedtls-sys").join("headers/esp32s3/"), @@ -348,6 +348,29 @@ fn compile(workspace: &Path, compilation_target: &CompilationTarget) -> Result<( )?; file.write_all(content.replace("-Wdocumentation", "").as_bytes())?; + // This add the function prototype for `mbedtls_mpi_exp_mod_soft()` since it + // is not provided in the espressif fork of mbedtls. + if let Err(error) = writeln!( + fs::OpenOptions::new().write(true).append(true).open( + tmpsrc + .path() + .join("mbedtls") + .join("include") + .join("mbedtls") + .join("bignum.h"), + )?, + "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 + );" + ) { + eprintln!("Could not write function prototype to bignum.h"); + eprintln!("{error}"); + } + // Compile mbedtls and generate libraries to link against log::info!("Compiling mbedtls"); let dst = Config::new(tmpsrc.path().join("mbedtls")) diff --git a/xtask/toolchains/toolchain-clang-esp32.cmake b/xtask/toolchains/toolchain-clang-esp32.cmake new file mode 100644 index 0000000..1147fae --- /dev/null +++ b/xtask/toolchains/toolchain-clang-esp32.cmake @@ -0,0 +1,20 @@ +set(CMAKE_SYSTEM_NAME Generic) + +# Install with `espup install --extended-llvm` +set(CMAKE_C_COMPILER "$ENV{CLANG_PATH}") + +set(CMAKE_AR llvm-ar) +set(CMAKE_RANLIB llvm-ranlib) +set(CMAKE_OBJDUMP xtensa-esp32-elf-objdump) + +set(CMAKE_C_FLAGS "--target=xtensa-esp-elf -mcpu=esp32" + CACHE STRING "C Compiler Base Flags" + FORCE) + +set(CMAKE_CXX_FLAGS "--target=xtensa-esp-elf -mcpu=esp32 " + CACHE STRING "C++ Compiler Base Flags" + FORCE) + +set(CMAKE_ASM_FLAGS "--target=xtensa-esp-elf -mcpu=esp32 -Xassembler --longcalls" + CACHE STRING "Assembler Base Flags" + FORCE) diff --git a/xtask/toolchains/toolchain-clang-esp32c3.cmake b/xtask/toolchains/toolchain-clang-esp32c3.cmake new file mode 100644 index 0000000..e8da1d9 --- /dev/null +++ b/xtask/toolchains/toolchain-clang-esp32c3.cmake @@ -0,0 +1,20 @@ +set(CMAKE_SYSTEM_NAME Generic) + +# Install with `espup install --extended-llvm` +set(CMAKE_C_COMPILER "$ENV{CLANG_PATH}") + +set(CMAKE_AR llvm-ar) +set(CMAKE_RANLIB llvm-ranlib) +set(CMAKE_OBJDUMP riscv32-esp-elf-objdump) + +set(CMAKE_C_FLAGS "--target=riscv32-esp-elf -march=rv32imc -mabi=ilp32" + CACHE STRING "C Compiler Base Flags" + FORCE) + +set(CMAKE_CXX_FLAGS "--target=riscv32-esp-elf -march=rv32imc -mabi=ilp32" + CACHE STRING "C++ Compiler Base Flags" + FORCE) + +set(CMAKE_ASM_FLAGS "--target=riscv32-esp-elf -march=rv32imc -mabi=ilp32 " + CACHE STRING "Assembler Base Flags" + FORCE) diff --git a/xtask/toolchains/toolchain-clang-esp32s2.cmake b/xtask/toolchains/toolchain-clang-esp32s2.cmake new file mode 100644 index 0000000..de6b659 --- /dev/null +++ b/xtask/toolchains/toolchain-clang-esp32s2.cmake @@ -0,0 +1,20 @@ +set(CMAKE_SYSTEM_NAME Generic) + +# Install with `espup install --extended-llvm` +set(CMAKE_C_COMPILER "$ENV{CLANG_PATH}") + +set(CMAKE_AR llvm-ar) +set(CMAKE_RANLIB llvm-ranlib) +set(CMAKE_OBJDUMP xtensa-esp32s2-elf-objdump) + +set(CMAKE_C_FLAGS "--target=xtensa-esp-elf -mcpu=esp32s2 " + CACHE STRING "C Compiler Base Flags" + FORCE) + +set(CMAKE_CXX_FLAGS "--target=xtensa-esp-elf -mcpu=esp32s2" + CACHE STRING "C++ Compiler Base Flags" + FORCE) + +set(CMAKE_ASM_FLAGS "--target=xtensa-esp-elf -mcpu=esp32s2 -Xassembler --longcalls" + CACHE STRING "Assembler Base Flags" + FORCE) diff --git a/xtask/toolchains/toolchain-clang-esp32s3.cmake b/xtask/toolchains/toolchain-clang-esp32s3.cmake new file mode 100644 index 0000000..65278ed --- /dev/null +++ b/xtask/toolchains/toolchain-clang-esp32s3.cmake @@ -0,0 +1,12 @@ +set(CMAKE_SYSTEM_NAME Generic) + +# Install with `espup install --extended-llvm` +set(CMAKE_C_COMPILER "$ENV{CLANG_PATH}") + +set(CMAKE_AR llvm-ar) +set(CMAKE_RANLIB llvm-ranlib) +set(CMAKE_OBJDUMP xtensa-esp32s3-elf-objdump) + +set(CMAKE_C_FLAGS "--target=xtensa-esp-elf -mcpu=esp32s3" CACHE STRING "C Compiler Base Flags" FORCE) +set(CMAKE_CXX_FLAGS "--target=xtensa-esp-elf -mcpu=esp32s3" CACHE STRING "C++ Compiler Base Flags" FORCE) +set(CMAKE_ASM_FLAGS "--target=xtensa-esp-elf -mcpu=esp32s3 -Xassembler --longcalls " CACHE STRING "Assembler Base Flags" FORCE) diff --git a/xtask/toolchains/toolchain-esp32.cmake b/xtask/toolchains/toolchain-esp32.cmake deleted file mode 100755 index a47426b..0000000 --- a/xtask/toolchains/toolchain-esp32.cmake +++ /dev/null @@ -1,8 +0,0 @@ -set(CMAKE_SYSTEM_NAME Generic) - -set(CMAKE_C_COMPILER xtensa-esp32-elf-gcc) -set(CMAKE_CXX_COMPILER xtensa-esp32-elf-g++) -set(CMAKE_ASM_COMPILER xtensa-esp32-elf-gcc) - -set(CMAKE_C_FLAGS "-mlongcalls -Wno-frame-address" CACHE STRING "C Compiler Base Flags" FORCE) -set(CMAKE_CXX_FLAGS "-mlongcalls -Wno-frame-address" CACHE STRING "C++ Compiler Base Flags" FORCE) diff --git a/xtask/toolchains/toolchain-esp32c3.cmake b/xtask/toolchains/toolchain-esp32c3.cmake deleted file mode 100755 index 4b09631..0000000 --- a/xtask/toolchains/toolchain-esp32c3.cmake +++ /dev/null @@ -1,9 +0,0 @@ -set(CMAKE_SYSTEM_NAME Generic) - -set(CMAKE_C_COMPILER riscv32-esp-elf-gcc) -set(CMAKE_CXX_COMPILER riscv32-esp-elf-g++) -set(CMAKE_ASM_COMPILER riscv32-esp-elf-gcc) - -set(CMAKE_C_FLAGS "-march=rv32imc" CACHE STRING "C Compiler Base Flags" FORCE) -set(CMAKE_CXX_FLAGS "-march=rv32imc" CACHE STRING "C++ Compiler Base Flags" FORCE) -set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -march=rv32imc --specs=nosys.specs" CACHE STRING "Linker Base Flags" FORCE) diff --git a/xtask/toolchains/toolchain-esp32s2.cmake b/xtask/toolchains/toolchain-esp32s2.cmake deleted file mode 100755 index 620ed2e..0000000 --- a/xtask/toolchains/toolchain-esp32s2.cmake +++ /dev/null @@ -1,8 +0,0 @@ -set(CMAKE_SYSTEM_NAME Generic) - -set(CMAKE_C_COMPILER xtensa-esp32s2-elf-gcc) -set(CMAKE_CXX_COMPILER xtensa-esp32s2-elf-g++) -set(CMAKE_ASM_COMPILER xtensa-esp32s2-elf-gcc) - -set(CMAKE_C_FLAGS "-mlongcalls" CACHE STRING "C Compiler Base Flags" FORCE) -set(CMAKE_CXX_FLAGS "-mlongcalls" CACHE STRING "C++ Compiler Base Flags" FORCE) diff --git a/xtask/toolchains/toolchain-esp32s3.cmake b/xtask/toolchains/toolchain-esp32s3.cmake deleted file mode 100755 index 7bbf4a5..0000000 --- a/xtask/toolchains/toolchain-esp32s3.cmake +++ /dev/null @@ -1,8 +0,0 @@ -set(CMAKE_SYSTEM_NAME Generic) - -set(CMAKE_C_COMPILER xtensa-esp32s3-elf-gcc) -set(CMAKE_CXX_COMPILER xtensa-esp32s3-elf-g++) -set(CMAKE_ASM_COMPILER xtensa-esp32s3-elf-gcc) - -set(CMAKE_C_FLAGS "-mlongcalls" CACHE STRING "C Compiler Base Flags" FORCE) -set(CMAKE_CXX_FLAGS "-mlongcalls" CACHE STRING "C++ Compiler Base Flags" FORCE)