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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 482CBC636CD for ; Tue, 7 Feb 2023 04:07:03 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 17A6185D88; Tue, 7 Feb 2023 05:06:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dVVO40fQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DBA7F85D27; Tue, 7 Feb 2023 05:05:15 +0100 (CET) Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) (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 F065185D22 for ; Tue, 7 Feb 2023 05:05:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-yb1-xb2e.google.com with SMTP id d132so17022158ybb.5 for ; Mon, 06 Feb 2023 20:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zPIBI/rEygOigp0TYJSQZvf5lnrXGEN6Rtqg7YitcTs=; b=dVVO40fQ/dSqXmxiv9giz8ulrNQSk7OPLkeKkXBcjLRUlRVdE0/xzFvcY+gXrPOfHr hN1DVYX+XoOYALkCAk0FoReJRcOuqFmMbLnQGEGo3fiO1OhLSA2ICGXIkK57yiub2dJk lpI0pqmlHSaVllGeekxg0SeSIvOWHmNdf71i4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zPIBI/rEygOigp0TYJSQZvf5lnrXGEN6Rtqg7YitcTs=; b=pEhdre2ixpWZTv/19GYQhXppBzWhheNYfVu63jlNXaKt0yaErEHZqSrdPVe18o6AKl Qc49LJjWrMn4bKdcSCLCNehLwI2MRqAc4/wxU0FI2idew8L2KNdf4Yup6nB40UZhVQLf s+Keug6L39EPPYVCsLzN/1Wwn6Cne2jSbKGJscpNXGMrO04rwpZ7+Akeukf7cgw23KGb RSofNLFFXD3AFIfO/5tsLM7aqT4aUeVhU/b8o10o4i3UbbUOt6A3agYtzLVesOgmhMnL uAOtC3M+U0WxW0h1eRYjb0zf4KsrB8mdEivJA1GVUIM9IhLsVcOu4XHHqyQwRnmEDB9I qCJw== X-Gm-Message-State: AO0yUKUZJ7s+DUMful6mayljGiA+FkhAL6U1GMo20FGYFoJk/1NdSAMb L20fIYCNmIxMmFiTG2IfrwtX/Rnvq/yIcazAKdzyQg== X-Google-Smtp-Source: AK7set+JQsHb7fTMotlM4FxIpiHDbtn/SxK8QdaQ9qnYu/MNogNMSi+FV31TcMFS+k3k4V321GMC3TPLq6TQSriNY9U= X-Received: by 2002:a5b:b10:0:b0:85b:fcd2:b743 with SMTP id z16-20020a5b0b10000000b0085bfcd2b743mr249596ybp.176.1675742704842; Mon, 06 Feb 2023 20:05:04 -0800 (PST) MIME-Version: 1.0 References: <1654107991-598-1-git-send-email-loic.poulain@linaro.org> <1654107991-598-5-git-send-email-loic.poulain@linaro.org> In-Reply-To: From: Simon Glass Date: Mon, 6 Feb 2023 21:02:16 -0700 Message-ID: Subject: Re: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process To: Loic Poulain Cc: kettenis@openbsd.org, michal.simek@xilinx.com, trini@konsulko.com, u-boot@lists.denx.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean Hi Loic, On Mon, 6 Feb 2023 at 15:12, Loic Poulain wrote: > > Hi Simon, > > Le lun. 6 f=C3=A9vr. 2023 =C3=A0 18:12, Simon Glass a = =C3=A9crit : >> >> Hi Loic, >> >> On Wed, 1 Jun 2022 at 12:27, Loic Poulain wrot= e: >> > >> > Mark sha256_process as weak to allow hardware specific implementation. >> > Add parameter for supporting multiple blocks processing. >> > >> > Signed-off-by: Loic Poulain >> > --- >> > lib/sha256.c | 26 +++++++++++++++++++------- >> > 1 file changed, 19 insertions(+), 7 deletions(-) >> > >> > diff --git a/lib/sha256.c b/lib/sha256.c >> > index c1fe93d..50b0b51 100644 >> > --- a/lib/sha256.c >> > +++ b/lib/sha256.c >> > @@ -14,6 +14,8 @@ >> > #include >> > #include >> > >> > +#include >> > + >> > const uint8_t sha256_der_prefix[SHA256_DER_LEN] =3D { >> > 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, >> > 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, >> > @@ -55,7 +57,7 @@ void sha256_starts(sha256_context * ctx) >> > ctx->state[7] =3D 0x5BE0CD19; >> > } >> > >> > -static void sha256_process(sha256_context *ctx, const uint8_t data[64= ]) >> > +static void sha256_process_one(sha256_context *ctx, const uint8_t dat= a[64]) >> > { >> > uint32_t temp1, temp2; >> > uint32_t W[64]; >> > @@ -186,6 +188,18 @@ static void sha256_process(sha256_context *ctx, c= onst uint8_t data[64]) >> > ctx->state[7] +=3D H; >> > } >> > >> > +__weak void sha256_process(sha256_context *ctx, const unsigned char *= data, >> > + unsigned int blocks) >> > +{ >> > + if (!blocks) >> > + return; >> > + >> > + while (blocks--) { >> > + sha256_process_one(ctx, data); >> > + data +=3D 64; >> > + } >> > +} >> > + >> > void sha256_update(sha256_context *ctx, const uint8_t *input, uint32_= t length) >> > { >> > uint32_t left, fill; >> > @@ -204,17 +218,15 @@ void sha256_update(sha256_context *ctx, const ui= nt8_t *input, uint32_t length) >> > >> > if (left && length >=3D fill) { >> > memcpy((void *) (ctx->buffer + left), (void *) input, = fill); >> > - sha256_process(ctx, ctx->buffer); >> > + sha256_process(ctx, ctx->buffer, 1); >> > length -=3D fill; >> > input +=3D fill; >> > left =3D 0; >> > } >> > >> > - while (length >=3D 64) { >> > - sha256_process(ctx, input); >> > - length -=3D 64; >> > - input +=3D 64; >> > - } >> > + sha256_process(ctx, input, length / 64); >> > + input +=3D length / 64 * 64; >> > + length =3D length % 64; >> > >> > if (length) >> > memcpy((void *) (ctx->buffer + left), (void *) input, = length); >> > -- >> > 2.7.4 >> > >> >> I just came across this patch as it broke minnowmax. > > > Ok, is it a build time or runtime break? Build, but you need the binary blobs to see it :-( > >> >> >> This should be using driver model, not weak functions. Please can you >> take a look? > > > Yes I can look at it in the next few days. I have used weak function beca= use it=E2=80=99s an architecture feature offered by armv8 instructions, It= =E2=80=99s not strictly speaking an internal device/IP. Thanks. Right, same as hardware-accelerated hashing hardware in my book. See hash.c which has become a mess. We have been trying to make do with a list of algos, but given all the updates I think needs a new UCLASS_HASH with the same operations as in hash.h Regards, Simon