From patchwork Mon Aug 21 16:18:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 715392 Delivered-To: patch@linaro.org Received: by 2002:a5d:484e:0:b0:317:ecd7:513f with SMTP id n14csp1925932wrs; Mon, 21 Aug 2023 09:21:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2jg9KnVEU6IMVFjAa4/bz8p5pIG/hYXoZC9FCyKo4uAtNvN+gcve9So6bQb0PgTycuiRU X-Received: by 2002:a0c:b699:0:b0:646:1c12:a7a2 with SMTP id u25-20020a0cb699000000b006461c12a7a2mr8600938qvd.33.1692634911878; Mon, 21 Aug 2023 09:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692634911; cv=none; d=google.com; s=arc-20160816; b=kZv5oRcqVX45Fsnd4MbRLgfs54G0n1PNflrzysFBSShtIIgezcbVNz95InsaW+HNcW OICJcN3ghmh8zyoKLU8OepKdx6DoRytpDYO0Oj2lpsRXH4PoJk+iK16cZN4UruDiypjB VeQmbbDgVnwD6VwyeygLwqoLxDPbYYkp94MPcGRURxIIfzOPW8pEK1qNDKHp1GrjvEZg PNMSZfWiKlJSY/71bREyD0a/5Ns9IEC815MJ9F+3JDFQq4OVNpb0p2ntRFYms9bgwzE2 3s2f5SGD+n+kOCDAqqngnJQlKTjaYAUWgspw+wbVfh5oGj0B2T2c93RRFr8GePqbYIzc dkyg== 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=v9aGtnTZpFDMgY3v11X1zR3alCRPd1TwbYXyjZl8p88=; fh=4xNVIrgzKzsUJFZ/LK5iWzslbipp0obh3zmyxXTMM5Q=; b=Zucdk4qb84qisgGhPnIxse/xZlGoWPexNEtMrM77q7jyqlMJEsrLa2x92nqj191/jU MfpK+Tkr568e1RynPiqK4/B18Db26E3AV2CJLVxqhsVLH/1cGSYInK3/Ll8sIQDK3JHc 4hYUwv5ODTfiy4FxCVTXuCzmuxNU8vAdmHyUyg6MIjKdZVXjqDX/tCaEg4xvD5oXiabs 9Ir+5AB7fMxHW3wDusTZJ9EIYxA6kkKcWqwFUEre/C2jemVgF+hEEjw6Jtj9P3A94QH9 Fhoo3vkSAFHvxnEQ1TxIAacoN/5IyGs+xvmvP2P0/PnUISZ6YRAJCJr80OAm27jk7TBO ABYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YkRmhrz4; 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 x15-20020a0ce0cf000000b006418e9adf3fsi5020533qvk.202.2023.08.21.09.21.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Aug 2023 09:21:51 -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=YkRmhrz4; 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 1qY7cq-0001oP-T1; Mon, 21 Aug 2023 12:19:32 -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 1qY7cZ-0001Vb-A1 for qemu-devel@nongnu.org; Mon, 21 Aug 2023 12:19:17 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qY7cS-0005dZ-RB for qemu-devel@nongnu.org; Mon, 21 Aug 2023 12:19:10 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bba48b0bd2so21246505ad.3 for ; Mon, 21 Aug 2023 09:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692634747; x=1693239547; 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=v9aGtnTZpFDMgY3v11X1zR3alCRPd1TwbYXyjZl8p88=; b=YkRmhrz4bFm+nEFxqDe/RyAxNveMWtH8J4e6a8ZZPGW4EgcCGkImG8BzpuuZM2xdVk wJ5230HdpgWIlQvp1Y2+6eqXvyJ93OkGhnBxlxVfEt4jui6I55yUw1Yh1KiDVKgZZsJH ATceOlujXKy1QPvSCTcaySY9UIaFBv748Iu8VPICPekPgr0WPtEHiSbD7I/FuvXEmnz5 tkyl+IhgEREKTo3YAVlF0PrUFm48E6vgkQISZg5ySnP/WmvecqMeuUC/LP1qLmYnbfM9 XCwOF5n326/Bozoz5/TjQJQf9L3fnGDseYKlvbnZ6zGW5VuXoNe75bJ1xA5rpt11T3p3 XjgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692634747; x=1693239547; 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=v9aGtnTZpFDMgY3v11X1zR3alCRPd1TwbYXyjZl8p88=; b=ErW7ghAIJOG/CBpvN8OPMtIH1YruPXKcpbL1PeMWL9fVhb07NnPVQ+CE09+6vJbtO4 ukM9hjgEVPa0LdvwtT5J1AQNJfZrWDAftlaokEcoTqVkZ/NFFn12FCmAfTvtMzo0Zfse xouFWzC5slukQCwQ7HfIMDBvMdGGjigtGx/Kz0uwiDmTIXaCocwZFW8u1GhwUQEXbmNU R5L5WtDTcCEiWShjlbzw7dBJzKRdiIc59ZsV5+Fa6waxEvRoiG3uS2IBhZy3CA+wTglj n1fXWaSgT+oao+aqCu8wu6vGEwsiKWWLgTKDU5bP/XMFsv4hXFZvzDjhS/d3nxnWursc JmGw== X-Gm-Message-State: AOJu0YzFUdEKdmCkNmDg1nQXRuzDTAOniKKReKLFw630lJZUOZtN5AJJ LOMRcVAyHVIlYhz0TGwluSMtjqsWzmzz+rT2eSg= X-Received: by 2002:a17:903:278f:b0:1bc:e6a:205f with SMTP id jw15-20020a170903278f00b001bc0e6a205fmr4731120plb.20.1692634747440; Mon, 21 Aug 2023 09:19:07 -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.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 09:19:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, ardb@kernel.org Subject: [PATCH v3 13/19] crypto: Add generic 64-bit carry-less multiply routine Date: Mon, 21 Aug 2023 09:18:47 -0700 Message-Id: <20230821161854.419893-14-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::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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 --- host/include/generic/host/crypto/clmul.h | 15 +++++++++++++++ include/crypto/clmul.h | 19 +++++++++++++++++++ crypto/clmul.c | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 host/include/generic/host/crypto/clmul.h diff --git a/host/include/generic/host/crypto/clmul.h b/host/include/generic/host/crypto/clmul.h new file mode 100644 index 0000000000..915bfb88d3 --- /dev/null +++ b/host/include/generic/host/crypto/clmul.h @@ -0,0 +1,15 @@ +/* + * No host specific carry-less multiply acceleration. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef GENERIC_HOST_CRYPTO_CLMUL_H +#define GENERIC_HOST_CRYPTO_CLMUL_H + +#define HAVE_CLMUL_ACCEL false +#define ATTR_CLMUL_ACCEL + +Int128 clmul_64_accel(uint64_t, uint64_t) + QEMU_ERROR("unsupported accel"); + +#endif /* GENERIC_HOST_CRYPTO_CLMUL_H */ diff --git a/include/crypto/clmul.h b/include/crypto/clmul.h index 0ea25a252c..c82d2d7559 100644 --- a/include/crypto/clmul.h +++ b/include/crypto/clmul.h @@ -8,6 +8,9 @@ #ifndef CRYPTO_CLMUL_H #define CRYPTO_CLMUL_H +#include "qemu/int128.h" +#include "host/crypto/clmul.h" + /** * clmul_8x8_low: * @@ -61,4 +64,20 @@ uint64_t clmul_16x2_odd(uint64_t, uint64_t); */ uint64_t clmul_32(uint32_t, uint32_t); +/** + * clmul_64: + * + * Perform a 64x64->128 carry-less multiply. + */ +Int128 clmul_64_gen(uint64_t, uint64_t); + +static inline Int128 clmul_64(uint64_t a, uint64_t b) +{ + if (HAVE_CLMUL_ACCEL) { + return clmul_64_accel(a, b); + } else { + return clmul_64_gen(a, b); + } +} + #endif /* CRYPTO_CLMUL_H */ diff --git a/crypto/clmul.c b/crypto/clmul.c index 36ada1be9d..abf79cc49a 100644 --- a/crypto/clmul.c +++ b/crypto/clmul.c @@ -92,3 +92,21 @@ uint64_t clmul_32(uint32_t n, uint32_t m32) } return r; } + +Int128 clmul_64_gen(uint64_t n, uint64_t m) +{ + uint64_t rl = 0, rh = 0; + + /* Bit 0 can only influence the low 64-bit result. */ + if (n & 1) { + rl = m; + } + + for (int i = 1; i < 64; ++i) { + uint64_t mask = -(n & 1); + rl ^= (m << i) & mask; + rh ^= (m >> (64 - i)) & mask; + n >>= 1; + } + return int128_make128(rl, rh); +}