From patchwork Wed Jun 1 18:26:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577820 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp855861mab; Wed, 1 Jun 2022 11:27:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGe/u/eb9XQsNWJgTLprqJVGUJFC/s+PCTptHLZROmBsvltexLxqR6N3xYH36LQyBK+1jH X-Received: by 2002:a05:6e02:1949:b0:2d3:c0fb:322 with SMTP id x9-20020a056e02194900b002d3c0fb0322mr867445ilu.242.1654108028765; Wed, 01 Jun 2022 11:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654108028; cv=none; d=google.com; s=arc-20160816; b=Er8FOGDkkr/slS1GatNRUx7ohMtPH06ebVoWEzzaTnp7+RfsUfjfd+L90OIS2S7kAE ws/3Oz00Pj98BPi2zaBdRDNGqZPLrSMOsTjOjBpH83QHTKKERv2dMj8o4gS6KfvasWhK 5XYXxJJIJaT8QUXdObQpf0KcaIvSF0yIviPEzQkkuSR7HNvKpGyUgOzseJekzEJl+QRV ME5ZMO0jLEXN6zpNaNkOtLrm+k0a3k/aQlctKsPMfKsvRu33oUdoCUas0tUQCBxeITC0 tCRjcLTNAzpJSTXIbjRCrXjoOEoU41/xk6Z6ZXc0DBU9ch+GcLexsQIdaIrUn7JwVtfA xqbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=kr/94tNekPBZeCdcj8+L+G1wx4zgQ1djGmyIcxwPsAc=; b=tSp56RIhh1UfjqbPgAPzGxMFrWIjUST9Hn0cpNYlXzQfwFXx5LRlxz3588Weq8ZGYA t9qpcTZ/JxrWCDpmOgZctrPsFqFEuqQSeazVWAESAlRix9pK7BS45gYkb7+/xDkHW0oj 09c7wVsnRpg3yLRWsOlcrXIuZGzkd24Y/GydjU6Sadl3MM8Fk/7GhGHxT4pU30zBn4fC VjIGUnkZLWVge32HSdPkPN+HsBuN7IV3yWV0rkzJ/1AGvoeEGxFw+PtVaedpnS8q4gP/ /LuyL387kY9kDg/775F0lmVMbTKC5ZrZwVu7JAvlbajOB4wlNFBPUdkIJ6ibjfUyyoRa k0QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A3crAFoD; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id p1-20020a92da41000000b002d38f939ecdsi2359874ilq.109.2022.06.01.11.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:27:08 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A3crAFoD; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 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-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);