Skip to content

Conversation

sylvioalves
Copy link
Contributor

Add hardware-accelerated crypto drivers for Espressif SoCs, enabling
SHA hashing and AES encryption/decryption operations.

SHA Driver Support:

  • Algorithms: SHA-224, SHA-256, SHA-384, SHA-512
  • ESP32: All algorithms (single-shot operations only)
  • ESP32-S2/S3: All algorithms (with multi-part support)
  • ESP32-C2/C3/C6/H2: SHA-224/256 only (with multi-part support)

AES Driver Support:

  • Modes: ECB, CBC, CTR
  • Key lengths: AES-128, AES-192, AES-256
  • ESP32: All modes and key sizes
  • ESP32-S2/S3: All modes, AES-128/256 only
  • ESP32-C2/C3/C6/H2: All modes, all key sizes

Also expands crypto test suite to validate SHA-224/256/384/512
algorithms with unified test vector framework.

@sylvioalves sylvioalves force-pushed the feature/espressif-crypto-driver branch from 7abb36a to fa84648 Compare October 21, 2025 11:35
Copy link

github-actions bot commented Oct 21, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_espressif zephyrproject-rtos/hal_espressif@78fb21d zephyrproject-rtos/hal_espressif@669f24e (main) zephyrproject-rtos/[email protected]

Additional metadata changed:

Name URL Submodules West cmds module.yml Blobs
hal_espressif 1x 🆕

DNM label due to: 1 project with metadata changes and 1 blob change

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-hal_espressif DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Oct 21, 2025
@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: Crypto / RNG area: Samples Samples area: Devicetree Bindings area: Xtensa Xtensa Architecture platform: ESP32 Espressif ESP32 area: Boards/SoCs area: RISCV RISCV Architecture (32-bit & 64-bit) labels Oct 21, 2025
@sylvioalves sylvioalves force-pushed the feature/espressif-crypto-driver branch from fa84648 to 9581d40 Compare October 21, 2025 11:39
@sylvioalves sylvioalves force-pushed the feature/espressif-crypto-driver branch 4 times, most recently from a38175e to f6a1fc9 Compare October 21, 2025 13:46
Add into device tree SHA and AES peripherals.

Signed-off-by: Sylvio Alves <[email protected]>
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 <[email protected]>
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 <[email protected]>
Allow ESP32 SoCs to run AES sample.

Signed-off-by: Sylvio Alves <[email protected]>
Make sure all crypto driver returns proper error
when feature is not supported.

Signed-off-by: Sylvio Alves <[email protected]>
Select SHA24, SHA256 and SHA384 as part of the shim driver.

Signed-off-by: Sylvio Alves <[email protected]>
Refactor hash tests to support SHA-224, SHA-256, SHA-384, and SHA-512
algorithms with a unified test vector framework.

This improves test coverage and makes it easier to verify hardware
crypto drivers that support multiple SHA variants.

Signed-off-by: Sylvio Alves <[email protected]>
@sylvioalves sylvioalves force-pushed the feature/espressif-crypto-driver branch from f6a1fc9 to 1a95dcc Compare October 21, 2025 19:07
Copy link

@sylvioalves sylvioalves removed the DNM (manifest) This PR should not be merged (controlled by action-manifest) label Oct 21, 2025
@sylvioalves
Copy link
Contributor Author

Binary blobs are due to #97804, which updated hal before this.

Copy link
Contributor

@LucasTambor LucasTambor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also change the sample.yaml and testcase.yaml to provide support for the new SoCs

.cipher_async_callback_set = aes_cipher_async_cb_set,
};

#define ESP_AES_DEVICE_INIT(inst) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identation

.hash_async_callback_set = sha_hash_async_cb_set,
};

#define ESP_SHA_DEVICE_INIT(inst) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identation

Copy link

@marekmatej marekmatej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left few remarks, overal LGTM

status = "disabled";
};

sha: sha@6003b000 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set SHA address to 0x60089000 and AES to 0x60088000


config CRYPTO_ESP32_SHA_SESSIONS_MAX
int "Max ESP32 SHA sessions"
default 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make a valid range and default to 1 in order not to waste memory?


#define DT_DRV_COMPAT espressif_esp32_sha

static const uint32_t sha224_init_state[8] = {0xd89e05c1U, 0x07d57c36U, 0x17dd7030U, 0x39590ef7U,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are those magic numbers origin? Can you make them macros with basic explanation?

case CRYPTO_HASH_ALGO_SHA256:
return true;

#if SOC_SHA_SUPPORT_SHA384 || SOC_SHA_SUPPORT_SHA512

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this SHA384 || SHA512 condition is redundant and worsens the readability

last2[B - 8 + i] = (uint8_t)(bit_len >> (56 - 8 * i));
}

return 2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single comment about default return value 2 would help here

{
ARG_UNUSED(dev);

#if SOC_SHA_SUPPORT_RESUME

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the ESP32 the only chip that lacks the multi-part support?


config ESP32_CRYPTO_AES_SESSIONS_MAX
int "Max ESP32 AES sessions"
default 4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, I'd limit the default number of allowed session and maybe provide the range of maximum sessions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants