From patchwork Thu Jul 13 21:14:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 702239 Delivered-To: patch@linaro.org Received: by 2002:adf:db4e:0:b0:314:25da:8dc4 with SMTP id f14csp742173wrj; Thu, 13 Jul 2023 14:18:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlGxivmqYMWvw0off4Bp4xgit2f+T1JdE0NWOmjj1zQfu3CSW+vdBwevt+EsG6N1nXI5i4re X-Received: by 2002:a05:622a:16:b0:403:b112:1435 with SMTP id x22-20020a05622a001600b00403b1121435mr3654562qtw.28.1689283102187; Thu, 13 Jul 2023 14:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689283102; cv=none; d=google.com; s=arc-20160816; b=XEUgjBAVmFash04zTnXHubvHzCFCEPZ6Rj+6pgyQNd/boVPvJErVhM7eaUQVN7QwpG lTJuF9lzuG3LLS2GLyOjZS69+5Hv4W/W4Rf1HJacaLp6btFfXh51dQm/w7/5mbtqRIrp yA0KXAr7ydUfyN+cF292yi8EB77G9dBcwGJt0JgDyubWE+/sTPTLstpSoFcHaPE++hPT jbI4OmpVfGZr6JXieksnB9izTxyd/z68Z1naa3+kbUuNlEnqq6a9p9I2GOMF6K34h63e O+SyCJnRUNRt545TARF6rwCyY1mqhfz7ZWWWIyOoKZ/VFox6mobo0wBUBRJrGuIL81Qb aYmg== 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=/VchOJmp/PdkjGrWpO7FtoJjXcBbpTQPyllwuZ+9STU=; fh=4xNVIrgzKzsUJFZ/LK5iWzslbipp0obh3zmyxXTMM5Q=; b=i1pdw6UfzxACR0Oqp9Riq6nRjD4ovQa0bBQ0PnFiz7k2kZnur+D9wpEdE7ACpciQaw Iq5yoEyF/p6bOe9HzhEt4IFf5fkvcvd4qWImJmuvlwgrcaDBekpikL/95MsdBohFTBSw /UwSlTPIc+bL4gNBsUV4XpMiO1QUs3xH5+pG9f1/0riGZLpeRtQsxYZewj8t985mBCED 6H/LlTURHWLFaBbGe6l9kL8k73JjAf8//X/nTHH52PqGfaO82+HZZ6RglMC/ZKxS9QtM ng2TesPV7/YVsJbsuC5qgSB9ODp5CNfodUwX1Br5zJBiL5YZe0l5IDVaNjgdMCVveqnW zXzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kQIxRxw+; 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 z15-20020a05622a028f00b004039f269d11si3641983qtw.100.2023.07.13.14.18.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2023 14:18:22 -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=kQIxRxw+; 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 1qK3eM-0000Jw-4S; Thu, 13 Jul 2023 17:14:58 -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 1qK3eI-0000I9-FO for qemu-devel@nongnu.org; Thu, 13 Jul 2023 17:14:54 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qK3eG-00017U-Pq for qemu-devel@nongnu.org; Thu, 13 Jul 2023 17:14:54 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbca8935bfso11255705e9.3 for ; Thu, 13 Jul 2023 14:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689282891; x=1691874891; 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=/VchOJmp/PdkjGrWpO7FtoJjXcBbpTQPyllwuZ+9STU=; b=kQIxRxw+RpNmTfB3c1AJOyZkE7mchlHaPAT2bg6WzywfUo8ez/Yd7xbPK/RVIX57sH NJIme9uP6JJ7Crj2jt9tWtynUR0XvMF9szTlWYQ1HNLvadNUBlmf9aheVhCJwWpK0IMa JZ8ka0+8liKeZYqjQOYO0HRRPSFxosYlqD34hx4LpXsMKpF0AqwILFzVWeZgaKFJEYiT CTyrxJB66E49ypDteL2SDkN7vv5J/zVB7rM/lXH0C1IeKoemmJx+sY8y8E/j3JMCSyTv pO7sli3LScNCQ77N6oJd0zC69LRIyAOgJrXqCOfa9IBpLhMczH6ozD4+Lz2wVYiXrA2F Uozg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689282891; x=1691874891; 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=/VchOJmp/PdkjGrWpO7FtoJjXcBbpTQPyllwuZ+9STU=; b=eN2seIlvjbkXJhLlKbQnzTEsG3S4DmSedpzt5aEKqombqvDPtqcuLETK6HTMkIwV2i X1YHONrlZjNsa0NxHxj69BHSrWmuPEABd1CDI72ZUmiUtuyVOUbJuLZ5Jhw3Jyp6mdiu x2FiEosbt1Cb6QD76H8aP5GB0pWNY4EO1AdcD6J04L2U8Fe/HADTIjhSBL7ONaTX0GDF 1TYQTXlP0g0yrV4bkrw5Q9MrC+YBWDVgGRUsqLS5QJIwMjItaWRCLBKo8EuWJ4f5v3Nv nYSW33dH64ccQTND4q7LinORj8q+QnXBX5+ROg1/DhwGvQ4Aq7vEkei1Ai5Yv/X2V3XE S/OQ== X-Gm-Message-State: ABy/qLZ1PZzP5w4hq01twc9e4a5MkaLHod+AOBuUXUEIxcXNGX127k03 kGEVXVEglDmuFce3rDP0Usq/D3dEXSPLRlYBxNW1vvBw X-Received: by 2002:adf:ed4c:0:b0:313:f347:eea0 with SMTP id u12-20020adfed4c000000b00313f347eea0mr2351551wro.60.1689282891100; Thu, 13 Jul 2023 14:14:51 -0700 (PDT) Received: from stoup.. ([85.193.156.66]) by smtp.gmail.com with ESMTPSA id n12-20020adff08c000000b0030ada01ca78sm8973747wro.10.2023.07.13.14.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 14:14:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, ardb@kernel.org Subject: [PATCH 09/18] crypto: Add generic 32-bit carry-less multiply routines Date: Thu, 13 Jul 2023 22:14:26 +0100 Message-Id: <20230713211435.13505-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713211435.13505-1-richard.henderson@linaro.org> References: <20230713211435.13505-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32f.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, T_SCC_BODY_TEXT_LINE=-0.01 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 --- host/include/generic/host/crypto/clmul.h | 4 +++ include/crypto/clmul.h | 23 ++++++++++++++++++ crypto/clmul.c | 31 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/host/include/generic/host/crypto/clmul.h b/host/include/generic/host/crypto/clmul.h index cba8bbf3e4..3fbb1576cf 100644 --- a/host/include/generic/host/crypto/clmul.h +++ b/host/include/generic/host/crypto/clmul.h @@ -19,4 +19,8 @@ #define clmul_16x4_even clmul_16x4_even_gen #define clmul_16x4_odd clmul_16x4_odd_gen +#define clmul_32 clmul_32_gen +#define clmul_32x2_even clmul_32x2_even_gen +#define clmul_32x2_odd clmul_32x2_odd_gen + #endif /* GENERIC_HOST_CRYPTO_CLMUL_H */ diff --git a/include/crypto/clmul.h b/include/crypto/clmul.h index b701bac9d6..ce43c9aeb1 100644 --- a/include/crypto/clmul.h +++ b/include/crypto/clmul.h @@ -88,6 +88,29 @@ Int128 clmul_16x4_even_gen(Int128, Int128); */ Int128 clmul_16x4_odd_gen(Int128, Int128); +/** + * clmul_32: + * + * Perform a 32x32->64 carry-less multiply. + */ +uint64_t clmul_32_gen(uint32_t, uint32_t); + +/** + * clmul_32x2_even: + * + * Perform two 32x32->64 carry-less multiplies. + * The odd words of the inputs are ignored. + */ +Int128 clmul_32x2_even_gen(Int128, Int128); + +/** + * clmul_32x2_odd: + * + * Perform two 32x32->64 carry-less multiplies. + * The even words of the inputs are ignored. + */ +Int128 clmul_32x2_odd_gen(Int128, Int128); + #include "host/crypto/clmul.h" #endif /* CRYPTO_CLMUL_H */ diff --git a/crypto/clmul.c b/crypto/clmul.c index 69a3b6f7ff..c197cd5f21 100644 --- a/crypto/clmul.c +++ b/crypto/clmul.c @@ -113,3 +113,34 @@ Int128 clmul_16x4_odd_gen(Int128 n, Int128 m) rh = clmul_16x2_odd_gen(int128_gethi(n), int128_gethi(m)); return int128_make128(rl, rh); } + +uint64_t clmul_32_gen(uint32_t n, uint32_t m32) +{ + uint64_t r = 0; + uint64_t m = m32; + + for (int i = 0; i < 32; ++i) { + r ^= n & 1 ? m : 0; + n >>= 1; + m <<= 1; + } + return r; +} + +Int128 clmul_32x2_even_gen(Int128 n, Int128 m) +{ + uint64_t rl, rh; + + rl = clmul_32_gen(int128_getlo(n), int128_getlo(m)); + rh = clmul_32_gen(int128_gethi(n), int128_gethi(m)); + return int128_make128(rl, rh); +} + +Int128 clmul_32x2_odd_gen(Int128 n, Int128 m) +{ + uint64_t rl, rh; + + rl = clmul_32_gen(int128_getlo(n) >> 32, int128_getlo(m) >> 32); + rh = clmul_32_gen(int128_gethi(n) >> 32, int128_gethi(m) >> 32); + return int128_make128(rl, rh); +}