From patchwork Mon Aug 21 16:18:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 715393 Delivered-To: patch@linaro.org Received: by 2002:a5d:484e:0:b0:317:ecd7:513f with SMTP id n14csp1925953wrs; Mon, 21 Aug 2023 09:21:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGANLpgJYa2hEp8aOMhh+Ir2KY/bGDUho7OHC3nL+rSOGdZpHssJD3fwi6QvRqOWo6rYw0m X-Received: by 2002:ac8:7dcc:0:b0:400:797e:d694 with SMTP id c12-20020ac87dcc000000b00400797ed694mr10120968qte.11.1692634915171; Mon, 21 Aug 2023 09:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692634915; cv=none; d=google.com; s=arc-20160816; b=EjumCNmjuHuA0EpqBBGUxhnEpYtFAHt17/cYNL4hPqEQKVFfFt2fhZ8IGNCrek514Z nQOuVjpk/nU0gpf4ic+MRTGaq1L0/ENHcBBDkr8djZLZmLu3Mawtch5vyScQw8DWc9pD eEw1svJG4b7hQ02yLVJKaoyEKu+TnaA1Ztw0WqZ7ZmzULOxmuoOUiut25iS03V6WHeYi RBtj4qh9mWkhRBCW005wakl2aP37Y4OT9YkPMOzBMr/buINGpUWu1pR/QlfEGdHER2FE O4dSTaudDOiaazXajZquI/yG2uauO58lIaQDvq9oQdtuzGTSuZifYQI2sQMVnCG2IRfJ DofA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=u46/76awb7qaVCGpS1Wp9lBTQhA5OFbmzjWjo/GEWhA=; fh=4xNVIrgzKzsUJFZ/LK5iWzslbipp0obh3zmyxXTMM5Q=; b=a5j7c2yLNNNI4JXLYpMR3lXWk/ubDO2wGYJjwp6C8ThPntNolx1XeOi/qQaZtZCgW9 L1dS+/Qv/WFcmbvKAEQal6fxD5fGWAey/DgQO861tLrYBuHXs1LfDMnxhhhHpOCA9aUo 39KpERCxNI3Q4I9uNC1082I2+o7iDE9V5lGdu4smCHxoVp/tx8NEsFryutikiZpQWhz9 R7DTMZ6OFSZAS3iNYj0AfyA3ElJASSHwPjUAISg2FuX8/SlkAtu1xM+LJuiPG87AW9Jw BQNqP/A+j5Ne30CrSqcXIBPYnkctc/3Bt3g5+Kq1G2wELz/K/ETIPWDsr2ivBgN3XjPy Z6cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dkEsU7mr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r1-20020ac85c81000000b00403b5a14298si4965349qta.650.2023.08.21.09.21.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Aug 2023 09:21:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dkEsU7mr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qY7cn-0001gi-OU; Mon, 21 Aug 2023 12:19:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qY7cO-0001Tk-0Y for qemu-devel@nongnu.org; Mon, 21 Aug 2023 12:19:05 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qY7cL-0005bi-No for qemu-devel@nongnu.org; Mon, 21 Aug 2023 12:19:03 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bd9b4f8e0eso21234125ad.1 for ; Mon, 21 Aug 2023 09:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692634740; x=1693239540; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u46/76awb7qaVCGpS1Wp9lBTQhA5OFbmzjWjo/GEWhA=; b=dkEsU7mrh/Aaf5+tRoyHr9crd4Tul2iahjevYFk1TwWQ7ZR8LCGoH4SCWkGWGTjnGH jmMLggHxSjg+EToygCn1SaP+FCpehfGneGD8NzcHRMZOAypOPBvTJELX3Tvolgw0hAAP 7nCYMfPfrJwFhrA1I2mKxOKyJXNpIVjen9Ixj2p2oa3Uk79H4UkTjstLz7vmj1BNCARH Eo9Tst97QGOVipf5f8S02p7RzBDLKsT4gtcfrEGDFCwWDLwIKxoJ2yQFlNmpZhqgOvJX 5rzoQu1Mms8tExFRzuZmjLuJBAakHV6P8ecOuT/6nytoj1I65UdQGnpUT5ELDHRApK4w 3M9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692634740; x=1693239540; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u46/76awb7qaVCGpS1Wp9lBTQhA5OFbmzjWjo/GEWhA=; b=aLMmC5KFgky51w23e/l82lZFcp5gP0MarsBKztVdCX5JVjgVx6zyrNlW/OLDXdM5Xy HV1/Du1TC4KJi7gvSA2suhZMIouaKz1jrendonXtGrOEwGIt/vDsxd57krgkcbozkVo2 FKT12tg7jFuKwLNOu8Z0yUR85acCEGiN4ibhADE7OkCsMYvLvFdJ0tXk3oe/+ESL758T wJncWFBBfiPHpK62kIdVgzUNcpmW6CUyB5I8uOBLIT2hDi1VOS2O68aKRfYo/+TzV2cj NInZT14gENYfN9IoNB5Z+Jrm8L2SWVgCoqpPDXkIrdhBzFD2FFy/cIvtWB323wvhIRYJ 1mgg== X-Gm-Message-State: AOJu0YzAzmbsThkeUgw5jModwjRa336VKZ2qg2k/m2O4vv2rHc4BqZJZ 44oahZToSI9RSPcOV3dRTdMqpoKConT/Sje2Ub0= X-Received: by 2002:a17:902:d705:b0:1bb:1523:b311 with SMTP id w5-20020a170902d70500b001bb1523b311mr4298283ply.41.1692634740262; Mon, 21 Aug 2023 09:19:00 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:2c08:e710:4459:46f1]) by smtp.gmail.com with ESMTPSA id e16-20020a17090301d000b001ab2b4105ddsm7234549plh.60.2023.08.21.09.18.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 09:18:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, ardb@kernel.org Subject: [PATCH v3 05/19] crypto: Add generic 16-bit carry-less multiply routines Date: Mon, 21 Aug 2023 09:18:39 -0700 Message-Id: <20230821161854.419893-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230821161854.419893-1-richard.henderson@linaro.org> References: <20230821161854.419893-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson Reviewed-by: Ard Biesheuvel --- include/crypto/clmul.h | 16 ++++++++++++++++ crypto/clmul.c | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/crypto/clmul.h b/include/crypto/clmul.h index 153b5e3057..c7ad28aa85 100644 --- a/include/crypto/clmul.h +++ b/include/crypto/clmul.h @@ -38,4 +38,20 @@ uint64_t clmul_8x4_odd(uint64_t, uint64_t); */ uint64_t clmul_8x4_packed(uint32_t, uint32_t); +/** + * clmul_16x2_even: + * + * Perform two 16x16->32 carry-less multiplies. + * The odd words of the inputs are ignored. + */ +uint64_t clmul_16x2_even(uint64_t, uint64_t); + +/** + * clmul_16x2_odd: + * + * Perform two 16x16->32 carry-less multiplies. + * The even bytes of the inputs are ignored. + */ +uint64_t clmul_16x2_odd(uint64_t, uint64_t); + #endif /* CRYPTO_CLMUL_H */ diff --git a/crypto/clmul.c b/crypto/clmul.c index 82d873fee5..2c87cfbf8a 100644 --- a/crypto/clmul.c +++ b/crypto/clmul.c @@ -58,3 +58,24 @@ uint64_t clmul_8x4_packed(uint32_t n, uint32_t m) { return clmul_8x4_even_int(unpack_8_to_16(n), unpack_8_to_16(m)); } + +uint64_t clmul_16x2_even(uint64_t n, uint64_t m) +{ + uint64_t r = 0; + + n &= 0x0000ffff0000ffffull; + m &= 0x0000ffff0000ffffull; + + for (int i = 0; i < 16; ++i) { + uint64_t mask = (n & 0x0000000100000001ull) * 0xffffffffull; + r ^= m & mask; + n >>= 1; + m <<= 1; + } + return r; +} + +uint64_t clmul_16x2_odd(uint64_t n, uint64_t m) +{ + return clmul_16x2_even(n >> 16, m >> 16); +}