public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Simon Glass <sjg@chromium.org>
Cc: Raymond Mao <raymond.mao@linaro.org>,
	u-boot@lists.denx.de, manish.pandey2@arm.com,
	Tom Rini <trini@konsulko.com>, Stefan Bosch <stefan_b@posteo.net>,
	Mario Six <mario.six@gdsys.cc>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Michal Simek <michal.simek@amd.com>,
	Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	Andrejs Cainikovs <andrejs.cainikovs@toradex.com>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Sean Anderson <seanga2@gmail.com>, Andrew Davis <afd@ti.com>,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Sumit Garg <sumit.garg@linaro.org>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Jesse Taube <mr.bossman075@gmail.com>, Bryan Brattlof <bb@ti.com>,
	"Leon M. Busch-George" <leon@georgemail.eu>,
	Igor Opaniuk <igor.opaniuk@gmail.com>,
	Bin Meng <bmeng.cn@gmail.com>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>,
	AKASHI Takahiro <akashi.tkhro@gmail.com>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Alexander Gendin <agendin@matrox.com>,
	Jonathan Humphreys <j-humphreys@ti.com>,
	Eddie James <eajames@linux.ibm.com>,
	Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
Subject: Re: [PATCH v6 07/28] hash: integrate hash on mbedtls
Date: Fri, 13 Sep 2024 18:04:28 +0300	[thread overview]
Message-ID: <ZuRUfI6RoPiTAiva@hera> (raw)
In-Reply-To: <CAFLszThL=Z_=Qome2ZzwdqcUxX4bVg7MsMKMgk05TkrV2wcMGg@mail.gmail.com>


Hi Simon,

Apologies lost that email

> On Sun, Sep 01, 2024 at 02:09:44PM -0600, Simon Glass wrote:
> Hi Ilias,
>
> On Fri, 30 Aug 2024 at 03:37, Ilias Apalodimas
> <ilias.apalodimas@linaro.org> wrote:
> >
> > Hi Simon,
> >
> > On Thu, 29 Aug 2024 at 18:01, Simon Glass <sjg@chromium.org> wrote:
> > >
> > > Hi Raymond,
> > >
> > > On Fri, 16 Aug 2024 at 15:47, Raymond Mao <raymond.mao@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@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.
> > > > Changes in v5
> > > > - Add __maybe_unused to solve linker errors in some platforms.
> > > > - replace malloc with calloc.
> > > > Changes in v6
> > > > - None.
> > > >
> > > >  common/hash.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > > >  1 file changed, 146 insertions(+)
> > >
> > > I am not seeing the benefit of replacing U-Boot's hashing algorithms.
> > > They work well and don't change. Also it seems to be making the code a
> > > lot uglier, with an uncertain timeline for clean-up.
> >
> > A lot uglier where? It adds a few wrappers that fit into the current
> > design and callbacks.
> > I don't think what you are asking is possible. To do assymetric
> > crypto, signatures  etc -- and in the future add TLS support in wget
> > mbedTLS relies on its internal hashing functions for the cipher suites
> > it supports. So what you are asking would just make the code even
> > larger. Raymond can you please double check?
>
> It's really just a case of dropping the hash calls. It should not
> cause any other problems, so far as I can see, but I have not dug in
> in detail.
>
> Re TLS is relying on its internal hashing functions, is this what you
> are talking about?
>
> $ git grep mbedtls_sha1_free
> common/hash.c:          mbedtls_sha1_free(ctx);
> common/hash.c:          mbedtls_sha1_free((mbedtls_sha1_context *)ctx);
> lib/mbedtls/external/mbedtls/include/mbedtls/sha1.h:void
> mbedtls_sha1_free(mbedtls_sha1_context *ctx);
> lib/mbedtls/external/mbedtls/library/md.c:
> mbedtls_sha1_free(ctx->md_ctx);
> lib/mbedtls/external/mbedtls/library/psa_crypto_hash.c:
> mbedtls_sha1_free(&operation->ctx.sha1);
> lib/mbedtls/external/mbedtls/library/sha1.c:void
> mbedtls_sha1_free(mbedtls_sha1_context *ctx)
> lib/mbedtls/external/mbedtls/library/sha1.c:    mbedtls_sha1_free(ctx);
> lib/mbedtls/external/mbedtls/library/sha1.c:    mbedtls_sha1_free(&ctx);
> lib/mbedtls/external/mbedtls/library/sha1.c:    mbedtls_sha1_free(&ctx);
> lib/mbedtls/sha1.c:     mbedtls_sha1_free(ctx);
>
> I see this in psa_crypto_hash.c (not sure what that is though).
PSA is Platform Security Architecture for Arm. They define APIs etc and
some crypto ops can move to the Secure World.

As I responded later down the thread, mbedTLS config.h file allows you to define
alternative implementations. The benefit that I see by using mbedTLS hashing,
is that we can switch on new algorithms by enabling an option in mbedTLS.
OTOH some work will be needed to plug new algorithms in U-Boot and as you
point out HW accel will not work -- Unless we define the accelerator
functions in the config file above. But that doesn't solve your problem of
having one extra ifdef in hash.c

>
> > > Can you do the rest of the integration first?
>
> I believe this is the best approach. We need to permit using crypto
> acceleration too (via driver model), which is obviously impossible if
> mbed algorithms are using built-in hashing.
>

Look on the response above, we can, but I don't love the solution.

> The biggest challenge here is that common/hash.c needs some love, as I
> mentioned in an earlier version.

Fair enough. So the way I see it we got three options.
- We pull in the current one and explicitly state that mbedTLS != HW accel
  for now and plan for a wider refactoring.
- we write a few wrappers to adjust the u-boot functions and define
  those in the mbedTLS config file. We could then go back and try to make
  mbedTLS work with the existing hw accels. This is doable but
- we treat mbedTLS as a 'hardware accelerator', define hw_sha_init etc and
  make wrappers for that. This does solve the extra ifdefery, but OTOH
  mbedTLS will never work with hw accelerators so I'd say no.

Raymond, can you take a look at (2) and see if it works? You basically have
to rip out all the hashing code and define wrappers on top of
hash_block() that mbedTLS can use

Thanks
/Ilias

