[PATCH v4 08/29] hash: integrate hash on mbedtls

Simon Glass sjg at chromium.org
Fri Jul 5 10:35:56 CEST 2024


Hi,

On Wed, Jul 3, 2024, 09:56 Ilias Apalodimas <ilias.apalodimas at linaro.org> wrote:
>
> Hi Raymond
>
> On Tue, 2 Jul 2024 at 21:27, Raymond Mao <raymond.mao at linaro.org> wrote:
> >
> > Integrate common/hash.c on the hash shim layer so that hash APIs
> > from mbedtls can be leveraged by boot/image and efi_loader.
> >
> > Signed-off-by: Raymond Mao <raymond.mao at linaro.org>
> > ---
> > Changes in v2
> > - Use the original head files instead of creating new ones.
> > Changes in v3
> > - Add handle checkers for malloc.
> > Changes in v4
> > - None.
> >
> >  common/hash.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 143 insertions(+)
> >
> > diff --git a/common/hash.c b/common/hash.c
> > index ac63803fed9..96caf074374 100644
> > --- a/common/hash.c
> > +++ b/common/hash.c
> > @@ -35,6 +35,141 @@
> >  #include <u-boot/sha512.h>
> >  #include <u-boot/md5.h>
> >
> > +#if CONFIG_IS_ENABLED(MBEDTLS_LIB_CRYPTO)
> > +
> > +static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
> > +{
> > +       int ret;
> > +       mbedtls_sha1_context *ctx = malloc(sizeof(mbedtls_sha1_context));


Why do we need allocation here? We should avoid it where possible.

> > +
> > +       if (!ctx)
> > +               return -ENOMEM;
> > +
> > +       mbedtls_sha1_init(ctx);
> > +       ret = mbedtls_sha1_starts(ctx);
> > +       if (!ret) {
> > +               *ctxp = ctx;
> > +       } else {
> > +               mbedtls_sha1_free(ctx);
> > +               free(ctx);
> > +       }
> > +
> > +       return ret;
> > +}
> > +

[..]

Regards,
Simon


More information about the U-Boot mailing list