[PATCH 8/9] crypto: allwinner: add sun8i-ce ECDSA verifier
Simon Glass
sjg at chromium.org
Thu Jul 2 22:04:04 CEST 2026
Hi James,
On 2026-07-02T01:46:51, James Hilliard <james.hilliard1 at gmail.com> wrote:
> crypto: allwinner: add sun8i-ce ECDSA verifier
>
> The H616 Crypto Engine includes an ECC engine which can verify ECDSA
> signatures. Add a UCLASS_ECDSA child for the sun8i-ce parent so FIT
> signature verification can use the hardware block from U-Boot proper and
> SPL.
>
> The CE takes explicit curve parameters for each operation. Provide tables
> for the curves accepted by U-Boot's FIT ECDSA parser: secp224r1,
> prime256v1, secp384r1 and secp521r1.
>
> The CE input buffer uses fixed-width curve fields. Reuse the parameter
> packing logic for the message digest as well, so wider digests are
> truncated to the leftmost curve-width bytes according to ECDSA rules.
>
> Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
>
> drivers/crypto/allwinner/sun8i-ce/Kconfig | 29 ++
> drivers/crypto/allwinner/sun8i-ce/Makefile | 1 +
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 8 +
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-ecdsa.c | 413 +++++++++++++++++++++
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 4 +
> 5 files changed, 455 insertions(+)
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-ecdsa.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-ecdsa.c
> @@ -0,0 +1,413 @@
> +static const struct sunxi_ecdsa_curve sunxi_ecdsa_curves[] = {
These tables add around 1.5K of const data and all four curves are
always built in, even though a verified-boot setup typically uses a
single curve. The SPL SRAM budget on these SoCs is quite tight, so it
may be worth guarding each curve with its own Kconfig option (or at
least the two larger ones). What do you think?
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-ecdsa.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-ecdsa.c
> @@ -0,0 +1,413 @@
> + sunxi_ecdsa_copy_le_param(&dst, curve, curve->n, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, s, curve->bytes);
> + /* ECDSA uses the leftmost bits when the digest is wider than the key. */
> + sunxi_ecdsa_copy_le_param(&dst, curve, hash, hash_len);
> + sunxi_ecdsa_copy_le_param(&dst, curve, r, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, curve->p, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, curve->a, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, curve->gx, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, curve->gy, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, pubkey->x, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, pubkey->y, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, curve->n, curve->bytes);
> + sunxi_ecdsa_copy_le_param(&dst, curve, r, curve->bytes);
Please can you add a comment documenting the CE input-buffer layout?
The ordering is non-obvious and the repeated n and r entries look like
a mistake to anyone without the Allwinner documentation. A short list
of the twelve fields, with a reference to the manual or BSP source,
would help future maintainers.
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-ecdsa.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-ecdsa.c
> @@ -0,0 +1,413 @@
> + task->t_dlen = SUNXI_ECDSA_PARAMS * bytes;
> + task->t_src[0].addr = sunxi_ce_desc_dma_addr(priv, src);
> + task->t_src[0].len = task->t_dlen / sizeof(u32);
> + task->t_dst[0].addr = sunxi_ce_desc_dma_addr(priv, dst);
> + task->t_dst[0].len = curve->words;
Just to check, is t_dlen really in bytes for the ECC method? The
scatter-gather lengths here are in words, and for the cipher path the
AES driver switches t_dlen between bytes and words based on the
cipher_t_dlen_in_bytes variant flag. If the ECC unit is always
byte-sized on H616 then this is fine, but a comment saying so would
avoid confusion - and if a future variant differs, this should
probably use a variant flag too. Also, which of the four curves have
you been able to test on hardware? Please mention that in the commit
message or cover letter.
Regards,
Simon
More information about the U-Boot
mailing list