Commit graph

190 commits

Author SHA1 Message Date
Sylvio Alves
c64a74e711 espressif: adapt to hal_espressif IDF master sync
Adapt all Espressif SoC and driver code to the updated
hal_espressif module synced with IDF master branch.

Main changes:
- clock control: delegate peripheral clock gating to HAL
  layer using new clock/reset APIs
- SPI/GDMA: adapt to restructured DMA HAL with new channel
  allocation and configuration interfaces
- ethernet: add RMII clock configuration and PHY management
- GPIO: simplify using direct HAL function calls
- flash: adapt to updated SPI flash HAL interfaces
- linker scripts: update IRAM/DRAM mappings for new HAL
  object files
- DTS: fix ESP32-S2 PSRAM dcache1 address to match actual
  MMU mapping region (0x3f800000 DRAM1 instead of 0x3f500000
  DPORT which lacks 8-bit access capability)
- west.yml: update hal_espressif revision

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-03-13 11:38:18 +01:00
William Markezana
0ced331a53 drivers: crypto: bflb: add SEC_ENG per-block drivers
Add hardware crypto drivers for the Bouffalo Lab SEC Engine:

- AES: ECB, CBC, CTR modes with 128/192/256-bit keys
- SHA: SHA-224 and SHA-256 (SHA-384/512 not supported in HW)
- GMAC: Galois MAC (GF(2^128) multiply)

Each sub-block is a separate driver with its own Kconfig and
DT compatible. All drivers recover SEC_ENG_BASE from the DT
sub-block address to work with HAL register offsets.

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-03-11 20:53:43 -04:00
Tony Han
d747277488 drivers: crypto: aes: add driver for Microchip AES
Add driver for Microchip Advanced Encryption Standard (AES), update
Kconfig and make files.

Signed-off-by: Tony Han <tony.han@microchip.com>
2026-03-10 09:30:02 +01:00
Haoran Jiang
06b27fd34f drivers: crypto: sf32lb: Add sf32lb crypto drivers
Add sf32lb crypto drivers, include AES and SHA algo

Signed-off-by: Haoran Jiang <halfsweet@halfsweet.cn>
2026-03-04 11:38:33 +01:00
Valerio Setti
7c37e95875 drivers: crypto: mbedtls_shim: remove legacy code
Remove inclusions that date back to the original addition of this driver
and that are no more required when PSA API is used.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-03-02 11:04:26 +01:00
Gaetan Perrot
649831c8eb drivers: crypto: ataes132a: fix semaphore leak on early return
In ataes132a_aes_ecb_block(), error paths could return after
k_sem_take() without releasing device_sem, leading to a potential
deadlock on subsequent calls.

Ensure k_sem_give() is called on all early-return paths after the
semaphore is taken.

This fixes a potential deadlock when invalid buffer sizes are
detected after acquiring the device semaphore.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-02-16 11:09:32 +01:00
Gaetan Perrot
4feabb725e drivers: crypto: ataes132a: fix error propagation
Use int return type for command results to avoid truncating negative
errno values and ensure proper error propagation.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-02-16 11:09:32 +01:00
Mathieu Choplain
a11688fab5 drivers: *: stm32: don't check if clock device is ready
If the clock device (i.e., RCC) failed to initialize, we have bigger
problems than trying to call clock_control_{off,on,configure} on it.
Don't bother checking to save some footprint.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-13 18:59:16 +00:00
Pieter De Gendt
f71da28f90 drivers: crypto: Put device API into iterable section
Update some crypto drivers to use the DEVICE_API macro.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-10 22:19:30 +01:00
Shreya Kulkarni
3b98cce4f2 drivers: crypto: ataes132a: fix multiple Coverity defects
Addressed stability and security issues identified by Coverity in
the ATaes132a crypto driver:

- CID 434625: Added range validation for 'count' to prevent tainted
  scalar usage and buffer underflow in response processing.
- CID 487700 & 487763: Implemented overflow guards for 'buf_len' to
  prevent integer overflow and type truncation when calling
  ataes132a_send_command.
- CID 487746: Applied explicit type casting to CRC calculations to
  satisfy static analysis regarding integer promotion.

Signed-off-by: Shreya Kulkarni <kulkarnishreya2421@gmail.com>
2026-02-09 11:17:12 +01:00
Benjamin Cabé
4d33f3bde0 drivers: crypto: use proper essential type in boolean variables assignments
As per Zephyr coding guideline #59, "operands shall not be of an
inappropriate essential type". This makes sure boolean variables are
assigned true/false values, not 1/0.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-02-05 10:20:22 +00:00
Gaetan Perrot
e819733d0f drivers: crypto: smartbond: fix typos in comments
Fix spelling and wording issues in comments.

