All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Raymond Mao <raymond.mao@linaro.org>
Cc: u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>,
	Stefan Bosch <stefan_b@posteo.net>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Michal Simek <michal.simek@amd.com>,
	Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>,
	Simon Glass <sjg@chromium.org>,
	Leo Yu-Chi Liang <ycliang@andestech.com>,
	Andrejs Cainikovs <andrejs.cainikovs@toradex.com>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Sean Anderson <seanga2@gmail.com>,
	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>,
	Sergei Antonov <saproj@gmail.com>, Ilya Lukin <4.shket@gmail.com>,
	Bin Meng <bmeng@tinylab.org>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>,
	AKASHI Takahiro <akashi.tkhro@gmail.com>,
	Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>,
	Alexander Gendin <agendin@matrox.com>,
	Manorit Chawdhry <m-chawdhry@ti.com>,
	Eddie James <eajames@linux.ibm.com>,
	Oleksandr Suvorov <oleksandr.suvorov@foundries.io>
Subject: Re: [PATCH v3 06/25] mbedtls: add digest shim layer for MbedTLS
Date: Fri, 31 May 2024 09:45:43 +0300	[thread overview]
Message-ID: <ZllyFyDaeiB68yih@hera> (raw)
In-Reply-To: <20240528140955.1960172-7-raymond.mao@linaro.org>

On Tue, May 28, 2024 at 07:09:17AM -0700, Raymond Mao wrote:
> Implement digest shim layer on top of MbedTLS crypto library.
>
> Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
> ---
> Changes in v2
> - Split the shim layer into separated files and use the original head
>   files instead of creating new ones.
> Changes in v3
> - Refactored sha1_hmac and removed non-watchdog md5 function.
>
>  include/u-boot/sha1.h |   4 ++
>  lib/mbedtls/Makefile  |   7 +++
>  lib/mbedtls/md5.c     |  59 ++++++++++++++++++++++
>  lib/mbedtls/sha1.c    | 111 ++++++++++++++++++++++++++++++++++++++++++
>  lib/mbedtls/sha256.c  |  65 +++++++++++++++++++++++++
>  lib/mbedtls/sha512.c  |  96 ++++++++++++++++++++++++++++++++++++
>  6 files changed, 342 insertions(+)
>  create mode 100644 lib/mbedtls/md5.c
>  create mode 100644 lib/mbedtls/sha1.c
>  create mode 100644 lib/mbedtls/sha256.c
>  create mode 100644 lib/mbedtls/sha512.c
>
> diff --git a/include/u-boot/sha1.h b/include/u-boot/sha1.h
> index ee46fe947a0..6120284ad4f 100644
> --- a/include/u-boot/sha1.h
> +++ b/include/u-boot/sha1.h
> @@ -37,6 +37,10 @@ extern "C" {
>  #define SHA1_SUM_LEN	20
>  #define SHA1_DER_LEN	15
>
> +#define K_IPAD_VAL 0x36
> +#define K_OPAD_VAL 0x5C
> +#define K_PAD_LEN 64
> +
>  extern const uint8_t sha1_der_prefix[];
>
>  #if defined(CONFIG_MBEDTLS_LIB_CRYPTO)
> diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile
> index 85f0a3cfd07..b8eda9638f4 100644
> --- a/lib/mbedtls/Makefile
> +++ b/lib/mbedtls/Makefile
> @@ -14,6 +14,13 @@ ccflags-y += \
>  	-I$(src)/external/mbedtls/library \
>  	# This line is intentionally left blank
>
> +# shim layer for hash
> +obj-$(CONFIG_MBEDTLS_LIB_CRYPTO) += hash_mbedtls.o
> +hash_mbedtls-$(CONFIG_$(SPL_)MD5) += md5.o
> +hash_mbedtls-$(CONFIG_$(SPL_)SHA1) += sha1.o
> +hash_mbedtls-$(CONFIG_$(SPL_)SHA256) += sha256.o
> +hash_mbedtls-$(CONFIG_$(SPL_)SHA512) += sha512.o
> +
>  obj-$(CONFIG_MBEDTLS_LIB_CRYPTO) += mbedtls_lib_crypto.o
>  mbedtls_lib_crypto-y := \
>  	$(MBEDTLS_LIB_DIR)/aes.o \
> diff --git a/lib/mbedtls/md5.c b/lib/mbedtls/md5.c
> new file mode 100644
> index 00000000000..aa8c159f66f
> --- /dev/null
> +++ b/lib/mbedtls/md5.c
> @@ -0,0 +1,59 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Hash shim layer on MbedTLS Crypto library
> + *
> + * Copyright (c) 2023 Linaro Limited
> + * Author: Raymond Mao <raymond.mao@linaro.org>
> + */
> +#include "compiler.h"
> +
> +#ifndef USE_HOSTCC
> +#include <watchdog.h>
> +#endif /* USE_HOSTCC */
> +#include <u-boot/md5.h>
> +
> +void MD5Init(MD5Context *ctx)
> +{
> +	mbedtls_md5_init(ctx);
> +	mbedtls_md5_starts(ctx);
> +}
> +
> +void MD5Update(MD5Context *ctx, unsigned char const *buf, unsigned int len)
> +{
> +	mbedtls_md5_update(ctx, buf, len);
> +}
> +
> +void MD5Final(unsigned char digest[16], MD5Context *ctx)
> +{
> +	mbedtls_md5_finish(ctx, digest);
> +	mbedtls_md5_free(ctx);
> +}
> +
> +void md5_wd(const unsigned char *input, unsigned int len,
> +	    unsigned char output[16], unsigned int chunk_sz)
> +{
> +	MD5Context context;
> +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
> +	const unsigned char *end, *curr;
> +	int chunk;
> +#endif
> +
> +	MD5Init(&context);
> +
> +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)

 IS_ENABLED() etc instead of ifdefs please throughout  the file

> +	curr = input;
> +	end = input + len;
> +	while (curr < end) {
> +		chunk = end - curr;
> +		if (chunk > chunk_sz)
> +			chunk = chunk_sz;
> +		MD5Update(&context, curr, chunk);
> +		curr += chunk;
> +		schedule();
> +	}
> +	const unsigned char *end, *curr;
> +	int chunk;
> +#endif
> +
> +	sha1_starts(&ctx);
> +
>
[...]

Thanks
/Ilias

  reply	other threads:[~2024-05-31  6:45 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-28 14:09 [PATCH v3 00/25] [RFC] Integrate MbedTLS v3.6 LTS with U-Boot Raymond Mao
2024-05-28 14:09 ` [PATCH v3 01/25] CI: Exclude MbedTLS subtree for CONFIG checks Raymond Mao
2024-05-28 14:09 ` [PATCH v3 02/25] mbedtls: Add script to update MbedTLS subtree Raymond Mao
2024-05-31  6:32   ` Ilias Apalodimas
2024-06-04 20:10     ` Andy Shevchenko
2024-06-05  7:11       ` Ilias Apalodimas
2024-06-05  9:27         ` Andy Shevchenko
2024-05-28 14:09 ` [PATCH v3 03/25] mbedtls: add mbedtls into the build system Raymond Mao
2024-05-29 16:58   ` Tom Rini
2024-05-29 17:42     ` Raymond Mao
2024-05-29 18:01       ` Tom Rini
2024-05-29 18:38         ` Raymond Mao
2024-05-29 18:42           ` Tom Rini
2024-05-29 19:42             ` Raymond Mao
2024-05-29 19:47               ` Tom Rini
2024-05-30 14:37                 ` Raymond Mao
2024-05-30 15:47                   ` Ilias Apalodimas
2024-05-30 16:14                     ` Raymond Mao
2024-05-30 20:17                 ` Ilias Apalodimas
2024-05-31 17:07                   ` Raymond Mao
2024-06-04 17:47                     ` Tom Rini
2024-05-31  6:37   ` Ilias Apalodimas
2024-06-04 20:17   ` Andy Shevchenko
2024-06-04 21:50     ` Raymond Mao
2024-06-05  9:30       ` Andy Shevchenko
2024-06-05  9:35         ` Ilias Apalodimas
2024-06-05 10:17           ` Andy Shevchenko
2024-06-05 13:30             ` Ilias Apalodimas
2024-06-05 14:28               ` Raymond Mao
2024-06-05 15:20               ` Tom Rini
2024-05-28 14:09 ` [PATCH v3 04/25] lib: Adapt digest header files to MbedTLS Raymond Mao
2024-05-28 14:09 ` [PATCH v3 05/25] md5: Remove md5 non-watchdog API Raymond Mao
2024-05-31  6:39   ` Ilias Apalodimas
2024-05-31  6:46   ` Michal Simek
2024-05-28 14:09 ` [PATCH v3 06/25] mbedtls: add digest shim layer for MbedTLS Raymond Mao
2024-05-31  6:45   ` Ilias Apalodimas [this message]
2024-05-28 14:09 ` [PATCH v3 07/25] hash: integrate hash on mbedtls Raymond Mao
2024-05-28 14:09 ` [PATCH v3 08/25] makefile: add mbedtls include directories Raymond Mao
2024-05-28 14:09 ` [PATCH v3 09/25] mbedtls/external: support Microsoft Authentication Code Raymond Mao
2024-05-28 14:09 ` [PATCH v3 10/25] mbedtls/external: support PKCS9 Authenticate Attributes Raymond Mao
2024-05-28 14:09 ` [PATCH v3 11/25] mbedtls/external: support decoding multiple signer's cert Raymond Mao
2024-05-28 14:09 ` [PATCH v3 12/25] mbedtls/external: update MbedTLS PKCS7 test suites Raymond Mao
2024-05-28 14:09 ` [PATCH v3 13/25] mbedtls: add public key porting layer Raymond Mao
2024-05-28 14:09 ` [PATCH v3 14/25] lib/crypto: Adapt public_key header with MbedTLS Raymond Mao
2024-05-28 14:09 ` [PATCH v3 15/25] mbedtls: add X509 cert parser porting layer Raymond Mao
2024-05-31 11:42   ` Ilias Apalodimas
2024-06-04 16:05     ` Raymond Mao
2024-06-04 16:53       ` Ilias Apalodimas
2024-06-04 18:01         ` Tom Rini
2024-05-28 14:09 ` [PATCH v3 16/25] lib/crypto: Adapt x509_cert_parser to MbedTLS Raymond Mao
2024-05-28 14:09 ` [PATCH v3 17/25] mbedtls: add PKCS7 parser porting layer Raymond Mao
2024-05-28 14:09 ` [PATCH v3 18/25] lib/crypto: Adapt PKCS7 parser to MbedTLS Raymond Mao
2024-05-28 14:09 ` [PATCH v3 19/25] mbedtls: add MSCode parser porting layer Raymond Mao
2024-05-31 10:03   ` Ilias Apalodimas
2024-06-04 16:26     ` Raymond Mao
2024-05-28 14:09 ` [PATCH v3 20/25] lib/crypto: Adapt mscode_parser to MbedTLS Raymond Mao
2024-05-28 14:09 ` [PATCH v3 21/25] mbedtls: add RSA helper layer on MbedTLS Raymond Mao
2024-05-31  9:59   ` Ilias Apalodimas
2024-06-04 16:43     ` Raymond Mao
2024-05-28 14:09 ` [PATCH v3 22/25] lib/rypto: Adapt rsa_helper to MbedTLS Raymond Mao
2024-05-28 14:09 ` [PATCH v3 23/25] asn1_decoder: remove ASN1 decoder when using MbedTLS Raymond Mao
2024-05-28 14:09 ` [PATCH v3 24/25] test: Remove ASN1 library test Raymond Mao
2024-05-31  6:50   ` Ilias Apalodimas
2024-05-28 14:09 ` [PATCH v3 25/25] configs: enable MbedTLS as default setting Raymond Mao

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=ZllyFyDaeiB68yih@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=4.shket@gmail.com \
    --cc=abdellatif.elkhlifi@arm.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@tinylab.org \
    --cc=eajames@linux.ibm.com \
    --cc=igor.opaniuk@gmail.com \
    --cc=leon@georgemail.eu \
    --cc=m-chawdhry@ti.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=michal.simek@amd.com \
    --cc=mr.bossman075@gmail.com \
    --cc=oleksandr.suvorov@foundries.io \
    --cc=raymond.mao@linaro.org \
    --cc=saproj@gmail.com \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=stefan_b@posteo.net \
    --cc=trini@konsulko.com \
    --cc=tuomas.tynkkynen@iki.fi \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    --cc=ycliang@andestech.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.