From patchwork Wed Jun 1 18:26:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577821 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp856013mab; Wed, 1 Jun 2022 11:27:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRn26JSm9m/UcTtrXgHb0v2Lsf5ymo4DKb8FRS5yiuUJGmmHEUMB6X9tehm1N9KFApNNvz X-Received: by 2002:a5e:930e:0:b0:649:d7f0:ebc5 with SMTP id k14-20020a5e930e000000b00649d7f0ebc5mr672650iom.80.1654108040049; Wed, 01 Jun 2022 11:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654108040; cv=none; d=google.com; s=arc-20160816; b=fj+YsvrmOPOtpqXJXoZOoi0TLJ8N3IkElIziJAjJMIsCDyfYdMaxlNaYIRqwcC5dyB GKOul102DGpyYGDgjyL1zRKXvPg2Jpo+LcDDIU1HYB4ZzPCAgYUl/14qnEak9FgYjUZd 29duo27lDZJ8NPS8DFSQVbZtc/5YOiBd64/PNnM7wgjfw8jnh3pfhttrATrYCmxwD6jK N25H/Gj55s0K/jJPtoSjWdBDB1z95zBaX5y+h1CfCmeg7jqzzdgsU8J9q7BShWMTiPdL 8fiL5veLuCkH7tR/FausVq8RbxO7Ezwb7tJWgYOjT/S6nk8M4qG7W2Hwnyx2XdsFdGlp dceQ== 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=ZrWxC2ZbJYHaqKbgWdRgJlNfvrDv8IFgpnMmkDU8qWg=; b=JTQOs7vY8Xg6cdbELHiv6V95Kd9+6Lp9mqR4rDmmITY8tbarmNcsz/cXJ0iE6JRyBv W9z0pK5jf3ip9oeMPj+n4X7UfJpDjVpeSwTuQUVvwTmqq0kvAAMnYocf/+28zxZmsnBh XFuBXUqhgEiw1onAA17REH0USsvgfMtH9zSzfWrlwctW5YP/dSOnJKxY6KZn4LvGgCvL 3DGPzA8ArU/ODri4bxMlvJr33KQOWeDyAlnl5Maw4P6rHMpyMEuVtPcFapvpa2KANkz0 h9IBDhzqY7d60QbMIG92wPP7NxfjpGJasx0AzM00VelN75y55tNWoyyloP4HCjv0ku0t rugg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nSn3tD3W; 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 w18-20020a5ed612000000b0065db4969184si2558361iom.20.2022.06.01.11.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:27:20 -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=nSn3tD3W; 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 5F3D784314; Wed, 1 Jun 2022 20:26:55 +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="nSn3tD3W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EE3D8842E4; 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-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (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 3E8BE842E4 for ; Wed, 1 Jun 2022 20:26:36 +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-x333.google.com with SMTP id c5-20020a1c3505000000b0038e37907b5bso3552659wma.0 for ; Wed, 01 Jun 2022 11:26:36 -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=ZrWxC2ZbJYHaqKbgWdRgJlNfvrDv8IFgpnMmkDU8qWg=; b=nSn3tD3WBe7DMUt/TvcGaasU9AHSx7U1lVtn0afD4MbgafJpxlkYWpfqS6Wr4JIlMd HTQAOtl8c3ylfe5DTB4zPAmDHD5tsdlvI5SCNFHFhoKwbg7pxjYayKpvqewn1lu00VVl eQWQ2DQB9eXQTsrnNiSWZMo1nbjEX5DE4pCWZ7m8CsyEZzkwVmONRqpKbD7bDVnPSt0e rEUFj2ADbT2F4x214ipSjvQnEHt2Eyuab2mjr5Tsg8fnat00o3nxs632vqkGtBTlrvFf UNFTzDrk5nTfSbo9RhoQ4pehnbKYnoZhkAnAqLAOoprQ7Abu6MJ0mNh6NXo6vRG2KJZh 0flA== 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=ZrWxC2ZbJYHaqKbgWdRgJlNfvrDv8IFgpnMmkDU8qWg=; b=A0FT2cK/7/dh7nrS6p4+1p4pULqlIiFeXoLgKeuYfvAxisfWlP04nehVP2W7WpZDQk uiANxcBqSUiGOFOvj4ul5Zk0VR861ue05glLlI3Dw3Ng3t/2y0jFi6UHLD8T9h3OZrmI neYtcOfqus/JzmtZyyVc0g2zfdy+V+HGHtzfxXPCqqNbtbO1sJMb0bHXRhT2UKHO7Evd vwILLxNR5MoqaDh40B+xIOSs6Lz+nbImNDcmtyscYzO0PU194CzRjd2eznNC/tx1e/lD PTbWsIgQ4ayGe+VaX+EyabHWj2HkVoX4ODYWxEo5xMBZghWTp61a0fGKWp+BN7ZKk20a 3D8A== X-Gm-Message-State: AOAM5318jBZF807i2vLNBTnJHR8bVf4lb7NdjIwWEFC30fad4bpVSXv1 Byqrd1SgfUPBKK0btL3SlOV7lg== X-Received: by 2002:a05:600c:1c22:b0:397:5c31:6669 with SMTP id j34-20020a05600c1c2200b003975c316669mr29610004wms.78.1654107995752; Wed, 01 Jun 2022 11:26:35 -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.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2022 11:26:35 -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 1/5] lib: sha1: Add support for hardware specific sha1_process Date: Wed, 1 Jun 2022 20:26:27 +0200 Message-Id: <1654107991-598-2-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 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);