Skip to content

drivers: crypto: bee: add PSA hardware accelerator driver - #15

Open
ZhiyuanTang17 wants to merge 2 commits into
rtkconnectivity:hal_realtek_v4.4from
ZhiyuanTang17:tzy/bee-psa-driver
Open

ZhiyuanTang17 wants to merge 2 commits into
rtkconnectivity:hal_realtek_v4.4from
ZhiyuanTang17:tzy/bee-psa-driver

Conversation

@ZhiyuanTang17

Copy link
Copy Markdown

Add a PSA crypto driver for the Realtek Bee hardware crypto
engine. The driver is built when CONFIG_CRYPTO_BEE_PSA_ACCELERATOR
is set and provides PSA-compatible implementations for:

  • SHA-256 (compute, streaming)
  • AES-ECB/CBC/CFB/OFB/CTR (one-shot and multipart)
  • AES-CCM AEAD (one-shot and multipart)
  • P-256 ECDSA sign/verify (RTL87X2G only)
  • P-256 ECDH key agreement (RTL87X2G only)

The driver is structured as a portable core (crypto_bee_psa.c)
plus a thin platform adapter (crypto_bee_psa_adapter.c) that
calls the hardware engine APIs from the HAL.

Expose the AES block-cipher and PKE/ECC ROM function declarations
in the rtl8752h and rtl87x2g HAL headers, and add the
corresponding ROM entry-point addresses to the RTL87X2G linker
script.

🤖 Generated with Claude Code

Add a PSA crypto driver for the Realtek Bee hardware crypto
engine. The driver is built when CONFIG_CRYPTO_BEE_PSA_ACCELERATOR
is set and provides PSA-compatible implementations for:

  - SHA-256 (compute, streaming)
  - AES-ECB/CBC/CFB/OFB/CTR (one-shot and multipart)
  - AES-CCM AEAD (one-shot and multipart)
  - P-256 ECDSA sign/verify (RTL87X2G only)
  - P-256 ECDH key agreement (RTL87X2G only)

The driver is structured as a portable core (crypto_bee_psa.c)
plus a thin platform adapter (crypto_bee_psa_adapter.c) that
calls the hardware engine APIs from the HAL.

Expose the AES block-cipher and PKE/ECC ROM function declarations
in the rtl8752h and rtl87x2g HAL headers, and add the
corresponding ROM entry-point addresses to the RTL87X2G linker
script.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Zhiyuan Tang <zhiyuan_tang@realsil.com.cn>
RTL87x2J exposes AES (ECB/CBC) and SHA (SHA-224, SHA-256) through a
different ROM API than other Bee SoC series.  Extend the PSA hardware
accelerator driver to support RTL87x2J across all layers:

bee/drivers/crypto/inc/rtl87x2j/
  Add vendor header files for the RTL87x2J AES and SHA2 ROM driver:
  aes_interface.h, sha2_interface.h, aes_dma_types.h.

CMakeLists.txt
  Include the above directory when building for SOC_SERIES_RTL87X2J.

crypto_bee_psa_adapter.h / .c
  - Introduce bee_aes_mode_t to abstract AES_WORK_MODE (RTL87x2J) vs
    T_HW_AES_MODE (other series) and matching BEE_AES_MODE_CBC/ECB
    aliases so call sites are SoC-family-agnostic.
  - Add a dedicated RTL87x2J path in bee_aes_hw_crypt_block() that
    drives the aes_encrypt()/aes_decrypt() ROM functions and clears the
    hardware busy flag via AES_BASE after each operation.
  - Rename the one-shot hash entry point to bee_sha2_hw_compute() and
    add a hash_length parameter to support both SHA-224 (28 B) and
    SHA-256 (32 B).
  - Add bee_sha2_hw_start/update/finish() multipart API for RTL87x2J,
    backed by sha2_iv_init(), sha2_cpu_update(), and sha2_finish(); a
    restore helper re-seeds the hardware IV register from the saved
    SHA2_CTX on each call so context switching is safe.

crypto_bee_psa_types.h
  Use SHA2_CTX as the internal context type for RTL87x2J (selected via
  CONFIG_SOC_SERIES_RTL87X2J); retain HW_SHA256_CTX for other series.

crypto_bee_psa.c
  - Extend bee_psa_hash_compute/setup/update/finish/clone to accept
    PSA_ALG_SHA_224 on RTL87x2J in addition to PSA_ALG_SHA_256.
  - Derive required_size from PSA_HASH_LENGTH(alg) instead of
    hard-coding the SHA-256 length, so SHA-224 output is sized
    correctly.
  - Use BEE_AES_MODE_ECB/CBC aliases in cipher paths to remain
    portable across SoC families.

bee/ld/rtl87x2j/bootloader.ld
  Add PROVIDE() entries for all AES ROM symbols (aes_cmac,
  aes_cpu_operate, aes_decrypt, aes_dma_*, aes_encrypt, aes_init) and
  SHA2 ROM symbols (sha2, sha2_cpu_finish, sha2_cpu_update,
  sha2_dma_*, sha2_get_digest*, sha2_init, sha2_iv_init, sha2_start)
  required by the crypto driver at link time.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant