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 2F9C9C433EF for ; Thu, 16 Sep 2021 15:43:37 +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 6633661212 for ; Thu, 16 Sep 2021 15:43:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6633661212 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 B0FA283131; Thu, 16 Sep 2021 17:43:32 +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="c13wPgvz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DD5583131; Thu, 16 Sep 2021 17:43:30 +0200 (CEST) Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (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 8BD8F80608 for ; Thu, 16 Sep 2021 17:43:23 +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-ot1-x332.google.com with SMTP id x10-20020a056830408a00b004f26cead745so8846755ott.10 for ; Thu, 16 Sep 2021 08:43:23 -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=hjGGkJ/rn95tbqa84xr7cZCePVox4nyrYgwmtYCoFyQ=; b=c13wPgvzVeFCkBK4Gl/ByYfnStWdC4bIp9KduspSxhKMods0Rsm34i78qznxrYlh/z oWLpjawn4r7MkBIm3E0DzoNG+MFMChBrrF+Oi3UkcGGBJA+EhtRpBIVNEE3F76ESQkY/ 3WYgAq1xe25xc36lJIKSUUxGulvUpTESk2qajoxmMuVCAfJDl2IC4Kysh/EgScfv1cOY dDtlWqdJIyT2og9kzQfOnQ6aZKim2YIcx2Vgl1uOoTGj/EKnnY8ow/BW+ujtO/E55cve Zm/2YmujNUs+xmziBQqCEODBDb5n5gGH9Td7hnQyN3nQXD5XrLXhNvR6CudZRLyWryCe FXgQ== 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=hjGGkJ/rn95tbqa84xr7cZCePVox4nyrYgwmtYCoFyQ=; b=HfOnRTwKLnn2bZo+SZX1whdJbIUINW5Ts2iQ97f0h43ylTtdqTCvqN5rcTF+SZN5tH dh9US/c0UAqoc3qF0SDkkB84o+B50RbK0TTJ4I5LhjRol+Jt6xLVoAT/dWOvaN+hL36S vzIJPOe7yIOcOa0zv2IDaww4/Y11bV8OPjpm0U7kQUVY/0WiXOF/HByyfTRrr+yzI0mK jUI1h0sGkUiR6RsMvExNO1Dv6lc09OfcXs+v3n4XOPS/UkPk89g/lRKq6mslET5bTxaT okT7ErPDAl3F3HTCqdz8mNU72Dble85Tvg25HyOBzT0kgJxKgYSzJHaNArfqIYLMCyHi mFbw== X-Gm-Message-State: AOAM532C6YxABaCkrByYT43qm9l1sDjccy3nyRpQ/iN9w3eDAOz2KCeF /rh90wsUA0jjPLme5/wKeVKdqcuE2fs= X-Google-Smtp-Source: ABdhPJxgI+f2TFW+UacUQsBl7cNo9DG8lzYOzLHPis/DpftmWpu7BD9x3HhLshfdrOD4d3UTkeSwoQ== X-Received: by 2002:a05:6830:149a:: with SMTP id s26mr5253453otq.59.1631807001601; Thu, 16 Sep 2021 08:43:21 -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 w24sm229532oow.5.2021.09.16.08.43.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Sep 2021 08:43:20 -0700 (PDT) Subject: Re: [PATCH 2/4] dm: hash: Add new UCLASS_HASH support 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-3-chiawei_wang@aspeedtech.com> From: "Alex G." Message-ID: Date: Thu, 16 Sep 2021 10:43:19 -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-3-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 Hi, On 7/29/21 8:08 PM, Chia-Wei Wang wrote: > Add UCLASS_HASH for hash driver development. Thus the > hash drivers (SW or HW-accelerated) can be developed > in the DM-based fashion. Software hashing implementations are shared tightly with host tools. With DM, there's no opportunity for code sharing with host tools. The design question that I have is "do we want to DM hashes, or do we want to DM hardware accelerators for hashes?" I did some parallel work expose remaining hash algos via hash_lookup_algo() and hash_progressive_lookup_algo(). > Signed-off-by: Chia-Wei Wang > --- > drivers/crypto/Kconfig | 2 + > drivers/crypto/Makefile | 1 + > drivers/crypto/hash/Kconfig | 5 ++ > drivers/crypto/hash/Makefile | 5 ++ > drivers/crypto/hash/hash-uclass.c | 121 ++++++++++++++++++++++++++++++ > include/dm/uclass-id.h | 1 + > include/u-boot/hash.h | 61 +++++++++++++++ > 7 files changed, 196 insertions(+) > create mode 100644 drivers/crypto/hash/Kconfig > create mode 100644 drivers/crypto/hash/Makefile > create mode 100644 drivers/crypto/hash/hash-uclass.c > create mode 100644 include/u-boot/hash.h > > diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig > index 1ea116be75..0082177c21 100644 > --- a/drivers/crypto/Kconfig > +++ b/drivers/crypto/Kconfig > @@ -1,5 +1,7 @@ > menu "Hardware crypto devices" > > +source drivers/crypto/hash/Kconfig > + Hashes are useful outside of cryptographic functions, so it seems odd to merge them in crypto. For example, CRC32 is not a hash useful in crypto, but otherwise widely used in u-boot. [snip] > diff --git a/drivers/crypto/hash/hash-uclass.c b/drivers/crypto/hash/hash-uclass.c > new file mode 100644 > index 0000000000..446eb9e56a > --- /dev/null > +++ b/drivers/crypto/hash/hash-uclass.c > @@ -0,0 +1,121 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (c) 2021 ASPEED Technology Inc. > + * Author: ChiaWei Wang > + */ > + > +#define LOG_CATEGORY UCLASS_HASH > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct hash_info { > + char *name; > + uint32_t digest_size; > +}; > + > +static const struct hash_info hash_info[HASH_ALGO_NUM] = { > + [HASH_ALGO_CRC16_CCITT] = { "crc16-ccitt", 2 }, > + [HASH_ALGO_CRC32] = { "crc32", 4 }, > + [HASH_ALGO_MD5] = { "md5", 16 }, > + [HASH_ALGO_SHA1] = { "sha1", 20 }, > + [HASH_ALGO_SHA256] = { "sha256", 32 }, > + [HASH_ALGO_SHA384] = { "sha384", 48 }, > + [HASH_ALGO_SHA512] = { "sha512", 64}, > +}; It seems a step backwards to have to enum {} our hash algos, since we already identify them by their strings (e.g. "sha256"). and then associated ops structure. The > + > +enum HASH_ALGO hash_algo_lookup_by_name(const char *name) string -> hash_lookup_algo() -> ops struct Is the current way to do things. hash_algo_lookup_by_name() does the roundabout through an enum. That doesn't make sense to me. Alex