Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1956137rdb; Sun, 19 Nov 2023 18:37:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFa7SvrwociHRLK0wrVYHcJ021F2nUS1UUgTXciU8UlSLX7pBvqfOUAO0IStF+Hk2BP1B7n X-Received: by 2002:a17:902:6941:b0:1cc:76c4:5144 with SMTP id k1-20020a170902694100b001cc76c45144mr4414126plt.12.1700447844782; Sun, 19 Nov 2023 18:37:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700447844; cv=none; d=google.com; s=arc-20160816; b=yZYA46i8EBY/2D/8e03qPSgX06Nd/b4dFAPDnQ6nE56Ec4Kp5df2SQ4js+RkVxjLlh Ob7ORpewNnvCoW33oiOJMf6fSgV+NHuRY9kdzvBDozRp86z7Oq/cE61uyz8Sjz1kKGmb 5pbazOuxCwFG0vAp5V0oV+IVqR+1cemmgmusmUFa94VZx+yYMriOOXY5ujqO2rX4XjlA fE2olbboThkkeJ4jWCVD6lfyCyiYffvNdgD753ElveGGdzGFv9Njsu5UCyursBQmwI2M KhdJiOaHJ5gtBmGsudit4rpfoNVJZnPkYE37E9lpedAF2vXKheBZSwYaKGVhmJnxpDvh OK5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=5Zq4RPXM6eCo+MpwtSfj3ACqp+KpQugLsNlxVZl0DlA=; fh=zpHLWyeRR7dOHHeejsRbDoIpNWos9Mc4VkbV5zLYyvU=; b=THDvAe4LGRreiMfaPuiBUK7HDxWTyQ9TjHCkzSS2GbL2jY4O1uYq3+IVdCS9UegB1+ xEHZKKhZV98Ju5wHIV+z7QRq1MqL5M9tcEk2BWKF7nE3HhqXV2qxQEHgR7+7/RylQioU ykEoo2flHKIOkLKeApuMexh0yIsLpPF+JZ3Ud9fJ0qVRECTvp68KuutjHV3YlS5aIAOp oQwVKh2mpX8KhWBk/xCdcgtHD0FI5IcVGh9eBQEvksK/9hvjaluaEIhYLeRq1/Qf29TP wTUDnazilaKfzLdN5hXTAaFkU3WC7wqvYxpQcl7QvK5Eaxwq0HcP9cuFo3PGaUfjwsez B54A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=EC+qeQww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id g23-20020a1709029f9700b001cc3397aa27si6972340plq.62.2023.11.19.18.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 18:37:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=EC+qeQww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 40C3D8096BB2; Sun, 19 Nov 2023 18:37:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231755AbjKTCg6 (ORCPT + 99 others); Sun, 19 Nov 2023 21:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbjKTCg5 (ORCPT ); Sun, 19 Nov 2023 21:36:57 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F815D4D for ; Sun, 19 Nov 2023 18:36:47 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1cc9b626a96so28098795ad.2 for ; Sun, 19 Nov 2023 18:36:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1700447807; x=1701052607; darn=vger.kernel.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5Zq4RPXM6eCo+MpwtSfj3ACqp+KpQugLsNlxVZl0DlA=; b=EC+qeQww2Qbz1pVNrG7CDHkr29EqOhCoUDUtrGFLYnBSZtA7a6YnbWwkknY1qDfb8f m5A263wA3nuUQoZoNZU4ccXDVu3eyasp3WuEps5w0LDViM4avcuN66e7Wf7WmdlJN7kv +U2MoY58R2xf7k4IkuZnVigCINhxIpjCnqIGph9qMzNdYrrQt8dE/nm5xDeEtRJPSXws QBKzFCK/hMMU6Vj9hKpVM08Z6baaveeuC+TW5iZGo7XYiQAjIw5MOOh51qQHX5B8yA++ xudu3M6K9zruEG8bJ2AtPOaBLn0iJI8OvdEoqJFAw1C5ctjQpXjSpTCcULUxoS0n4ZS/ f98w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700447807; x=1701052607; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Zq4RPXM6eCo+MpwtSfj3ACqp+KpQugLsNlxVZl0DlA=; b=n/VPG1JMQqDFxW/UT1LE1OekrTbHq7w8OxzmCYk37zxNrCgrwc8iJCvKS2AYAzCVYF ot5K1CPZDBVtlH/BP4vNU6N7IAK704FN4A8P6T+PeR0/vqs46PYjoaEp5/NxtKerhhSg IR43XafJVyVkFn3CHJndWmYUxt6JkFCxiJB4nNzA2Q1PugLmwHN8yY26QNWbvsmErOXx DWwnWDjjyX+W6S6vL/Kl6GDkLF1J0IOkAq+7F6UvZI5ALakbeLOb5dVVzP5qR2/YIB2a m8L6OHbv0hTRevwUd8CWh7gNXd9sM7WJ6YgYUU0928O8TCoqgv9ln6T5ChPai4zHzoHd 3BiQ== X-Gm-Message-State: AOJu0YyDxhHJsn+c65J6W2zJ2YmJRNMXJOWNl46gcKPe3SnaBzm+jY4Z Vtfg4jQQ5AdVSGUYC36SnyM64w== X-Received: by 2002:a17:902:a5c9:b0:1cc:60ca:8f24 with SMTP id t9-20020a170902a5c900b001cc60ca8f24mr4758601plq.45.1700447806758; Sun, 19 Nov 2023 18:36:46 -0800 (PST) Received: from [192.168.244.11] ([49.216.222.216]) by smtp.gmail.com with ESMTPSA id h6-20020a170902eec600b001bb1f0605b2sm4939926plb.214.2023.11.19.18.36.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Nov 2023 18:36:46 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.7\)) Subject: Re: [PATCH 06/12] RISC-V: crypto: add accelerated AES-CBC/CTR/ECB/XTS implementations From: Jerry Shih In-Reply-To: Date: Mon, 20 Nov 2023 10:36:19 +0800 Cc: Paul Walmsley , palmer@dabbelt.com, Albert Ou , herbert@gondor.apana.org.au, davem@davemloft.net, andy.chiu@sifive.com, greentime.hu@sifive.com, conor.dooley@microchip.com, guoren@kernel.org, bjorn@rivosinc.com, heiko@sntech.de, ardb@kernel.org, phoebe.chen@sifive.com, hongrong.hsu@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20231025183644.8735-1-jerry.shih@sifive.com> <20231025183644.8735-7-jerry.shih@sifive.com> <20231109080549.GC1245@sol.localdomain> To: Eric Biggers X-Mailer: Apple Mail (2.3445.9.7) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 19 Nov 2023 18:37:22 -0800 (PST) On Nov 10, 2023, at 12:06, Jerry Shih wrote: > On Nov 9, 2023, at 16:05, Eric Biggers wrote: >> On Thu, Oct 26, 2023 at 02:36:38AM +0800, Jerry Shih wrote: >>> +# prepare input data(v24), iv(v28), bit-reversed-iv(v16), = bit-reversed-iv-multiplier(v20) >>> +sub init_first_round { >>> .... >>> + # Prepare GF(2^128) multiplier [1, x, x^2, x^3, ...] in v8. >>> + slli $T0, $LEN32, 2 >>> + @{[vsetvli "zero", $T0, "e32", "m1", "ta", "ma"]} >>> + # v2: [`1`, `1`, `1`, `1`, ...] >>> + @{[vmv_v_i $V2, 1]} >>> + # v3: [`0`, `1`, `2`, `3`, ...] >>> + @{[vid_v $V3]} >>> + @{[vsetvli "zero", $T0, "e64", "m2", "ta", "ma"]} >>> + # v4: [`1`, 0, `1`, 0, `1`, 0, `1`, 0, ...] >>> + @{[vzext_vf2 $V4, $V2]} >>> + # v6: [`0`, 0, `1`, 0, `2`, 0, `3`, 0, ...] >>> + @{[vzext_vf2 $V6, $V3]} >>> + slli $T0, $LEN32, 1 >>> + @{[vsetvli "zero", $T0, "e32", "m2", "ta", "ma"]} >>> + # v8: [1<<0=3D1, 0, 0, 0, 1<<1=3Dx, 0, 0, 0, 1<<2=3Dx^2, 0, 0, = 0, ...] >>> + @{[vwsll_vv $V8, $V4, $V6]} >>=20 >> This code assumes that '1 << i' fits in 64 bits, for 0 <=3D i < vl. >>=20 >> I think that works out to an implicit assumption that VLEN <=3D 2048. = I.e., >> AES-XTS encryption/decryption would produce the wrong result on = RISC-V >> implementations with VLEN > 2048. >>=20 >> Perhaps it should be explicitly checked that VLEN <=3D 2048? >>=20 >> - Eric >=20 > Yes, we could just have the simple checking like: >=20 > riscv_vector_vlen() >=3D 128 || riscv_vector_vlen() <=3D2048 >=20 > We could also truncate the VL inside for VLEN>2048 case. > Let me think more about these two approaches.=20 >=20 > -Jerry I use the simplest solution. Setup the check for vlen: riscv_vector_vlen() >=3D 128 || riscv_vector_vlen() <=3D2048 It will have a situation that we will not enable accelerated aes-xts for = `vlen>2048`. I would like to make a `todo` task to fix that in the future. -Jerry=