From nobody Thu Nov 28 10:55:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694153667; cv=none; d=zohomail.com; s=zohoarc; b=eHFaPPUSPmnnIXlFYufJd5dmmZhBVKKFdJScKt27+PPng+OuMmj7F36D7FioOLvPKcQp1dmBJ/1Zj2kpFUXMOigKxcCBTV7SbonKGplKprlrLnn3Ul3a/Sec1syWU4f4h9wvInPwf3hhKkhL2snZQmMt6QgwPUJ1QxeRnIzVUhs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694153667; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sm5kdR4zPqERpHwNfrDrMNoNCsEGBcjXZveAeFuP0TY=; b=F7YRwnDafHj4T5ss6CyT8fUQE2WwFR1tRGmPW/AYAAylox+8cJlGb1gUNdSz120uvw+CCW4BXJbGm1tSvH/0zANKvzvzIjC2SHQM2rFtpZpNH/t+JxinqLgWf0TyigqpfaygdVBcS7BBvWZJhlXj2Os5dJHNvaMQAPS5NWpPBMo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694153667034618.3497802593286; Thu, 7 Sep 2023 23:14:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeUed-0008IL-63; Fri, 08 Sep 2023 02:07:43 -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 1qeUeb-000891-D3 for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:07:41 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeUeV-0007p5-NO for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:07:40 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c0db66af1bso12627095ad.2 for ; Thu, 07 Sep 2023 23:07:35 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id q1-20020a170902dac100b001c3267ae31bsm715231plx.301.2023.09.07.23.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 23:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694153253; x=1694758053; darn=nongnu.org; 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=sm5kdR4zPqERpHwNfrDrMNoNCsEGBcjXZveAeFuP0TY=; b=sqGmyToYWjbr7YcKfKgBYVl0VBtkPFsKrX1MrtQCPovpVenDJGjfLwJoVmgYq5eFcC W9nrm2NadyL7HG9sQaAbUaLNBvZtBES/dpZ6cKbhXWmHY1TRmqMiN25fgyLy6YGWxsVS 6AcImHUOEcTfNIiotyosOQGxTjI/Yxa3BzNHsapt5BdxJFlPIwu72SLmJQuXj3ApiOGS ujh7q27Vk97ABqFNixmxWU+Yzdv8QStvDuBqVAUrTZgVmtMIIDOFIhlPINgLagwn8xvt kobgcjnGjQDZaZM6QKlFol/rigUvOcz5Ao7dkNqS3invd3bxAxLphoP1ybVsIUO7Fhb3 osVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694153253; x=1694758053; 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=sm5kdR4zPqERpHwNfrDrMNoNCsEGBcjXZveAeFuP0TY=; b=enZNsMrFeDngow2/RZWp9kMYoPpEcfgW59V7bKlcR5WqoDILFJO9o7CyDfI1XD3mM4 /efbtwxVXF/iWsiPw6V+SoB0gQOSMD3XNM+YwUVkFbWJqJjEhodd4FvuClaKzPbMXDzB cfts4facvHCleOHwa4TygvT12Pjd1eZILHQVD7igIcVHoeUhy3nnbT7z1SFh4wyGAbfo rw+eKPIkscgVi6CHMo1E9UJisStb3BmEsnvgRvR3TI/6wMH0NYq5rY4V5VvbncSomXPi 5SIYn9L8Q7efE0OmaC2m7XDz1N5bnEYhT0PGUbUjucAqY47yNPLP36m0P3PvfC4JWOvV USVQ== X-Gm-Message-State: AOJu0YxWxjya+8HNhMwS5c9jtaECB01ZoEInyEAQLb36TSd7GS2Ahw2G v0YNXKJpN6BhqyB6wRF3eduzZWcZhw7kqs40 X-Google-Smtp-Source: AGHT+IF4iDlPLdiu4Jcis6dnXVE5fmlBYh0DPyl7ZdL15Xkz/OFXXG/E7jxXFh9Q56bRVxZA+88kew== X-Received: by 2002:a17:902:f7c7:b0:1b8:7fd7:e022 with SMTP id h7-20020a170902f7c700b001b87fd7e022mr1737965plw.28.1694153252826; Thu, 07 Sep 2023 23:07:32 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Ard Biesheuvel , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Palmer Dabbelt , Alistair Francis Subject: [PULL 41/65] target/riscv: Use accelerated helper for AES64KS1I Date: Fri, 8 Sep 2023 16:04:07 +1000 Message-ID: <20230908060431.1903919-42-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230908060431.1903919-1-alistair.francis@wdc.com> References: <20230908060431.1903919-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=alistair23@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694153669459100019 From: Ard Biesheuvel Use the accelerated SubBytes/ShiftRows/AddRoundKey AES helper to implement the first half of the key schedule derivation. This does not actually involve shifting rows, so clone the same value into all four columns of the AES vector to counter that operation. Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Palmer Dabbelt Cc: Alistair Francis Signed-off-by: Ard Biesheuvel Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Message-ID: <20230831154118.138727-1-ardb@kernel.org> Signed-off-by: Alistair Francis --- target/riscv/crypto_helper.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c index 4d65945429..bb084e00ef 100644 --- a/target/riscv/crypto_helper.c +++ b/target/riscv/crypto_helper.c @@ -148,24 +148,17 @@ target_ulong HELPER(aes64ks1i)(target_ulong rs1, targ= et_ulong rnum) =20 uint8_t enc_rnum =3D rnum; uint32_t temp =3D (RS1 >> 32) & 0xFFFFFFFF; - uint8_t rcon_ =3D 0; - target_ulong result; + AESState t, rc =3D {}; =20 if (enc_rnum !=3D 0xA) { temp =3D ror32(temp, 8); /* Rotate right by 8 */ - rcon_ =3D round_consts[enc_rnum]; + rc.w[0] =3D rc.w[1] =3D round_consts[enc_rnum]; } =20 - temp =3D ((uint32_t)AES_sbox[(temp >> 24) & 0xFF] << 24) | - ((uint32_t)AES_sbox[(temp >> 16) & 0xFF] << 16) | - ((uint32_t)AES_sbox[(temp >> 8) & 0xFF] << 8) | - ((uint32_t)AES_sbox[(temp >> 0) & 0xFF] << 0); + t.w[0] =3D t.w[1] =3D t.w[2] =3D t.w[3] =3D temp; + aesenc_SB_SR_AK(&t, &t, &rc, false); =20 - temp ^=3D rcon_; - - result =3D ((uint64_t)temp << 32) | temp; - - return result; + return t.d[0]; } =20 target_ulong HELPER(aes64im)(target_ulong rs1) --=20 2.41.0