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 4DFD1C433EF for ; Wed, 1 Jun 2022 18:27:08 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E313E842E6; Wed, 1 Jun 2022 20:26:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="A3crAFoD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 26288842F8; Wed, 1 Jun 2022 20:26:42 +0200 (CEST) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 0C28D83F24 for ; Wed, 1 Jun 2022 20:26:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=loic.poulain@linaro.org Received: by mail-wm1-x32b.google.com with SMTP id f7-20020a1c3807000000b0039c1a10507fso1558539wma.1 for ; Wed, 01 Jun 2022 11:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kr/94tNekPBZeCdcj8+L+G1wx4zgQ1djGmyIcxwPsAc=; b=A3crAFoDh1HT+Iewls0pHWqwMGaC33bnUo6liqvngUYQlaTVhjh5d2f3yxQLfxExpH jXMSFUFk5micBQ7R2+WlzW56EgmPxPAlaFVmptgAeWWnBN/YilmdAz8iiK2FPPrmK3Vs 1tl/64Ru6U68CaYed/xfGlbaK5A1T05UeaRPirlp0DZNKUBMSAgQvQ7SSCpkZvXR12WZ QdVhqZx9CR7iQ252fCrr4UCTilyB3uWngZNI4awZdfNHIEl++Ze3wuTFmO6d18AnTYZs qq+UX0NpvkNNkf5aB7YCS9DYeB4FsKCeK6SeRb7EOPz7tVCF0O0NB9C0CzhVXDV1uwky bEcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kr/94tNekPBZeCdcj8+L+G1wx4zgQ1djGmyIcxwPsAc=; b=0KG08110a6lnCq4BkAtoXP3G9TYL2oWCVpKXO43HitDTEZOErWyBNnIq/iM6vYDtev 5ZjEXVu452Z6WjUUzH4Z/xJDda9PCmdn2S1rbx9qNlFcFGSeHVo0BtM8k6WiAsvZoASY d0bdGFT64hlHpBEg1mEbejvuc07tDYi+wnrZjjdk1eaiS/whByi0Bpw+l8sbknntA7qd pLw9HsaNV8zPAOCmu+nF7sIXNNMIB78Pkpm7C9EXOzyVDUD5hCj1ObrfP0Iux2A1VU+r yiup1WI3d3bBG1rGyq8l+/WLXhwNOaUpQlCQJmH1YUpKCzpD3fkmsLOhO0DZxhsfnFnP NB8A== X-Gm-Message-State: AOAM530jBFlz/zCYWCugsJtdfcMOVjI0l+wgrNU2S8lpQ1aK5yTkqxEy IM5c1cxHDQiEQYtYv52rjoBWJA== X-Google-Smtp-Source: ABdhPJyqbqMiIiukKbCmORMPwrm4RfPtNo+Usz+bjUmRbxSAruCvQa/t+WuAPzWMLM4e75d/SSpzpw== X-Received: by 2002:a05:600c:190b:b0:394:880f:ae2c with SMTP id j11-20020a05600c190b00b00394880fae2cmr606890wmq.79.1654107998532; Wed, 01 Jun 2022 11:26:38 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:58:ccc3:729d:30c2]) by smtp.gmail.com with ESMTPSA id m30-20020a05600c3b1e00b00395f15d993fsm6672837wms.5.2022.06.01.11.26.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2022 11:26:38 -0700 (PDT) From: Loic Poulain To: trini@konsulko.com Cc: u-boot@lists.denx.de, michal.simek@xilinx.com, kettenis@openbsd.org, Loic Poulain Subject: [PATCH v2 4/5] lib: sha256: Add support for hardware specific sha256_process Date: Wed, 1 Jun 2022 20:26:30 +0200 Message-Id: <1654107991-598-5-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1654107991-598-1-git-send-email-loic.poulain@linaro.org> References: <1654107991-598-1-git-send-email-loic.poulain@linaro.org> 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.5 at phobos.denx.de X-Virus-Status: Clean 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] = { 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] = 0x5BE0CD19; } -static void sha256_process(sha256_context *ctx, const uint8_t data[64]) +static void sha256_process_one(sha256_context *ctx, const uint8_t data[64]) { uint32_t temp1, temp2; uint32_t W[64]; @@ -186,6 +188,18 @@ static void sha256_process(sha256_context *ctx, const uint8_t data[64]) ctx->state[7] += 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 += 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 uint8_t *input, uint32_t length) if (left && length >= fill) { memcpy((void *) (ctx->buffer + left), (void *) input, fill); - sha256_process(ctx, ctx->buffer); + sha256_process(ctx, ctx->buffer, 1); length -= fill; input += fill; left = 0; } - while (length >= 64) { - sha256_process(ctx, input); - length -= 64; - input += 64; - } + sha256_process(ctx, input, length / 64); + input += length / 64 * 64; + length = length % 64; if (length) memcpy((void *) (ctx->buffer + left), (void *) input, length); -- 2.7.4