No functional change.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-01-30 18:04:31 +01:00
Flavio Ceolin
6d64ee11ea drivers: crypto_smartbond: Fix comments indentation
Fix indentation in multiple comments in this driver.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2026-01-29 09:06:50 +01:00
Flavio Ceolin
bc5512f431 drivers: crypto_smartbond: Fix typos
Fix multiple typos in crypto_smartbond driver.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2026-01-29 09:06:50 +01:00
Flavio Ceolin
3edbd9236b drivers: crypto/mcux_dcp: Avoid race condition
Avoid race condition when allocating sessions.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2026-01-29 09:06:50 +01:00
Flavio Ceolin
c22d225bcb drivers: crypto_ataes132a: Wrong constant in init
ataes132a_state is an array of CRYPTO_MAX_SESSION length.

This constant must be used when iterating over its elements
and not ATAES132A_AES_KEY_SIZE (even they having the same
value).

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2026-01-29 09:06:50 +01:00
Gaetan Perrot
bca0b43be9 drivers: crypto: intel_sha: make set_resume_length_dw1 void
intel_sha_set_resume_length_dw1() never reports errors
and always returns 0.
The error check at the call site is therefore dead code.

Make the function void and drop the unused error handling.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-01-12 12:36:48 -06:00
Gaetan Perrot
f017f4cb91 drivers: crypto: intel_sha: make set_ctl_enable void
intel_sha_set_ctl_enable() never reports errors
and always returns 0.
The error check at the call site is therefore dead code.

Make the function void and drop the unused error handling.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-01-12 12:36:48 -06:00
TOKITA Hiroshi
41a86eb1fe drivers: crypto: Add initial support for rpi_pico sha256 accelerator
Add basic support for RaspberryPi Pico's SHA256 hardware accelerator.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2025-12-31 11:00:21 +00:00
Jeremy Bettis
f14ccdf462 drivers: Add const to rts5912_sha256_process() input
rts5913_sha256_update was changed in #94218, but this function passes
it's input into rts5912_sha256_process also.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
2025-12-16 10:06:45 -06:00
Valerio Setti
d76477f9eb drivers: crypto: mbedtls_shim: fix crash in AES-ECB for RISCV 64 bits
Using "pkt->out_len" as the output length of "psa_cipher_[en|de]crypt"
caused a crash in RISCV 64 bits platforms due to misaligned address
access.
The solution is to add a temporary value on the stack to store this lenght
and only after the [en|de]cryption copy it to "pkt->out_len".

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-15 07:29:29 -05:00
Johan Hedberg
69946a1253 drivers: crypto_mbedtls_shim: Fix build with Clang/LLVM
drivers/crypto/crypto_mbedtls_shim.c:310:3: error: label followed by a
declaration is a C23 extension [-Werror,-Wc23-extensions]
                 uint16_t tag_len = ctx->mode_params.ccm_info.tag_len;
                 ^

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-12-05 13:38:37 +02:00
Valerio Setti
4cf7cd5748 drivers: crypto: mbedtls_shim: allow tag len to be specified in CCM
Retrieve the desired tag length from the "struct cipher_ctx" being passed
to "cipher_begin_session()" when using CCM.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-04 14:01:02 -05:00
Tony Han
6d52c87443 drivers: crypto: hash: add driver for Microchip SHA
Add driver for Microchip Secure Hash Algorithm (SHA), update Kconfig
and make files.

Signed-off-by: Tony Han <tony.han@microchip.com>
2025-12-03 09:11:40 -05:00
Tony Han
ac31be0d98 drivers: crypto: Kconfig: rename Kconfig.xec to Kconfig.mchp
Rename to Kconfig.mchp for Microchip crypto drivers support.

Signed-off-by: Tony Han <tony.han@microchip.com>
2025-12-03 09:11:40 -05:00
Ha Duong Quang
aab99a548b driver: crypto: add NXP S32 CRYPTO HSE driver
Add device tree node for MU instances that will be used by HSE and RTU
for s32z270.

Add support hash crypto for NXP S32 with Algo 2:
SHA224, SHA256, SHA384 and SHA512.

Add support cipher crypto with ECB, CBC and CTR mode by using ram key
catalog.

Add support 128/256 bits ram key length.

