From patchwork Sat Aug 19 01:02:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 715013 Delivered-To: patch@linaro.org Received: by 2002:a5d:484e:0:b0:317:ecd7:513f with SMTP id n14csp801280wrs; Fri, 18 Aug 2023 18:04:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOrMxALoN36sIsky0AcXB8RWybcDEfxJHj3GiWij0ewGQ2+y1R1srWBa7XT4Ma4wEmhboD X-Received: by 2002:a05:6214:5ecc:b0:641:8ba9:68ab with SMTP id mn12-20020a0562145ecc00b006418ba968abmr815185qvb.42.1692407096480; Fri, 18 Aug 2023 18:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692407096; cv=none; d=google.com; s=arc-20160816; b=CpBMmAt88VKHrXSyODwz9T8HutVG7HkxkbgSRGGLXtRMOs3NhRsyikg3Wwp0UeetlT MP8Mj6CcHojroxh4zqSsOFug7JdgXHDci2RzFppLmsNyCG0PxF4Pm25he5vmQsoNQxNN jjhPO8GmPm4fOPhEOJQs3lE7x+ZLlWD2LgQwEsW+aLPtxiZZSsShVBPvTTv6FV6PiR0J /O/53MxOLqxK1Ob2HlVCBrxyvoOyStM+e+23M2lpPi/6Jhqu74ZchYGbTVfNdp+DNotI xK7ncbDCCI8jKggVO8iHxVvpvn3D25UBw4avzSb27wPBs55mid2tYLh503BcJZf7PUyG CiYQ== 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=OchzeURE1BgR8OyI+34sloHIxez963wM6RFcZPAc55w=; fh=4xNVIrgzKzsUJFZ/LK5iWzslbipp0obh3zmyxXTMM5Q=; b=YG9y8b2Lx3GV+yq15Q5VxObM4Wt3DkUarvh3MEuvUIE0Xe+cytmO2ZN7lZ5tiILPd1 d/lPwiY36oksb2mj2WMxtEZQ+velyDl33QF7H81PDHCP2BbArpxcUjnSts2XxtNrChME dBz67YX2FVxYhW039IthniRBRctzmuTzT5sOYMQ0yN8yLpxp4ta0roSxmILNSEz83qRD 98e6KSHOmF8f8aej3l68N+NaYQCBndXR6wdoql2gZTHFNoZGghxRHldXRAXCX0rFntAW Vcje0JnQA+IWUWO/jYxJhijgwi11IH+Z+sKuV3xDZHWsCmTQVDNjNDLdOMLv2V+y8gFE rswQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SzIYJkjo; 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 x6-20020a05620a448600b00767468da8f2si2029135qkp.350.2023.08.18.18.04.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Aug 2023 18:04:56 -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=SzIYJkjo; 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 1qXAML-0008Si-HK; Fri, 18 Aug 2023 21:02:33 -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 1qXAMJ-0008Rj-OV for qemu-devel@nongnu.org; Fri, 18 Aug 2023 21:02:31 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qXAMH-0007MD-Hh for qemu-devel@nongnu.org; Fri, 18 Aug 2023 21:02:31 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bc3d94d40fso12489645ad.3 for ; Fri, 18 Aug 2023 18:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692406948; x=1693011748; 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=OchzeURE1BgR8OyI+34sloHIxez963wM6RFcZPAc55w=; b=SzIYJkjoisy0WLLry0ywCtUCLnDiVrgW1pnm1NuMQSwe1ZDHuk8B7Wsk2XhgiGdpa1 oiBQvm4ipIb/ZtYwXzgKfcWNpAsFxtysnknB0tmJdJbFWxyTe4b0Th1a/dHl3G4De9Ei nLYTCgHKF8UUGoP5kxkStMFdyusB112mRQMVVs9TJTXafS1EZesZptwqNLGleAoaDJT6 benQoqmMXYJh8/R5rjJureg6wSsj66tJ6X8i/BF0FSULcfezgf5vd+COqzmNBLC6p0Rm fzQU/Q6LN68a7rBNvBDmXRdP+XsZOqUVG8BxnjDeMr463nWA5/NYjshj6IVjLCxwF/1w ZqLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692406948; x=1693011748; 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=OchzeURE1BgR8OyI+34sloHIxez963wM6RFcZPAc55w=; b=h27oTEn99FlyR3aft3KuBauaxfGYJsh5duVahDuVg6P16M471JUJJxOxDgvooy9dsM /owCBdfY+KruYNNLXT0yRP0RSKTmSjHPTGlYeYKrHkrwK70m9jHpoUEIDmA0wdc9tait oJuQTqeL9alevtBUGY4WE1huupf4TLvEbW7JE+tvwFuNCkPyXcL5zgSFUpB9HLHJLJZL rbdw0rvBdyNf2fWo6xTkyQn13qA9Yv2YTgnEdJhtd7q665WJI9i91m8SwzeDU7KEyYi7 nclMmBMXh3eogPJV45snYLqXRhY3B/P/T4SQDt2VTUutt7n/va6UlBkEzbsXN1eVW77F WStA== X-Gm-Message-State: AOJu0YwyYf8iY+aTqPmQ6rURp4v6Zl7R7ibot/givHfGhhMQh2+rERLx I0eugrwYYT/5BlfQeGgFQuJZivS/B0tNu8Arnrg= X-Received: by 2002:a17:902:a5c2:b0:1bf:41b6:938e with SMTP id t2-20020a170902a5c200b001bf41b6938emr822326plq.40.1692406948260; Fri, 18 Aug 2023 18:02:28 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:cf24:6daf:2b9e:7972]) by smtp.gmail.com with ESMTPSA id b13-20020a170902d50d00b001b87bedcc6fsm2372019plg.93.2023.08.18.18.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 18:02:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, ardb@kernel.org Subject: [PATCH v2 09/18] crypto: Add generic 32-bit carry-less multiply routines Date: Fri, 18 Aug 2023 18:02:09 -0700 Message-Id: <20230819010218.192706-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230819010218.192706-1-richard.henderson@linaro.org> References: <20230819010218.192706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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 | 7 +++++++ crypto/clmul.c | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/crypto/clmul.h b/include/crypto/clmul.h index c7ad28aa85..0ea25a252c 100644 --- a/include/crypto/clmul.h +++ b/include/crypto/clmul.h @@ -54,4 +54,11 @@ uint64_t clmul_16x2_even(uint64_t, uint64_t); */ uint64_t clmul_16x2_odd(uint64_t, uint64_t); +/** + * clmul_32: + * + * Perform a 32x32->64 carry-less multiply. + */ +uint64_t clmul_32(uint32_t, uint32_t); + #endif /* CRYPTO_CLMUL_H */ diff --git a/crypto/clmul.c b/crypto/clmul.c index 2c87cfbf8a..36ada1be9d 100644 --- a/crypto/clmul.c +++ b/crypto/clmul.c @@ -79,3 +79,16 @@ uint64_t clmul_16x2_odd(uint64_t n, uint64_t m) { return clmul_16x2_even(n >> 16, m >> 16); } + +uint64_t clmul_32(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; +}