From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF808C43219 for ; Thu, 16 Sep 2021 15:48:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 146C361212 for ; Thu, 16 Sep 2021 15:48:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 146C361212 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 81D0183146; Thu, 16 Sep 2021 17:48:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EJKMgPjT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A45FE83157; Thu, 16 Sep 2021 17:48:50 +0200 (CEST) Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D9D1582DB3 for ; Thu, 16 Sep 2021 17:48:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-oi1-x233.google.com with SMTP id p2so9677426oif.1 for ; Thu, 16 Sep 2021 08:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=L6SaIgB2PHDrQXbJ0yQsbMqQVbRiQlA53Ic8kqBBcGI=; b=EJKMgPjTgRYGihX7ntKUGnW5md1sVXWT2LWznpdrQF2xjrVfbmXKktVmVpVHVTBnXz VNbcfx4OViO5q1I7G+Xp4nWwzWYQiZChGnsQ+oaMTrom7EosE8HeT053sXMPUBP8/dWo StFcT011Sb9ZqQWwD6FiAYVjoT1h2IZsG4wE7MSM1Cp8JtjDvGoLL/edjOL+5x1s85+S 9dbUXvaTzNEhbZC2sq8nhqxxege2WKhj6MGnwbGE+FyA2tUsDhSavvPOD7jrYWSOfMrc pSHLRvnu1h1Bj+0/UdjjC/ZlCq85TN0ttBkslVi/B+fRtJMAblqd0CGkDoaZ9JkIkT03 7FjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=L6SaIgB2PHDrQXbJ0yQsbMqQVbRiQlA53Ic8kqBBcGI=; b=VowG6d5Wu2wPhEn2CunR9TWxcfn/6rnFV+3f9j/++RZznm/YUagE9Ct+H0aDV4iwsa OHZ0cCn14s/Mscp35u3XKp/QiN3IjP0oQ8DtmDvg2YDOPJlFN9ljl7JS0xRi0FTdyQrf Nz7fxiGGTPTXLImHaDjQyZFuw/EcAJ7Zda0Ns7TybEowvpMPZKJCX1nTbCGQ5n/DIWUX IIHT8eVNeB3mQw0DlnDECgZ+JHmgdI6a+1J7d8vgayy9kdV4X+ZvjHKZMfNOm6OULiDU s6NtqCIPX4HJIczr+MUkWM8/5TYnJcQV9xv/RrP81zVHrwjvRCbD4AJrrR6lD4sKgzDM pzeQ== X-Gm-Message-State: AOAM531wWLC3Qk9zL7fv/f8xhvUpbz2qa4ktL79AJ48gSq6GCuvUtMh/ uDtbtYY/z9EBOZ9hBAEKzJS/qumAp1o= X-Google-Smtp-Source: ABdhPJw9/zzHUR7DlAPm6hUwpbLUVlGl/kzxK/TlQG2hJLTrE1q8WudzgBZqUFUeFxdp7yyh6RekaQ== X-Received: by 2002:a05:6808:199b:: with SMTP id bj27mr9724261oib.118.1631807325138; Thu, 16 Sep 2021 08:48:45 -0700 (PDT) Received: from nuclearis3.gtech (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id r23sm805420otu.54.2021.09.16.08.48.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Sep 2021 08:48:44 -0700 (PDT) Subject: Re: [PATCH 3/4] crypto: hash: Add software hash DM driver To: Chia-Wei Wang , sjg@chromium.org, trini@konsulko.com, u-boot@lists.denx.de References: <20210730010805.17845-1-chiawei_wang@aspeedtech.com> <20210730010805.17845-4-chiawei_wang@aspeedtech.com> From: "Alex G." Message-ID: <0ed7f244-2d80-3d4b-22f5-c978406f95b8@gmail.com> Date: Thu, 16 Sep 2021 10:48:43 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210730010805.17845-4-chiawei_wang@aspeedtech.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 > --- > 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 > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* 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