Signed-off-by: Ha Duong Quang <ha.duongquang@nxp.com>
2025-12-02 11:20:29 +01:00
Valerio Setti
711f13fff6 drivers: crypto: mbedtls_shim: improve session handling
Add a new function to free an mbedtls_shim session:
'mbedtls_free_session()'. Together with 'mbedtls_get_unused_session()',
these will be the only entry points to acquire/release sessions.
In this way it's easier to ensure that the mutex is properly held while
setting the 'in_use' parameter.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Valerio Setti
cc65c9543b drivers: crypto: mbedtls_shim: replace legacy cipher API with PSA API
Replace legacy crypto API for cipher (ECB, CBC) and AEAD (CCM, GCM) with
PSA API.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Valerio Setti
678542d899 drivers: crypto: mbedtls_shim: replace legacy hash API with PSA API
Replace usage of legacy crypto hash functions from Mbed TLS with PSA API.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Valerio Setti
91dbaf5c45 drivers: crypto: mbedtls_shim: move mbedtls_get_unused_session_index()
Move mbedtls_get_unused_session_index() at the top of the file and leave
cipher and hash functions below.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Valerio Setti
0cee013a3f drivers: crypto: mbedtls_shim: add _cipher_ to cipher ops
Another small renaming for cipher ops that just adds "_cipher_" in the
function's name.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Valerio Setti
37197f869a drivers: crypto: mbedtls_shim: general renaming
This commit just implements some renaming:
* mbedTLS -> Mbed TLS
* MbedTLS -> Mbed TLS
* MTLS_ -> MBEDTLS_
* mtls_ -> mbedtls_
* mtls_ccm -> ccm_ctx
* mtls_gcm -> gcm_ctx
* mtls_aes -> aes_ctx
* mtls_sha256 -> sha256_ctx
* mtls_sha512 -> sha512_ctx

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Valerio Setti
5eb2f46e0d drivers: crypto: mbedtls_shim: rename module
Use full name for the module so "mtls" -> "mbedtls"

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Josuah Demangeon
30950b888d style: drivers: sort Kconfig and CMake includes
Use the "zephyr-keep-sorted-start/stop" comment to have CI check
the alphabetical order of includes, to help reducing the chance
of conflicts while contributing drivers.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-11-17 13:48:03 -05:00
Etienne Carriere
b0ccb2295f drivers: stm32: use STM32_CLOCK_INFO_BY_NAME() and friends
Use STM32_CLOCK_INFO(), STM32_DT_INST_CLOCK_INFO(),
STM32_CLOCK_INFO_BY_NAME() and STM32_DT_INST_CLOCK_INFO_BY_NAME()
helper macros in STM32 drivers.

Using these macros ensure the clock division factor is properly
populated according to DT information. Prior these changes some
drivers only got the bus and bits position information and missed
the clock division information which is fine only when this division
factor information is 0.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2025-11-14 15:26:17 +02:00
Badr Bacem KAABIA
0719c9eca2 crypto: mbedtls_shim: Fix concurrency and deadlock issues
- **Fix session mutex handling:** Ensure the `mtls_sessions_lock` is
    always released in `mtls_get_unused_session_index` on failure
    to prevent deadlocks.
- **Protect `in_use` flag:** Added mutex protection when setting
    `in_use = false` in free functions.
- **Cleanup on setup failure:** Added calls to `mbedtls_*_free()`
    in `mtls_session_setup()` when key initialization fails.
- **Free logic fix:** Corrected `if/else` structure in
    `mtls_session_free()` to ensure the correct context is freed.

Signed-off-by: Badr Bacem KAABIA <badrbacemkaabia@gmail.com>
2025-11-13 12:01:44 +02:00
Badr Bacem KAABIA
577f60dcd7 crypto: mbedtls_shim: Remove incorrect out_len calculation in AEAD decrypt
Remove erroneous calculation of `apkt->pkt->out_len` in
`mtls_ccm_decrypt_auth` and `mtls_gcm_decrypt_auth`.
The output length should be handled by the caller or the
AEAD decryption process itself.

Signed-off-by: Badr Bacem KAABIA <badrbacemkaabia@gmail.com>
2025-11-13 12:01:44 +02:00
Badr Bacem KAABIA
01b0280bad crypto: mbedtls_shim: Fix typos
Corrected "encrypt" log messages to "decrypt."

Signed-off-by: Badr Bacem KAABIA <badrbacemkaabia@gmail.com>
2025-11-13 12:01:44 +02:00
Loic Domaigne
1b0950035e drivers: crypto: crypto_ataes132a fix missing count check
Coverity reported an untrusted loop bound caused by a missing check on
the count value in ataes132a_send_command() for the response received
from the device.  As per datasheet section 6.1, count should be at least
3 bytes (1 byte for count, and 2 bytes for the 16 bits CRC).

