From patchwork Wed Jun 1 10:03:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577788 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp421460mab; Wed, 1 Jun 2022 03:04:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3OtS8a6lf41VBxsCmYe7e6scEPaPvwcffhh9HG+qe2rjaTlMbJ2CAst3l8buKXT+iaGAV X-Received: by 2002:a05:6638:1342:b0:330:f462:1a8f with SMTP id u2-20020a056638134200b00330f4621a8fmr13825194jad.249.1654077853716; Wed, 01 Jun 2022 03:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654077853; cv=none; d=google.com; s=arc-20160816; b=lRLjoAno1I0y5VwK7WVLIY+526dgBE26l5+MDYZvPt6Nix7yqmzxYoj6dwKGqurWkh WOM/OBq/115eciqx+Oki3aOTwAZeKYaphgCxlDQOJc72s4TDVebk5aqHOHUxom3PvMWH XvM0887PI+MStHSTSFH1iYgV48tJpkH2NA5yWjMrlY945PiFmDfdYwU2OXbam83itfhj 7dEN6kg8twMoCR+tgzX8Pu3NVczlvIyKqAHARvf9aZUN2PPDv0oCu98RMOBv8VlitpUb zRTbyiKEbBYuu1L/ibJEGL4fxZe7Cp66vcpiE53i+Ygu3dyWb3G6Ks3MafG6NUGTsG5g iKxw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=ZrWxC2ZbJYHaqKbgWdRgJlNfvrDv8IFgpnMmkDU8qWg=; b=Q5Rk2kXUIEtdvd/AckF7LdtNwRohZxpcANAqqtN58nZG2gFSppMi/KUkeTwSesgYWd Slh8Y3/bonf60kD32zgvETjgg6AsBqWo20Vt/2EAYCZfWW6Xyt7b/BxzpQHndu7+BJhL awyk2L5168tskTFGyEtJEEqXWYj4or/IGFLzFWvsVoj9quWpkcU8tEnRvAkLCJgDNuru VUXzLhwOfk6c4lwawpnQj7SuF5SW3yB0CHJy/3pVkd1PH36E957NUXP1uevsMRD2O1ou hr+3mtYU4jFVBGO2zUAby0vBIvav9HQ26IknYAh8y99XokMutgJbt/uEcoY39WKNYAP/ Su8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bviUTxCK; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id y3-20020a5e9203000000b00668f3e50025si1052815iop.94.2022.06.01.03.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 03:04:13 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bviUTxCK; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 7FAA483E81; Wed, 1 Jun 2022 12:04:08 +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="bviUTxCK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9FE5A83F72; Wed, 1 Jun 2022 12:04:06 +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-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (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 AFC9083E71 for ; Wed, 1 Jun 2022 12:04:02 +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-wr1-x432.google.com with SMTP id q7so1613991wrg.5 for ; Wed, 01 Jun 2022 03:04:02 -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; bh=ZrWxC2ZbJYHaqKbgWdRgJlNfvrDv8IFgpnMmkDU8qWg=; b=bviUTxCKeBkT0nI5kht6KG2I21iuiW34TFaysjmpnjyh4dhPnegpZVfvq/pB1KLIT6 Y8Ca2j6IdEVowWVUzkY07lE8ZJoU70vdgqyMpaxmRmyPb+EdjGO/idmRbAnM1IWZ2UrP RglH1yfnaojL0n4zpOrFp3jFDAp6lo6ZVc6PXtr33a/92zSHvV6H/YUpgcXsyEtiqxr2 ovjJqtFTIrkt+mtcr4kAJphVha5Vxj/tg9Fe1x16Eg3JwVHgKso56p4asUfxljB3Rs5N WwYCKIxkcUlzHitpLX9j+FUxH8FY2Hhlt1rrgqd/iBFhM3nob4rf2vjebk2AB6jPTxax XMRA== 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; bh=ZrWxC2ZbJYHaqKbgWdRgJlNfvrDv8IFgpnMmkDU8qWg=; b=tutyzWmp86UVNbMqd+LIvkVvbuTTpLKzCcEI+lWNo+Nw8TOxPmxnCVuBDmVCIEXdn+ nZCxQz4CRsJZFNZXDEZF1Xb5IwCjjZIX1IhBtKtSWX2ZmiRC6Z9MKpthdGcjxXdMvXw2 1E4lbUj+t8lgaba5xanXG1ZMJKGNQISIvWQvmOh/kUkf/PDohDhCbEUIwMOX9tTqEX9v 8xzmpHoLSCDwFUptqRdEbaeYoHCQA5+MKnO2P0C1cbccCcbtZkrwNLO908bdo6jXhTyY R4LiHUbgCW0vAZGVTzM4KygOhJp6QZJIAefQDRNAjxKkscRgePimhAqjqtqEOjztTZ44 RpOw== X-Gm-Message-State: AOAM531fvbc/z8d71KeeIacGtOMEfZR6/rIY2Qdz2koagxICmkl/xAIV dKSQ9BhPx4iE07MShkaeYRlTmw== X-Received: by 2002:adf:ed01:0:b0:20c:c137:aaeb with SMTP id a1-20020adfed01000000b0020cc137aaebmr53408486wro.638.1654077842069; Wed, 01 Jun 2022 03:04:02 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:58:ccc3:729d:30c2]) by smtp.gmail.com with ESMTPSA id i12-20020a7bc94c000000b0039736892653sm1468058wml.27.2022.06.01.03.04.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2022 03:04:01 -0700 (PDT) From: Loic Poulain To: trini@konsulko.com, kettenis@openbsd.org Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH 1/3] lib: sha1: Add support for hardware specific sha1_process Date: Wed, 1 Jun 2022 12:03:57 +0200 Message-Id: <1654077839-29147-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 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 sha1_process as weak to allow hardware specific implementation. Add parameter to support for multiple blocks processing. Signed-off-by: Loic Poulain --- lib/sha1.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/sha1.c b/lib/sha1.c index 8154e1e..e5e42bc 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -25,6 +25,8 @@ #include #include +#include + const uint8_t sha1_der_prefix[SHA1_DER_LEN] = { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 @@ -65,7 +67,7 @@ void sha1_starts (sha1_context * ctx) ctx->state[4] = 0xC3D2E1F0; } -static void sha1_process(sha1_context *ctx, const unsigned char data[64]) +static void __maybe_unused sha1_process_one(sha1_context *ctx, const unsigned char data[64]) { unsigned long temp, W[16], A, B, C, D, E; @@ -219,6 +221,18 @@ static void sha1_process(sha1_context *ctx, const unsigned char data[64]) ctx->state[4] += E; } +__weak void sha1_process(sha1_context *ctx, const unsigned char *data, + unsigned int blocks) +{ + if (!blocks) + return; + + while (blocks--) { + sha1_process_one(ctx, data); + data += 64; + } +} + /* * SHA-1 process buffer */ @@ -242,17 +256,15 @@ void sha1_update(sha1_context *ctx, const unsigned char *input, if (left && ilen >= fill) { memcpy ((void *) (ctx->buffer + left), (void *) input, fill); - sha1_process (ctx, ctx->buffer); + sha1_process(ctx, ctx->buffer, 1); input += fill; ilen -= fill; left = 0; } - while (ilen >= 64) { - sha1_process (ctx, input); - input += 64; - ilen -= 64; - } + sha1_process(ctx, input, ilen / 64); + input += ilen / 64 * 64; + ilen = ilen % 64; if (ilen > 0) { memcpy ((void *) (ctx->buffer + left), (void *) input, ilen);