[PATCH v4 03/14] test: lib: ecdsa: add initial test

Simon Glass sjg at chromium.org
Mon Apr 20 04:11:29 CEST 2026


Hi Philippe,

On 2026-04-17T13:02:04, Philippe Reynes <philippe.reynes at softathome.com> wrote:
> test: lib: ecdsa: add initial test
>
> Adds tests to check that the function ecdsa_hash_verify
> using mbedtls is valid.
>
> Signed-off-by: Philippe Reynes <philippe.reynes at softathome.com>
>
> include/u-boot/sha256.h |   2 +
>  include/u-boot/sha512.h |   3 +
>  test/lib/Makefile       |   1 +
>  test/lib/ecdsa.c        | 453 ++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 459 insertions(+)

> diff --git a/test/lib/ecdsa.c b/test/lib/ecdsa.c
> @@ -0,0 +1,453 @@
> +     } else {
> +             ut_failf(uts, __FILE__, __LINE__, __func__, "Unknown hash type (%s)", tv->hash_type);
> +             return -EINVAL;
> +     }

Can you use ut_reportf() here?

> diff --git a/include/u-boot/sha256.h b/include/u-boot/sha256.h
> @@ -15,6 +15,8 @@
> +#define SHA256_DEF_CHUNK_SZ 0x10000

I suspect you could use the existing CHUNKSZ_SHA256 (64 * 1024)
instead. The same applies to SHA384_DEF_CHUNK_SZ and
SHA512_DEF_CHUNK_SZ

> diff --git a/test/lib/ecdsa.c b/test/lib/ecdsa.c
> @@ -0,0 +1,453 @@
> +static int ecdsa_test(struct unit_test_state *uts,
> +                   const struct ecdsa_test_vector_s *tv)
> +{
> +     struct ecdsa_public_key pubkey;
> +     unsigned char x[528 / 8];
> +     unsigned char y[528 / 8];
> +     unsigned char hash[512 / 8];
> +     size_t hash_len;
> +     unsigned char signature[528 / 8 * 2];
> +     size_t sig_len;
> +     int ret;

The magic number 528 is confusing since secp521r1 uses 521 bits.
Please can you add a comment or define a constant like
DIV_ROUND_UP(521, 8) ?

Reviewed-by: Simon Glass <sjg at chromium.org>

Regards,
Simon


More information about the U-Boot mailing list