While I'm expecting this condition to be very rare, it doesn't hurt to
implement a proper checking and report an error if count<3.

Coverity CID: 434625

Signed-off-by: Loic Domaigne <tech@domaigne.com>
2025-11-06 14:02:39 -05:00
Sylvio Alves
998d9ab04f drivers: crypto: expand mbedTLS shim driver capabilities
Select SHA24, SHA256 and SHA384 as part of the shim driver.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-10-28 11:51:04 +02:00
Sylvio Alves
4b4332ac18 drivers: crypto: return -ENOTSUP when needed
Make sure all crypto driver returns proper error
when feature is not supported.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-10-28 11:51:04 +02:00
Sylvio Alves
9b3bb86855 drivers: crypto: add Espressif HW AES support
Add hardware-accelerated AES driver for Espressif SoCs supporting
ECB, CBC, and CTR cipher modes with AES-128, AES-192, and AES-256
key lengths.

Supported modes:
- ECB (Electronic Codebook)
- CBC (Cipher Block Chaining)
- CTR (Counter)

Supported SoCs:
- ESP32: All modes, all key sizes
- ESP32-S2/S3: All modes, AES-128/256 only
- ESP32-C2/C3/C6/H2: All modes, all key sizes

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-10-24 13:21:24 -04:00
Sylvio Alves
391ffabd66 drivers: crypto: add Espressif HW SHA support
Add hardware-accelerated SHA driver for Espressif SoCs supporting
SHA-224, SHA-256, SHA-384, and SHA-512 algorithms.

Supported SoCs:
- ESP32: SHA-224/256/384/512 (single-shot operations)
- ESP32-S2/S3: SHA-224/256/384/512 (with multi-part support)
- ESP32-C2/C3/C6/H2: SHA-224/256 (with multi-part support)

Tested with Zephyr crypto subsystem hash_compute() API.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-10-24 13:21:24 -04:00
Titouan Christophe
b677e828d0 drivers: crypto: hash_pkt.in_buf is now constant
Previous commit made the input buffer of the hash packet constant.
Let's therefore adapt typing where used, and remove inappropriate
casts of constant buffers to non-constant ones.

All the "backend" hashing functions already take a constant input,
these changes only affect the "plumbing" between the Zephyr crypto
API and the actual implementation where applicable.

Signed-off-by: Titouan Christophe <titouan.christophe@mind.be>
2025-10-21 22:55:24 +03:00
Elmo Lan
79d7ce61d2 driver: crypto: fix timing discrepancies
Use a temporary variable to store and compare the reference time
instead of calling the time function multiple times,
which may lead to slight mismatches in comparison due to timing drift.

Signed-off-by: Elmo Lan <elmo_lan@realtek.com>
2025-09-02 07:56:56 +02:00
Julien Panis
22d04f7f93 drivers: crypto: cc23x0: Add power management
Add PM support to cc23x0 AES module.

Signed-off-by: Julien Panis <jpanis@baylibre.com>
2025-08-29 22:55:37 -04:00
Alain Volmat
14525b99d5 drivers: crypto: stm32: ensure RESET is selected
stm32 crypto driver requires a reset control hence ensure that
CONFIG_RESET is properly selected to allow proper build.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-08-18 17:49:28 +02:00
Bayrem Gharsellaoui
95934d2abd drivers: crypto: Add STM32 HASH hardware driver
Add STM32 HASH driver with SHA-224/256 support for STM32U5

Signed-off-by: Bayrem Gharsellaoui <bayrem.gharsellaoui@protonmail.com>
2025-08-15 10:10:24 +03:00
Loic Domaigne
28f37e522a drivers: crypto: crypto_ataes132a fix memset undefined behavior
Coverity reported a memory - illegal accesses when using memset in
ataes132a_aes_ecb_block(). This can happen when the input block is
exactly 16 bytes: memset(&param_buffer[19], 0x0, 0) is called. But this
is an undefined behaviour in C even if size is 0, as &param_buffer[19]
is an invalid pointer.

The fix consists of simply skipping memset() in this case, since there's
nothing to zero out.

Coverity CID: 434642

Signed-off-by: Loic Domaigne <tech@domaigne.com>
2025-07-10 10:13:17 -05:00
Pisit Sawangvonganan
b8a8173c1f drivers: kconfig: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in `Kconfig` files within the `drivers` directory.
Additionally, incorporates a fix recommended by the reviewer.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-07-01 10:58:54 -10:00