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); From patchwork Wed Jun 1 10:03:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577789 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp421595mab; Wed, 1 Jun 2022 03:04:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn37k+26jnA2263T3cLFJFKNHPe06iJnKEa9vxOt1QCJWjCbhsZ6K8gHpHYvMCLVIRQ8TF X-Received: by 2002:a05:6602:2c0c:b0:5f0:793f:cb9e with SMTP id w12-20020a0566022c0c00b005f0793fcb9emr27777148iov.122.1654077865727; Wed, 01 Jun 2022 03:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654077865; cv=none; d=google.com; s=arc-20160816; b=egX1UfcACaI37IMWWlkMbdN08Wkp1yfYjduOk+HN/kv4K+OfgRpoWZy272A3TefMkS D8iwVFFBEe6uYWCa5+30gKG8nVv4gs2ob4WvF9bQkhxrtkCG7ZelZH93GWfmZH+7IaGV 2LwTUfd93vqnNN6n1abL1xpabrACZvrOQ9LXyfM2FBm0V1N07WhEbC3xf0eGZpcOM9F8 p9b30O2mq55NrkhdqBNroaDhrTQxYfEidm5KMGq8UCHsEoNSoTDKnQ8Qxcq4i2YZiLpk q4jUIn1EVYwCADhda3Ie1u2o3LHyTBcqPokFAaB85n2I94c/f0sbxyDT+ZpQk/dMcOsC gWUw== 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=CgQwNieogSZi5Giiq6vExpaf+DO6Y0Tpvrxy01wpfV3vK9xorln3K/NVqelVDADwfc sDhwZ4fDUkMMZ+q0nKQILx+fUq+2aG8nUx9k+cMSNo4OV/+swIwt5ktfUBPEqGiA2EEZ vgAwZhsr+mJ6YOTWRdkTEk02Fu0FGeSitWSoSBe+ioCnahMt9JaE9oxJWyNUZrJ+U3Ru uX1B42d64t1H9GPBVb53sEIv+MTZsHk9hHvEVMTZZkReATCZPDe1DIl6JJv/BMbfVC2d zUce03M7dkIEDOS73Upqx2id+QOfG+XZFCcgFRjR6IJnzoZANyk6u6laC1GPgBSLREty va9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P4XMGr1K; 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 k4-20020a056e021a8400b002d1a271e716si1525523ilv.44.2022.06.01.03.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 03:04:25 -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=P4XMGr1K; 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 AA9B88427B; Wed, 1 Jun 2022 12:04:12 +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="P4XMGr1K"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 456AE840D8; Wed, 1 Jun 2022 12:04:09 +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-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 3362C8421F for ; Wed, 1 Jun 2022 12:04: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=loic.poulain@linaro.org Received: by mail-wm1-x335.google.com with SMTP id y24so671002wmq.5 for ; Wed, 01 Jun 2022 03:04:04 -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=P4XMGr1KnSQQGqwnQpT4diGoUTt3mblqAyOHL2F5Sh3HKbj/GFniFeTfZvGQG2oK+w vLW8YARt+ZJaEZ3Hy9Gtq4jdiMcOaAkPyaQ/opilW+EwgcSdnIrF4CyD6Om1P0XesgN5 QP84vzSxM8V76tzcwQ8US1UhKjGmXWZgO05kAYpbQ9ypWBflaKAtMxV8ZYdor5lnlkzQ rMEgbuos0E07kRJAsnJyKk0+NswRN0yotx1e2tJLFG0PAcTvTeBeD36Em3aY4d3ftXtV hsas9/nq8xhQCPOZIsukq7Trw+Lzkvx0dGYFUWg+ELlLymwzH5BrrVHVheSzkrQgRWlg MMHw== 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=ywEGy4FHsDT11UsUqorzNuG9CUA3V5ZxqZ1eW+NRYg6PR6Har7fLnXVQSUvc9OEdsL s0RItYnKIoVKiIurPexxVkrgbJaPimk/k+OhsZv8vzJ+DvKtplNB7RIq58Zd/jYORrja LoLBNaYabQn9ICdln+otp26cZZWthJUZNPybh5ODAZCDbN8dOa17hkkDXcdDYJGf7ZMq HhZ67dj2qbpADl8JPq1UuIcXp8ktiOZQixCiicgJYzfDXvO0sVig0p6ksLx2AARNmdFK pWVnHFLxuTgcAHss47JPnZKfSfmNhb4OSpnxMU65baeMdK8skKPhnZ6rN0p0zrwrnE8T JrQg== X-Gm-Message-State: AOAM532KZ96mmTdzhLwS9utZ8vMRcIWhaw82yCj70R6MLoRELXJ2l0lY CdAVy+AlMXYmOHjydy+Lc9MeuA== X-Received: by 2002:a7b:cbda:0:b0:397:48d6:6c9f with SMTP id n26-20020a7bcbda000000b0039748d66c9fmr28035077wmi.10.1654077843661; Wed, 01 Jun 2022 03:04:03 -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.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2022 03:04:03 -0700 (PDT) From: Loic Poulain To: trini@konsulko.com, kettenis@openbsd.org Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH 2/3] sha1: Fix digest state size/type Date: Wed, 1 Jun 2022 12:03:58 +0200 Message-Id: <1654077839-29147-2-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1654077839-29147-1-git-send-email-loic.poulain@linaro.org> References: <1654077839-29147-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 10:03:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 577790 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:8f0c:0:0:0:0 with SMTP id mq12csp421743mab; Wed, 1 Jun 2022 03:04:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMObIX17V6MMkmonKsmrRGrPRX2wGo7XMkhvbVNmPbMfC1ADgDIjuJCoEkzITf8fEXqa7S X-Received: by 2002:a05:6e02:1646:b0:2d3:789a:58a with SMTP id v6-20020a056e02164600b002d3789a058amr13967196ilu.197.1654077878180; Wed, 01 Jun 2022 03:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654077878; cv=none; d=google.com; s=arc-20160816; b=gLKRtLUHlthLQbx7dYd5duQe+6vHnfsbSlQMLqwpwV6UdZjbwPvt7sGVQHnCKBuVoY ncMWSr9xskQsgYBYn/LpxyxWRX8rXzwi6wA8M2xxODS8sjrKyAa0uuRMn/unXe6Mj6tV LmKygzTMXkpltc3Nv6881C6nJsPGfuA03yTaonQznAmgo6A5E2WZpEdfCpi+y4GnqcCH wlTD5lZxIRV7SOetRZXlVUuuY6Dtk/uu/WJR5/t6KiwYoaeaGdTzb0QXCEYRxBS4p4j3 vu3oOVWS0icWV8aUp2VBaJHTxWujSm1+LmpzQ+1QOs4C2T5EKR7BTs3D/X//MS3CczJn oEEg== 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=Bmv1LLqO1nNKEQM/voAEcCSARAcP7y5/Dq+YU/CIMp8=; b=xfYYkcVmFfZZ/Uxk2U8ooQjftkbug42JkD2nLY5jC7zty2KLHv3cYs0sLNXBQVAAEA 8QD/W2ZIjzUMj6n18bGbAUSgeo2OcC44QoMlXNPKRj3nbfGhivqNvlXCd12nHgzgSHB3 jnKAPqYwRX+aQno+uLJd/O7yAB2dx48ILJAj01uHC+nEQPUm1CBuKkaWJ17bWdJwRsSh u5/4YgX1UojPOHSzYwlvRzq68huBuNKxT1Uyl8WZgNgp3ckWPmmwnhXrPx4hSwT7TvKo zBv0GWFSRxbY8BjLSy6PIwJIEE49u94wx7oNxfUYeFMneE22O1di4LmhnpbMMdEXQtgW hSuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GCnpLfio; 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 u2-20020a022e42000000b0032ed4829dd0si1266410jae.76.2022.06.01.03.04.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 03:04:38 -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=GCnpLfio; 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 C041084250; Wed, 1 Jun 2022 12:04:17 +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="GCnpLfio"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D509A8424E; Wed, 1 Jun 2022 12:04:10 +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-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 8B54C84250 for ; Wed, 1 Jun 2022 12:04:05 +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-x329.google.com with SMTP id z17so680781wmf.1 for ; Wed, 01 Jun 2022 03:04:05 -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=Bmv1LLqO1nNKEQM/voAEcCSARAcP7y5/Dq+YU/CIMp8=; b=GCnpLfioaFIyGgkY9rFCYYbAMtD1un+b5151fup0PnqLKO8pcz0xZgZId8oNmb+9ib 8hBMcVDfZTwlW4dm+MvnW+ooeqO9WKd1FRIGT9kDfpda/NGee1pTLEOR3jSZqnatOfGc 8710wsjCzgI8RKuS7Qrc3NydRcFscVePqvTJWPyJKfrDvNSpTZV461dqeGX8Uc7Ppj0P R7XUPmQojsAherEUzQNeGV+LT+M7+wE1KNMLFRmyVv2LIdBccB0Y9gDnugvDbsLWkNjg 76uXm+arbQHJFr3oBRPgZUql6+KiiimSmD+Zmm7ECaOsd9q2v+WJSMo4gvaO0vf2kdPM DPBA== 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=Bmv1LLqO1nNKEQM/voAEcCSARAcP7y5/Dq+YU/CIMp8=; b=OH5dLcs/nrsookpEwSjWaL6IbJfec5lmr2PEY5LX/J1R/Ndv1r/qHKh07lACShPwXV sATMOyXk+3ZrqM9dJZzq7AO76nzoz1/zZdEqmpp6PfsvTL8WYy/CaVISeIHR23pP5ANl aQj6VXkH0OwNdgoVsN/6HBZG+IHKwcZMesx4nNDUmPLfUyDbpMu1mKXmI+TZBYrE6KdC eCuxkbnCmYbwaLSVMrNYPwR+EwnIB497SJZykzHlHa/jNHDSikGMX0cB1NSqm8F2q90C aTwCCJ3hOJID7I1/vOck2pvM1KP3mYHCF2uu4t7g+OIBDGKGNBt8R6t0kdkFvgrwa9Ff T8+g== X-Gm-Message-State: AOAM530ZUEmw90uW11Gx6J2aZu+RwqqVJqi4A9vyU+lM9qOEjMVrWcmx pEvYeIOkNjXtPQI+85kpgjUaBA== X-Received: by 2002:a05:600c:2d86:b0:397:4743:5d25 with SMTP id i6-20020a05600c2d8600b0039747435d25mr27121941wmg.11.1654077844913; Wed, 01 Jun 2022 03:04:04 -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.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2022 03:04:04 -0700 (PDT) From: Loic Poulain To: trini@konsulko.com, kettenis@openbsd.org Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH 3/3] armv8 SHA-1 using ARMv8 Crypto Extensions: Date: Wed, 1 Jun 2022 12:03:59 +0200 Message-Id: <1654077839-29147-3-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1654077839-29147-1-git-send-email-loic.poulain@linaro.org> References: <1654077839-29147-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 | 10 +++ 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, 164 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..675cbb8 100644 --- a/arch/arm/cpu/armv8/Kconfig +++ b/arch/arm/cpu/armv8/Kconfig @@ -171,4 +171,14 @@ 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 +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..f826da3 --- /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..97a6733 --- /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.S - 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); +}