>
> Regards,
> Simon

  reply	other threads:[~2024-09-13 15:04 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-16 21:43 [PATCH v6 00/28] Integrate MbedTLS v3.6 LTS with U-Boot Raymond Mao
2024-08-16 21:43 ` [PATCH v6 01/28] CI: Exclude MbedTLS subtree for CONFIG checks Raymond Mao
2024-08-16 21:43 ` [PATCH v6 02/28] mbedtls: add mbedtls into the build system Raymond Mao
2024-08-28  8:30   ` Ilias Apalodimas
2024-08-16 21:43 ` [PATCH v6 03/28] lib: Adapt digest header files to MbedTLS Raymond Mao
2024-08-28  9:25   ` Ilias Apalodimas
2024-09-03 15:12     ` Raymond Mao
2024-08-16 21:43 ` [PATCH v6 04/28] md5: Remove md5 non-watchdog API Raymond Mao
2024-08-16 21:43 ` [PATCH v6 05/28] sha1: Remove sha1 " Raymond Mao
2024-08-16 21:43 ` [PATCH v6 06/28] mbedtls: add digest shim layer for MbedTLS Raymond Mao
2024-08-28 10:37   ` Ilias Apalodimas
2024-09-03 15:28     ` Raymond Mao
2024-09-06  7:56       ` Ilias Apalodimas
2024-08-16 21:43 ` [PATCH v6 07/28] hash: integrate hash on mbedtls Raymond Mao
2024-08-28  9:53   ` Ilias Apalodimas
2024-09-03 15:49     ` Raymond Mao
2024-08-29 15:01   ` Simon Glass
2024-08-30  9:36     ` Ilias Apalodimas
2024-09-01 20:09       ` Simon Glass
2024-09-13 15:04         ` Ilias Apalodimas [this message]
2024-09-16 15:42           ` Simon Glass
2024-09-17 13:01             ` Ilias Apalodimas
2024-09-19 14:10               ` Simon Glass
2024-09-16 16:45           ` Raymond Mao
2024-09-03 15:54       ` Raymond Mao
2024-09-06  7:36         ` Ilias Apalodimas
2024-09-06 14:00           ` Raymond Mao
2024-09-06 14:05             ` Ilias Apalodimas
2024-09-03 15:45     ` Raymond Mao
2024-08-16 21:43 ` [PATCH v6 08/28] mbedtls: Enable smaller implementation for SHA256/512 Raymond Mao
2024-08-19 21:03   ` Tom Rini
2024-08-16 21:43 ` [PATCH v6 09/28] mbedtls/external: support Microsoft Authentication Code Raymond Mao
2024-08-28  8:33   ` Ilias Apalodimas
2024-08-16 21:43 ` [PATCH v6 10/28] mbedtls/external: support PKCS9 Authenticate Attributes Raymond Mao
2024-08-28  8:53   ` Ilias Apalodimas
2024-08-16 21:44 ` [PATCH v6 11/28] mbedtls/external: support decoding multiple signer's cert Raymond Mao
2024-08-16 21:44 ` [PATCH v6 12/28] mbedtls/external: update MbedTLS PKCS7 test suites Raymond Mao
2024-08-28  8:33   ` Ilias Apalodimas
2024-08-16 21:44 ` [PATCH v6 13/28] public_key: move common functions to public key helper Raymond Mao
2024-08-16 21:44 ` [PATCH v6 14/28] x509: move common functions to x509 helper Raymond Mao
2024-08-16 21:44 ` [PATCH v6 15/28] pkcs7: move common functions to PKCS7 helper Raymond Mao
2024-08-16 21:44 ` [PATCH v6 16/28] mbedtls: add public key porting layer Raymond Mao
2024-08-28 10:27   ` Ilias Apalodimas
2024-08-16 21:44 ` [PATCH v6 17/28] lib/crypto: Adapt public_key header with MbedTLS Raymond Mao
2024-08-16 21:44 ` [PATCH v6 18/28] mbedtls: add X509 cert parser porting layer Raymond Mao
2024-08-16 21:44 ` [PATCH v6 19/28] lib/crypto: Adapt x509_cert_parser to MbedTLS Raymond Mao
2024-08-16 21:44 ` [PATCH v6 20/28] mbedtls: add PKCS7 parser porting layer Raymond Mao
2024-08-16 21:44 ` [PATCH v6 21/28] lib/crypto: Adapt PKCS7 parser to MbedTLS Raymond Mao
2024-08-16 21:44 ` [PATCH v6 22/28] mbedtls: add MSCode parser porting layer Raymond Mao
2024-08-28 10:16   ` Ilias Apalodimas
2024-08-28 10:16   ` Ilias Apalodimas
2024-08-16 21:44 ` [PATCH v6 23/28] lib/crypto: Adapt mscode_parser to MbedTLS Raymond Mao
2024-08-16 21:44 ` [PATCH v6 24/28] mbedtls: add RSA helper layer on MbedTLS Raymond Mao
2024-08-28 10:28   ` Ilias Apalodimas
2024-08-16 21:44 ` [PATCH v6 25/28] lib/rypto: Adapt rsa_helper to MbedTLS Raymond Mao
2024-08-16 21:44 ` [PATCH v6 26/28] asn1_decoder: add build options for ASN1 decoder Raymond Mao
2024-08-28  8:55   ` Ilias Apalodimas
2024-08-16 21:44 ` [PATCH v6 27/28] test: Remove ASN1 library test Raymond Mao
2024-08-16 21:44 ` [PATCH v6 28/28] configs: enable MbedTLS as default setting Raymond Mao
2024-08-28  8:54   ` Ilias Apalodimas
2024-08-17 15:58 ` [PATCH v6 00/28] Integrate MbedTLS v3.6 LTS with U-Boot Simon Glass
2024-09-03 14:59   ` Raymond Mao
2024-09-06  0:43     ` Simon Glass
2024-09-06 14:50       ` Raymond Mao
2024-09-06 15:27         ` Tom Rini
2024-09-06 17:20           ` Raymond Mao
2024-09-10 18:44         ` Simon Glass
2024-09-10 21:29           ` Raymond Mao
2024-09-04 12:48   ` Peter Robinson
2024-09-04 16:43     ` Tom Rini
2024-09-06  7:01       ` Ilias Apalodimas
2024-09-06  0:43     ` Simon Glass
2024-09-06  9:05       ` Peter Robinson
2024-08-19 21:04 ` Tom Rini
2024-09-03 15:03   ` Raymond Mao
2024-09-11 19:15     ` Raymond Mao
2024-08-20  0:28 ` Tom Rini
2024-08-20  0:29   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZuRUfI6RoPiTAiva@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=afd@ti.com \
    --cc=agendin@matrox.com \
    --cc=akashi.tkhro@gmail.com \
    --cc=alpernebiyasak@gmail.com \
    --cc=andrejs.cainikovs@toradex.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bb@ti.com \
    --cc=bmeng.cn@gmail.com \
    --cc=eajames@linux.ibm.com \
    --cc=igor.opaniuk@gmail.com \
    --cc=j-humphreys@ti.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=leon@georgemail.eu \
    --cc=manish.pandey2@arm.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=mario.six@gdsys.cc \
    --cc=michal.simek@amd.com \
    --cc=mkorpershoek@baylibre.com \
    --cc=mr.bossman075@gmail.com \
    --cc=oleksandr.suvorov@foundries.io \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=raymond.mao@linaro.org \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=stefan_b@posteo.net \
    --cc=sumit.garg@linaro.org \
    --cc=trini@konsulko.com \
    --cc=tuomas.tynkkynen@iki.fi \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox