public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Alex G." <mr.nuke.me@gmail.com>
To: Chia-Wei Wang <chiawei_wang@aspeedtech.com>,
	sjg@chromium.org, trini@konsulko.com, u-boot@lists.denx.de
Subject: Re: [PATCH 3/4] crypto: hash: Add software hash DM driver
Date: Thu, 16 Sep 2021 10:48:43 -0500	[thread overview]
Message-ID: <0ed7f244-2d80-3d4b-22f5-c978406f95b8@gmail.com> (raw)
In-Reply-To: <20210730010805.17845-4-chiawei_wang@aspeedtech.com>



On 7/29/21 8:08 PM, Chia-Wei Wang wrote:
> Add purely software-implmented drivers to support multiple
> hash operations including CRC, MD5, and SHA family.
> 
> This driver is based on the new hash uclass.
> 
> Signed-off-by: Chia-Wei Wang <chiawei_wang@aspeedtech.com>
> ---
>   drivers/crypto/hash/Kconfig   |  11 ++
>   drivers/crypto/hash/Makefile  |   1 +
>   drivers/crypto/hash/hash_sw.c | 301 ++++++++++++++++++++++++++++++++++
>   3 files changed, 313 insertions(+)
>   create mode 100644 drivers/crypto/hash/hash_sw.c
> 
> diff --git a/drivers/crypto/hash/Kconfig b/drivers/crypto/hash/Kconfig
> index e226144b9b..cd29a5c6a4 100644
> --- a/drivers/crypto/hash/Kconfig
> +++ b/drivers/crypto/hash/Kconfig
> @@ -3,3 +3,14 @@ config DM_HASH
>   	depends on DM
>   	help
>   	  If you want to use driver model for Hash, say Y.
> +
> +config HASH_SOFTWARE
> +	bool "Enable driver for Hash in software"
> +	depends on DM_HASH
> +	depends on MD5
> +	depends on SHA1
> +	depends on SHA256
> +	depends on SHA512_ALGO

I would have expected a U_BOOT_DRIVER() for each hash algo, rather than 
a U_BOOT_DRIVER() wich encompassess all possible algos. If I'm trying to 
use SHA256 in SPL, I might not have the room too add SHA1 and MD5, so 
I'd have issues using HASH_SOFTWARE, as designed.

> diff --git a/drivers/crypto/hash/hash_sw.c b/drivers/crypto/hash/hash_sw.c
> new file mode 100644
> index 0000000000..fea9d12609
> --- /dev/null
> +++ b/drivers/crypto/hash/hash_sw.c
> @@ -0,0 +1,301 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (c) 2021 ASPEED Technology Inc.
> + * Author: ChiaWei Wang <chiawei_wang@aspeedtech.com>
> + */
> +#include <config.h>
> +#include <common.h>
> +#include <dm.h>
> +#include <log.h>
> +#include <malloc.h>
> +#include <watchdog.h>
> +#include <u-boot/hash.h>
> +#include <u-boot/crc.h>
> +#include <u-boot/md5.h>
> +#include <u-boot/sha1.h>
> +#include <u-boot/sha256.h>
> +#include <u-boot/sha512.h>
> +
> +/* CRC16-CCITT */
> +static void hash_init_crc16_ccitt(void *ctx)
> +{
> +	*((uint16_t *)ctx) = 0;

Undefined behavior: Pointer aliased type-punning. I would suggest using 
memset(). Might not be necessarrym as expleined in the next comment.

> +static void hash_update_crc16_ccitt(void *ctx, const void *ibuf, uint32_t ilen)
> +static void hash_finish_crc16_ccitt(void *ctx, void *obuf)
> +/* CRC32 */
> +static void hash_init_crc32(void *ctx)
> +static void hash_update_crc32(void *ctx, const void *ibuf, uint32_t ilen)
> +static void hash_finish_crc32(void *ctx, void *obuf)
> +/* SHA1 */
> +static void hash_init_sha1(void *ctx)
> +/* SHA256 */
> +/* SHA384 */
> +/* SHA512 */

This logic already exists in common/hash.c for hash_Lookup_algo() and 
hash_progressive_algo().

Alex


  parent reply	other threads:[~2021-09-16 15:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30  1:08 [PATCH 0/4] crypto: Add new UCLASS_HASH Chia-Wei Wang
2021-07-30  1:08 ` [PATCH 1/4] lib/md5: Export progressive APIs Chia-Wei Wang
2021-09-02 13:28   ` Tom Rini
2021-07-30  1:08 ` [PATCH 2/4] dm: hash: Add new UCLASS_HASH support Chia-Wei Wang
2021-09-02 13:28   ` Tom Rini
2021-09-22 16:19     ` Simon Glass
2021-09-22 23:56       ` ChiaWei Wang
2021-09-24  2:49         ` Simon Glass
2021-09-16 15:43   ` Alex G.
2021-09-22  3:18     ` ChiaWei Wang
2021-09-24  2:49     ` Simon Glass
2021-09-27 15:37       ` Alex G.
2021-09-27 20:17         ` Simon Glass
2021-07-30  1:08 ` [PATCH 3/4] crypto: hash: Add software hash DM driver Chia-Wei Wang
2021-09-02 13:28   ` Tom Rini
2021-09-16 15:48   ` Alex G. [this message]
2021-09-22  3:18     ` ChiaWei Wang
2021-07-30  1:08 ` [PATCH 4/4] fit: Use DM hash driver if supported Chia-Wei Wang
2021-09-02 13:28   ` Tom Rini
2021-09-16 15:59   ` Alex G.
2021-09-22  3:18     ` ChiaWei Wang
2021-08-25  1:21 ` [PATCH 0/4] crypto: Add new UCLASS_HASH ChiaWei Wang

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=0ed7f244-2d80-3d4b-22f5-c978406f95b8@gmail.com \
    --to=mr.nuke.me@gmail.com \
    --cc=chiawei_wang@aspeedtech.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.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