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); From patchwork Wed Jun 1 18:26:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577822 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp856149mab; Wed, 1 Jun 2022 11:27:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9ignoUAhEVcYlRPX9igeql3gr96NFGANOc9KbVqDW6TKJlhG+URaeTS0UIchyP9htG7cA X-Received: by 2002:a5d:9d8b:0:b0:663:9916:da83 with SMTP id ay11-20020a5d9d8b000000b006639916da83mr631157iob.116.1654108051768; Wed, 01 Jun 2022 11:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654108051; cv=none; d=google.com; s=arc-20160816; b=AQvl6KMP+DcDWrKuCn45Acsv1+bPg4nUJVq6JR0TjhGs93syuExrd5d2nf9q9ZtV6H k0WCsdjd0XT16jpGmOxt3sYfUzaztz31AVRAmBYrJSEOsSThEx42TtRTlj1ubgX0M+xX 99iKg+fhxviuNgZWzj99hXHOjpJcP6o6GVVqUK6EyRRGsKFrXRd4Ypy/HlhGWaBEiOn8 1VZuABdt7q+X40rcXJCo0nRNHs96i+30cjz5H+GtoMwh5pKWC10Fy3FBY2U7CzwFjhZv qDVCN3VBEjAwBe9Rkly14xd2zX2hAu8SWZH11C4zB7RSPdfcB+l3uOljHs6D30Aqy6cz +X9w== 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=gMyVf0z8ELy4OJBY+5pNJ/DtFVWLyBR7Gr3yxzzebhc=; b=lbb/2uVhnHZxYPX0zr6VC/+Zxx6tRaxJofnVIkdfNaJ9c2Be92ZzdWjbAF1etnDUNv fh5Q/xwBeVq8f6/RL6gGtN6YDKxf3zYF5Wl3zX2WUCc0sp19PTCfcKYpYOMEfQKeykd8 RTYDJEh+l2xKJtFyOJZ/cnM0v8QwmLHeJ6zJnz8c6OB7Jt1hPYFEyP9G9Nrr7Qiubjg+ whIK2RYchxsB/dmKKPOpyxJ041m3iJX5o4/fMUDOrUHphu264KJSYk/3O+rOg01rHQDG AXKwPHTtz9MHZJ8gaJwE6xtJZiGsCXFRqJ+xpup7jsA0hA1drIvJ53ilRfsjcOeC1kqo k2nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m2ZlL5Mr; 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 i23-20020a023b57000000b00330a26a54e5si2435481jaf.94.2022.06.01.11.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:27:31 -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=m2ZlL5Mr; 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 617D484308; Wed, 1 Jun 2022 20:26:59 +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="m2ZlL5Mr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 55245842FA; Wed, 1 Jun 2022 20:26:43 +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-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 42888842EA for ; Wed, 1 Jun 2022 20:26:37 +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-x435.google.com with SMTP id k16so3486478wrg.7 for ; Wed, 01 Jun 2022 11:26:37 -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=gMyVf0z8ELy4OJBY+5pNJ/DtFVWLyBR7Gr3yxzzebhc=; b=m2ZlL5MrrA1qKHPAKuvZEso6+Mf5e3ZmMlBP12uvP+1xiw8f8ZzVxEMvxwYo72etPS d9d5VM4oqpAd/u1OtIYuTux+CCT+TGlSvBEg4aLFi+ImEHwcG6uwK2G/DhYLa7dtuX9l lRYYcdNGeIJkVPOsaoPPtxw4Ggw/Kb5lIRwv7xbKUijBbn6Rta2R9WqL4TdnLHn6cVey UohAcZujrzdCx78k7IPxo6tlCBRpwH3L1I0DedNloF/5F4+CLux9YEo5HTq/ups58tUm DiaI0sfm5Dcc9nrMbOqkxj+GFdgC/9X08XsOP2mYi5kaCMfJplNwvRNG55HLou3EsGtZ MWKg== 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=gMyVf0z8ELy4OJBY+5pNJ/DtFVWLyBR7Gr3yxzzebhc=; b=yKsNxCjovntnUyqvJAkdSEZloi2egv0VTsXqEruC38fDKPrINoN1UwYHM+V1l+AcuJ 2Jr+ZiO+G+Q9p6RmBMR1qj1pM3cTKN337U0Y7Gzh5IuHdst5OID+T6cK0weMUnqmM2S9 UbOU6dsRjJux2tL4oLHPO8ZqdUwL8lNEfKnxBPsmJi/iw+UHgt/1Ao1lG6RgAj2KDNDc PwXE7UE+mCtO2QM+Y1nFp/xFy/YRM6ECFrUhAeKg/mtM6Z+wrPBFFDT1wiFGXjJs5FLl LmEonqqTFZ+ytbH8v+/guW+Z2gHbRLypOvZ1KyAFedZOuVMmqM6aTLlrcb1SSpb+Q8Hg mXyA== X-Gm-Message-State: AOAM532tW9fN7DO9V/Js8l1o6MxyNFVpyD1IEtiA6X83a94JYrfDE7Bb gEI66+e5Lr8X8jXo8reBAg4zEw== X-Received: by 2002:adf:ea51:0:b0:212:49af:a519 with SMTP id j17-20020adfea51000000b0021249afa519mr588926wrn.95.1654107996735; Wed, 01 Jun 2022 11:26:36 -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.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2022 11:26:36 -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 2/5] sha1: Fix digest state size/type Date: Wed, 1 Jun 2022 20:26:28 +0200 Message-Id: <1654107991-598-3-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 sha1 digest size is 5*32-bit => 160-bit. Using 64-bit unsigned long does not cause issue with the current sha1 implementation, but could be problematic for vectorized access. Signed-off-by: Loic Poulain --- include/u-boot/sha1.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/u-boot/sha1.h b/include/u-boot/sha1.h index 283f103..09fee59 100644 --- a/include/u-boot/sha1.h +++ b/include/u-boot/sha1.h @@ -30,7 +30,7 @@ extern const uint8_t sha1_der_prefix[]; typedef struct { unsigned long total[2]; /*!< number of bytes processed */ - unsigned long state[5]; /*!< intermediate digest state */ + uint32_t state[5]; /*!< intermediate digest state */ unsigned char buffer[64]; /*!< data block being processed */ } sha1_context; From patchwork Wed Jun 1 18:26:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577819 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp855720mab; Wed, 1 Jun 2022 11:26:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHDUs5qJlSLkRPIUbZlUUye2/hj5Nyopc1xGEnjEm0LabSIF4koSxH1l8N+xINM5uPnOiL X-Received: by 2002:a05:6e02:154b:b0:2d3:d112:5a0a with SMTP id j11-20020a056e02154b00b002d3d1125a0amr866974ilu.131.1654108017266; Wed, 01 Jun 2022 11:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654108017; cv=none; d=google.com; s=arc-20160816; b=lhgc5eEmyGFGfBO7crID/ca/NEUIF4FcycTup/dpjakWQ1VQsMMHp+efXF4DDx3LJU QjETSwoK21wzGNLIBzQvf6G56xvRgsW6zPfFFSv2E7L367vYbtRGq0Fe6R4GJonOCG3p b/0OTOcn/QP21/YRORwZ2zXjym/qjB05D2aHCzSsN+MGvw4lHL0FfWW+0UQyxmMkWEqH 0++kVg8DKsqQ97/0s7ZvstikmiCwbygJDFzoD5bxPxYuhlM+ZsLqjUHUFXqZ6RaoK13C cZw8nnCAYNWJpgCJI+S/yVIyVYzRfszCMPetCibpc2zEcGfbJ3yg1GhfobIYqCg3DAnY G7lQ== 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=pVML34C0RVOhrh1vp8HIbwYce19Tv309oZoJ8AIERs8=; b=n/3fu8IMfIm7fd/maqiDyi3cWw/O1FFIfv91jdRxGSNPjhLYZ3I+vIEmhBHA+8QtBD WHR+wk2uSPlezK5PSX7UPNyi8Xqrg7c9rtC1tpOUPjNTsYq8g3jUxkRkzCILVHCOAyr+ MG77iWd5rvTSpWeqxhXhXzzncpESfAt5ex3DHN2FdQYUTeOYV+6iF8Ob75oyaP97yPr3 +QXMy+Qr1fPH38jv2lzo7C8q37mfoPH0JHpQ4BABqSa5dGLiHHDecFnIFlhjE6SX7WLP E5tx/nUFKWrHmjdHK6jW7B5Ms9loIkPe0D52J9p+uItyiSuT5LxIE1oO/blRHyNtX0lQ 94AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LVMQ+QgO; 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 s3-20020a025103000000b0032e19f07fd4si2316627jaa.144.2022.06.01.11.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:26:57 -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=LVMQ+QgO; 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 A435A842EC; Wed, 1 Jun 2022 20:26:45 +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="LVMQ+QgO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8438983F24; 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-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 08912842F2 for ; Wed, 1 Jun 2022 20:26:38 +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-x435.google.com with SMTP id k16so3486478wrg.7 for ; Wed, 01 Jun 2022 11:26:38 -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=pVML34C0RVOhrh1vp8HIbwYce19Tv309oZoJ8AIERs8=; b=LVMQ+QgO7x4lEa/jRM27YUN89ZthqY9qmk71SYTxASin+FKBpTL+bOudWzW4DCvgr+ d5YYb4IZnSI8VMDJpjnvkFs1qQKf6fQJ014Z59LaeSKV8jxjYLBHsoWDSDwL/4F5AtQ0 aaHCd9KOJ6PvmiDli4CzVq7NFvh8BhWkiNxF8m5cuG6Bj5xVSVM/+M4zelx4sF9z8Ooe eLqwFNMdd2tTQ6E9daLfDizqVBrctcf97E6qSZkFXUd/rk1F0JPfEVwKsCQviRBvx5ZK 9DHP597bieObolxrtkDPg4UYqOrVjFqbR06EbdnUIX/U0h3XY+mU68Vs98XNmMrmcVk9 caaQ== 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=pVML34C0RVOhrh1vp8HIbwYce19Tv309oZoJ8AIERs8=; b=FkSS+CriQ2qdunE4w8l8QIq4XN1CtS1vDPjzU+EaQHRoA1yQg4Go+uoNADhOhzmt53 fnGvs7ZFc5G+VLnFoU0jQWqI2kD7aP+mE9b370pKzpDnmb0QGQHJ2Nb6XZTpS7wmO769 dmGn1pm/PhCkPpSTQRlB6TVj6P5pS/mDAvOH5m+2pwk83eyzOZDSI+ZYOqdwwU7oQLp2 T33ZJ7n5PXb+2HcJ0EJVNSiU8O0gyACylKoAh6uaegnFv7ZFjgnXShGyf3YxL3Snupd9 OTlN0sDpEIu50HkMk8e5zMkMf4r33Sn11WxatAFkGmGMqn6r2fY5jXrGEz2OJEZ+wg+L kV2w== X-Gm-Message-State: AOAM530HoX7lCdIoowK+mp/8lRpdApVDO9kGEpaTuGLOpU3ugvMJeGnm utPBnwmYXJk7e2Lc41kQyE/ZwBnEhjVY0g== X-Received: by 2002:adf:eb8e:0:b0:20c:b378:67b2 with SMTP id t14-20020adfeb8e000000b0020cb37867b2mr621042wrn.164.1654107997640; Wed, 01 Jun 2022 11:26:37 -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.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2022 11:26:37 -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 3/5] armv8 SHA-1 using ARMv8 Crypto Extensions: Date: Wed, 1 Jun 2022 20:26:29 +0200 Message-Id: <1654107991-598-4-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 This patch adds support for the SHA-1 Secure Hash Algorithm for CPUs that have support for the SHA-1 part of the ARM v8 Crypto Extensions. It greatly improves sha-1 based operations, about 10x faster on iMX8M evk board. ~12ms vs ~165ms for a 20MiB kernel sha-1 verification. asm implementation is a simplified version of the Linux version (from Ard Biesheuvel). Signed-off-by: Loic Poulain --- arch/arm/cpu/armv8/Kconfig | 11 ++++ arch/arm/cpu/armv8/Makefile | 1 + arch/arm/cpu/armv8/sha1_ce_core.S | 132 ++++++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha1_ce_glue.c | 21 ++++++ 4 files changed, 165 insertions(+) create mode 100644 arch/arm/cpu/armv8/sha1_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha1_ce_glue.c diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig index 9967376..0b11ca8 100644 --- a/arch/arm/cpu/armv8/Kconfig +++ b/arch/arm/cpu/armv8/Kconfig @@ -171,4 +171,15 @@ config ARMV8_SECURE_BASE endif +menuconfig ARMV8_CRYPTO + bool "ARM64 Accelerated Cryptographic Algorithms" + +if ARMV8_CRYPTO + +config ARMV8_CE_SHA1 + bool "SHA-1 digest algorithm (ARMv8 Crypto Extensions)" + default y if SHA1 + +endif + endif diff --git a/arch/arm/cpu/armv8/Makefile b/arch/arm/cpu/armv8/Makefile index 85fe047..ff2495c 100644 --- a/arch/arm/cpu/armv8/Makefile +++ b/arch/arm/cpu/armv8/Makefile @@ -44,3 +44,4 @@ obj-$(CONFIG_TARGET_HIKEY) += hisilicon/ obj-$(CONFIG_ARMV8_PSCI) += psci.o obj-$(CONFIG_TARGET_BCMNS3) += bcmns3/ obj-$(CONFIG_XEN) += xen/ +obj-$(CONFIG_ARMV8_CE_SHA1) += sha1_ce_glue.o sha1_ce_core.o diff --git a/arch/arm/cpu/armv8/sha1_ce_core.S b/arch/arm/cpu/armv8/sha1_ce_core.S new file mode 100644 index 0000000..fbf2714 --- /dev/null +++ b/arch/arm/cpu/armv8/sha1_ce_core.S @@ -0,0 +1,132 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * sha1_ce_core.S - SHA-1 secure hash using ARMv8 Crypto Extensions + * + * Copyright (C) 2014 Linaro Ltd + * Copyright (C) 2022 Linaro Ltd + */ + +#include +#include +#include +#include + + .text + .arch armv8-a+crypto + + k0 .req v0 + k1 .req v1 + k2 .req v2 + k3 .req v3 + + t0 .req v4 + t1 .req v5 + + dga .req q6 + dgav .req v6 + dgb .req s7 + dgbv .req v7 + + dg0q .req q12 + dg0s .req s12 + dg0v .req v12 + dg1s .req s13 + dg1v .req v13 + dg2s .req s14 + + .macro add_only, op, ev, rc, s0, dg1 + .ifc \ev, ev + add t1.4s, v\s0\().4s, \rc\().4s + sha1h dg2s, dg0s + .ifnb \dg1 + sha1\op dg0q, \dg1, t0.4s + .else + sha1\op dg0q, dg1s, t0.4s + .endif + .else + .ifnb \s0 + add t0.4s, v\s0\().4s, \rc\().4s + .endif + sha1h dg1s, dg0s + sha1\op dg0q, dg2s, t1.4s + .endif + .endm + + .macro add_update, op, ev, rc, s0, s1, s2, s3, dg1 + sha1su0 v\s0\().4s, v\s1\().4s, v\s2\().4s + add_only \op, \ev, \rc, \s1, \dg1 + sha1su1 v\s0\().4s, v\s3\().4s + .endm + + .macro loadrc, k, val, tmp + movz \tmp, :abs_g0_nc:\val + movk \tmp, :abs_g1:\val + dup \k, \tmp + .endm + + /* + * void sha1_armv8_ce_process(uint32_t state[5], uint8_t const *src, + * uint32_t blocks) + */ +ENTRY(sha1_armv8_ce_process) + /* load round constants */ + loadrc k0.4s, 0x5a827999, w6 + loadrc k1.4s, 0x6ed9eba1, w6 + loadrc k2.4s, 0x8f1bbcdc, w6 + loadrc k3.4s, 0xca62c1d6, w6 + + /* load state (4+1 digest states) */ + ld1 {dgav.4s}, [x0] + ldr dgb, [x0, #16] + + /* load input (64 bytes into v8->v11 16B vectors) */ +0: ld1 {v8.4s-v11.4s}, [x1], #64 + sub w2, w2, #1 +#if __BYTE_ORDER == __LITTLE_ENDIAN + rev32 v8.16b, v8.16b + rev32 v9.16b, v9.16b + rev32 v10.16b, v10.16b + rev32 v11.16b, v11.16b +#endif + +1: add t0.4s, v8.4s, k0.4s + mov dg0v.16b, dgav.16b + + add_update c, ev, k0, 8, 9, 10, 11, dgb + add_update c, od, k0, 9, 10, 11, 8 + add_update c, ev, k0, 10, 11, 8, 9 + add_update c, od, k0, 11, 8, 9, 10 + add_update c, ev, k1, 8, 9, 10, 11 + + add_update p, od, k1, 9, 10, 11, 8 + add_update p, ev, k1, 10, 11, 8, 9 + add_update p, od, k1, 11, 8, 9, 10 + add_update p, ev, k1, 8, 9, 10, 11 + add_update p, od, k2, 9, 10, 11, 8 + + add_update m, ev, k2, 10, 11, 8, 9 + add_update m, od, k2, 11, 8, 9, 10 + add_update m, ev, k2, 8, 9, 10, 11 + add_update m, od, k2, 9, 10, 11, 8 + add_update m, ev, k3, 10, 11, 8, 9 + + add_update p, od, k3, 11, 8, 9, 10 + add_only p, ev, k3, 9 + add_only p, od, k3, 10 + add_only p, ev, k3, 11 + add_only p, od + + /* update state */ + add dgbv.2s, dgbv.2s, dg1v.2s + add dgav.4s, dgav.4s, dg0v.4s + + /* loop on next block? */ + cbz w2, 2f + b 0b + + /* store new state */ +2: st1 {dgav.4s}, [x0] + str dgb, [x0, #16] + mov w0, w2 + ret +ENDPROC(sha1_armv8_ce_process) diff --git a/arch/arm/cpu/armv8/sha1_ce_glue.c b/arch/arm/cpu/armv8/sha1_ce_glue.c new file mode 100644 index 0000000..780b119 --- /dev/null +++ b/arch/arm/cpu/armv8/sha1_ce_glue.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * sha1_ce_glue.c - SHA-1 secure hash using ARMv8 Crypto Extensions + * + * Copyright (C) 2022 Linaro Ltd + */ + +#include +#include + +extern void sha1_armv8_ce_process(uint32_t state[5], uint8_t const *src, + uint32_t blocks); + +void sha1_process(sha1_context *ctx, const unsigned char *data, + unsigned int blocks) +{ + if (!blocks) + return; + + sha1_armv8_ce_process(ctx->state, data, blocks); +} 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); From patchwork Wed Jun 1 18:26:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577823 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp856327mab; Wed, 1 Jun 2022 11:27:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuueVzuwndslPItQ+l6o/9jzleWsqCNNVZpQGIff3S5j1QL9AiNwYtH+hlVcApMwOuBw59 X-Received: by 2002:a05:6638:16d6:b0:32e:1d23:da71 with SMTP id g22-20020a05663816d600b0032e1d23da71mr859892jat.195.1654108064042; Wed, 01 Jun 2022 11:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654108064; cv=none; d=google.com; s=arc-20160816; b=ClbfBbQ+bFQcTpeWhiZjonUWZnXOpXqNC4JUnpd+Gz9IoqYT/e5mQUSeq99cmzsdu2 FHI6SbB5FI5+zBQ3f/HK9jOWEDN6Nf1nvLaPlAxRkgSLzLkK0cdwoSl0TKX36fYrnxUq KcAWAlZr5o6NBiPfvBIz3x3UcU74cD30JQ/SP0FixFW8Lx62s2hPQLDyusH9YXJts2vj cK6OMZ97slwS/gsHpHSE241EK2A0fy9+zl1ajfxaQIDIzjJ2pGziqOiwjSc+wZtiPy/b GmbhhuQXrQ9KwfDA8ot6KCU4KkrhekLh0/oGtZupJ282cry+Ye01BrhGqAOWIVWbKQtE 0HWw== 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=IqoggFa0bpk378ZDhWjg79ElSHZ5vkFsTdicvgfmxYI=; b=qCaqRYBnNoBJymN4hdpuU7wf9Jng9mUg0ngYzHMSKbSDVuAvpTpD9VYOWF2YQ0k1ff DONcFn7OQTw09gtRiSYyvQ9BvtY7jOJ6djBggM5ugP6PfTFLnlr1glvpVOzpkMZYcjwu q2LCoT0uUpyzaODQ0MUiTJPTM95/3Vbd3/mCRMzPrrFO3VwZs7Tsmnu80MeIaYehxIVB IIX587Ilg9bDj9Ye47rbIpGLZ6R1P6M44D10Qb/UDpZ+aBoaPbzcN71YF8u82rd8ahac X+/D6sXabAKhdkPDR1YXQmXwuy1JKoWXYbwTHznbooWGso2cGuFcwJzoAX/3qO/0G2LZ aJfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HR2k8bSM; 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 h29-20020a056e021d9d00b002cf473192casi3339761ila.107.2022.06.01.11.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 11:27:44 -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=HR2k8bSM; 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 7EA38842FE; Wed, 1 Jun 2022 20:27:04 +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="HR2k8bSM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1950483F24; Wed, 1 Jun 2022 20:26:46 +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 04170842D4 for ; Wed, 1 Jun 2022 20:26:40 +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 s24so3462947wrb.10 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=IqoggFa0bpk378ZDhWjg79ElSHZ5vkFsTdicvgfmxYI=; b=HR2k8bSM4Kymhv3Fp6uqrwF+qzeCSEOss7Lmav9TG76tn8K9Bdwm/VcpZ4HLWII86w ajsn9W1e59KFoMQUKmICGKGBKZXfVpviSy/YbOKLuyQPTFp0NYFYneE2VYrD6IYPGxti T0mMHquIzAj+aUDSixv331C1u0iYz/h0DnAF4m41nW7kZt3gdd5uueGAqUpfSOQWfgrV EHYJPEwBSWFUnpMSrKcvnsQCE8ui8Khypx9eQzn9bZHhgCJPCp0BVOdZO4ElwQxLNyaI 9IcdDehThoJtoUQkVpeSk1O+rXkmiXGSvYDl55I82YFewZDaFYRvaywlslL9YXpfJcUy X7Zw== 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=IqoggFa0bpk378ZDhWjg79ElSHZ5vkFsTdicvgfmxYI=; b=zoCHqs6g1h6iB0AQ3VrbpFon+QNBFae8iotoSxdGi1gGfyqaGEITVOgi0H4+SsigAX 9S3YIqRpcLEo3XzTGSQoNpqjiUiQXcRtmJQ7NtS15i+mq660SuuKV8AyWImMJSO2iDyb tDfVAlJZVDk13s8AZOK5wb4dcftYCCtzJam4cbBOaVSVwQBYfh6/g2tLdH5gqnJZGv59 STVgsN/KyuvmASvHlfmog9rLjgWvXyCmbD09I/ntGsU6uR4I0BU3eOnqZ5GN9O2U9lmo FozdMoPC6+zm0jt5uP3E9cSZR8kSC90pdiPOqSp2dHrS611dFuHwglVkFM4BctqYVbuh BkiQ== X-Gm-Message-State: AOAM531EQD2T8sS6jt1DZvTmnYbqvuPyIKXAR5lZvNYY/sL3wl1QdGm7 0w192eWY5fgERHVVua6QQEqRZA== X-Received: by 2002:a5d:584a:0:b0:20f:dec9:7597 with SMTP id i10-20020a5d584a000000b0020fdec97597mr590603wrf.157.1654107999393; Wed, 01 Jun 2022 11:26:39 -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.38 (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 5/5] armv8 SHA-256 using ARMv8 Crypto Extensions Date: Wed, 1 Jun 2022 20:26:31 +0200 Message-Id: <1654107991-598-6-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 This patch adds support for the SHA-256 Secure Hash Algorithm for CPUs that have support for the SHA-256 part of the ARM v8 Crypto Extensions. It greatly improves sha-256 based operations, about 17x faster on iMX8M evk board. ~12ms vs ~208ms for a 20MiB kernel sha-256 verification. asm implementation is a simplified version of the Linux version (from Ard Biesheuvel). Signed-off-by: Loic Poulain --- arch/arm/cpu/armv8/Kconfig | 4 ++ arch/arm/cpu/armv8/Makefile | 1 + arch/arm/cpu/armv8/sha256_ce_core.S | 134 ++++++++++++++++++++++++++++++++++++ arch/arm/cpu/armv8/sha256_ce_glue.c | 21 ++++++ 4 files changed, 160 insertions(+) create mode 100644 arch/arm/cpu/armv8/sha256_ce_core.S create mode 100644 arch/arm/cpu/armv8/sha256_ce_glue.c diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig index 0b11ca8..0494a08 100644 --- a/arch/arm/cpu/armv8/Kconfig +++ b/arch/arm/cpu/armv8/Kconfig @@ -180,6 +180,10 @@ config ARMV8_CE_SHA1 bool "SHA-1 digest algorithm (ARMv8 Crypto Extensions)" default y if SHA1 +config ARMV8_CE_SHA256 + bool "SHA-256 digest algorithm (ARMv8 Crypto Extensions)" + default y if SHA256 + endif endif diff --git a/arch/arm/cpu/armv8/Makefile b/arch/arm/cpu/armv8/Makefile index ff2495c..2e4bf9e 100644 --- a/arch/arm/cpu/armv8/Makefile +++ b/arch/arm/cpu/armv8/Makefile @@ -45,3 +45,4 @@ obj-$(CONFIG_ARMV8_PSCI) += psci.o obj-$(CONFIG_TARGET_BCMNS3) += bcmns3/ obj-$(CONFIG_XEN) += xen/ obj-$(CONFIG_ARMV8_CE_SHA1) += sha1_ce_glue.o sha1_ce_core.o +obj-$(CONFIG_ARMV8_CE_SHA256) += sha256_ce_glue.o sha256_ce_core.o diff --git a/arch/arm/cpu/armv8/sha256_ce_core.S b/arch/arm/cpu/armv8/sha256_ce_core.S new file mode 100644 index 0000000..fbae3ca --- /dev/null +++ b/arch/arm/cpu/armv8/sha256_ce_core.S @@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * sha256-ce-core.S - core SHA-256 transform using v8 Crypto Extensions + * + * Copyright (C) 2014 Linaro Ltd + * Copyright (C) 2022 Linaro Ltd + */ + + #include + #include + #include + #include + + .text + .arch armv8-a+crypto + + dga .req q20 + dgav .req v20 + dgb .req q21 + dgbv .req v21 + + t0 .req v22 + t1 .req v23 + + dg0q .req q24 + dg0v .req v24 + dg1q .req q25 + dg1v .req v25 + dg2q .req q26 + dg2v .req v26 + + .macro add_only, ev, rc, s0 + mov dg2v.16b, dg0v.16b + .ifeq \ev + add t1.4s, v\s0\().4s, \rc\().4s + sha256h dg0q, dg1q, t0.4s + sha256h2 dg1q, dg2q, t0.4s + .else + .ifnb \s0 + add t0.4s, v\s0\().4s, \rc\().4s + .endif + sha256h dg0q, dg1q, t1.4s + sha256h2 dg1q, dg2q, t1.4s + .endif + .endm + + .macro add_update, ev, rc, s0, s1, s2, s3 + sha256su0 v\s0\().4s, v\s1\().4s + add_only \ev, \rc, \s1 + sha256su1 v\s0\().4s, v\s2\().4s, v\s3\().4s + .endm + + /* + * The SHA-256 round constants + */ + .align 4 +.Lsha2_rcon: + .word 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5 + .word 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5 + .word 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3 + .word 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174 + .word 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc + .word 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da + .word 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7 + .word 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967 + .word 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13 + .word 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85 + .word 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3 + .word 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070 + .word 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5 + .word 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3 + .word 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208 + .word 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + + /* + * void sha256_armv8_ce_process(struct sha256_ce_state *sst, + * uint8_t const *src, uint32_t blocks) + */ +ENTRY(sha256_armv8_ce_process) + /* load round constants */ + adr x8, .Lsha2_rcon + ld1 { v0.4s- v3.4s}, [x8], #64 + ld1 { v4.4s- v7.4s}, [x8], #64 + ld1 { v8.4s-v11.4s}, [x8], #64 + ld1 {v12.4s-v15.4s}, [x8] + + /* load state */ + ldp dga, dgb, [x0] + + /* load input */ +0: ld1 {v16.4s-v19.4s}, [x1], #64 + sub w2, w2, #1 +#if __BYTE_ORDER == __LITTLE_ENDIAN + rev32 v16.16b, v16.16b + rev32 v17.16b, v17.16b + rev32 v18.16b, v18.16b + rev32 v19.16b, v19.16b +#endif + +1: add t0.4s, v16.4s, v0.4s + mov dg0v.16b, dgav.16b + mov dg1v.16b, dgbv.16b + + add_update 0, v1, 16, 17, 18, 19 + add_update 1, v2, 17, 18, 19, 16 + add_update 0, v3, 18, 19, 16, 17 + add_update 1, v4, 19, 16, 17, 18 + + add_update 0, v5, 16, 17, 18, 19 + add_update 1, v6, 17, 18, 19, 16 + add_update 0, v7, 18, 19, 16, 17 + add_update 1, v8, 19, 16, 17, 18 + + add_update 0, v9, 16, 17, 18, 19 + add_update 1, v10, 17, 18, 19, 16 + add_update 0, v11, 18, 19, 16, 17 + add_update 1, v12, 19, 16, 17, 18 + + add_only 0, v13, 17 + add_only 1, v14, 18 + add_only 0, v15, 19 + add_only 1 + + /* update state */ + add dgav.4s, dgav.4s, dg0v.4s + add dgbv.4s, dgbv.4s, dg1v.4s + + /* handled all input blocks? */ + cbnz w2, 0b + + /* store new state */ +3: stp dga, dgb, [x0] + ret +ENDPROC(sha256_armv8_ce_process) diff --git a/arch/arm/cpu/armv8/sha256_ce_glue.c b/arch/arm/cpu/armv8/sha256_ce_glue.c new file mode 100644 index 0000000..67dd796 --- /dev/null +++ b/arch/arm/cpu/armv8/sha256_ce_glue.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * sha256_ce_glue.c - SHA-256 secure hash using ARMv8 Crypto Extensions + * + * Copyright (C) 2022 Linaro Ltd + */ + +#include +#include + +extern void sha256_armv8_ce_process(uint32_t state[8], uint8_t const *src, + uint32_t blocks); + +void sha256_process(sha256_context *ctx, const unsigned char *data, + unsigned int blocks) +{ + if (!blocks) + return; + + sha256_armv8_ce_process(ctx->state, data, blocks); +}