From patchwork Tue Jun 20 11:07:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694454 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244046wrm; Tue, 20 Jun 2023 04:09:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7CeVRFP93yn+L2e+0psM/jb4l6S0Okq3pdayYvw4r6iKynQfRw7CUnOjQ6Gcw/mzXs4qxm X-Received: by 2002:a05:620a:8f8c:b0:763:9b93:1da with SMTP id ri12-20020a05620a8f8c00b007639b9301damr3259494qkn.30.1687259365834; Tue, 20 Jun 2023 04:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259365; cv=none; d=google.com; s=arc-20160816; b=d+6lGvasEG7U8FnWpizAn/w7xTeYsaE+n0qdskVLSG9s9gwdKGAY5607ea9Pn/xxKT pA0L5nuDo01x87ZdMyANIBiR8mS07hMNw7za4zl4B/MXlFPKWVSDCT7MO+VxYtL+oFKK FgFigqO4elwPeYxniCDx8wr1px06kWNuF6a43y53HyOKeK+5i3m8s//5ql73md6jNh/Q KX9MqyY0FIOk1VWriABPJ2ytwQrMnUTDSzLmnzPj0UdTgEOi1PrivEcMK4yuDeMYTVfY Gp3CCfBaJEt/AXc0vU7m4HL6PP/64GvSjXGQtvg2/51Os4UxueozdNNwDIAucK8843Gg 3PMQ== 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=KMA70dMb1SJ/eTe/2+zO5JW0aBcXeIGHYSkfDyZwFgY=; b=NkH/BaceWRSiyPx1HBuGTPN4S7l66TBLU5EeE7t4K3E75eeztp2JEgXXW2xJuGWBwO WLje5ls6ZdiYeiwzJ3evw48/4eDj/aKhpqUA8iPN18tlC2GZeDAKVZj8Y30IVxAQND+1 9k7KHdclRalGgqNMxBm/+4zWO+axPdNxbNlWzVgScRL0FFfxMrHfw7KBGqHYKs+QUuIf RDehl+VG49zjTsl96hFZ5T4Ll7w7owb9JF8ucWO8Su7gwCiDqMgHD3swW7FgHB2/HXoM yDeh8mQZ5u0tMADHwV9PZBWwH2KO1F5I0A+uccbcirWaqx2LVnFeX239L7HkDjO0r4hk w+EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UYRywv7K; 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 y16-20020a05620a09d000b0075c974cdbd9si710968qky.69.2023.06.20.04.09.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:09:25 -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=UYRywv7K; 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 1qBZDW-0005n9-MO; Tue, 20 Jun 2023 07:08:10 -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 1qBZDU-0005lM-O6 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:08 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDR-00049q-2z for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:08 -0400 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-51a3e6a952aso5466547a12.3 for ; Tue, 20 Jun 2023 04:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259283; x=1689851283; 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=KMA70dMb1SJ/eTe/2+zO5JW0aBcXeIGHYSkfDyZwFgY=; b=UYRywv7Kiz7a6XsDJg1V8MBG665jQi+z+ltEsjQp7q+0kTD8tMhhv9YxihgSquUY77 VeyDOTX15Dol2LpINP3ARmA9t3m+CVUZAPO719C6cceQxxKJS3bHPl05F7PXDJ8J0EEP OtZ9bInoM7K624yvFvLJQjoPPm5HNQbWIg0NcsxDUmCgmYYfyMC+9Fbi2bRX8PLfhIEC aUj4a7Gtu29C3kysqQhXdV06Cbc0fqFGa51i8FjW8eVuYFXrGJJkBYdrQTXG06bbcKKY 2DkPv2IYAYxlZgBp1RCKudE/6QyeeG7b6XW1U6DHKKwZnqmdkJzX6y8C4eC9vJfDz1Zu naBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259283; x=1689851283; 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=KMA70dMb1SJ/eTe/2+zO5JW0aBcXeIGHYSkfDyZwFgY=; b=fHMG3bmss0S166xtuFTktyo2dTwTD9fUln/RMyvq84GOARALcGtHprmBtj8my2c02N qHbEcpzwlN4J5C18ji711GV04uSViFkjNkth40xO0eL1lgJJubi3NZoyE6ylKq7hKBFU ZnZlRQkaM/uxLE/GNUKrTh3aoXEJSX0ZJKGgNFI0FxyZ7b8LVWXDTLBWg90UtubVMhiU iZTyroXXFGkALROB5cNUNUg4LiY+ByIHsJeGw0mvehzdjopj4+y+HkNHbFC5IwXIWgQT 3HnYmHskDKCGn2sc6zm0HcIonZ21EWQETQdu1D73YKEWA988E0djYwvy/NKJFzjQ5yBY FIdQ== X-Gm-Message-State: AC+VfDz0DakKi3OBqNfZnesT6leibNib9Leqe9au6OdUlCC8H61Xbo3N eV3YNrr7Ok8+Lr5B36a+d1PlEf0RsbX9Rl+Y6eJkdKxJ X-Received: by 2002:a17:907:983:b0:96f:a935:8997 with SMTP id bf3-20020a170907098300b0096fa9358997mr10658835ejc.12.1687259283321; Tue, 20 Jun 2023 04:08:03 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PATCH v3 01/37] util: Add cpuinfo-ppc.c Date: Tue, 20 Jun 2023 13:07:22 +0200 Message-Id: <20230620110758.787479-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-ed1-x536.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=unavailable 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 Move the code from tcg/. Fix a bug in that PPC_FEATURE2_ARCH_3_10 is actually spelled PPC_FEATURE2_ARCH_3_1. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel Henrique Barboza Signed-off-by: Richard Henderson --- host/include/ppc/host/cpuinfo.h | 29 ++++++++++++++++ host/include/ppc64/host/cpuinfo.h | 1 + tcg/ppc/tcg-target.h | 16 ++++----- util/cpuinfo-ppc.c | 56 +++++++++++++++++++++++++++++++ tcg/ppc/tcg-target.c.inc | 44 +----------------------- util/meson.build | 2 ++ 6 files changed, 97 insertions(+), 51 deletions(-) create mode 100644 host/include/ppc/host/cpuinfo.h create mode 100644 host/include/ppc64/host/cpuinfo.h create mode 100644 util/cpuinfo-ppc.c diff --git a/host/include/ppc/host/cpuinfo.h b/host/include/ppc/host/cpuinfo.h new file mode 100644 index 0000000000..df11e8d417 --- /dev/null +++ b/host/include/ppc/host/cpuinfo.h @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Host specific cpu indentification for ppc. + */ + +#ifndef HOST_CPUINFO_H +#define HOST_CPUINFO_H + +/* Digested version of */ + +#define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */ +#define CPUINFO_V2_06 (1u << 1) +#define CPUINFO_V2_07 (1u << 2) +#define CPUINFO_V3_0 (1u << 3) +#define CPUINFO_V3_1 (1u << 4) +#define CPUINFO_ISEL (1u << 5) +#define CPUINFO_ALTIVEC (1u << 6) +#define CPUINFO_VSX (1u << 7) + +/* Initialized with a constructor. */ +extern unsigned cpuinfo; + +/* + * We cannot rely on constructor ordering, so other constructors must + * use the function interface rather than the variable above. + */ +unsigned cpuinfo_init(void); + +#endif /* HOST_CPUINFO_H */ diff --git a/host/include/ppc64/host/cpuinfo.h b/host/include/ppc64/host/cpuinfo.h new file mode 100644 index 0000000000..2f036a0627 --- /dev/null +++ b/host/include/ppc64/host/cpuinfo.h @@ -0,0 +1 @@ +#include "host/include/ppc/host/cpuinfo.h" diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h index c7552b6391..9a41fab8cc 100644 --- a/tcg/ppc/tcg-target.h +++ b/tcg/ppc/tcg-target.h @@ -25,6 +25,8 @@ #ifndef PPC_TCG_TARGET_H #define PPC_TCG_TARGET_H +#include "host/cpuinfo.h" + #define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) #define TCG_TARGET_NB_REGS 64 @@ -61,14 +63,12 @@ typedef enum { tcg_isa_3_10, } TCGPowerISA; -extern TCGPowerISA have_isa; -extern bool have_altivec; -extern bool have_vsx; - -#define have_isa_2_06 (have_isa >= tcg_isa_2_06) -#define have_isa_2_07 (have_isa >= tcg_isa_2_07) -#define have_isa_3_00 (have_isa >= tcg_isa_3_00) -#define have_isa_3_10 (have_isa >= tcg_isa_3_10) +#define have_isa_2_06 (cpuinfo & CPUINFO_V2_06) +#define have_isa_2_07 (cpuinfo & CPUINFO_V2_07) +#define have_isa_3_00 (cpuinfo & CPUINFO_V3_0) +#define have_isa_3_10 (cpuinfo & CPUINFO_V3_1) +#define have_altivec (cpuinfo & CPUINFO_ALTIVEC) +#define have_vsx (cpuinfo & CPUINFO_VSX) /* optional instructions automatically implemented */ #define TCG_TARGET_HAS_ext8u_i32 0 /* andi */ diff --git a/util/cpuinfo-ppc.c b/util/cpuinfo-ppc.c new file mode 100644 index 0000000000..d95adc8ccd --- /dev/null +++ b/util/cpuinfo-ppc.c @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Host specific cpu indentification for ppc. + */ + +#include "qemu/osdep.h" +#include "host/cpuinfo.h" + +#ifdef CONFIG_GETAUXVAL +# include +#else +# include +# include "elf.h" +#endif + +unsigned cpuinfo; + +/* Called both as constructor and (possibly) via other constructors. */ +unsigned __attribute__((constructor)) cpuinfo_init(void) +{ + unsigned info = cpuinfo; + unsigned long hwcap, hwcap2; + + if (info) { + return info; + } + + hwcap = qemu_getauxval(AT_HWCAP); + hwcap2 = qemu_getauxval(AT_HWCAP2); + info = CPUINFO_ALWAYS; + + /* Version numbers are monotonic, and so imply all lower versions. */ + if (hwcap2 & PPC_FEATURE2_ARCH_3_1) { + info |= CPUINFO_V3_1 | CPUINFO_V3_0 | CPUINFO_V2_07 | CPUINFO_V2_06; + } else if (hwcap2 & PPC_FEATURE2_ARCH_3_00) { + info |= CPUINFO_V3_0 | CPUINFO_V2_07 | CPUINFO_V2_06; + } else if (hwcap2 & PPC_FEATURE2_ARCH_2_07) { + info |= CPUINFO_V2_07 | CPUINFO_V2_06; + } else if (hwcap & PPC_FEATURE_ARCH_2_06) { + info |= CPUINFO_V2_06; + } + + if (hwcap2 & PPC_FEATURE2_HAS_ISEL) { + info |= CPUINFO_ISEL; + } + if (hwcap & PPC_FEATURE_HAS_ALTIVEC) { + info |= CPUINFO_ALTIVEC; + /* We only care about the portion of VSX that overlaps Altivec. */ + if (hwcap & PPC_FEATURE_HAS_VSX) { + info |= CPUINFO_VSX; + } + } + + cpuinfo = info; + return info; +} diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc index 5c8378f8f6..c866f2c997 100644 --- a/tcg/ppc/tcg-target.c.inc +++ b/tcg/ppc/tcg-target.c.inc @@ -101,10 +101,7 @@ #define ALL_GENERAL_REGS 0xffffffffu #define ALL_VECTOR_REGS 0xffffffff00000000ull -TCGPowerISA have_isa; -static bool have_isel; -bool have_altivec; -bool have_vsx; +#define have_isel (cpuinfo & CPUINFO_ISEL) #ifndef CONFIG_SOFTMMU #define TCG_GUEST_BASE_REG 30 @@ -3879,45 +3876,6 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) static void tcg_target_init(TCGContext *s) { - unsigned long hwcap = qemu_getauxval(AT_HWCAP); - unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2); - - have_isa = tcg_isa_base; - if (hwcap & PPC_FEATURE_ARCH_2_06) { - have_isa = tcg_isa_2_06; - } -#ifdef PPC_FEATURE2_ARCH_2_07 - if (hwcap2 & PPC_FEATURE2_ARCH_2_07) { - have_isa = tcg_isa_2_07; - } -#endif -#ifdef PPC_FEATURE2_ARCH_3_00 - if (hwcap2 & PPC_FEATURE2_ARCH_3_00) { - have_isa = tcg_isa_3_00; - } -#endif -#ifdef PPC_FEATURE2_ARCH_3_10 - if (hwcap2 & PPC_FEATURE2_ARCH_3_10) { - have_isa = tcg_isa_3_10; - } -#endif - -#ifdef PPC_FEATURE2_HAS_ISEL - /* Prefer explicit instruction from the kernel. */ - have_isel = (hwcap2 & PPC_FEATURE2_HAS_ISEL) != 0; -#else - /* Fall back to knowing Power7 (2.06) has ISEL. */ - have_isel = have_isa_2_06; -#endif - - if (hwcap & PPC_FEATURE_HAS_ALTIVEC) { - have_altivec = true; - /* We only care about the portion of VSX that overlaps Altivec. */ - if (hwcap & PPC_FEATURE_HAS_VSX) { - have_vsx = true; - } - } - tcg_target_available_regs[TCG_TYPE_I32] = 0xffffffff; tcg_target_available_regs[TCG_TYPE_I64] = 0xffffffff; if (have_altivec) { diff --git a/util/meson.build b/util/meson.build index 3a93071d27..a375160286 100644 --- a/util/meson.build +++ b/util/meson.build @@ -113,4 +113,6 @@ if cpu == 'aarch64' util_ss.add(files('cpuinfo-aarch64.c')) elif cpu in ['x86', 'x86_64'] util_ss.add(files('cpuinfo-i386.c')) +elif cpu in ['ppc', 'ppc64'] + util_ss.add(files('cpuinfo-ppc.c')) endif From patchwork Tue Jun 20 11:07:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694455 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244047wrm; Tue, 20 Jun 2023 04:09:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5J5jyEOIiTjH57e6hFaPDis7GuOU6W9XsrMkrEv/QOVYSVUWo8W+P+KfHGilCMslSKDIJq X-Received: by 2002:a05:6214:194c:b0:62d:d993:e77c with SMTP id q12-20020a056214194c00b0062dd993e77cmr13583144qvk.38.1687259365830; Tue, 20 Jun 2023 04:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259365; cv=none; d=google.com; s=arc-20160816; b=a7opvTuiDe0Vdfb//g1qnWNKKxAKsI2usaTiuyzJ1nb+s8frGiO7xbv8GDrsKOVIim QtCxMAJbDW1roHTvDNW0B0srsum4BRwHMnmYsepPvvASj0Lh0aiVFm8BGPEPf5KGm9HD Dp9gPFklgEH5mBL+Rv/pC3f4HibFc9K5JYeDbR/E8RHJpeIGanqj0DBdaIIvnWfBpLZr S7KNOE248E+//XVR00Rf6PJu7lYV8yYloPKrPtmOcVhp9RSguTHLsEYOxvsGyfbbgKj0 vX+NAdV8C8LPyqli5yJuNUAaqn4UxpchvFDvhH2wjSMruFB4he9unIfy97m0M4aRiQaO NDyw== 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=OpRVYlKltusqiNlnM3FFgwEvDrZ/lV3Us1h4Ds72Lxk=; b=P6ergGvvSXNoqA6gNxWMTPX2JdQshUBHOeuVwcIPF+NkwUdTGJikJLmh/zxistV9R1 PCArQXLPBzV3+IpB3WOVnuDiBlf2x/JnfiJPjGUA5YsJ4hDGmA6grpocJj91707dBITd KeVsxVfP6TtttSrviYHfmuPzsuLCkYCPuk3qR0cUeVRzu21n/4FibCfSoNp/yuwArkDb iOI6licHU0ZnCmVdho+cSnKhWfvf/muf0ynWqMZd1xg56XBfOLXmUN3V1fSQcsHX7/qE BcW3AMEOgPxfBZpV4zKA/oGX9Qgj8UTL4bdaPu8LAdAiWkFnSPsQ8qgXNhyGh8KesIvr LHSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NbCD1AMk; 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 t9-20020a0562140c6900b0061ac2bf9f0dsi718069qvj.435.2023.06.20.04.09.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:09:25 -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=NbCD1AMk; 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 1qBZDY-0005oz-Qt; Tue, 20 Jun 2023 07:08:12 -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 1qBZDX-0005ne-8L for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:11 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDS-0004AK-N4 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:10 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-988c495f35fso235817866b.1 for ; Tue, 20 Jun 2023 04:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259284; x=1689851284; 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=OpRVYlKltusqiNlnM3FFgwEvDrZ/lV3Us1h4Ds72Lxk=; b=NbCD1AMkk59OnZ1Z/c6bH5Q2hfcOK9iZ34d+FlLuuN03n35GwnuKRNyXTKeS/Dgjg+ pmU6J2D/+K2J9xBchhAvOjStOF50uPk/+q4Uvu1cDTNYXY+g3gYVE7JjN6YWqgDesGmC PsR0dn+574iuDW+n+DvIs/K3pRl2ySyUFe23MP++9Kqp8S0fPIOrdIT7Vx7grqZXDkO9 NJ5e3BR6Ib4tutPilgI8RKGgWqHJwRNSgIonSi3RkpxPgUkgfmBBpqleWjv0j4oImR83 DJtzPRVC5zVKJAlcWLFqfUneOSDIXaHtLl9NVlFqUyL9JGX5yJalHDQKEg31R6z1zHY9 8SJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259285; x=1689851285; 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=OpRVYlKltusqiNlnM3FFgwEvDrZ/lV3Us1h4Ds72Lxk=; b=G0LYqwwTe204wJ44CoT3fNiC7LTr4STdmWLaahzyXwPgG5m0qUWnK/Cl53WYZpQGi7 mi9nOpupZs1SgW566UJjPKIWl8thrDwa7ok0A+ucBC7Qlxh/1ByU3DfTdFg29wCGZ4tw SbyMMXhj0CAsEWewO5ldHu+i8cEITh3Fm74MTb+YObDNwylQ0kIsQEj0a7i47k/Z1z18 YsjqWw1wsRAH6iHOH16JDFUu9IbX2zNH/JHhlbhY2u5Ofj5Zw0G6fT8uQMYjNjPdvbni xsaCQFmcYz6Al+Q7g7pEZoKp+mz+F/r+RCu0lPQA5Uf2cRjeEpXQJx/of5IrUL8no/st dmLg== X-Gm-Message-State: AC+VfDzYikokUMhppRTuyxkX1r6VoJ+B8w2nbtyydiIKacXuGuHL1ZIz OemtCvHOgInTViX1MO0YXL74MnHRedDZkX/sRET0wKtc X-Received: by 2002:a17:907:9811:b0:988:ce71:7a84 with SMTP id ji17-20020a170907981100b00988ce717a84mr4022488ejc.27.1687259284560; Tue, 20 Jun 2023 04:08:04 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v3 02/37] tests/multiarch: Add test-aes Date: Tue, 20 Jun 2023 13:07:23 +0200 Message-Id: <20230620110758.787479-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62f.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=unavailable 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 Use a shared driver and backends for i386, aarch64, ppc64, riscv64. Acked-by: Alex Bennée Signed-off-by: Richard Henderson --- tests/tcg/aarch64/test-aes.c | 58 ++++++++ tests/tcg/i386/test-aes.c | 68 +++++++++ tests/tcg/ppc64/test-aes.c | 116 +++++++++++++++ tests/tcg/riscv64/test-aes.c | 76 ++++++++++ tests/tcg/multiarch/test-aes-main.c.inc | 183 ++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 4 + tests/tcg/i386/Makefile.target | 4 + tests/tcg/ppc64/Makefile.target | 1 + tests/tcg/riscv64/Makefile.target | 13 ++ 9 files changed, 523 insertions(+) create mode 100644 tests/tcg/aarch64/test-aes.c create mode 100644 tests/tcg/i386/test-aes.c create mode 100644 tests/tcg/ppc64/test-aes.c create mode 100644 tests/tcg/riscv64/test-aes.c create mode 100644 tests/tcg/multiarch/test-aes-main.c.inc diff --git a/tests/tcg/aarch64/test-aes.c b/tests/tcg/aarch64/test-aes.c new file mode 100644 index 0000000000..2cd324f09b --- /dev/null +++ b/tests/tcg/aarch64/test-aes.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "../multiarch/test-aes-main.c.inc" + +bool test_SB_SR(uint8_t *o, const uint8_t *i) +{ + /* aese also adds round key, so supply zero. */ + asm("ld1 { v0.16b }, [%1]\n\t" + "movi v1.16b, #0\n\t" + "aese v0.16b, v1.16b\n\t" + "st1 { v0.16b }, [%0]" + : : "r"(o), "r"(i) : "v0", "v1", "memory"); + return true; +} + +bool test_MC(uint8_t *o, const uint8_t *i) +{ + asm("ld1 { v0.16b }, [%1]\n\t" + "aesmc v0.16b, v0.16b\n\t" + "st1 { v0.16b }, [%0]" + : : "r"(o), "r"(i) : "v0", "memory"); + return true; +} + +bool test_SB_SR_MC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + return false; +} + +bool test_ISB_ISR(uint8_t *o, const uint8_t *i) +{ + /* aesd also adds round key, so supply zero. */ + asm("ld1 { v0.16b }, [%1]\n\t" + "movi v1.16b, #0\n\t" + "aesd v0.16b, v1.16b\n\t" + "st1 { v0.16b }, [%0]" + : : "r"(o), "r"(i) : "v0", "v1", "memory"); + return true; +} + +bool test_IMC(uint8_t *o, const uint8_t *i) +{ + asm("ld1 { v0.16b }, [%1]\n\t" + "aesimc v0.16b, v0.16b\n\t" + "st1 { v0.16b }, [%0]" + : : "r"(o), "r"(i) : "v0", "memory"); + return true; +} + +bool test_ISB_ISR_AK_IMC(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + return false; +} + +bool test_ISB_ISR_IMC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + return false; +} diff --git a/tests/tcg/i386/test-aes.c b/tests/tcg/i386/test-aes.c new file mode 100644 index 0000000000..199395e6cc --- /dev/null +++ b/tests/tcg/i386/test-aes.c @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "../multiarch/test-aes-main.c.inc" +#include + +static bool test_SB_SR(uint8_t *o, const uint8_t *i) +{ + __m128i vi = _mm_loadu_si128((const __m128i_u *)i); + + /* aesenclast also adds round key, so supply zero. */ + vi = _mm_aesenclast_si128(vi, _mm_setzero_si128()); + + _mm_storeu_si128((__m128i_u *)o, vi); + return true; +} + +static bool test_MC(uint8_t *o, const uint8_t *i) +{ + return false; +} + +static bool test_SB_SR_MC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + __m128i vi = _mm_loadu_si128((const __m128i_u *)i); + __m128i vk = _mm_loadu_si128((const __m128i_u *)k); + + vi = _mm_aesenc_si128(vi, vk); + + _mm_storeu_si128((__m128i_u *)o, vi); + return true; +} + +static bool test_ISB_ISR(uint8_t *o, const uint8_t *i) +{ + __m128i vi = _mm_loadu_si128((const __m128i_u *)i); + + /* aesdeclast also adds round key, so supply zero. */ + vi = _mm_aesdeclast_si128(vi, _mm_setzero_si128()); + + _mm_storeu_si128((__m128i_u *)o, vi); + return true; +} + +static bool test_IMC(uint8_t *o, const uint8_t *i) +{ + __m128i vi = _mm_loadu_si128((const __m128i_u *)i); + + vi = _mm_aesimc_si128(vi); + + _mm_storeu_si128((__m128i_u *)o, vi); + return true; +} + +static bool test_ISB_ISR_AK_IMC(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + return false; +} + +static bool test_ISB_ISR_IMC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + __m128i vi = _mm_loadu_si128((const __m128i_u *)i); + __m128i vk = _mm_loadu_si128((const __m128i_u *)k); + + vi = _mm_aesdec_si128(vi, vk); + + _mm_storeu_si128((__m128i_u *)o, vi); + return true; +} diff --git a/tests/tcg/ppc64/test-aes.c b/tests/tcg/ppc64/test-aes.c new file mode 100644 index 0000000000..1d2be488e9 --- /dev/null +++ b/tests/tcg/ppc64/test-aes.c @@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "../multiarch/test-aes-main.c.inc" + +#undef BIG_ENDIAN +#define BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) + +static unsigned char bswap_le[16] __attribute__((aligned(16))) = { + 8,9,10,11,12,13,14,15, + 0,1,2,3,4,5,6,7 +}; + +bool test_SB_SR(uint8_t *o, const uint8_t *i) +{ + /* vcipherlast also adds round key, so supply zero. */ + if (BIG_ENDIAN) { + asm("lxvd2x 32,0,%1\n\t" + "vspltisb 1,0\n\t" + "vcipherlast 0,0,1\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i) : "memory", "v0", "v1"); + } else { + asm("lxvd2x 32,0,%1\n\t" + "lxvd2x 34,0,%2\n\t" + "vspltisb 1,0\n\t" + "vperm 0,0,0,2\n\t" + "vcipherlast 0,0,1\n\t" + "vperm 0,0,0,2\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i), "r"(bswap_le) : "memory", "v0", "v1", "v2"); + } + return true; +} + +bool test_MC(uint8_t *o, const uint8_t *i) +{ + return false; +} + +bool test_SB_SR_MC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + if (BIG_ENDIAN) { + asm("lxvd2x 32,0,%1\n\t" + "lxvd2x 33,0,%2\n\t" + "vcipher 0,0,1\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i), "r"(k) : "memory", "v0", "v1"); + } else { + asm("lxvd2x 32,0,%1\n\t" + "lxvd2x 33,0,%2\n\t" + "lxvd2x 34,0,%3\n\t" + "vperm 0,0,0,2\n\t" + "vperm 1,1,1,2\n\t" + "vcipher 0,0,1\n\t" + "vperm 0,0,0,2\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i), "r"(k), "r"(bswap_le) + : "memory", "v0", "v1", "v2"); + } + return true; +} + +bool test_ISB_ISR(uint8_t *o, const uint8_t *i) +{ + /* vcipherlast also adds round key, so supply zero. */ + if (BIG_ENDIAN) { + asm("lxvd2x 32,0,%1\n\t" + "vspltisb 1,0\n\t" + "vncipherlast 0,0,1\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i) : "memory", "v0", "v1"); + } else { + asm("lxvd2x 32,0,%1\n\t" + "lxvd2x 34,0,%2\n\t" + "vspltisb 1,0\n\t" + "vperm 0,0,0,2\n\t" + "vncipherlast 0,0,1\n\t" + "vperm 0,0,0,2\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i), "r"(bswap_le) : "memory", "v0", "v1", "v2"); + } + return true; +} + +bool test_IMC(uint8_t *o, const uint8_t *i) +{ + return false; +} + +bool test_ISB_ISR_AK_IMC(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + if (BIG_ENDIAN) { + asm("lxvd2x 32,0,%1\n\t" + "lxvd2x 33,0,%2\n\t" + "vncipher 0,0,1\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i), "r"(k) : "memory", "v0", "v1"); + } else { + asm("lxvd2x 32,0,%1\n\t" + "lxvd2x 33,0,%2\n\t" + "lxvd2x 34,0,%3\n\t" + "vperm 0,0,0,2\n\t" + "vperm 1,1,1,2\n\t" + "vncipher 0,0,1\n\t" + "vperm 0,0,0,2\n\t" + "stxvd2x 32,0,%0" + : : "r"(o), "r"(i), "r"(k), "r"(bswap_le) + : "memory", "v0", "v1", "v2"); + } + return true; +} + +bool test_ISB_ISR_IMC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + return false; +} diff --git a/tests/tcg/riscv64/test-aes.c b/tests/tcg/riscv64/test-aes.c new file mode 100644 index 0000000000..3d7ef0e33a --- /dev/null +++ b/tests/tcg/riscv64/test-aes.c @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "../multiarch/test-aes-main.c.inc" + +bool test_SB_SR(uint8_t *o, const uint8_t *i) +{ + uint64_t *o8 = (uint64_t *)o; + const uint64_t *i8 = (const uint64_t *)i; + + asm("aes64es %0,%2,%3\n\t" + "aes64es %1,%3,%2" + : "=&r"(o8[0]), "=&r"(o8[1]) : "r"(i8[0]), "r"(i8[1])); + return true; +} + +bool test_MC(uint8_t *o, const uint8_t *i) +{ + return false; +} + +bool test_SB_SR_MC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + uint64_t *o8 = (uint64_t *)o; + const uint64_t *i8 = (const uint64_t *)i; + const uint64_t *k8 = (const uint64_t *)k; + + asm("aes64esm %0,%2,%3\n\t" + "aes64esm %1,%3,%2\n\t" + "xor %0,%0,%4\n\t" + "xor %1,%1,%5" + : "=&r"(o8[0]), "=&r"(o8[1]) + : "r"(i8[0]), "r"(i8[1]), "r"(k8[0]), "r"(k8[1])); + return true; +} + +bool test_ISB_ISR(uint8_t *o, const uint8_t *i) +{ + uint64_t *o8 = (uint64_t *)o; + const uint64_t *i8 = (const uint64_t *)i; + + asm("aes64ds %0,%2,%3\n\t" + "aes64ds %1,%3,%2" + : "=&r"(o8[0]), "=&r"(o8[1]) : "r"(i8[0]), "r"(i8[1])); + return true; +} + +bool test_IMC(uint8_t *o, const uint8_t *i) +{ + uint64_t *o8 = (uint64_t *)o; + const uint64_t *i8 = (const uint64_t *)i; + + asm("aes64im %0,%0\n\t" + "aes64im %1,%1" + : "=r"(o8[0]), "=r"(o8[1]) : "0"(i8[0]), "1"(i8[1])); + return true; +} + +bool test_ISB_ISR_AK_IMC(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + return false; +} + +bool test_ISB_ISR_IMC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k) +{ + uint64_t *o8 = (uint64_t *)o; + const uint64_t *i8 = (const uint64_t *)i; + const uint64_t *k8 = (const uint64_t *)k; + + asm("aes64dsm %0,%2,%3\n\t" + "aes64dsm %1,%3,%2\n\t" + "xor %0,%0,%4\n\t" + "xor %1,%1,%5" + : "=&r"(o8[0]), "=&r"(o8[1]) + : "r"(i8[0]), "r"(i8[1]), "r"(k8[0]), "r"(k8[1])); + return true; +} diff --git a/tests/tcg/multiarch/test-aes-main.c.inc b/tests/tcg/multiarch/test-aes-main.c.inc new file mode 100644 index 0000000000..0039f8ba55 --- /dev/null +++ b/tests/tcg/multiarch/test-aes-main.c.inc @@ -0,0 +1,183 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include +#include +#include +#include +#include + +static bool test_SB_SR(uint8_t *o, const uint8_t *i); +static bool test_MC(uint8_t *o, const uint8_t *i); +static bool test_SB_SR_MC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k); + +static bool test_ISB_ISR(uint8_t *o, const uint8_t *i); +static bool test_IMC(uint8_t *o, const uint8_t *i); +static bool test_ISB_ISR_AK_IMC(uint8_t *o, const uint8_t *i, const uint8_t *k); +static bool test_ISB_ISR_IMC_AK(uint8_t *o, const uint8_t *i, const uint8_t *k); + +/* + * From https://doi.org/10.6028/NIST.FIPS.197-upd1, + * Appendix B -- Cipher Example + * + * Note that the formatting of the 4x4 matrices in the document is + * column-major, whereas C is row-major. Therefore to get the bytes + * in the same order as the text, the matrices are transposed. + * + * Note that we are not going to test SubBytes or ShiftRows separately, + * so the "After SubBytes" column is omitted, using only the combined + * result "After ShiftRows" column. + */ + +/* Ease the inline assembly by aligning everything. */ +typedef struct { + uint8_t b[16] __attribute__((aligned(16))); +} State; + +typedef struct { + State start, after_sr, after_mc, round_key; +} Round; + +static const Round rounds[] = { + /* Round 1 */ + { { { 0x19, 0x3d, 0xe3, 0xbe, /* start */ + 0xa0, 0xf4, 0xe2, 0x2b, + 0x9a, 0xc6, 0x8d, 0x2a, + 0xe9, 0xf8, 0x48, 0x08, } }, + + { { 0xd4, 0xbf, 0x5d, 0x30, /* after shiftrows */ + 0xe0, 0xb4, 0x52, 0xae, + 0xb8, 0x41, 0x11, 0xf1, + 0x1e, 0x27, 0x98, 0xe5, } }, + + { { 0x04, 0x66, 0x81, 0xe5, /* after mixcolumns */ + 0xe0, 0xcb, 0x19, 0x9a, + 0x48, 0xf8, 0xd3, 0x7a, + 0x28, 0x06, 0x26, 0x4c, } }, + + { { 0xa0, 0xfa, 0xfe, 0x17, /* round key */ + 0x88, 0x54, 0x2c, 0xb1, + 0x23, 0xa3, 0x39, 0x39, + 0x2a, 0x6c, 0x76, 0x05, } } }, + + /* Round 2 */ + { { { 0xa4, 0x9c, 0x7f, 0xf2, /* start */ + 0x68, 0x9f, 0x35, 0x2b, + 0x6b, 0x5b, 0xea, 0x43, + 0x02, 0x6a, 0x50, 0x49, } }, + + { { 0x49, 0xdb, 0x87, 0x3b, /* after shiftrows */ + 0x45, 0x39, 0x53, 0x89, + 0x7f, 0x02, 0xd2, 0xf1, + 0x77, 0xde, 0x96, 0x1a, } }, + + { { 0x58, 0x4d, 0xca, 0xf1, /* after mixcolumns */ + 0x1b, 0x4b, 0x5a, 0xac, + 0xdb, 0xe7, 0xca, 0xa8, + 0x1b, 0x6b, 0xb0, 0xe5, } }, + + { { 0xf2, 0xc2, 0x95, 0xf2, /* round key */ + 0x7a, 0x96, 0xb9, 0x43, + 0x59, 0x35, 0x80, 0x7a, + 0x73, 0x59, 0xf6, 0x7f, } } }, + + /* Round 3 */ + { { { 0xaa, 0x8f, 0x5f, 0x03, /* start */ + 0x61, 0xdd, 0xe3, 0xef, + 0x82, 0xd2, 0x4a, 0xd2, + 0x68, 0x32, 0x46, 0x9a, } }, + + { { 0xac, 0xc1, 0xd6, 0xb8, /* after shiftrows */ + 0xef, 0xb5, 0x5a, 0x7b, + 0x13, 0x23, 0xcf, 0xdf, + 0x45, 0x73, 0x11, 0xb5, } }, + + { { 0x75, 0xec, 0x09, 0x93, /* after mixcolumns */ + 0x20, 0x0b, 0x63, 0x33, + 0x53, 0xc0, 0xcf, 0x7c, + 0xbb, 0x25, 0xd0, 0xdc, } }, + + { { 0x3d, 0x80, 0x47, 0x7d, /* round key */ + 0x47, 0x16, 0xfe, 0x3e, + 0x1e, 0x23, 0x7e, 0x44, + 0x6d, 0x7a, 0x88, 0x3b, } } }, +}; + +static void verify_log(const char *prefix, const State *s) +{ + printf("%s:", prefix); + for (int i = 0; i < sizeof(State); ++i) { + printf(" %02x", s->b[i]); + } + printf("\n"); +} + +static void verify(const State *ref, const State *tst, const char *which) +{ + if (!memcmp(ref, tst, sizeof(State))) { + return; + } + + printf("Mismatch on %s\n", which); + verify_log("ref", ref); + verify_log("tst", tst); + exit(EXIT_FAILURE); +} + +int main() +{ + int i, n = sizeof(rounds) / sizeof(Round); + State t; + + for (i = 0; i < n; ++i) { + if (test_SB_SR(t.b, rounds[i].start.b)) { + verify(&rounds[i].after_sr, &t, "SB+SR"); + } + } + + for (i = 0; i < n; ++i) { + if (test_MC(t.b, rounds[i].after_sr.b)) { + verify(&rounds[i].after_mc, &t, "MC"); + } + } + + /* The kernel of Cipher(). */ + for (i = 0; i < n - 1; ++i) { + if (test_SB_SR_MC_AK(t.b, rounds[i].start.b, rounds[i].round_key.b)) { + verify(&rounds[i + 1].start, &t, "SB+SR+MC+AK"); + } + } + + for (i = 0; i < n; ++i) { + if (test_ISB_ISR(t.b, rounds[i].after_sr.b)) { + verify(&rounds[i].start, &t, "ISB+ISR"); + } + } + + for (i = 0; i < n; ++i) { + if (test_IMC(t.b, rounds[i].after_mc.b)) { + verify(&rounds[i].after_sr, &t, "IMC"); + } + } + + /* The kernel of InvCipher(). */ + for (i = n - 1; i > 0; --i) { + if (test_ISB_ISR_AK_IMC(t.b, rounds[i].after_sr.b, + rounds[i - 1].round_key.b)) { + verify(&rounds[i - 1].after_sr, &t, "ISB+ISR+AK+IMC"); + } + } + + /* + * The kernel of EqInvCipher(). + * We must compute a different round key: apply InvMixColumns to + * the standard round key, per KeyExpansion vs KeyExpansionEIC. + */ + for (i = 1; i < n; ++i) { + if (test_IMC(t.b, rounds[i - 1].round_key.b) && + test_ISB_ISR_IMC_AK(t.b, rounds[i].after_sr.b, t.b)) { + verify(&rounds[i - 1].after_sr, &t, "ISB+ISR+IMC+AK"); + } + } + + return EXIT_SUCCESS; +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 3430fd3cd8..d217474d0d 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -74,6 +74,10 @@ endif AARCH64_TESTS += sve-ioctls sve-ioctls: CFLAGS+=-march=armv8.1-a+sve +AARCH64_TESTS += test-aes +test-aes: CFLAGS += -O -march=armv8-a+aes +test-aes: test-aes-main.c.inc + # Vector SHA1 sha1-vector: CFLAGS=-O3 sha1-vector: sha1.c diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target index 821822ed0c..3ba61e3880 100644 --- a/tests/tcg/i386/Makefile.target +++ b/tests/tcg/i386/Makefile.target @@ -28,6 +28,10 @@ run-test-i386-bmi2: QEMU_OPTS += -cpu max test-i386-adcox: CFLAGS=-O2 run-test-i386-adcox: QEMU_OPTS += -cpu max +test-aes: CFLAGS += -O -msse2 -maes +test-aes: test-aes-main.c.inc +run-test-aes: QEMU_OPTS += -cpu max + # # hello-i386 is a barebones app # diff --git a/tests/tcg/ppc64/Makefile.target b/tests/tcg/ppc64/Makefile.target index b084963b9a..5721c159f2 100644 --- a/tests/tcg/ppc64/Makefile.target +++ b/tests/tcg/ppc64/Makefile.target @@ -36,5 +36,6 @@ run-vector: QEMU_OPTS += -cpu POWER10 PPC64_TESTS += signal_save_restore_xer PPC64_TESTS += xxspltw +PPC64_TESTS += test-aes TESTS += $(PPC64_TESTS) diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target index 9973ba3b5f..4b14a67f48 100644 --- a/tests/tcg/riscv64/Makefile.target +++ b/tests/tcg/riscv64/Makefile.target @@ -1,6 +1,13 @@ # -*- Mode: makefile -*- # RISC-V specific tweaks +config-cc.mak: Makefile + $(quiet-@)( \ + $(call cc-option,-mrv64g_zk, CROSS_CC_HAS_ZK) \ + ) 3> config-cc.mak + +-include config-cc.mak + VPATH += $(SRC_PATH)/tests/tcg/riscv64 TESTS += test-div TESTS += noexec @@ -9,3 +16,9 @@ TESTS += noexec TESTS += test-noc test-noc: LDFLAGS = -nostdlib -static run-test-noc: QEMU_OPTS += -cpu rv64,c=false + +ifneq ($(CROSS_CC_HAS_ZK),) +TESTS += test-aes +test-aes: CFLAGS += -O -march=rv64gzk +run-test-aes: QEMU_OPTS += -cpu rv64,zk=on +endif From patchwork Tue Jun 20 11:07:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694460 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244769wrm; Tue, 20 Jun 2023 04:11:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7NXTPLoL9nMZckcb3qUQ9ovZLTM/BVpThjUwy9hwXZLi7ws3iCTezcAAKUYzpdlZP9oQAz X-Received: by 2002:a05:620a:3e8b:b0:762:3f5d:4c8b with SMTP id tv11-20020a05620a3e8b00b007623f5d4c8bmr8879368qkn.46.1687259464611; Tue, 20 Jun 2023 04:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259464; cv=none; d=google.com; s=arc-20160816; b=PbT3HtokG9tnHClUO3srXZkgZRS0Eu99jWxEgeLNLHhr2wvPFD/7nWIhy0YwtQSUq6 6/jztQLhdOugV0y+r/+UTT5N7sfENy9H74GfXM+p9f+0dGgiyPPz6GJz1EA9l1z5tM3V hdsQmlMPtdStmRLnWE8v6nFEYixzxk8ueDM4imcKgsQfUd+lcmJjLm6RhpC3rX1j76VY gxav6yC9j9fl9g74eQSnvGroUtCwPJru8EQ37ZQg/AsbgGV3859cJus8pZvORHYVUpSb Yd7zFP9Bejj7CArFp3n58kQbxmz/WssVUBUgt48OYE+iNOwScVRJV/uR2S+9oe25vAi2 e3pw== 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=oDegPUeqJ78xBO4pGFYHur8C+Wi6RpRKy5K2/MXINzU=; b=QHUq6/4X6cjf/sLfpdP4gZjxuW8btJAdQdvVH472fturIwydgl9m0SyAlgCq/kV4mP U/yBgc4veXoVBFc+nXbb3WLN4fXs7eB3h/KdgNZSj4O8hNpFPOFKQGCHBXpXM2mFuYEt uuFhw7GX+OdfR/8DTD5S19ZMY/ndrtWbRt82qpWr6KFNN5+7EEMxcp6aGtW6pVAmj+0O mZuWuiQWb/YRF6wNHA12tcxEP4q/8Tpw1wENbyHjb70Oj3MEhrgcsfhd+mgbQ93XdALQ XmasFDynYnrRLAUSS1IBWBynmgAoDFPisshHJgf3s98B883txCfptXsssQZ2Dbn7Um1S wRQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rRnC7LzY; 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 c21-20020ae9e215000000b00763b5beda2csi240644qkc.417.2023.06.20.04.11.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:11:04 -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=rRnC7LzY; 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 1qBZDZ-0005qD-I2; Tue, 20 Jun 2023 07:08:13 -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 1qBZDY-0005od-1Y for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:12 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDT-0004Ap-AH for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:11 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9891c73e0fbso143512266b.1 for ; Tue, 20 Jun 2023 04:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259286; x=1689851286; 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=oDegPUeqJ78xBO4pGFYHur8C+Wi6RpRKy5K2/MXINzU=; b=rRnC7LzYIb5DjcIaKNvdgfq7ylGGi2hTWnsWGGUYj4pgr0vNbfbLji+YphsT8pzZZj iw6xkDzBUKqsyz/XJeedGn7XWUoGXNlGztBbNEMeW9cFtiqkCkPJmNf0vXndFYBZAiVB bJtpJfHH7iYMHwtuFvGW/AI+eKIVbDfZbeVuOJfNYGSQTBPYEN5BiUf5LdUDf5WPT6SQ b65pWsJ25Qptaq4qiHDUhbnoZ5Fh3A4sTsPD0QjaAKPgqn5v8SezqUAEm0WbU88xTR3U GPAhUIBHdoueoIU6Qu7p6aRwTln2HQEYTaoD+vNfTE5pStuBFt9GMIkS2OiPqcBph+c6 1YsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259286; x=1689851286; 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=oDegPUeqJ78xBO4pGFYHur8C+Wi6RpRKy5K2/MXINzU=; b=Nj+SDqByzBIpT9mfMPFSy0GFdyTwR1LY2rNhnmDVaPsX/4uqINYtIbpm/U3YqxK/Ag +U8YPS5I11xHNMzLmbXIF9kmJ1tK5aDCewDsTo3jtind7bp3f42SgupTQr/6Wz1NpUOe vwQws94JRT16LhhBPpbBYmMPRaG8JyreONWhEOswo1o6PZqIypcOeUWBkNHbHZmHmrlf fRBqyZ2mqmSQyHZIY/31KvdQvCUTBu2IsCV+SqYJrbTGh6+zY3Ig0xcrt4plx7DxqkOt Oc7FqV75DP8nSt0nZzUf5Ser2t56epblGpa7RMns+hqe0KdRthFUp1vOvj+1K4FvOnCu G6YQ== X-Gm-Message-State: AC+VfDzEqeCM/pHms8N0M/1PQjYS/2/NWz6kOjhpjXrpDJIpHpEHVK1F oFoe9uphAZjIXVa82dkt6gqiAel9ni2qGJ9kZ3i8w/Dh X-Received: by 2002:a17:907:d26:b0:977:d468:827 with SMTP id gn38-20020a1709070d2600b00977d4680827mr12299912ejc.17.1687259285802; Tue, 20 Jun 2023 04:08:05 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 03/37] target/arm: Move aesmc and aesimc tables to crypto/aes.c Date: Tue, 20 Jun 2023 13:07:24 +0200 Message-Id: <20230620110758.787479-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62f.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=unavailable 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 We do not currently have a table in crypto/ for just MixColumns. Move both tables for consistency. Acked-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/crypto/aes.h | 6 ++ crypto/aes.c | 140 ++++++++++++++++++++++++++++++++ target/arm/tcg/crypto_helper.c | 143 ++------------------------------- 3 files changed, 151 insertions(+), 138 deletions(-) diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 822d64588c..24b073d569 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -34,6 +34,12 @@ extern const uint8_t AES_isbox[256]; extern const uint8_t AES_shifts[16]; extern const uint8_t AES_ishifts[16]; +/* AES MixColumns, for use with rot32. */ +extern const uint32_t AES_mc_rot[256]; + +/* AES InvMixColumns, for use with rot32. */ +extern const uint32_t AES_imc_rot[256]; + /* AES InvMixColumns */ /* AES_imc[x][0] = [x].[0e, 09, 0d, 0b]; */ /* AES_imc[x][1] = [x].[0b, 0e, 09, 0d]; */ diff --git a/crypto/aes.c b/crypto/aes.c index af72ff7779..67bb74b8e3 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -116,6 +116,146 @@ const uint8_t AES_ishifts[16] = { 0, 13, 10, 7, 4, 1, 14, 11, 8, 5, 2, 15, 12, 9, 6, 3 }; +/* + * MixColumns lookup table, for use with rot32. + */ +const uint32_t AES_mc_rot[256] = { + 0x00000000, 0x03010102, 0x06020204, 0x05030306, + 0x0c040408, 0x0f05050a, 0x0a06060c, 0x0907070e, + 0x18080810, 0x1b090912, 0x1e0a0a14, 0x1d0b0b16, + 0x140c0c18, 0x170d0d1a, 0x120e0e1c, 0x110f0f1e, + 0x30101020, 0x33111122, 0x36121224, 0x35131326, + 0x3c141428, 0x3f15152a, 0x3a16162c, 0x3917172e, + 0x28181830, 0x2b191932, 0x2e1a1a34, 0x2d1b1b36, + 0x241c1c38, 0x271d1d3a, 0x221e1e3c, 0x211f1f3e, + 0x60202040, 0x63212142, 0x66222244, 0x65232346, + 0x6c242448, 0x6f25254a, 0x6a26264c, 0x6927274e, + 0x78282850, 0x7b292952, 0x7e2a2a54, 0x7d2b2b56, + 0x742c2c58, 0x772d2d5a, 0x722e2e5c, 0x712f2f5e, + 0x50303060, 0x53313162, 0x56323264, 0x55333366, + 0x5c343468, 0x5f35356a, 0x5a36366c, 0x5937376e, + 0x48383870, 0x4b393972, 0x4e3a3a74, 0x4d3b3b76, + 0x443c3c78, 0x473d3d7a, 0x423e3e7c, 0x413f3f7e, + 0xc0404080, 0xc3414182, 0xc6424284, 0xc5434386, + 0xcc444488, 0xcf45458a, 0xca46468c, 0xc947478e, + 0xd8484890, 0xdb494992, 0xde4a4a94, 0xdd4b4b96, + 0xd44c4c98, 0xd74d4d9a, 0xd24e4e9c, 0xd14f4f9e, + 0xf05050a0, 0xf35151a2, 0xf65252a4, 0xf55353a6, + 0xfc5454a8, 0xff5555aa, 0xfa5656ac, 0xf95757ae, + 0xe85858b0, 0xeb5959b2, 0xee5a5ab4, 0xed5b5bb6, + 0xe45c5cb8, 0xe75d5dba, 0xe25e5ebc, 0xe15f5fbe, + 0xa06060c0, 0xa36161c2, 0xa66262c4, 0xa56363c6, + 0xac6464c8, 0xaf6565ca, 0xaa6666cc, 0xa96767ce, + 0xb86868d0, 0xbb6969d2, 0xbe6a6ad4, 0xbd6b6bd6, + 0xb46c6cd8, 0xb76d6dda, 0xb26e6edc, 0xb16f6fde, + 0x907070e0, 0x937171e2, 0x967272e4, 0x957373e6, + 0x9c7474e8, 0x9f7575ea, 0x9a7676ec, 0x997777ee, + 0x887878f0, 0x8b7979f2, 0x8e7a7af4, 0x8d7b7bf6, + 0x847c7cf8, 0x877d7dfa, 0x827e7efc, 0x817f7ffe, + 0x9b80801b, 0x98818119, 0x9d82821f, 0x9e83831d, + 0x97848413, 0x94858511, 0x91868617, 0x92878715, + 0x8388880b, 0x80898909, 0x858a8a0f, 0x868b8b0d, + 0x8f8c8c03, 0x8c8d8d01, 0x898e8e07, 0x8a8f8f05, + 0xab90903b, 0xa8919139, 0xad92923f, 0xae93933d, + 0xa7949433, 0xa4959531, 0xa1969637, 0xa2979735, + 0xb398982b, 0xb0999929, 0xb59a9a2f, 0xb69b9b2d, + 0xbf9c9c23, 0xbc9d9d21, 0xb99e9e27, 0xba9f9f25, + 0xfba0a05b, 0xf8a1a159, 0xfda2a25f, 0xfea3a35d, + 0xf7a4a453, 0xf4a5a551, 0xf1a6a657, 0xf2a7a755, + 0xe3a8a84b, 0xe0a9a949, 0xe5aaaa4f, 0xe6abab4d, + 0xefacac43, 0xecadad41, 0xe9aeae47, 0xeaafaf45, + 0xcbb0b07b, 0xc8b1b179, 0xcdb2b27f, 0xceb3b37d, + 0xc7b4b473, 0xc4b5b571, 0xc1b6b677, 0xc2b7b775, + 0xd3b8b86b, 0xd0b9b969, 0xd5baba6f, 0xd6bbbb6d, + 0xdfbcbc63, 0xdcbdbd61, 0xd9bebe67, 0xdabfbf65, + 0x5bc0c09b, 0x58c1c199, 0x5dc2c29f, 0x5ec3c39d, + 0x57c4c493, 0x54c5c591, 0x51c6c697, 0x52c7c795, + 0x43c8c88b, 0x40c9c989, 0x45caca8f, 0x46cbcb8d, + 0x4fcccc83, 0x4ccdcd81, 0x49cece87, 0x4acfcf85, + 0x6bd0d0bb, 0x68d1d1b9, 0x6dd2d2bf, 0x6ed3d3bd, + 0x67d4d4b3, 0x64d5d5b1, 0x61d6d6b7, 0x62d7d7b5, + 0x73d8d8ab, 0x70d9d9a9, 0x75dadaaf, 0x76dbdbad, + 0x7fdcdca3, 0x7cdddda1, 0x79dedea7, 0x7adfdfa5, + 0x3be0e0db, 0x38e1e1d9, 0x3de2e2df, 0x3ee3e3dd, + 0x37e4e4d3, 0x34e5e5d1, 0x31e6e6d7, 0x32e7e7d5, + 0x23e8e8cb, 0x20e9e9c9, 0x25eaeacf, 0x26ebebcd, + 0x2fececc3, 0x2cededc1, 0x29eeeec7, 0x2aefefc5, + 0x0bf0f0fb, 0x08f1f1f9, 0x0df2f2ff, 0x0ef3f3fd, + 0x07f4f4f3, 0x04f5f5f1, 0x01f6f6f7, 0x02f7f7f5, + 0x13f8f8eb, 0x10f9f9e9, 0x15fafaef, 0x16fbfbed, + 0x1ffcfce3, 0x1cfdfde1, 0x19fefee7, 0x1affffe5, +}; + +/* + * Inverse MixColumns lookup table, for use with rot32. + */ +const uint32_t AES_imc_rot[256] = { + 0x00000000, 0x0b0d090e, 0x161a121c, 0x1d171b12, + 0x2c342438, 0x27392d36, 0x3a2e3624, 0x31233f2a, + 0x58684870, 0x5365417e, 0x4e725a6c, 0x457f5362, + 0x745c6c48, 0x7f516546, 0x62467e54, 0x694b775a, + 0xb0d090e0, 0xbbdd99ee, 0xa6ca82fc, 0xadc78bf2, + 0x9ce4b4d8, 0x97e9bdd6, 0x8afea6c4, 0x81f3afca, + 0xe8b8d890, 0xe3b5d19e, 0xfea2ca8c, 0xf5afc382, + 0xc48cfca8, 0xcf81f5a6, 0xd296eeb4, 0xd99be7ba, + 0x7bbb3bdb, 0x70b632d5, 0x6da129c7, 0x66ac20c9, + 0x578f1fe3, 0x5c8216ed, 0x41950dff, 0x4a9804f1, + 0x23d373ab, 0x28de7aa5, 0x35c961b7, 0x3ec468b9, + 0x0fe75793, 0x04ea5e9d, 0x19fd458f, 0x12f04c81, + 0xcb6bab3b, 0xc066a235, 0xdd71b927, 0xd67cb029, + 0xe75f8f03, 0xec52860d, 0xf1459d1f, 0xfa489411, + 0x9303e34b, 0x980eea45, 0x8519f157, 0x8e14f859, + 0xbf37c773, 0xb43ace7d, 0xa92dd56f, 0xa220dc61, + 0xf66d76ad, 0xfd607fa3, 0xe07764b1, 0xeb7a6dbf, + 0xda595295, 0xd1545b9b, 0xcc434089, 0xc74e4987, + 0xae053edd, 0xa50837d3, 0xb81f2cc1, 0xb31225cf, + 0x82311ae5, 0x893c13eb, 0x942b08f9, 0x9f2601f7, + 0x46bde64d, 0x4db0ef43, 0x50a7f451, 0x5baafd5f, + 0x6a89c275, 0x6184cb7b, 0x7c93d069, 0x779ed967, + 0x1ed5ae3d, 0x15d8a733, 0x08cfbc21, 0x03c2b52f, + 0x32e18a05, 0x39ec830b, 0x24fb9819, 0x2ff69117, + 0x8dd64d76, 0x86db4478, 0x9bcc5f6a, 0x90c15664, + 0xa1e2694e, 0xaaef6040, 0xb7f87b52, 0xbcf5725c, + 0xd5be0506, 0xdeb30c08, 0xc3a4171a, 0xc8a91e14, + 0xf98a213e, 0xf2872830, 0xef903322, 0xe49d3a2c, + 0x3d06dd96, 0x360bd498, 0x2b1ccf8a, 0x2011c684, + 0x1132f9ae, 0x1a3ff0a0, 0x0728ebb2, 0x0c25e2bc, + 0x656e95e6, 0x6e639ce8, 0x737487fa, 0x78798ef4, + 0x495ab1de, 0x4257b8d0, 0x5f40a3c2, 0x544daacc, + 0xf7daec41, 0xfcd7e54f, 0xe1c0fe5d, 0xeacdf753, + 0xdbeec879, 0xd0e3c177, 0xcdf4da65, 0xc6f9d36b, + 0xafb2a431, 0xa4bfad3f, 0xb9a8b62d, 0xb2a5bf23, + 0x83868009, 0x888b8907, 0x959c9215, 0x9e919b1b, + 0x470a7ca1, 0x4c0775af, 0x51106ebd, 0x5a1d67b3, + 0x6b3e5899, 0x60335197, 0x7d244a85, 0x7629438b, + 0x1f6234d1, 0x146f3ddf, 0x097826cd, 0x02752fc3, + 0x335610e9, 0x385b19e7, 0x254c02f5, 0x2e410bfb, + 0x8c61d79a, 0x876cde94, 0x9a7bc586, 0x9176cc88, + 0xa055f3a2, 0xab58faac, 0xb64fe1be, 0xbd42e8b0, + 0xd4099fea, 0xdf0496e4, 0xc2138df6, 0xc91e84f8, + 0xf83dbbd2, 0xf330b2dc, 0xee27a9ce, 0xe52aa0c0, + 0x3cb1477a, 0x37bc4e74, 0x2aab5566, 0x21a65c68, + 0x10856342, 0x1b886a4c, 0x069f715e, 0x0d927850, + 0x64d90f0a, 0x6fd40604, 0x72c31d16, 0x79ce1418, + 0x48ed2b32, 0x43e0223c, 0x5ef7392e, 0x55fa3020, + 0x01b79aec, 0x0aba93e2, 0x17ad88f0, 0x1ca081fe, + 0x2d83bed4, 0x268eb7da, 0x3b99acc8, 0x3094a5c6, + 0x59dfd29c, 0x52d2db92, 0x4fc5c080, 0x44c8c98e, + 0x75ebf6a4, 0x7ee6ffaa, 0x63f1e4b8, 0x68fcedb6, + 0xb1670a0c, 0xba6a0302, 0xa77d1810, 0xac70111e, + 0x9d532e34, 0x965e273a, 0x8b493c28, 0x80443526, + 0xe90f427c, 0xe2024b72, 0xff155060, 0xf418596e, + 0xc53b6644, 0xce366f4a, 0xd3217458, 0xd82c7d56, + 0x7a0ca137, 0x7101a839, 0x6c16b32b, 0x671bba25, + 0x5638850f, 0x5d358c01, 0x40229713, 0x4b2f9e1d, + 0x2264e947, 0x2969e049, 0x347efb5b, 0x3f73f255, + 0x0e50cd7f, 0x055dc471, 0x184adf63, 0x1347d66d, + 0xcadc31d7, 0xc1d138d9, 0xdcc623cb, 0xd7cb2ac5, + 0xe6e815ef, 0xede51ce1, 0xf0f207f3, 0xfbff0efd, + 0x92b479a7, 0x99b970a9, 0x84ae6bbb, 0x8fa362b5, + 0xbe805d9f, 0xb58d5491, 0xa89a4f83, 0xa397468d, +}; + /* AES_imc[x][0] = [x].[0e, 09, 0d, 0b]; */ /* AES_imc[x][1] = [x].[0b, 0e, 09, 0d]; */ /* AES_imc[x][2] = [x].[0d, 0b, 0e, 09]; */ diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index d28690321f..06254939d2 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -80,149 +80,16 @@ void HELPER(crypto_aese)(void *vd, void *vn, void *vm, uint32_t desc) static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, bool decrypt) { - static uint32_t const mc[][256] = { { - /* MixColumns lookup table */ - 0x00000000, 0x03010102, 0x06020204, 0x05030306, - 0x0c040408, 0x0f05050a, 0x0a06060c, 0x0907070e, - 0x18080810, 0x1b090912, 0x1e0a0a14, 0x1d0b0b16, - 0x140c0c18, 0x170d0d1a, 0x120e0e1c, 0x110f0f1e, - 0x30101020, 0x33111122, 0x36121224, 0x35131326, - 0x3c141428, 0x3f15152a, 0x3a16162c, 0x3917172e, - 0x28181830, 0x2b191932, 0x2e1a1a34, 0x2d1b1b36, - 0x241c1c38, 0x271d1d3a, 0x221e1e3c, 0x211f1f3e, - 0x60202040, 0x63212142, 0x66222244, 0x65232346, - 0x6c242448, 0x6f25254a, 0x6a26264c, 0x6927274e, - 0x78282850, 0x7b292952, 0x7e2a2a54, 0x7d2b2b56, - 0x742c2c58, 0x772d2d5a, 0x722e2e5c, 0x712f2f5e, - 0x50303060, 0x53313162, 0x56323264, 0x55333366, - 0x5c343468, 0x5f35356a, 0x5a36366c, 0x5937376e, - 0x48383870, 0x4b393972, 0x4e3a3a74, 0x4d3b3b76, - 0x443c3c78, 0x473d3d7a, 0x423e3e7c, 0x413f3f7e, - 0xc0404080, 0xc3414182, 0xc6424284, 0xc5434386, - 0xcc444488, 0xcf45458a, 0xca46468c, 0xc947478e, - 0xd8484890, 0xdb494992, 0xde4a4a94, 0xdd4b4b96, - 0xd44c4c98, 0xd74d4d9a, 0xd24e4e9c, 0xd14f4f9e, - 0xf05050a0, 0xf35151a2, 0xf65252a4, 0xf55353a6, - 0xfc5454a8, 0xff5555aa, 0xfa5656ac, 0xf95757ae, - 0xe85858b0, 0xeb5959b2, 0xee5a5ab4, 0xed5b5bb6, - 0xe45c5cb8, 0xe75d5dba, 0xe25e5ebc, 0xe15f5fbe, - 0xa06060c0, 0xa36161c2, 0xa66262c4, 0xa56363c6, - 0xac6464c8, 0xaf6565ca, 0xaa6666cc, 0xa96767ce, - 0xb86868d0, 0xbb6969d2, 0xbe6a6ad4, 0xbd6b6bd6, - 0xb46c6cd8, 0xb76d6dda, 0xb26e6edc, 0xb16f6fde, - 0x907070e0, 0x937171e2, 0x967272e4, 0x957373e6, - 0x9c7474e8, 0x9f7575ea, 0x9a7676ec, 0x997777ee, - 0x887878f0, 0x8b7979f2, 0x8e7a7af4, 0x8d7b7bf6, - 0x847c7cf8, 0x877d7dfa, 0x827e7efc, 0x817f7ffe, - 0x9b80801b, 0x98818119, 0x9d82821f, 0x9e83831d, - 0x97848413, 0x94858511, 0x91868617, 0x92878715, - 0x8388880b, 0x80898909, 0x858a8a0f, 0x868b8b0d, - 0x8f8c8c03, 0x8c8d8d01, 0x898e8e07, 0x8a8f8f05, - 0xab90903b, 0xa8919139, 0xad92923f, 0xae93933d, - 0xa7949433, 0xa4959531, 0xa1969637, 0xa2979735, - 0xb398982b, 0xb0999929, 0xb59a9a2f, 0xb69b9b2d, - 0xbf9c9c23, 0xbc9d9d21, 0xb99e9e27, 0xba9f9f25, - 0xfba0a05b, 0xf8a1a159, 0xfda2a25f, 0xfea3a35d, - 0xf7a4a453, 0xf4a5a551, 0xf1a6a657, 0xf2a7a755, - 0xe3a8a84b, 0xe0a9a949, 0xe5aaaa4f, 0xe6abab4d, - 0xefacac43, 0xecadad41, 0xe9aeae47, 0xeaafaf45, - 0xcbb0b07b, 0xc8b1b179, 0xcdb2b27f, 0xceb3b37d, - 0xc7b4b473, 0xc4b5b571, 0xc1b6b677, 0xc2b7b775, - 0xd3b8b86b, 0xd0b9b969, 0xd5baba6f, 0xd6bbbb6d, - 0xdfbcbc63, 0xdcbdbd61, 0xd9bebe67, 0xdabfbf65, - 0x5bc0c09b, 0x58c1c199, 0x5dc2c29f, 0x5ec3c39d, - 0x57c4c493, 0x54c5c591, 0x51c6c697, 0x52c7c795, - 0x43c8c88b, 0x40c9c989, 0x45caca8f, 0x46cbcb8d, - 0x4fcccc83, 0x4ccdcd81, 0x49cece87, 0x4acfcf85, - 0x6bd0d0bb, 0x68d1d1b9, 0x6dd2d2bf, 0x6ed3d3bd, - 0x67d4d4b3, 0x64d5d5b1, 0x61d6d6b7, 0x62d7d7b5, - 0x73d8d8ab, 0x70d9d9a9, 0x75dadaaf, 0x76dbdbad, - 0x7fdcdca3, 0x7cdddda1, 0x79dedea7, 0x7adfdfa5, - 0x3be0e0db, 0x38e1e1d9, 0x3de2e2df, 0x3ee3e3dd, - 0x37e4e4d3, 0x34e5e5d1, 0x31e6e6d7, 0x32e7e7d5, - 0x23e8e8cb, 0x20e9e9c9, 0x25eaeacf, 0x26ebebcd, - 0x2fececc3, 0x2cededc1, 0x29eeeec7, 0x2aefefc5, - 0x0bf0f0fb, 0x08f1f1f9, 0x0df2f2ff, 0x0ef3f3fd, - 0x07f4f4f3, 0x04f5f5f1, 0x01f6f6f7, 0x02f7f7f5, - 0x13f8f8eb, 0x10f9f9e9, 0x15fafaef, 0x16fbfbed, - 0x1ffcfce3, 0x1cfdfde1, 0x19fefee7, 0x1affffe5, - }, { - /* Inverse MixColumns lookup table */ - 0x00000000, 0x0b0d090e, 0x161a121c, 0x1d171b12, - 0x2c342438, 0x27392d36, 0x3a2e3624, 0x31233f2a, - 0x58684870, 0x5365417e, 0x4e725a6c, 0x457f5362, - 0x745c6c48, 0x7f516546, 0x62467e54, 0x694b775a, - 0xb0d090e0, 0xbbdd99ee, 0xa6ca82fc, 0xadc78bf2, - 0x9ce4b4d8, 0x97e9bdd6, 0x8afea6c4, 0x81f3afca, - 0xe8b8d890, 0xe3b5d19e, 0xfea2ca8c, 0xf5afc382, - 0xc48cfca8, 0xcf81f5a6, 0xd296eeb4, 0xd99be7ba, - 0x7bbb3bdb, 0x70b632d5, 0x6da129c7, 0x66ac20c9, - 0x578f1fe3, 0x5c8216ed, 0x41950dff, 0x4a9804f1, - 0x23d373ab, 0x28de7aa5, 0x35c961b7, 0x3ec468b9, - 0x0fe75793, 0x04ea5e9d, 0x19fd458f, 0x12f04c81, - 0xcb6bab3b, 0xc066a235, 0xdd71b927, 0xd67cb029, - 0xe75f8f03, 0xec52860d, 0xf1459d1f, 0xfa489411, - 0x9303e34b, 0x980eea45, 0x8519f157, 0x8e14f859, - 0xbf37c773, 0xb43ace7d, 0xa92dd56f, 0xa220dc61, - 0xf66d76ad, 0xfd607fa3, 0xe07764b1, 0xeb7a6dbf, - 0xda595295, 0xd1545b9b, 0xcc434089, 0xc74e4987, - 0xae053edd, 0xa50837d3, 0xb81f2cc1, 0xb31225cf, - 0x82311ae5, 0x893c13eb, 0x942b08f9, 0x9f2601f7, - 0x46bde64d, 0x4db0ef43, 0x50a7f451, 0x5baafd5f, - 0x6a89c275, 0x6184cb7b, 0x7c93d069, 0x779ed967, - 0x1ed5ae3d, 0x15d8a733, 0x08cfbc21, 0x03c2b52f, - 0x32e18a05, 0x39ec830b, 0x24fb9819, 0x2ff69117, - 0x8dd64d76, 0x86db4478, 0x9bcc5f6a, 0x90c15664, - 0xa1e2694e, 0xaaef6040, 0xb7f87b52, 0xbcf5725c, - 0xd5be0506, 0xdeb30c08, 0xc3a4171a, 0xc8a91e14, - 0xf98a213e, 0xf2872830, 0xef903322, 0xe49d3a2c, - 0x3d06dd96, 0x360bd498, 0x2b1ccf8a, 0x2011c684, - 0x1132f9ae, 0x1a3ff0a0, 0x0728ebb2, 0x0c25e2bc, - 0x656e95e6, 0x6e639ce8, 0x737487fa, 0x78798ef4, - 0x495ab1de, 0x4257b8d0, 0x5f40a3c2, 0x544daacc, - 0xf7daec41, 0xfcd7e54f, 0xe1c0fe5d, 0xeacdf753, - 0xdbeec879, 0xd0e3c177, 0xcdf4da65, 0xc6f9d36b, - 0xafb2a431, 0xa4bfad3f, 0xb9a8b62d, 0xb2a5bf23, - 0x83868009, 0x888b8907, 0x959c9215, 0x9e919b1b, - 0x470a7ca1, 0x4c0775af, 0x51106ebd, 0x5a1d67b3, - 0x6b3e5899, 0x60335197, 0x7d244a85, 0x7629438b, - 0x1f6234d1, 0x146f3ddf, 0x097826cd, 0x02752fc3, - 0x335610e9, 0x385b19e7, 0x254c02f5, 0x2e410bfb, - 0x8c61d79a, 0x876cde94, 0x9a7bc586, 0x9176cc88, - 0xa055f3a2, 0xab58faac, 0xb64fe1be, 0xbd42e8b0, - 0xd4099fea, 0xdf0496e4, 0xc2138df6, 0xc91e84f8, - 0xf83dbbd2, 0xf330b2dc, 0xee27a9ce, 0xe52aa0c0, - 0x3cb1477a, 0x37bc4e74, 0x2aab5566, 0x21a65c68, - 0x10856342, 0x1b886a4c, 0x069f715e, 0x0d927850, - 0x64d90f0a, 0x6fd40604, 0x72c31d16, 0x79ce1418, - 0x48ed2b32, 0x43e0223c, 0x5ef7392e, 0x55fa3020, - 0x01b79aec, 0x0aba93e2, 0x17ad88f0, 0x1ca081fe, - 0x2d83bed4, 0x268eb7da, 0x3b99acc8, 0x3094a5c6, - 0x59dfd29c, 0x52d2db92, 0x4fc5c080, 0x44c8c98e, - 0x75ebf6a4, 0x7ee6ffaa, 0x63f1e4b8, 0x68fcedb6, - 0xb1670a0c, 0xba6a0302, 0xa77d1810, 0xac70111e, - 0x9d532e34, 0x965e273a, 0x8b493c28, 0x80443526, - 0xe90f427c, 0xe2024b72, 0xff155060, 0xf418596e, - 0xc53b6644, 0xce366f4a, 0xd3217458, 0xd82c7d56, - 0x7a0ca137, 0x7101a839, 0x6c16b32b, 0x671bba25, - 0x5638850f, 0x5d358c01, 0x40229713, 0x4b2f9e1d, - 0x2264e947, 0x2969e049, 0x347efb5b, 0x3f73f255, - 0x0e50cd7f, 0x055dc471, 0x184adf63, 0x1347d66d, - 0xcadc31d7, 0xc1d138d9, 0xdcc623cb, 0xd7cb2ac5, - 0xe6e815ef, 0xede51ce1, 0xf0f207f3, 0xfbff0efd, - 0x92b479a7, 0x99b970a9, 0x84ae6bbb, 0x8fa362b5, - 0xbe805d9f, 0xb58d5491, 0xa89a4f83, 0xa397468d, - } }; - union CRYPTO_STATE st = { .l = { rm[0], rm[1] } }; + const uint32_t *mc = decrypt ? AES_imc_rot : AES_mc_rot; int i; for (i = 0; i < 16; i += 4) { CR_ST_WORD(st, i >> 2) = - mc[decrypt][CR_ST_BYTE(st, i)] ^ - rol32(mc[decrypt][CR_ST_BYTE(st, i + 1)], 8) ^ - rol32(mc[decrypt][CR_ST_BYTE(st, i + 2)], 16) ^ - rol32(mc[decrypt][CR_ST_BYTE(st, i + 3)], 24); + mc[CR_ST_BYTE(st, i)] ^ + rol32(mc[CR_ST_BYTE(st, i + 1)], 8) ^ + rol32(mc[CR_ST_BYTE(st, i + 2)], 16) ^ + rol32(mc[CR_ST_BYTE(st, i + 3)], 24); } rd[0] = st.l[0]; From patchwork Tue Jun 20 11:07:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694479 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246829wrm; Tue, 20 Jun 2023 04:15:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5EXq9XK1RZQfhK8J1WENy0GQAumla+7IanJ4Hg62UyOv9b8ZPS3jjF2jnu1MTOhJRSt83Y X-Received: by 2002:a05:6214:19ce:b0:630:e03:a652 with SMTP id j14-20020a05621419ce00b006300e03a652mr12090992qvc.60.1687259747893; Tue, 20 Jun 2023 04:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259747; cv=none; d=google.com; s=arc-20160816; b=uMKQdT/iMEOc1n1WOtdfEO6RK7IHYYga+p70cW3gIefccGLRyDzj5I9lZYLtMURMgM 10GYNqq6PttGm5yCtDYa6XkGM7GO40JBEPjMaXa+R7/qvIgGmsYDKvNVvxA4hwi8sMjN hMX5OLghjhgHu+CCmdh3sfIQFK00ngvTpdv6yaq2f7cF09iT0EJIw/NCd/uh74mgxcMC bCnpPHzQ04VviaX4K65ER/9qg+4mtjpwAiH0ybxgSghcoFQaZhlW99QKemZet7JOJu7u ssucravTiBznyQilppwrOTAWtE1l6oFoIN7vscREFyY8zqS5hAz/nmcGjBBFPO6Ag3YM vzWg== 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=3m4966dsyDinAuTFstQnqcz3WJKkplFB9WOExFLrlCA=; b=Dj9YBLYjRlXGhBl5FgYmn2YgDm+aRzYywWVRMwgbO7rHGJuODnZXoBUpg1A+c3LkW6 Gb9zA3yQ8fDoZLYtQP9O1eg8teqUC6mBmrEsGN947VPaaByvpvHzHAPwuXj/GZjWCGde Nv+laGIltfmaF5EKFWWkMh6qPRrTgIBHn7hRc7+ckhtIbLBjxZ8s09LweXazS/ckrIBS wNg4NtLkGtPpaKa/XWKlN8SXKQQvuoVbjwNUNp8LknrxnMx4rpKNAApfVKithf1a2mxL WPNhpee4rXbgcaiYI803iAaEthP/W+faSOgtpnLvpXoraep9KRr/yqv7psUKSo28+3/K Zaqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E6cOxOtF; 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 14-20020a056214202e00b005cfbc45db52si744177qvf.264.2023.06.20.04.15.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:15:47 -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=E6cOxOtF; 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 1qBZDb-0005tZ-Mh; Tue, 20 Jun 2023 07:08:15 -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 1qBZDZ-0005qQ-Pj for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:13 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDU-0004BX-A3 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:13 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-988883b0d8fso376396466b.1 for ; Tue, 20 Jun 2023 04:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259287; x=1689851287; 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=3m4966dsyDinAuTFstQnqcz3WJKkplFB9WOExFLrlCA=; b=E6cOxOtF/5Ogc0KnbHapRi1XFRUJRBl8yFy10Lme2aT6tL1I2SVWahADI476hcClpp 3nZMHvqQ2Ba5kpUF8cv3Re6+YTx0I88tlHRPF5fQwx2ghc3DjRhASqgytWHOaxh6H266 m7KSgw0C/2A5AxribyBY9ZJCxydln3WgSlG1evtFd6J74INPHQbawdMsOnb8VGnPh+jM RArPJXL5+ZdhkvyFCP2CxBSoxQg2hUJM6aw1IoZKzOn/19/nMC4J0Mf8w0L7B0yBCf7u CLVh9EjgXcr+dqlJOAwjLfdXHw8FpWvhCEPaOShPkZuw1+4c3lJfT/yiGc2Z+1RzmiWJ TVJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259287; x=1689851287; 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=3m4966dsyDinAuTFstQnqcz3WJKkplFB9WOExFLrlCA=; b=FUn2hS8Ccl9Lduk5Rx1qLkF3pkNc5uVtQNE91jqnXYoPnsiIxzsxVM+RmeqJPJybsb h82yu2S/Jovd2p3I0A8uy3N6hzsC6y0QkcMR/5ApibGeRSrSizhGZvjk6nac9Yqy940J c3aNBKO8bgGROvEXlNJwYDlJdZYpfgtqSbDi6fhROYboEwj6LmrafGs+7Aqo4YHn9ZB2 u4CEkra61jQE1Ik4qI1ONccqeSOKO2rppriqozejwPaYOoN1AfpsBL6OdEWLhMoR83P5 yrxYB1IZfIybhqpCHmErh1k4pyneYBKi7m76v7gjvgzwMQ96B0LONaiQIS9dgpYskfDu 0aQw== X-Gm-Message-State: AC+VfDzAWRXlGowhkzYuQPpX9ztgZi7mGrZfiIuLk3R5nsaDNO3HBhtT 32DxbGXT3R0Kh5w3bEQSawmrj+S+LZ7hgay2mClsimGY X-Received: by 2002:a17:907:934d:b0:957:2e48:5657 with SMTP id bv13-20020a170907934d00b009572e485657mr9923738ejc.68.1687259286938; Tue, 20 Jun 2023 04:08:06 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 04/37] crypto/aes: Add constants for ShiftRows, InvShiftRows Date: Tue, 20 Jun 2023 13:07:25 +0200 Message-Id: <20230620110758.787479-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x632.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=unavailable 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 These symbols will avoid the indirection through memory when fully unrolling some new primitives. Acked-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- crypto/aes.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 67bb74b8e3..cdf937883d 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -108,12 +108,58 @@ const uint8_t AES_isbox[256] = { 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D, }; +/* AES ShiftRows, for complete unrolling. */ +enum { + AES_SH_0 = 0x0, + AES_SH_1 = 0x5, + AES_SH_2 = 0xa, + AES_SH_3 = 0xf, + AES_SH_4 = 0x4, + AES_SH_5 = 0x9, + AES_SH_6 = 0xe, + AES_SH_7 = 0x3, + AES_SH_8 = 0x8, + AES_SH_9 = 0xd, + AES_SH_A = 0x2, + AES_SH_B = 0x7, + AES_SH_C = 0xc, + AES_SH_D = 0x1, + AES_SH_E = 0x6, + AES_SH_F = 0xb, +}; + const uint8_t AES_shifts[16] = { - 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11 + AES_SH_0, AES_SH_1, AES_SH_2, AES_SH_3, + AES_SH_4, AES_SH_5, AES_SH_6, AES_SH_7, + AES_SH_8, AES_SH_9, AES_SH_A, AES_SH_B, + AES_SH_C, AES_SH_D, AES_SH_E, AES_SH_F, +}; + +/* AES InvShiftRows, for complete unrolling. */ +enum { + AES_ISH_0 = 0x0, + AES_ISH_1 = 0xd, + AES_ISH_2 = 0xa, + AES_ISH_3 = 0x7, + AES_ISH_4 = 0x4, + AES_ISH_5 = 0x1, + AES_ISH_6 = 0xe, + AES_ISH_7 = 0xb, + AES_ISH_8 = 0x8, + AES_ISH_9 = 0x5, + AES_ISH_A = 0x2, + AES_ISH_B = 0xf, + AES_ISH_C = 0xc, + AES_ISH_D = 0x9, + AES_ISH_E = 0x6, + AES_ISH_F = 0x3, }; const uint8_t AES_ishifts[16] = { - 0, 13, 10, 7, 4, 1, 14, 11, 8, 5, 2, 15, 12, 9, 6, 3 + AES_ISH_0, AES_ISH_1, AES_ISH_2, AES_ISH_3, + AES_ISH_4, AES_ISH_5, AES_ISH_6, AES_ISH_7, + AES_ISH_8, AES_ISH_9, AES_ISH_A, AES_ISH_B, + AES_ISH_C, AES_ISH_D, AES_ISH_E, AES_ISH_F, }; /* From patchwork Tue Jun 20 11:07:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694478 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246800wrm; Tue, 20 Jun 2023 04:15:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4E5Fhk+Rq7aNrhWt0/RBBf/w9o0QK3QonZCo8Hp3uh39/ynaTdSxeeROvLXB+nDkMmHZHI X-Received: by 2002:ac8:5aca:0:b0:3ff:3151:a8b0 with SMTP id d10-20020ac85aca000000b003ff3151a8b0mr264585qtd.16.1687259742469; Tue, 20 Jun 2023 04:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259742; cv=none; d=google.com; s=arc-20160816; b=ShH5A8a0WDEPwbvSu2HdR9CR2FlYYM8k7EtsIFqA0SgR/xJ2xlLSSnzub9l2o3THFC yksbEbSCSUebFbg2+I0akUTH9ElYK8rg8BWUYp+W2sRdanpumCfFeahirgaHyFy6T6vV 1iLho0GDmS8kyPsBvfQ4zXt7C9KkA0iXqkkQadD6dqro/o1li7pZ5teFsnSlO8jZ1anP IYZ3IF9XfZq8qos0DMfs/h7UNNeRGoha09SpnoITAYOd1Vc5dGZf9AAUJEzWl+zv4dFs KwduBS0ZwEE2XNAJJ2fxrwE8SfSoh9uFAgVxxcJgdUf3i13892YVESZzbhJys9MLyod1 21BQ== 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=vCazwpeLNv7EUcpMYF/LFadHN6FmWon+/yuhh5cv/iE=; b=hXlg2aHR58jkaJYI//sXOX+PoRw6hyATwW8H7q+nB+EuTYu93gwsq3ddf68Lket3Lb 8qtLgeM7GmMfJtuoJUdF7UD75mOyIrKACAFpHsboSwdaAm2Di6aaOPQnaFK/xVjLyybG LHDB2fRUC0XqSJFDg4mpWp8TBZj7/WDCxNZ1t3qNKXVMDe0rH6Yh2Qxu8ceQslorhTY2 fVPmxcTplKN2VCezZtRfQC0EREXwDRqI5CLbEYQeIGUPzkvFsqBQavBI1N4l4/q1umbh 2YyX5VE3PhCC+oQSRspleEIt8NooOcFCbo8oa4lydkmVBtI2vNNksrJ9tDcm82UMa5ZS WZkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mhSzZJnV; 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 t13-20020a05622a01cd00b003f205e65e7dsi663936qtw.234.2023.06.20.04.15.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:15:42 -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=mhSzZJnV; 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 1qBZDb-0005sr-Fc; Tue, 20 Jun 2023 07:08:15 -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 1qBZDa-0005s1-J4 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:14 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDV-0004Bz-R0 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:14 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-978863fb00fso717638366b.3 for ; Tue, 20 Jun 2023 04:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259288; x=1689851288; 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=vCazwpeLNv7EUcpMYF/LFadHN6FmWon+/yuhh5cv/iE=; b=mhSzZJnVW7NnuUtVrIOZY9AO+/qZ9n/8mc5pvRWxQDhZiexjFu6pQ40fZ+QjcwnTBB aLSannxOsIl8BoWIDq1nt/x81rGzOdxu9CdhRUpSLnnOYwprIaoqgAq7YW/fmjR2CPpS 5ZchOS4CUKG7uSvLryetZXMAEcroQ3tteVYH9othZXXqeNb8UC+/RSzs05JR/uRDivlN ffWhmKX8z8aIvJbYYrlRJPUbkKFa/N4LASJQonBuEVfM2SZ+0iw7sh2QYJ4oGmUWvbp8 +GtZzWweJbvggcKvC3BS6VWrD9Fkva20WXUx24L81TUKPUpGQVyENOUTIMEVgzvufvTD hRyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259288; x=1689851288; 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=vCazwpeLNv7EUcpMYF/LFadHN6FmWon+/yuhh5cv/iE=; b=VJwl10wo/mepk0iKX9nYcVmo7vLHwA3oFI9IqhQGCvQgpVHhnZvToQFyzF7LF8iXDg 6rXDCSNAM8uVKUQW+0DO/RD9xX9F+2a0pSCpnYFJ85STvCupNp11CDuW9C7+mAZduOgk 26Iv44wFqZdys5jy1KK+Z1oo8H/zBs4YgV7B+vb1xSqfDlET/nJXBsNhxs6tRjVhqu0d 3afOs47VMtBHY03DL5/NZMGuGCxlfYiqJECDZkxUE03MEHHDdiVSzGl5YPBjaK5mEFse R4b85zmICEGrmLna+mBUE3Aol+/6ZJl0l2YMeF6d5YmjLU7ggeBzaGmgREGSiLRQ0e4Q u4Cw== X-Gm-Message-State: AC+VfDwtYhe9tmaEa0krsWL6FAZ/QGZltW5Wyu2bFSrFln3+9fhxa9Mj WmfX8qldsQu/aGxY6RVtNiKitphHXio+Xw6N/Bs/jfWC X-Received: by 2002:a17:907:3188:b0:966:5a6c:752d with SMTP id xe8-20020a170907318800b009665a6c752dmr11035134ejb.20.1687259288171; Tue, 20 Jun 2023 04:08:08 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 05/37] crypto: Add aesenc_SB_SR_AK Date: Tue, 20 Jun 2023 13:07:26 +0200 Message-Id: <20230620110758.787479-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62a.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 Start adding infrastructure for accelerating guest AES. Begin with a SubBytes + ShiftRows + AddRoundKey primitive. Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- MAINTAINERS | 1 + host/include/generic/host/crypto/aes-round.h | 16 +++++++ include/crypto/aes-round.h | 44 +++++++++++++++++++ crypto/aes.c | 46 ++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 host/include/generic/host/crypto/aes-round.h create mode 100644 include/crypto/aes-round.h diff --git a/MAINTAINERS b/MAINTAINERS index 88b5a7ee0a..0214558d05 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3208,6 +3208,7 @@ M: Daniel P. Berrange S: Maintained F: crypto/ F: include/crypto/ +F: host/include/*/host/crypto/ F: qapi/crypto.json F: tests/unit/test-crypto-* F: tests/bench/benchmark-crypto-* diff --git a/host/include/generic/host/crypto/aes-round.h b/host/include/generic/host/crypto/aes-round.h new file mode 100644 index 0000000000..c5d8066179 --- /dev/null +++ b/host/include/generic/host/crypto/aes-round.h @@ -0,0 +1,16 @@ +/* + * No host specific aes acceleration. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef GENERIC_HOST_CRYPTO_AES_ROUND_H +#define GENERIC_HOST_CRYPTO_AES_ROUND_H + +#define HAVE_AES_ACCEL false +#define ATTR_AES_ACCEL + +void aesenc_SB_SR_AK_accel(AESState *, const AESState *, + const AESState *, bool) + QEMU_ERROR("unsupported accel"); + +#endif /* GENERIC_HOST_CRYPTO_AES_ROUND_H */ diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h new file mode 100644 index 0000000000..d675d2468f --- /dev/null +++ b/include/crypto/aes-round.h @@ -0,0 +1,44 @@ +/* + * AES round fragments, generic version + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Copyright (C) 2023 Linaro, Ltd. + */ + +#ifndef CRYPTO_AES_ROUND_H +#define CRYPTO_AES_ROUND_H + +/* Hosts with acceleration will usually need a 16-byte vector type. */ +typedef uint8_t AESStateVec __attribute__((vector_size(16))); + +typedef union { + uint8_t b[16]; + uint32_t w[4]; + uint64_t d[4]; + AESStateVec v; +} AESState; + +#include "host/crypto/aes-round.h" + +/* + * Perform SubBytes + ShiftRows + AddRoundKey. + */ + +void aesenc_SB_SR_AK_gen(AESState *ret, const AESState *st, + const AESState *rk); +void aesenc_SB_SR_AK_genrev(AESState *ret, const AESState *st, + const AESState *rk); + +static inline void aesenc_SB_SR_AK(AESState *r, const AESState *st, + const AESState *rk, bool be) +{ + if (HAVE_AES_ACCEL) { + aesenc_SB_SR_AK_accel(r, st, rk, be); + } else if (HOST_BIG_ENDIAN == be) { + aesenc_SB_SR_AK_gen(r, st, rk); + } else { + aesenc_SB_SR_AK_genrev(r, st, rk); + } +} + +#endif /* CRYPTO_AES_ROUND_H */ diff --git a/crypto/aes.c b/crypto/aes.c index cdf937883d..c00f10bad1 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -29,6 +29,7 @@ */ #include "qemu/osdep.h" #include "crypto/aes.h" +#include "crypto/aes-round.h" typedef uint32_t u32; typedef uint8_t u8; @@ -1249,6 +1250,51 @@ static const u32 rcon[] = { 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ }; +/* + * Perform SubBytes + ShiftRows + AddRoundKey. + */ +static inline void +aesenc_SB_SR_AK_swap(AESState *ret, const AESState *st, + const AESState *rk, bool swap) +{ + const int swap_b = swap ? 15 : 0; + AESState t; + + t.b[swap_b ^ 0x0] = AES_sbox[st->b[swap_b ^ AES_SH_0]]; + t.b[swap_b ^ 0x1] = AES_sbox[st->b[swap_b ^ AES_SH_1]]; + t.b[swap_b ^ 0x2] = AES_sbox[st->b[swap_b ^ AES_SH_2]]; + t.b[swap_b ^ 0x3] = AES_sbox[st->b[swap_b ^ AES_SH_3]]; + t.b[swap_b ^ 0x4] = AES_sbox[st->b[swap_b ^ AES_SH_4]]; + t.b[swap_b ^ 0x5] = AES_sbox[st->b[swap_b ^ AES_SH_5]]; + t.b[swap_b ^ 0x6] = AES_sbox[st->b[swap_b ^ AES_SH_6]]; + t.b[swap_b ^ 0x7] = AES_sbox[st->b[swap_b ^ AES_SH_7]]; + t.b[swap_b ^ 0x8] = AES_sbox[st->b[swap_b ^ AES_SH_8]]; + t.b[swap_b ^ 0x9] = AES_sbox[st->b[swap_b ^ AES_SH_9]]; + t.b[swap_b ^ 0xa] = AES_sbox[st->b[swap_b ^ AES_SH_A]]; + t.b[swap_b ^ 0xb] = AES_sbox[st->b[swap_b ^ AES_SH_B]]; + t.b[swap_b ^ 0xc] = AES_sbox[st->b[swap_b ^ AES_SH_C]]; + t.b[swap_b ^ 0xd] = AES_sbox[st->b[swap_b ^ AES_SH_D]]; + t.b[swap_b ^ 0xe] = AES_sbox[st->b[swap_b ^ AES_SH_E]]; + t.b[swap_b ^ 0xf] = AES_sbox[st->b[swap_b ^ AES_SH_F]]; + + /* + * Perform the AddRoundKey with generic vectors. + * This may be expanded to either host integer or host vector code. + * The key and output endianness match, so no bswap required. + */ + ret->v = t.v ^ rk->v; +} + +void aesenc_SB_SR_AK_gen(AESState *r, const AESState *s, const AESState *k) +{ + aesenc_SB_SR_AK_swap(r, s, k, false); +} + +void aesenc_SB_SR_AK_genrev(AESState *r, const AESState *s, const AESState *k) +{ + aesenc_SB_SR_AK_swap(r, s, k, true); +} + /** * Expand the cipher key into the encryption key schedule. */ From patchwork Tue Jun 20 11:07:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694476 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246324wrm; Tue, 20 Jun 2023 04:14:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vfBlZgM1cWaqUGGfEAkM6s7IoXS7KqbgMiGOx5muHPFvzzlXQE8r95NPr1e1vaGAlzDI+ X-Received: by 2002:a05:620a:4147:b0:75b:23a1:8e67 with SMTP id k7-20020a05620a414700b0075b23a18e67mr15627641qko.56.1687259678482; Tue, 20 Jun 2023 04:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259678; cv=none; d=google.com; s=arc-20160816; b=RsY7DN09OB/UCw+mGxSDBcMkHBExvz0iPp2hw2z9I3M0AHJCankDeu4aAcLjpmb8Ad cWJSk+L5QPNyE48yLnZloonhGwSlYvto5YplrSEtAzKmHK0jYYJYwx9sALdzA/JVS0d7 fzgYU9WDePQdhOYgZrKOtBseOXTd60G+3IhaKlSqRB/CjCICbTnpukuPvN16sYjjcBm/ PcizKj4qwD3R382XUPve76NsoOTddG8nJieYuofDijleE0gqit/PORTGMPHVqj/j5ju6 GoHg2S8PrzSwM0Eiy+QozJDTqn2cJYV1rBfkARRrooYK6++uG3TtIMgSJKLBP/bkf+BW ebOg== 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=fCbxuyj6w2doHmBool/Ak6eLq+V5O+przb+5Ur/gE60=; b=yuadxRXqe3mKr5J1nvqH3WJMt6xDjCtQkp7Ob+dssGYmTiei0SaTLCPfC7dsDiSUUA jcAdE8ae87KCf23PMEbOloh/owwx4k00WT2IjfUD0zuRVSay2lmYJdA/heJuUVFWdarq CqlCwuPL9QOYGP2GA/JzAd7XiJe/8iiWqUPLCqA75MC66a6x3/tfrLATqewLbs1X5UA8 3/EBQ4SIONJ2Ojtqoq0ROeLKcM0IlXwiwkbUqe/wHbOfI6zlSrlGhaVdv9XV+ZRh+5tZ DStvQAUISdczju1iGA4JKvQrfH66yIQTpfxtJKrSGhHaJ5qoB9VLeb3zv0m5TLIMejps B7UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YYtZzg0e; 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 f1-20020a05620a20c100b00747a2434dbcsi684701qka.776.2023.06.20.04.14.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:14:38 -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=YYtZzg0e; 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 1qBZDe-0005zY-Ak; Tue, 20 Jun 2023 07:08:18 -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 1qBZDc-0005vN-4j for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:16 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDX-0004Cf-9B for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:15 -0400 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-988f066f665so179812866b.2 for ; Tue, 20 Jun 2023 04:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259290; x=1689851290; 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=fCbxuyj6w2doHmBool/Ak6eLq+V5O+przb+5Ur/gE60=; b=YYtZzg0emy5SVG6ME1rhnRbp7rAQK/JhH2856Pq2KTOYfxIG0rrn1o9wL6breW5A7c zLTRSZjgfcXeitTTY4Ksk6dBpPnDKxwCOiZsVf9oiyn7M5XCSS7FgFyAn2iL9TZ2doNG FRxszCJ48A/TwgEyzbY2iB+Und4i/ZZGvJgOMSwEclW9KEoh1/SlsyIzeIvOp00pTk3C cbFfcmt36UFGr/7aowxAJhxa76qHZWcwb6NrkWRQRYS5WvWZAT7uFBludEAPPB7gnQQV lr8fNrbTiWNeke9i3DYWn/Wy4ZYYUExdloCJl25lA+V4xmnZ/TYJi8OgDZDFRHblQ+Ig FyFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259290; x=1689851290; 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=fCbxuyj6w2doHmBool/Ak6eLq+V5O+przb+5Ur/gE60=; b=KXo9rvl4IXkqXTQACAqXOLwHW2szyHVYUzwjo8pSmrU0yXdOpa5rL0+ngb8Bs787Qs 9548KlbILDepl8vsLGEQgKJAPdNdqtAegRdVScv3WU6whNbuCM1bmZakn6HjsYwI+Pac qCIrRArFpXMLjtW4wOxiDkw0RseJKIfpLeYYv69wwZXUoQEsJhi4Ms4jyJ0u57sjCxhu WxEqf5hqHE9MmL641e1FCJbsJGc/6Y6bZ6DJcP8XbdZog8Ld44Q7G0L3lU9VRc7dumCi YvN9vJBoGyRQtUJUGGtcaqadCLRhdd3AgDdH19hxOYQ3ye8W64EGn/ZIhGPqbhvu9Olw mxsw== X-Gm-Message-State: AC+VfDxwdH/bt5jxwTS2bZQezsTdb/HguO2k1e3EI1R/wdw34euzUurU L9n3G7WzY0Iz6pg+1HOGqZRy7I3UTAAHrqz90OHpQcwI X-Received: by 2002:a17:907:c0a:b0:96f:d345:d0f7 with SMTP id ga10-20020a1709070c0a00b0096fd345d0f7mr10714764ejc.62.1687259289828; Tue, 20 Jun 2023 04:08:09 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 06/37] target/i386: Use aesenc_SB_SR_AK Date: Tue, 20 Jun 2023 13:07:27 +0200 Message-Id: <20230620110758.787479-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x630.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=unavailable 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 This implements the AESENCLAST instruction. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/i386/ops_sse.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index fb63af7afa..63fdecbe03 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -19,6 +19,7 @@ */ #include "crypto/aes.h" +#include "crypto/aes-round.h" #if SHIFT == 0 #define Reg MMXReg @@ -2202,12 +2203,12 @@ void glue(helper_aesenc, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) void glue(helper_aesenclast, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) { - int i; - Reg st = *v; - Reg rk = *s; + for (int i = 0; i < SHIFT; i++) { + AESState *ad = (AESState *)&d->ZMM_X(i); + AESState *st = (AESState *)&v->ZMM_X(i); + AESState *rk = (AESState *)&s->ZMM_X(i); - for (i = 0; i < 8 << SHIFT; i++) { - d->B(i) = rk.B(i) ^ (AES_sbox[st.B(AES_shifts[i & 15] + (i & ~15))]); + aesenc_SB_SR_AK(ad, st, rk, false); } } From patchwork Tue Jun 20 11:07:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694458 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244495wrm; Tue, 20 Jun 2023 04:10:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6r0WYDAn98AYvlbMe863/yiP8hAtnTw8KbmvCV0r4U40CKvWQhOeZMHFgZviwSGRMa61nj X-Received: by 2002:a05:6214:1c85:b0:621:265e:f726 with SMTP id ib5-20020a0562141c8500b00621265ef726mr11736385qvb.43.1687259425457; Tue, 20 Jun 2023 04:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259425; cv=none; d=google.com; s=arc-20160816; b=i0UcP5KB9/h0R5mDPnCZOxB+OFkyoZjMjaNIsYjb3jsgj2sz5tyxPGALf74RevjUbi qIywt7gf00bxqgq1/huuB5mvDKx8Qh/jlL9A7qqCTEhErZ+8t6+BSi2+jHboB5vMERrw 5lB1i44UGSaG/CcIGZENSxvg2S9OxBBIyDfqOBu+6gcGa+99IA9zyqtAbL1q/QOGUIe0 Ont/jWr19alB4ek2GQCxxEd6/O1LBVkyzmZsQzT3r2/xXDAvtakNSX5EfiKESTlHpI/5 rfOiNJeETEqG2o1mcFmitHfe8lZ3tOSo7daK67OcXqaZA7Uh7IvTwYQoH8DsOzZiX70j 9fSg== 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=24csfVfVB/om++z3Dw6ZmC6sozEjrnY9D1BEg+uRKMI=; b=JBCB15U+FdCW1wL6YMjThYFxj9mTKamKNmBp58PIpw6sm/QgmGdGYIJHQuNoZj6OSe px3MA2Sc8bYWH8oOaFhEVt8hUuEbtxyPzKBwMc+++H9VGJsoT8Et/skXPlP8ly3dF4kA liHvqI2BtjatR1C0SdgjUbzY8yaeWJQPCCo6Mixs7p+wDUsikM3nQe9la1njMHZ7Mny0 2jveCi2ee9PAHjr6uaOajitYTbpiaZXRVy5wIXM5rX22vaGU3RZ/lpz//JCMQpH1ETfl 0MsGiljW/nRN24Q5ZHZfsW+x1Yje+atAvBOY5Now+1DS4kZj/kPzJKCeQ/x/xabERZ3D yPmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ep1i8g4U; 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 r4-20020a0562140c8400b006260a17e37bsi730942qvr.132.2023.06.20.04.10.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:10:25 -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=Ep1i8g4U; 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 1qBZDf-00063J-W1; Tue, 20 Jun 2023 07:08:20 -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 1qBZDd-0005yj-Oh for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:17 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDY-0004DU-VK for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:17 -0400 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5189f49c315so4819752a12.2 for ; Tue, 20 Jun 2023 04:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259291; x=1689851291; 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=24csfVfVB/om++z3Dw6ZmC6sozEjrnY9D1BEg+uRKMI=; b=Ep1i8g4UXYmNDu8Ua1ZGPGqRdJjXE9ba65yIErdiSR9vv+IIYadkDn+xbfi5nTGV5+ Ug7yBvqLZTlWRPr6vRC1LudeYNbvhVf9Y0BqWNRYgee0Ue3YhMJuGbQHx+XE87KZqQWs dkAW3WvEMQzRRshYDj5utDpLklu7coDNJ9Xk6xQsKA/mEM+ef3uuYb+arHRoLjEJZ31r AXFwtl4rqGhLpVQXMeC0oPUfzRuV/9V8j/XUavqnRw+dNhu+qzOT2jNV4HeuNSyWyFPd wH9QOECioRjBCWkjUX8swqyHhsEIpOb5wzuOUt/sbWH+UHTRmz6aVvW3HSvPWT8ETBSz 8BCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259291; x=1689851291; 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=24csfVfVB/om++z3Dw6ZmC6sozEjrnY9D1BEg+uRKMI=; b=SX2Wrmls9yH2ew2s2NUaJBkfMKnwXB8PqieGabDTJSwknGA6IKzQKpHGBJgMew4t8w GoST6Glo3dtEvBHVdSMNG4jQXMeoJgqbvveD4pXpu/HS+5ArWnq/W73AcDeln9IuM0hJ eCzceb5u4a85vlNYvDywu/g2sNW3KCucPXM05qtXXWMy59LOhYLc4712Tq1zCyQ1j9ZM DHkGCEC0pK0ebbfQk0On+5J1d+zKnTEdLOt+CfC6jZ4EeoQP2j1I0idgL/Rm256ioQVv jDNNayPCjAvrfOsWymBJ47tsilbml1MVIFGshnNYpneb3hnmlNjqZs3LdMaqzLi4wOin dQEA== X-Gm-Message-State: AC+VfDxQBeA5IIfVuFbkpke6TrOIK4oPbJLFPzhuwzEUVHOpVMYbgwVn Rs6BS2i2CkEv9TQJAhKkL3DFugWKS1Y+kieYhdvUUfHW X-Received: by 2002:a17:907:3189:b0:974:2169:5f81 with SMTP id xe9-20020a170907318900b0097421695f81mr10493104ejb.22.1687259291599; Tue, 20 Jun 2023 04:08:11 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 07/37] target/arm: Demultiplex AESE and AESMC Date: Tue, 20 Jun 2023 13:07:28 +0200 Message-Id: <20230620110758.787479-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-ed1-x529.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=unavailable 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 Split these helpers so that we are not passing 'decrypt' within the simd descriptor. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/arm/helper.h | 2 ++ target/arm/tcg/sve.decode | 4 ++-- target/arm/tcg/crypto_helper.c | 37 +++++++++++++++++++++++---------- target/arm/tcg/translate-a64.c | 13 ++++-------- target/arm/tcg/translate-neon.c | 4 ++-- target/arm/tcg/translate-sve.c | 8 ++++--- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/target/arm/helper.h b/target/arm/helper.h index 3335c2b10b..95e32a697a 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -552,7 +552,9 @@ DEF_HELPER_FLAGS_2(neon_qzip16, TCG_CALL_NO_RWG, void, ptr, ptr) DEF_HELPER_FLAGS_2(neon_qzip32, TCG_CALL_NO_RWG, void, ptr, ptr) DEF_HELPER_FLAGS_4(crypto_aese, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) +DEF_HELPER_FLAGS_4(crypto_aesd, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_3(crypto_aesmc, TCG_CALL_NO_RWG, void, ptr, ptr, i32) +DEF_HELPER_FLAGS_3(crypto_aesimc, TCG_CALL_NO_RWG, void, ptr, ptr, i32) DEF_HELPER_FLAGS_4(crypto_sha1su0, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) DEF_HELPER_FLAGS_4(crypto_sha1c, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) diff --git a/target/arm/tcg/sve.decode b/target/arm/tcg/sve.decode index 14b3a69c36..04b6fcc0cf 100644 --- a/target/arm/tcg/sve.decode +++ b/target/arm/tcg/sve.decode @@ -1629,8 +1629,8 @@ STNT1_zprz 1110010 .. 10 ..... 001 ... ..... ..... \ ### SVE2 Crypto Extensions # SVE2 crypto unary operations -# AESMC and AESIMC -AESMC 01000101 00 10000011100 decrypt:1 00000 rd:5 +AESMC 01000101 00 10000011100 0 00000 rd:5 +AESIMC 01000101 00 10000011100 1 00000 rd:5 # SVE2 crypto destructive binary operations AESE 01000101 00 10001 0 11100 0 ..... ..... @rdn_rm_e0 diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index 06254939d2..75882d9ea3 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -45,11 +45,9 @@ static void clear_tail_16(void *vd, uint32_t desc) clear_tail(vd, opr_sz, max_sz); } -static void do_crypto_aese(uint64_t *rd, uint64_t *rn, - uint64_t *rm, bool decrypt) +static void do_crypto_aese(uint64_t *rd, uint64_t *rn, uint64_t *rm, + const uint8_t *sbox, const uint8_t *shift) { - static uint8_t const * const sbox[2] = { AES_sbox, AES_isbox }; - static uint8_t const * const shift[2] = { AES_shifts, AES_ishifts }; union CRYPTO_STATE rk = { .l = { rm[0], rm[1] } }; union CRYPTO_STATE st = { .l = { rn[0], rn[1] } }; int i; @@ -60,7 +58,7 @@ static void do_crypto_aese(uint64_t *rd, uint64_t *rn, /* combine ShiftRows operation and sbox substitution */ for (i = 0; i < 16; i++) { - CR_ST_BYTE(st, i) = sbox[decrypt][CR_ST_BYTE(rk, shift[decrypt][i])]; + CR_ST_BYTE(st, i) = sbox[CR_ST_BYTE(rk, shift[i])]; } rd[0] = st.l[0]; @@ -70,18 +68,26 @@ static void do_crypto_aese(uint64_t *rd, uint64_t *rn, void HELPER(crypto_aese)(void *vd, void *vn, void *vm, uint32_t desc) { intptr_t i, opr_sz = simd_oprsz(desc); - bool decrypt = simd_data(desc); for (i = 0; i < opr_sz; i += 16) { - do_crypto_aese(vd + i, vn + i, vm + i, decrypt); + do_crypto_aese(vd + i, vn + i, vm + i, AES_sbox, AES_shifts); } clear_tail(vd, opr_sz, simd_maxsz(desc)); } -static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, bool decrypt) +void HELPER(crypto_aesd)(void *vd, void *vn, void *vm, uint32_t desc) +{ + intptr_t i, opr_sz = simd_oprsz(desc); + + for (i = 0; i < opr_sz; i += 16) { + do_crypto_aese(vd + i, vn + i, vm + i, AES_isbox, AES_ishifts); + } + clear_tail(vd, opr_sz, simd_maxsz(desc)); +} + +static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, const uint32_t *mc) { union CRYPTO_STATE st = { .l = { rm[0], rm[1] } }; - const uint32_t *mc = decrypt ? AES_imc_rot : AES_mc_rot; int i; for (i = 0; i < 16; i += 4) { @@ -99,10 +105,19 @@ static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, bool decrypt) void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t desc) { intptr_t i, opr_sz = simd_oprsz(desc); - bool decrypt = simd_data(desc); for (i = 0; i < opr_sz; i += 16) { - do_crypto_aesmc(vd + i, vm + i, decrypt); + do_crypto_aesmc(vd + i, vm + i, AES_mc_rot); + } + clear_tail(vd, opr_sz, simd_maxsz(desc)); +} + +void HELPER(crypto_aesimc)(void *vd, void *vm, uint32_t desc) +{ + intptr_t i, opr_sz = simd_oprsz(desc); + + for (i = 0; i < opr_sz; i += 16) { + do_crypto_aesmc(vd + i, vm + i, AES_imc_rot); } clear_tail(vd, opr_sz, simd_maxsz(desc)); } diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index 3baab6aa60..7d0c8f79a7 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -13210,7 +13210,6 @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn) int opcode = extract32(insn, 12, 5); int rn = extract32(insn, 5, 5); int rd = extract32(insn, 0, 5); - int decrypt; gen_helper_gvec_2 *genfn2 = NULL; gen_helper_gvec_3 *genfn3 = NULL; @@ -13221,20 +13220,16 @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn) switch (opcode) { case 0x4: /* AESE */ - decrypt = 0; genfn3 = gen_helper_crypto_aese; break; case 0x6: /* AESMC */ - decrypt = 0; genfn2 = gen_helper_crypto_aesmc; break; case 0x5: /* AESD */ - decrypt = 1; - genfn3 = gen_helper_crypto_aese; + genfn3 = gen_helper_crypto_aesd; break; case 0x7: /* AESIMC */ - decrypt = 1; - genfn2 = gen_helper_crypto_aesmc; + genfn2 = gen_helper_crypto_aesimc; break; default: unallocated_encoding(s); @@ -13245,9 +13240,9 @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn) return; } if (genfn2) { - gen_gvec_op2_ool(s, true, rd, rn, decrypt, genfn2); + gen_gvec_op2_ool(s, true, rd, rn, 0, genfn2); } else { - gen_gvec_op3_ool(s, true, rd, rd, rn, decrypt, genfn3); + gen_gvec_op3_ool(s, true, rd, rd, rn, 0, genfn3); } } diff --git a/target/arm/tcg/translate-neon.c b/target/arm/tcg/translate-neon.c index 03913de047..8de4ceb203 100644 --- a/target/arm/tcg/translate-neon.c +++ b/target/arm/tcg/translate-neon.c @@ -3451,9 +3451,9 @@ static bool trans_VMVN(DisasContext *s, arg_2misc *a) } WRAP_2M_3_OOL_FN(gen_AESE, gen_helper_crypto_aese, 0) -WRAP_2M_3_OOL_FN(gen_AESD, gen_helper_crypto_aese, 1) +WRAP_2M_3_OOL_FN(gen_AESD, gen_helper_crypto_aesd, 0) WRAP_2M_2_OOL_FN(gen_AESMC, gen_helper_crypto_aesmc, 0) -WRAP_2M_2_OOL_FN(gen_AESIMC, gen_helper_crypto_aesmc, 1) +WRAP_2M_2_OOL_FN(gen_AESIMC, gen_helper_crypto_aesimc, 0) WRAP_2M_2_OOL_FN(gen_SHA1H, gen_helper_crypto_sha1h, 0) WRAP_2M_2_OOL_FN(gen_SHA1SU1, gen_helper_crypto_sha1su1, 0) WRAP_2M_2_OOL_FN(gen_SHA256SU0, gen_helper_crypto_sha256su0, 0) diff --git a/target/arm/tcg/translate-sve.c b/target/arm/tcg/translate-sve.c index ff050626e6..b98f469cb1 100644 --- a/target/arm/tcg/translate-sve.c +++ b/target/arm/tcg/translate-sve.c @@ -7151,12 +7151,14 @@ TRANS_FEAT(USDOT_zzzz, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz, a->esz == 2 ? gen_helper_gvec_usdot_b : NULL, a, 0) TRANS_FEAT_NONSTREAMING(AESMC, aa64_sve2_aes, gen_gvec_ool_zz, - gen_helper_crypto_aesmc, a->rd, a->rd, a->decrypt) + gen_helper_crypto_aesmc, a->rd, a->rd, 0) +TRANS_FEAT_NONSTREAMING(AESIMC, aa64_sve2_aes, gen_gvec_ool_zz, + gen_helper_crypto_aesimc, a->rd, a->rd, 0) TRANS_FEAT_NONSTREAMING(AESE, aa64_sve2_aes, gen_gvec_ool_arg_zzz, - gen_helper_crypto_aese, a, false) + gen_helper_crypto_aese, a, 0) TRANS_FEAT_NONSTREAMING(AESD, aa64_sve2_aes, gen_gvec_ool_arg_zzz, - gen_helper_crypto_aese, a, true) + gen_helper_crypto_aesd, a, 0) TRANS_FEAT_NONSTREAMING(SM4E, aa64_sve2_sm4, gen_gvec_ool_arg_zzz, gen_helper_crypto_sm4e, a, 0) From patchwork Tue Jun 20 11:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694474 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246216wrm; Tue, 20 Jun 2023 04:14:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76D2puXSWtP6ZOR3q6RSyXQNDvopEnEstIcys7AUj27/Al3mGulP3L2Yy0LCF7KnEBYGhP X-Received: by 2002:ac8:7d07:0:b0:3fd:e953:74df with SMTP id g7-20020ac87d07000000b003fde95374dfmr3556818qtb.25.1687259665613; Tue, 20 Jun 2023 04:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259665; cv=none; d=google.com; s=arc-20160816; b=NGA21FNd7EspSewtbhs8YDCjiZFx1ipRznQzCCPTfHmm+llPcsM2uPDzRk04DVSHhe wLBz3VJb+z6R/76fOGLqS0rr776mC/ncjHEH39PTR6/kQrD4iqrOBfJftPbThD6O4pkl UteyJ/UJ2LuZ8XCNHpvueyCS2klkCl+yP0Qx7YQZfjFcRF7bPNg5ayk8enMuHNE00gkh nXW3nzAOfSWvWTDOpKwGM1VCjrDtBA50n68N/1ISAKuvqvzK2JrgF/8CnLfIoVWV+OZ5 UDDQAbB3CUsb8sabHzjHM1YHnutKEUlFPhoBzTP6pxV6LuROBR/LUlI88gw3UFBj387S KKww== 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=mjZWs2Y+Z9mHPnjXNP6VJFYBwuCl2SNNXRyLlkiAXFM=; b=imxeJItrAHlZr5APuL4ObZafUJcv483+WApS6pOwNJxz13oQVMPjowszoQon+So41N 9e+QuURkddCAbcAIELU+vCj2hxPidD4yecFjibH4V4c01iA7trWjJPjr7kLl4R+icS/f 9GgNJxDdkPmkrCMYQqx2TXbsQBx6CM/sW0gS23m7fjSK13CfqqNUo+U8lAh/n7x8E6EY eHluLImIEgn1d5+N3L/vpMI79eSqE1zd+CtnO0ISb83YPNkn2dzh7AeYkKapD0U/yTNE u3Tb8A+oWW99qWYgmCCMaTNnx0edSOu0jrTFpnqYQ/K4xM723uySeXxrocQy61XhAVsL Z5CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WtTpfhmL; 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 w3-20020a05622a190300b003f365244139si658154qtc.70.2023.06.20.04.14.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:14:25 -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=WtTpfhmL; 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 1qBZDg-00063c-DK; Tue, 20 Jun 2023 07:08:20 -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 1qBZDe-0005zl-CI for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:18 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDa-0004ET-FR for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:18 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9829a5ae978so717136966b.2 for ; Tue, 20 Jun 2023 04:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259293; x=1689851293; 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=mjZWs2Y+Z9mHPnjXNP6VJFYBwuCl2SNNXRyLlkiAXFM=; b=WtTpfhmL836K+SDKJZcnTDhDgLuRfsn2tUQaR+Ia6h+vYJ19/2sEg9HfMbl5DfxEAz mrQVHhwidUHoKlaKS+pS6yo/9BaxNdhFSgBUL4SCagAkRidQx+/CnFN4KhvH5/EnHVkr uOG7naBuHjCO0jQ9tN/R0Wak8YXWZ3M61uy3f1aFJ6pTZmBS3xpFHjgMbOw3eT6fOUbR 5J13df0NCNGtD+U3jyWeHFCBYqomFY5/RclGg+4zfeRMhfTMgUYOLEh1LKnlYpzoUdi4 2z2dLKhMIRltl3jikMstAWJo2OFkUDB82bco3eapx5xIH1nERF631xZ/qhSsQHziTenb GRVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259293; x=1689851293; 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=mjZWs2Y+Z9mHPnjXNP6VJFYBwuCl2SNNXRyLlkiAXFM=; b=AwJrkOgSgw3Zfbe7G5Lv0i86DPPVmdTsmU2h+Xi8C6slm7rCm6B7QXTKATMLVf3/XR vSHLXKJTxkxDDb8X1Uq9ImvYHCzkYdTW0qcysZXP8wh0uRHd/1kMlfRDwnlr5hqmEPFH wBhDUdo6d09/0WDyB+PBt5N2EmYt7Ms87RN+HfbTdguJfsylNc82J1gsmM9g2v1Myu17 yvWsD0KnmLwqYyzFcb9oJig+2ciC4uoB47w8LkNMjSbQWdGK9i7WS8fmrFGKT8UvgtoB syBYHHRQrK3jjcK/r8Q62Tz2xM+tJRfrDw7DaHbPO2Q+VvIvQA5U/ow0BcxoCAOQO0aK vLKg== X-Gm-Message-State: AC+VfDywjyvqopH7Q3K+xVpm94ILe1+UcgMyNDQ2d7RBHGoWLl9iF1qr r9cLLCHsGrjXiVBZFvJmVecIah0A78KUi8b+XVenj2Ro X-Received: by 2002:a17:907:6ea7:b0:988:9836:3fdb with SMTP id sh39-20020a1709076ea700b0098898363fdbmr6149505ejc.11.1687259293201; Tue, 20 Jun 2023 04:08:13 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 08/37] target/arm: Use aesenc_SB_SR_AK Date: Tue, 20 Jun 2023 13:07:29 +0200 Message-Id: <20230620110758.787479-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62e.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=unavailable 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 This implements the AESE instruction. Signed-off-by: Richard Henderson --- target/arm/tcg/crypto_helper.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index 75882d9ea3..00f3b21507 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -15,6 +15,7 @@ #include "exec/helper-proto.h" #include "tcg/tcg-gvec-desc.h" #include "crypto/aes.h" +#include "crypto/aes-round.h" #include "crypto/sm4.h" #include "vec_internal.h" @@ -45,6 +46,8 @@ static void clear_tail_16(void *vd, uint32_t desc) clear_tail(vd, opr_sz, max_sz); } +static const AESState aes_zero = { }; + static void do_crypto_aese(uint64_t *rd, uint64_t *rn, uint64_t *rm, const uint8_t *sbox, const uint8_t *shift) { @@ -70,7 +73,26 @@ void HELPER(crypto_aese)(void *vd, void *vn, void *vm, uint32_t desc) intptr_t i, opr_sz = simd_oprsz(desc); for (i = 0; i < opr_sz; i += 16) { - do_crypto_aese(vd + i, vn + i, vm + i, AES_sbox, AES_shifts); + AESState *ad = (AESState *)(vd + i); + AESState *st = (AESState *)(vn + i); + AESState *rk = (AESState *)(vm + i); + AESState t; + + /* + * Our uint64_t are in the wrong order for big-endian. + * The Arm AddRoundKey comes first, while the API AddRoundKey + * comes last: perform the xor here, and provide zero to API. + */ + if (HOST_BIG_ENDIAN) { + t.d[0] = st->d[1] ^ rk->d[1]; + t.d[1] = st->d[0] ^ rk->d[0]; + aesenc_SB_SR_AK(&t, &t, &aes_zero, false); + ad->d[0] = t.d[1]; + ad->d[1] = t.d[0]; + } else { + t.v = st->v ^ rk->v; + aesenc_SB_SR_AK(ad, &t, &aes_zero, false); + } } clear_tail(vd, opr_sz, simd_maxsz(desc)); } From patchwork Tue Jun 20 11:07:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694475 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246312wrm; Tue, 20 Jun 2023 04:14:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ59hZt9hjqkJ0VvLlnmOGLLIk2ZctLIH2A6z2dkDyoopi0c3z3IDYt0NDOSmsRKxS9pmTp4 X-Received: by 2002:a05:620a:8f09:b0:762:51c3:cfda with SMTP id rh9-20020a05620a8f0900b0076251c3cfdamr7064209qkn.7.1687259676950; Tue, 20 Jun 2023 04:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259676; cv=none; d=google.com; s=arc-20160816; b=HDJHtFJdmv3uk4NTKMiLO5F9PFm0eOEfo9aK4y6lNTmJNtS92+6cOupMXHBELjgcRW TNnusr8tiiExo5ElPqMRvhhtv0aMXn6D7kdaXCJIIWKHO8O/tRR94e0AWVo3RrMg53vf 2rs6OdoTe3P82osyE5Jr+1469O67ZtahNyOtQekaN5ILBun0swKNlH7LDH66vvXVhqha riVCDsUq9U9R3E4cBDVDBP93z47zPexkcZxo1oQ4dDHIVJRwY0SlAWqpAMcgVp5IDX0y 6TfH6ORQjeLw8igIQgZQ4CyCzvJM0gxGchPUUHa3ce+3NeqMEDytBvWLOeaNJrZ2KaqT 36XA== 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=CXOtR+skbBy3g0n+KA4k0jDRJwr6870/fEeTqXEf6Vk=; b=JoOHup37g/DBFyiCDS1MP5JpqI03OSX9diWlptLXdwJvDWrnLlqos0br8w5LLjE+0w l+Lf4iMiNee1XVkyLJpdLN/k/9l1Tuj0UtykwN72B3MzkvIxW6Oi2rY74z8DB9cNqgxu 5mK+nGC2f3uUvc8vuYwWmQUCrLxDDerzpguggz4voGvlti8agAWUT3labiv1KxpgX/lP iyZCJie/VepLC00gPcFIV6HsUsxu7KgcQ83/mXPQqgZ9akcIbT9fnHQ6O5CF83GPbHck CeYMEnC0FkYyBSE7eh1DNyZMVIp/BLZ3hB8IGrIU0m4rgHz2Ew/q5jiIaMqDo1xZUc6g 2o1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="CsckY/3o"; 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 g15-20020ae9e10f000000b00762192ababcsi690978qkm.402.2023.06.20.04.14.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:14:36 -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="CsckY/3o"; 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 1qBZDi-00065G-88; Tue, 20 Jun 2023 07:08:22 -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 1qBZDf-00062o-Lh for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:19 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDc-0004FD-4R for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:19 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-98802908fedso415220666b.1 for ; Tue, 20 Jun 2023 04:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259294; x=1689851294; 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=CXOtR+skbBy3g0n+KA4k0jDRJwr6870/fEeTqXEf6Vk=; b=CsckY/3o3nLyfBEzy/Wcg8Q2mo/JhZk7WYc7hQKd3JqcDbu8XKJl689fgJWtmzpttl 3fCNlv+61vMkrebTpLg5YtA5Y7vmdD7t4flcSCl7YyVJk8TKgtw9VrUgUkhLvobHCOSu FwclqOdOz8XjIEUG8dXOlWf2kjRIkfdTxMaIHwdD4bZwXlSOC2cHK6AYosNlrRQMNj94 r0KXH5spim2Fteb8F4fK2DqoXggSlTsykGUcl9jr3t9aPKQPxPaPmm5gJQCmPKjGVmKv i/uJaUv4t0U6wN2P9Kp90k0Ps+XM4jZpUKEnKZ31AaR4wrnO3b4t1aGMP1TH3SGorHtt krqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259294; x=1689851294; 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=CXOtR+skbBy3g0n+KA4k0jDRJwr6870/fEeTqXEf6Vk=; b=fTb4WqCbiUOYa4gXR+MZEIk0tojwy/KVym2ywxhiPBeGbV0cGoykz54EJd6MGWJAaj RI4KjKYTIz7NRIZtwZbIqZFQMs3hch5gA6kZlTWkbQ3aQ2HXYDZZLsYfRF5AJA5rYQft GTMbTLdK0CF/Ihml7g1Bv0KaFlhKDLP6V0zftjGKUgUdJ+Y46vW20sQtSOhZBsWk8NJo NWW4L5swla9bOtR8vYtGEI9pcT0lqLvULI5Adpx+TM28Fd8csaF/lL3i7DFRmlUU5r4a FsYa0WQLHlVsLSEINr2h6gUaxeBhD8RXHG2NJl5iBRrPEtV7NPadq++xi2UoIJIGuacX MX/g== X-Gm-Message-State: AC+VfDyBwiOjXYiaZYUK0mrQnfm2cb/Gbc5YkHRq4Shh2TzYyoA/0/bs 5VqVLue2EFX1zryKBrlCfBKtYeNntCL2B4Ea3/krvF/8 X-Received: by 2002:a17:907:1c96:b0:96f:8439:6143 with SMTP id nb22-20020a1709071c9600b0096f84396143mr11867211ejc.40.1687259294633; Tue, 20 Jun 2023 04:08:14 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PATCH v3 09/37] target/ppc: Use aesenc_SB_SR_AK Date: Tue, 20 Jun 2023 13:07:30 +0200 Message-Id: <20230620110758.787479-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62a.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=unavailable 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 This implements the VCIPHERLAST instruction. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel Henrique Barboza Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index d97a7f1f28..34257e9d76 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -25,6 +25,7 @@ #include "qemu/log.h" #include "exec/helper-proto.h" #include "crypto/aes.h" +#include "crypto/aes-round.h" #include "fpu/softfloat.h" #include "qapi/error.h" #include "qemu/guest-random.h" @@ -2947,13 +2948,7 @@ void helper_vcipher(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) void helper_vcipherlast(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) { - ppc_avr_t result; - int i; - - VECTOR_FOR_INORDER_I(i, u8) { - result.VsrB(i) = b->VsrB(i) ^ (AES_sbox[a->VsrB(AES_shifts[i])]); - } - *r = result; + aesenc_SB_SR_AK((AESState *)r, (AESState *)a, (AESState *)b, true); } void helper_vncipher(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) From patchwork Tue Jun 20 11:07:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694471 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246136wrm; Tue, 20 Jun 2023 04:14:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vxhgYpxJpbM3IWLUhAw1g5EkabhwE0tJESN8J1tsQ1f7AVQKxqj/EUhH0SuxgZeaMET9F X-Received: by 2002:a05:622a:14c7:b0:3ef:25ad:27fb with SMTP id u7-20020a05622a14c700b003ef25ad27fbmr15383602qtx.30.1687259654555; Tue, 20 Jun 2023 04:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259654; cv=none; d=google.com; s=arc-20160816; b=xLmk5BxsmLBGwlLPDP3SyzzmIiN/PetbjYH3W85kU2DutIofZLBZ8+G9dSbGhWqbNm NgblqAmgPnc3QgBwUOk8ep8SDc8sx6IC3yfiYNTRMIiIu2NQyfl8TYyyDA6eW0YK+iQM ixofBFwZKhOsX98N1xMakLU9m/ZCKANzXH74wbDEePQFNnZVyM/jpCr5Y9sc9GBuCysp tzRwB88k79bvARLKdbNGCSh8Zi/C+bswnUx/wgPTquHH6uFTlQc74geVQsIy29ld7kct 6JE/an3VwLniWmGj/ipp2i5TDm9D0mTk1iQIRD+DHNbo3xwGUyH6sqhD/spLRVg/ckns RqgQ== 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=pqEpHLv387miC8e5l2/HE3hMgLmxzv9wY41InkeK+gI=; b=K8VXNIN3w/EhsmL3ktWdzBWU4aS+Y/aNH1VY6RrpR6rrn2XbJs9Q1RL1TagiGcTcLo KruJHkRezicMC+zfQtItGBq5vKbb8VgUd+mlYmI/kA9sJO2wo12y2RtsH9wg0Y2pZrTd fV+kWjBIwkn3qfRnlTiMgNQvgvjp/lXDMR6DmG6jvrQNG4k5JtLC7thbfu5NiuMhhcGW DagHbYMn3RUs3s4n0yWHoqcTT3qsHRWRUcZVAa6fKC/8eRDjm0MAMZW+DE/00lJE2WkW amRzkeE5fQC9JJtsiv+6AWs46fqr02Vum/oWuC1kQcqQU+O1xZsuzdyGjKe6+XUAowcM 7lAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xQ02uryb; 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 t12-20020a05622a148c00b003faae0e94b1si696343qtx.440.2023.06.20.04.14.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:14:14 -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=xQ02uryb; 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 1qBZDh-00064p-U8; Tue, 20 Jun 2023 07:08:21 -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 1qBZDg-00063U-6j for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:20 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450: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 1qBZDd-0004G0-2z for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:19 -0400 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-988a2715b8cso399557966b.0 for ; Tue, 20 Jun 2023 04:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259295; x=1689851295; 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=pqEpHLv387miC8e5l2/HE3hMgLmxzv9wY41InkeK+gI=; b=xQ02urybD0UdA7ZrUaaXUhEzGh88jpXvfJ4bqeLFN+cv/AZTfVvFBgAs40ZbNouhtF KruIR5F5pGhxd/+X7ELeBIsCnZekbWQIWH+MK6vlRYYd+KFoOY0QWIhwfw9hTI3k3kJX CT/u+U2r5++PyO7JnqukFNrJ7txWYNIEjmVtZmaOjYYA3hG8+pb3o18D4O3P9OLSSdTf Tip1zEb0v4Ef5f9LjclgwYq6uw3+CLkivVEDIg8bf5UaMvCU3Vrl21TSBd3QomIP83Px Fjzf0Q9M5P95/sYOIflYRL8JF4vB8eUeHo4HEED1TWolihUhJzQd52//UEurhOSgViKE lVFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259295; x=1689851295; 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=pqEpHLv387miC8e5l2/HE3hMgLmxzv9wY41InkeK+gI=; b=EnUi2qJQrog0f/Bgoej1hv14l3iYQLz6fFDxfI3jBLXM0PNV/62SuWfj5ksw7FiVJQ jP+MfSEeT6Lmwvf3NmXWqFyWBjFgda3SrpZKgwZYHujukErdJupdA20x95aQEtUdAYY+ hsZ502Ih23EsLjPH+3pEwfCFIhlwGvvZnfe2HRDP9KPFiCTXy2JEoHAnILBWvc/VipRu av4j2/P8B99zxDNNRTuugezeREvGNTmD9k1hgQ9l+vmhl7bvXWSfXQpUP1rraNOClTAg 14HxyiO66URBcnLHxkB4SmAYdo/4xG46PdjJBE33UXrPYCg6RQ/kVnrhDJmqN3FPObkT YPxA== X-Gm-Message-State: AC+VfDxUZ9xSISf+/St1SqFXUTzhLkQ8SIKa0GkEGTReZvoXj3J7BcwB eFOW+wSYLC9RFqgVgstZYEdfOdNxM5b8/jeQZckbwOKj X-Received: by 2002:a17:907:6d25:b0:970:28c:f960 with SMTP id sa37-20020a1709076d2500b00970028cf960mr16104251ejc.17.1687259295724; Tue, 20 Jun 2023 04:08:15 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 10/37] target/riscv: Use aesenc_SB_SR_AK Date: Tue, 20 Jun 2023 13:07:31 +0200 Message-Id: <20230620110758.787479-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x634.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=unavailable 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 This implements the AES64ES instruction. Signed-off-by: Richard Henderson --- target/riscv/crypto_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c index 2ef30281b1..b072fed3e2 100644 --- a/target/riscv/crypto_helper.c +++ b/target/riscv/crypto_helper.c @@ -22,6 +22,7 @@ #include "exec/exec-all.h" #include "exec/helper-proto.h" #include "crypto/aes.h" +#include "crypto/aes-round.h" #include "crypto/sm4.h" #define AES_XTIME(a) \ @@ -136,6 +137,8 @@ target_ulong HELPER(aes32dsi)(target_ulong rs1, target_ulong rs2, AES_INVMIXBYTE(COL, 1, 2, 3, 0) << 8 | \ AES_INVMIXBYTE(COL, 0, 1, 2, 3) << 0) +static const AESState aes_zero = { }; + static inline target_ulong aes64_operation(target_ulong rs1, target_ulong rs2, bool enc, bool mix) { @@ -200,7 +203,12 @@ target_ulong HELPER(aes64esm)(target_ulong rs1, target_ulong rs2) target_ulong HELPER(aes64es)(target_ulong rs1, target_ulong rs2) { - return aes64_operation(rs1, rs2, true, false); + AESState t; + + t.d[HOST_BIG_ENDIAN] = rs1; + t.d[!HOST_BIG_ENDIAN] = rs2; + aesenc_SB_SR_AK(&t, &t, &aes_zero, false); + return t.d[HOST_BIG_ENDIAN]; } target_ulong HELPER(aes64ds)(target_ulong rs1, target_ulong rs2) From patchwork Tue Jun 20 11:07:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694489 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247437wrm; Tue, 20 Jun 2023 04:17:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7m4hYl08ew4smS10vHpYcsfVuFgtCznRCsGqYyB9d2oUTgoiJ7DtwbT20/gIDOuh7rU9lZ X-Received: by 2002:ad4:5d62:0:b0:62f:f23e:14fe with SMTP id fn2-20020ad45d62000000b0062ff23e14femr16883527qvb.20.1687259833886; Tue, 20 Jun 2023 04:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259833; cv=none; d=google.com; s=arc-20160816; b=YHTlc89QZb7bvDAkchX/qglKkpf6d/nGlS62Qc4xeqWnbj+WU1oxSo23b8wMFwa1rJ eTFD7V4Gb+wGOjc8df6oYU0fQGkyiNIDSyUqPxzA+5N5J3SNvxA6DxRtdw8So8MmVxP/ cLUgpD9ZyKDehkDilbFBfzI2UNrkFSRMAL4M1OmBTD4TrXy+mFNapuvBq1qiBj3rL1iZ 54zvN7PR4TY5rfMkfoKVeHNqOm9PuIwKTO6tU8pJSmhEQSgX6S2mJWKm+SFVRSArUC0G JSBATSMa5dXSVYMIeFAYnncrFsjZUleUapINWW4V7fl5cTfkGICj7T1d4tHne2T0NXzj dmIA== 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=RF9gkbqYy40O49MNRxkszLXC6NRN9VopxJ/DiScwWiQ=; b=0TU9r6U3jG5S4OMiuD90qsz7/zZfF45/lJQuif2X29EzPNzlfQp/sc4d7AHKk8Eo2+ MImoOzRKGdZvaOQ3gihx77am7Z/lStljbzXnQWeLegZiZmsUq1Dt4+B3dPCsUkPTmMOR /Vr9hx4ZMfvmNDcdPO2P2nCsBz/Rkx5AcJFK6KpWfKSqc7U99iBUmnjc+aZOEOiW0Z6h opc78DI0zL6AGVE6OBV+IEv1ccm5Lr/Kf9MyernKXGNzSsrW0VaHanq5PDjG211M+Jmm YRVpNH78tTsq59GmCxpChFu4Ax2GltWJ6TYt6zmhHUOZfluyqyX0ypeMdqVXwDZoF7cg gzXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fBJADhAM; 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 c21-20020ae9e215000000b00763b5beda2csi244646qkc.417.2023.06.20.04.17.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:17:13 -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=fBJADhAM; 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 1qBZDj-00066n-9N; Tue, 20 Jun 2023 07:08:23 -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 1qBZDh-00064O-Fl for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:21 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDe-0004Gw-GK for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:21 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-988a2715b8cso399563666b.0 for ; Tue, 20 Jun 2023 04:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259297; x=1689851297; 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=RF9gkbqYy40O49MNRxkszLXC6NRN9VopxJ/DiScwWiQ=; b=fBJADhAMiP4QNUtrnVCH9NPEqIkNx70zUzrL8agrNqowYCE1t+VnCOy/RoB1vJy5MC GKNxChM9un0ng7T6++w9/91t2G6s0sQaT/TkjFPGkWClTgCrEoOs4xg7OkTBTQMXpXCG xB5C0EAWBmXzsdIzTcVYVmm+iC4WIxMXP9HH0EvIp1b9EK6CsfsZC/rTAYUV57ri+LxT c7t5AlBW269ic3jylj8g76k2c8FKY29ur6q3B/PWMfS6XCgjhE6t0vqyG2Yz6oVxYSxK alJvKlFHcSdy4SnJXIB/YbcRagbAcC+tDih90Ax07C2pxwgsEDqbRZVE8iJmQNdoHRCy vLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259297; x=1689851297; 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=RF9gkbqYy40O49MNRxkszLXC6NRN9VopxJ/DiScwWiQ=; b=O/YhLFk+wZYSTL7K0gYpIToYj0PcH6K63uQnpNn7OG/vOV2frbyJQ7In/AXbZEHKMc YyOv7tFxhkvN+JHlkCrVBSadD8PmVUmemFUoy6+ZoMU/9g7oko5Tiy/GQ3f2gGztMemO NGX4oyePVF1IMoXsFgWrJ853X9+JFCDa/YD1jm4pqiJr+/dKwwBxpJnYke9j1hUwQRV6 Y9f/0SguBO8I564y2QOnH6ERptImbZYE74lsQhp8LSnKnfxnqvhT+4loziJRj3zo/+Zy gnwWul29UPY08w/L/hoSXcbOl1C5qsWlqYdf0mFHoRvV4hPAXiI3o69dL/4J0eR+3LZL Eejw== X-Gm-Message-State: AC+VfDx0JAoBg2zeu5G6uhVePgXx6jTMkMJ98oPCImCggS6o281+G3+X M8DcZLG1YWpVPlz82AcR90RY0uNVLiS738yMJH2S8pwm X-Received: by 2002:a17:907:7290:b0:988:e6dc:bfae with SMTP id dt16-20020a170907729000b00988e6dcbfaemr3300776ejc.24.1687259297234; Tue, 20 Jun 2023 04:08:17 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 11/37] crypto: Add aesdec_ISB_ISR_AK Date: Tue, 20 Jun 2023 13:07:32 +0200 Message-Id: <20230620110758.787479-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62a.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 Add a primitive for InvSubBytes + InvShiftRows + AddRoundKey. Signed-off-by: Richard Henderson Reviewed-by: Daniel P. Berrangé --- host/include/generic/host/crypto/aes-round.h | 4 ++ include/crypto/aes-round.h | 21 +++++++++ crypto/aes.c | 45 ++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/host/include/generic/host/crypto/aes-round.h b/host/include/generic/host/crypto/aes-round.h index c5d8066179..c9b9d732f0 100644 --- a/host/include/generic/host/crypto/aes-round.h +++ b/host/include/generic/host/crypto/aes-round.h @@ -13,4 +13,8 @@ void aesenc_SB_SR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); +void aesdec_ISB_ISR_AK_accel(AESState *, const AESState *, + const AESState *, bool) + QEMU_ERROR("unsupported accel"); + #endif /* GENERIC_HOST_CRYPTO_AES_ROUND_H */ diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h index d675d2468f..f917339104 100644 --- a/include/crypto/aes-round.h +++ b/include/crypto/aes-round.h @@ -41,4 +41,25 @@ static inline void aesenc_SB_SR_AK(AESState *r, const AESState *st, } } +/* + * Perform InvSubBytes + InvShiftRows + AddRoundKey. + */ + +void aesdec_ISB_ISR_AK_gen(AESState *ret, const AESState *st, + const AESState *rk); +void aesdec_ISB_ISR_AK_genrev(AESState *ret, const AESState *st, + const AESState *rk); + +static inline void aesdec_ISB_ISR_AK(AESState *r, const AESState *st, + const AESState *rk, bool be) +{ + if (HAVE_AES_ACCEL) { + aesdec_ISB_ISR_AK_accel(r, st, rk, be); + } else if (HOST_BIG_ENDIAN == be) { + aesdec_ISB_ISR_AK_gen(r, st, rk); + } else { + aesdec_ISB_ISR_AK_genrev(r, st, rk); + } +} + #endif /* CRYPTO_AES_ROUND_H */ diff --git a/crypto/aes.c b/crypto/aes.c index c00f10bad1..3d24781858 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1295,6 +1295,51 @@ void aesenc_SB_SR_AK_genrev(AESState *r, const AESState *s, const AESState *k) aesenc_SB_SR_AK_swap(r, s, k, true); } +/* + * Perform InvSubBytes + InvShiftRows + AddRoundKey. + */ +static inline void +aesdec_ISB_ISR_AK_swap(AESState *ret, const AESState *st, + const AESState *rk, bool swap) +{ + const int swap_b = swap ? 15 : 0; + AESState t; + + t.b[swap_b ^ 0x0] = AES_isbox[st->b[swap_b ^ AES_ISH_0]]; + t.b[swap_b ^ 0x1] = AES_isbox[st->b[swap_b ^ AES_ISH_1]]; + t.b[swap_b ^ 0x2] = AES_isbox[st->b[swap_b ^ AES_ISH_2]]; + t.b[swap_b ^ 0x3] = AES_isbox[st->b[swap_b ^ AES_ISH_3]]; + t.b[swap_b ^ 0x4] = AES_isbox[st->b[swap_b ^ AES_ISH_4]]; + t.b[swap_b ^ 0x5] = AES_isbox[st->b[swap_b ^ AES_ISH_5]]; + t.b[swap_b ^ 0x6] = AES_isbox[st->b[swap_b ^ AES_ISH_6]]; + t.b[swap_b ^ 0x7] = AES_isbox[st->b[swap_b ^ AES_ISH_7]]; + t.b[swap_b ^ 0x8] = AES_isbox[st->b[swap_b ^ AES_ISH_8]]; + t.b[swap_b ^ 0x9] = AES_isbox[st->b[swap_b ^ AES_ISH_9]]; + t.b[swap_b ^ 0xa] = AES_isbox[st->b[swap_b ^ AES_ISH_A]]; + t.b[swap_b ^ 0xb] = AES_isbox[st->b[swap_b ^ AES_ISH_B]]; + t.b[swap_b ^ 0xc] = AES_isbox[st->b[swap_b ^ AES_ISH_C]]; + t.b[swap_b ^ 0xd] = AES_isbox[st->b[swap_b ^ AES_ISH_D]]; + t.b[swap_b ^ 0xe] = AES_isbox[st->b[swap_b ^ AES_ISH_E]]; + t.b[swap_b ^ 0xf] = AES_isbox[st->b[swap_b ^ AES_ISH_F]]; + + /* + * Perform the AddRoundKey with generic vectors. + * This may be expanded to either host integer or host vector code. + * The key and output endianness match, so no bswap required. + */ + ret->v = t.v ^ rk->v; +} + +void aesdec_ISB_ISR_AK_gen(AESState *r, const AESState *s, const AESState *k) +{ + aesdec_ISB_ISR_AK_swap(r, s, k, false); +} + +void aesdec_ISB_ISR_AK_genrev(AESState *r, const AESState *s, const AESState *k) +{ + aesdec_ISB_ISR_AK_swap(r, s, k, true); +} + /** * Expand the cipher key into the encryption key schedule. */ From patchwork Tue Jun 20 11:07:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694484 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247063wrm; Tue, 20 Jun 2023 04:16:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zZaVxsuxzKA+V5DQbqhNf4wzzJ+EvKf28yl1v1Gn9oUtqlmGUGIbPA6nSeVXNrpOCVwne X-Received: by 2002:a05:620a:46a9:b0:75b:23a1:8348 with SMTP id bq41-20020a05620a46a900b0075b23a18348mr13410623qkb.67.1687259780526; Tue, 20 Jun 2023 04:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259780; cv=none; d=google.com; s=arc-20160816; b=v+TtTRFY7746MwXljB3G03t1rgzflRGvZOsTWLIwfGAYJzIDsUuRoEaqD1SYYiCef7 QcOHQRWYLvZQTjsYhvj2KpkDek2WpQ6Dj+8BUIca+v2xAP864E1QOG1rnrdXw96CRUp6 k3cIvbnlBOyl1g/alsfTeLYNo89CJFD8UNMajT/ZEhoM3a2wmPxA+pHOmhz/KZCoD9AM LIIpHEa8/JkhWMCfLDDuAIVaYzeMf3nZp5XS3cOO6EEhfMJKy2zvcwX0DlAzt5FdvwZy yvKyGDbpelMbKYZyx1YqI7fAbM+h1Ui7paYAhdcD4E3Pfi1xepm6SX7uXA2jhIdEV5gO e68w== 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=Vdmp9g0LETEOImAoeAZ0vz3CHG5eCYIT92dyMVPeN7s=; b=R8utKDl78rUxVHuy/oHsUYy5+srEhY3vYvPZCnX3pCrVR2x4bDVvy4Qvg5yrAX95ll toEwT/9pYT7/1hIIpGIhZgbaQD69xRuwwMFs6KBuhF1rC5yWejB5ZgVIuTzomUjEh/rB oWZtYuKNadGlbZPa2eocnAe7G4qqtVHoJ9Ld0+bkwxScxJxMelfVlp7/KYSN/dh5cFHm hwD14RwrUDeb9TPf8dIP26kSMZ17YkWenJIFB0A3SHt+dszj9jmRhFmby+RVwJf+8xOJ 63D4YvQegNaBZ7I23/5BaOF7Dz3/Yfv1vcjhZ87eXmGyTiKPT6NN5qsaSfA+STErkoDb PsQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=POXZzDwb; 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 j5-20020a05620a000500b00763b47bcb81si308417qki.750.2023.06.20.04.16.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:16:20 -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=POXZzDwb; 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 1qBZDl-00069M-Ih; Tue, 20 Jun 2023 07:08:25 -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 1qBZDi-00066H-QH for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:23 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDg-0004Iz-40 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:22 -0400 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-51a2661614cso6072756a12.2 for ; Tue, 20 Jun 2023 04:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259298; x=1689851298; 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=Vdmp9g0LETEOImAoeAZ0vz3CHG5eCYIT92dyMVPeN7s=; b=POXZzDwbBxVX8W7rYgGEU1p3NOiohanZdbS6eqbZd95rSQ28b8KjIpQEXgLolavkIl U8v5G31gB6S1zxvNNAFb8WR8Elr9DLRUueBe2IVA1yOtFXRF4/38cSj4V26+4VAzcfbC QEcCF3hg2l/omEgBApSMvnXihuHqVeL+96Jj+fG8j4zmnqYuv25wmN/E292eFjatEcjm XlYOemqRvbJKA9FvbD9Wmxjh1TqD3u7NySWEU6h4G86J0twSu9IZK4lOZG2fS5Gg5jM6 NBGvFPGxrz8HBRt/tIppt+cJgUAZR4bIQ/83p/VF0qGKUOzOOxzlLtL3DBXWgqEIWgmu sc2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259298; x=1689851298; 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=Vdmp9g0LETEOImAoeAZ0vz3CHG5eCYIT92dyMVPeN7s=; b=erDUwXYey7vcgiq/Jo6fYLfSj19Y/kQEj1nu09WckgvfbHNgWTZqUIsrgsekZtTzC1 Up7EGEr/Ewhq80r3xR5GZ84oGIp97hBGHMq2izs6t1xbcCBxtiAf0gHAx6/Ql63y16lm mp3Kw29p7oc07wn1UbA5HTvGKSWASXZq5jPp0N/v/zqh+j+TRtWogk6ijIqkCr4lbyBj mP2ix9Ti7nJfTYmpU/k3REEPt7+OAZgGX1tTXuW3li3UoxeXIF9Dnev3nUogHC7R3aqt hWBvZUAHJdlf9WE6Qk4tm3gBWe73B8c64ari4cYHVi5CdpgHozAHZveRjJu2cOlV9doh 5dsw== X-Gm-Message-State: AC+VfDz72UkeI67hH3P2weN5WSEjSuFyfDS1sMMggglTA3eCG89EAy0y /nI/Kc3E06r1DF6dA+UvzB79zBeHlzqiuXKNWae1YXpA X-Received: by 2002:a17:907:1609:b0:986:4789:1029 with SMTP id hb9-20020a170907160900b0098647891029mr11972896ejc.23.1687259298750; Tue, 20 Jun 2023 04:08:18 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 12/37] target/i386: Use aesdec_ISB_ISR_AK Date: Tue, 20 Jun 2023 13:07:33 +0200 Message-Id: <20230620110758.787479-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-ed1-x530.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=unavailable 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 This implements the AESDECLAST instruction. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/i386/ops_sse.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index 63fdecbe03..0a37bde595 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -2177,12 +2177,12 @@ void glue(helper_aesdec, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) void glue(helper_aesdeclast, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) { - int i; - Reg st = *v; - Reg rk = *s; + for (int i = 0; i < SHIFT; i++) { + AESState *ad = (AESState *)&d->ZMM_X(i); + AESState *st = (AESState *)&v->ZMM_X(i); + AESState *rk = (AESState *)&s->ZMM_X(i); - for (i = 0; i < 8 << SHIFT; i++) { - d->B(i) = rk.B(i) ^ (AES_isbox[st.B(AES_ishifts[i & 15] + (i & ~15))]); + aesdec_ISB_ISR_AK(ad, st, rk, false); } } From patchwork Tue Jun 20 11:07:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694463 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245100wrm; Tue, 20 Jun 2023 04:11:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Xtqx5oU7c9A8fGB+5jVNn9dIEufmthwBNtcPY1DKCxLcR9+3S0wtwtPVumnHE7HhQe0/e X-Received: by 2002:a05:620a:4542:b0:75b:23a1:830c with SMTP id u2-20020a05620a454200b0075b23a1830cmr17197230qkp.7.1687259507907; Tue, 20 Jun 2023 04:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259507; cv=none; d=google.com; s=arc-20160816; b=RRNTXVnJfv+F+Li1Y58LqGwLH56nQVOcesV7RgxQ+xZBcfD6wTrTSTJqkoSBJf/XMO tNL7e3iYIoWIbK3dgiEy2YOezlnRqVjQTIc5fUVNTMZBh+3rmoVPAyt6aimVCU8+6zE6 OgSzrpTwUMAhZ4Cya9/afltHM0Lt9cFfEloQOKlLNVisYFV9mgcmmaZWRD6IkfGOPytc 0esytevTqB77FKPY2eaLnQZ+moYEKIeIK8VrCEnu1eX/cnmedRM3SNniZyHz3o2Ac74n uHJRPuartz8PCxlXA8gV8ZI6iPixIScFFN5n1sqnyOEjRHvXvvU4ZBJYMq6GsFjUx+M5 5s8A== 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=UEsv77WByzgBc2oRedydI0QuEnu20ntgk1P70X2mStE=; b=vQFx+YvajyxGQyd/3uSVuT5hOIZRL/s+s6mQ5akHMCYkKFhZzhpiJtXXbGf6UMEmOl DLzqHPuAvxqNIzAg4F3phs4EDPKYprqLkCMeUQvEF0N2W710l1z5at1DmTe4C8Znscvf oRgeYJugPsqzjPsuD08JCnzy61uYZNpVqu17Lazo4PxWNayP1OloDPJ+NFplRF6pN448 hw3dXYRT6h3ij33vyJpsovG7HzN5OX8KEp9DMPawB7ct0ndFxOeEtrjc9Ir2JsLimDDo q4VYkeLUI0gMPlzVXez29I4eMniGBThkCmzkXw9td8WPi1DroPaWCmmojJvvyqCbLurS 8gbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZwEB19DP; 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 c24-20020a05620a165800b00763acf99b68si524405qko.113.2023.06.20.04.11.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:11:47 -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=ZwEB19DP; 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 1qBZDl-00069E-Ej; Tue, 20 Jun 2023 07:08:25 -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 1qBZDj-00067J-By for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:23 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDh-0004Jf-0g for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:22 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-987341238aeso542383566b.3 for ; Tue, 20 Jun 2023 04:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259299; x=1689851299; 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=UEsv77WByzgBc2oRedydI0QuEnu20ntgk1P70X2mStE=; b=ZwEB19DP0Y51HvcDx58pBIGaunhwqG0Iig5hiyxnmvTQbN3qvDT00cMtGJUIWLNARu UOV3epHi6fsBKOP+X1iw5k5UoCGhiRWeGZSIUiWrBhsu1kIpyIJhbDNXZQDaorSsfCau uI3Snu+9wae4lbTb3rKhWK9auoU/r/sPqX1/QUTz83Z30yIaB9CTAWhMucjzq7LI2zro 9tPJOYgvL67s727uWY4xQdNqrlNDMlmwI/grJKl7n5Q3kBDEBfqu6Vez4Te+3gQjwATk YOnVMB+3PYsJ87nmvSPimR9j4cm3VC2fb1nsq0TaZgB7DavZQ72RB2FmEkMMQHllJeIE XkEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259299; x=1689851299; 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=UEsv77WByzgBc2oRedydI0QuEnu20ntgk1P70X2mStE=; b=VWM+3inXq75XTv/572dg7pgSVhi4YGuQyErtmp9ohHwkbFnMTU0iR7HxQG9FO9vSvv vrjM7rloJp1N3sngZfTmPuiCvmPL5u1VpamnDHxHOHUVs3cMUBv+uSxRRJB31Pmq9TWD 0t8pRRySdwoqJ9666MvDnx9MooBgWph2xTbkjWfSN6rEOhabCH0T74fcOYT+t8WI6DWs Ts88aTHQf3kk13nQRIyoJa2IYA9VNSR/WsMpkQ2cM294Whsd7YwKphOyPhY5VerdMWVd ksMPLaf4hC0PmV8fSuBxYHlEf9XHJG7ZpA5vyF+cot9X/6rYtL2l/oXmyPCSeJr2ASxG 1x8A== X-Gm-Message-State: AC+VfDzJG586nI5KpJfWO+JiCYcJjJ1FA2EgPBDsN28jOFwF9Jyjt6ch N2qFUf8yQFS/qklYK3kGnsyS1cjuYZIRABPuVdppRUx/ X-Received: by 2002:a17:907:2d91:b0:977:cbaf:bc56 with SMTP id gt17-20020a1709072d9100b00977cbafbc56mr12474904ejc.43.1687259299761; Tue, 20 Jun 2023 04:08:19 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 13/37] target/arm: Use aesdec_ISB_ISR_AK Date: Tue, 20 Jun 2023 13:07:34 +0200 Message-Id: <20230620110758.787479-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x632.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 This implements the AESD instruction. Signed-off-by: Richard Henderson --- target/arm/tcg/crypto_helper.c | 37 +++++++++++++++------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index 00f3b21507..d2cb74e7fc 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -48,26 +48,6 @@ static void clear_tail_16(void *vd, uint32_t desc) static const AESState aes_zero = { }; -static void do_crypto_aese(uint64_t *rd, uint64_t *rn, uint64_t *rm, - const uint8_t *sbox, const uint8_t *shift) -{ - union CRYPTO_STATE rk = { .l = { rm[0], rm[1] } }; - union CRYPTO_STATE st = { .l = { rn[0], rn[1] } }; - int i; - - /* xor state vector with round key */ - rk.l[0] ^= st.l[0]; - rk.l[1] ^= st.l[1]; - - /* combine ShiftRows operation and sbox substitution */ - for (i = 0; i < 16; i++) { - CR_ST_BYTE(st, i) = sbox[CR_ST_BYTE(rk, shift[i])]; - } - - rd[0] = st.l[0]; - rd[1] = st.l[1]; -} - void HELPER(crypto_aese)(void *vd, void *vn, void *vm, uint32_t desc) { intptr_t i, opr_sz = simd_oprsz(desc); @@ -102,7 +82,22 @@ void HELPER(crypto_aesd)(void *vd, void *vn, void *vm, uint32_t desc) intptr_t i, opr_sz = simd_oprsz(desc); for (i = 0; i < opr_sz; i += 16) { - do_crypto_aese(vd + i, vn + i, vm + i, AES_isbox, AES_ishifts); + AESState *ad = (AESState *)(vd + i); + AESState *st = (AESState *)(vn + i); + AESState *rk = (AESState *)(vm + i); + AESState t; + + /* Our uint64_t are in the wrong order for big-endian. */ + if (HOST_BIG_ENDIAN) { + t.d[0] = st->d[1] ^ rk->d[1]; + t.d[1] = st->d[0] ^ rk->d[0]; + aesdec_ISB_ISR_AK(&t, &t, &aes_zero, false); + ad->d[0] = t.d[1]; + ad->d[1] = t.d[0]; + } else { + t.v = st->v ^ rk->v; + aesdec_ISB_ISR_AK(ad, &t, &aes_zero, false); + } } clear_tail(vd, opr_sz, simd_maxsz(desc)); } From patchwork Tue Jun 20 11:07:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694480 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246909wrm; Tue, 20 Jun 2023 04:16:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62ky7n77MePaXW8JxQdxw0tl5Skpnc2LXoBy2LTy9XvGolie208NjWJIHw6RGKsDV+c+Ue X-Received: by 2002:a05:6214:21cc:b0:629:58a7:9aab with SMTP id d12-20020a05621421cc00b0062958a79aabmr17352161qvh.32.1687259759792; Tue, 20 Jun 2023 04:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259759; cv=none; d=google.com; s=arc-20160816; b=YsTeXbfrTxVMyrz7UP6Qholpv9B7MjWygCCTUrvymKMd2RfbxlMtctlX0gfIakH4VU H+8Qfs2IMbBB2jxePN6PAaat1Ng8FHR4yLp7QCSDgnaDrWjDpEbYR+zvcaa3bvTRCG08 X84Rme5UMrdAKC6Vr3aWnASHPxbLfueh8C9CE1410mZQg/cTufyl8x67Y8fRvkoAej0m PPROOa0VD0Zk5+NKUlmQQHYBPUeW8f8GEUQICa8LDY7qX7gPyJ1PxP+zZdXrengjAaPa 9YmHe/jj4Csr6XWw01PNnV5QOqj8qqcFKe82G11kSxfXXfbLBor7/KFUdm6kjxv7JGSY 0TwA== 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=9eRhNGGsvyXPq3UhYSn/b3L2GTywYRMcqzsZGePD5qs=; b=siXzIniIB+Me8G3xaZ7EfSlIZu72hT3Uu91y5iLxXhWSOFc4P6tilaw1luDlc7LYXk kgZ/lGU/dnfaQATvncojdkl5bA/xj0fJic2O5HSfMhh8l0Rdn0GpPzDKubKdm1iwKfp1 Eh6GB5HRIB3SphzuSRS6BZWgGTMKzq6wJnSXQcCsOp23ZgvkGn8EB4IPgwlONMsZySb5 M4lrpZm1lmvO134lIiYsvRynj7UpC1/hVxOBav9+hd/j6x+FkrRKsklgWatbkfr/B4LV iWrx+vvvKhXTDu521ExiZSHYcKVtZufLHPAZXnLlXPyBXhvCrzUYuvtSGwqBTUZv214L OUUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qlRMKSDw; 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 r15-20020a0562140c4f00b006239faaf931si711832qvj.441.2023.06.20.04.15.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:15:59 -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=qlRMKSDw; 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 1qBZDn-0006Dd-R0; Tue, 20 Jun 2023 07:08:27 -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 1qBZDl-00069F-Br for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:25 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDi-0004KP-IT for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:25 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-987341238aeso542386466b.3 for ; Tue, 20 Jun 2023 04:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259301; x=1689851301; 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=9eRhNGGsvyXPq3UhYSn/b3L2GTywYRMcqzsZGePD5qs=; b=qlRMKSDw5jp18xRy31DWRLn5VTDlPGb2+rDlWqCbfGnGzbPgBpNsLxyKv7dA+LL6IY vVKOapqjTl61Ylvyn9ENKLqPxcIzQnjw3XIYkPskAG1IEq8f/nIDQPHYeh3BsL6j0nql IIRQTwWevJOg2b4jcs/YVBVy/6DXzaBm4ewMeZbBTaFmlig7FccnOiS5afiTxU4qzjXg MY23qUeiQaH8RHcyazg7Z5jlDwlMs32ikjSkEBceRtzAtuXPYaC70mQoWkpMnppVHrDC psHN2ZKKPyQ53P5TEWDsq/1G7JCYLP1VJad0SC70GHfxE98EtXK3d+r1CtnBEEEWrByQ zVOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259301; x=1689851301; 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=9eRhNGGsvyXPq3UhYSn/b3L2GTywYRMcqzsZGePD5qs=; b=duccV4rL/xwJ5oi2uZ8NDmmdSQiwtNjUH+hJdf7jbKvhUhufleQ1hUZMW3jJ0h6D3j EUwrrdZYYDf8n1hjr1sTj99sZ95vR2FiE97eW8dfwb0GN9YB+nua/S8EDG+YHI0PwHiX y+HmzQOgQtflQm/tCiezltNmnwavldQxGvtYkj0sso5BjStYskIfKTNaMYM3yLsmTEvA A8/1XuM5Ak4AgdymkaXQTEb8cQ/6NRZZp6XwhAmB3eYvY69CCA0WTnQ/YnCkg3H45QE4 dehg0BypYkPV6qas/lyV97ROc/GW3PxE8rECU1cX3tYgw3vtkslII9XaB3Lw/n0h4FQP goPA== X-Gm-Message-State: AC+VfDy98lFzlKu9KnTPvkEaqtiTyY1j/sT2b8aj0zzoI3vlbfZSv4ia bZmnwSiZh4e6otIBYVIDxTJcGnpKCIjDRlieLb4HTRQC X-Received: by 2002:a17:907:97cd:b0:989:5a7d:f43a with SMTP id js13-20020a17090797cd00b009895a7df43amr57930ejc.66.1687259301070; Tue, 20 Jun 2023 04:08:21 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PATCH v3 14/37] target/ppc: Use aesdec_ISB_ISR_AK Date: Tue, 20 Jun 2023 13:07:35 +0200 Message-Id: <20230620110758.787479-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x636.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=unavailable 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 This implements the VNCIPHERLAST instruction. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel Henrique Barboza Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index 34257e9d76..15f07fca2b 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -2973,13 +2973,7 @@ void helper_vncipher(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) void helper_vncipherlast(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) { - ppc_avr_t result; - int i; - - VECTOR_FOR_INORDER_I(i, u8) { - result.VsrB(i) = b->VsrB(i) ^ (AES_isbox[a->VsrB(AES_ishifts[i])]); - } - *r = result; + aesdec_ISB_ISR_AK((AESState *)r, (AESState *)a, (AESState *)b, true); } void helper_vshasigmaw(ppc_avr_t *r, ppc_avr_t *a, uint32_t st_six) From patchwork Tue Jun 20 11:07:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694481 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246911wrm; Tue, 20 Jun 2023 04:16:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Z3sJEG8FKWJxlhFmXvSl9gcbvwcfHQJ+Ju7uXhUyCcNLa1hpgKcsFZNylCYZsENUroQre X-Received: by 2002:a05:6214:2302:b0:626:3375:6fea with SMTP id gc2-20020a056214230200b0062633756feamr13237265qvb.22.1687259759950; Tue, 20 Jun 2023 04:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259759; cv=none; d=google.com; s=arc-20160816; b=X5yYPl+qblivyX/D0KaGeCAL9A2RSI9fQyF4RVV0wIMawdKEkAkIkklxBXDtISsi4Q Ue3FsyZAqBrIoEoq5sH7pkxTBpxcKt/IgwO63+mp9o9RS0/qAVsL8JwDauVqzMFCT56+ WplBrOKY+86eXq/rU2WPe3dniqiGYMNpPJgGBTbIQDBYmkVF4HUImi9VpDJtRNitdEqy 9qk7PwpWU2txmi0B6RCoc9/7lQxDmrNo4zBmez9gGwWzAsdUinpsG2uLuWMpRi0k8Dpa riocL4tKF+ccYZ8jJhxmwwEnXpw3lPpvboHPlsgSdy+czQFw25j7hfR9ctxbjkSrKmds n/dw== 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=QRqjQC8v/J/3z0IiE+GLS9BAOlnmnUcZezvum6TPI3k=; b=WqkCuknStikdaSQe4kCA6qOzy7ppBpUXgmogdnU8cUDNTJqyDzn88VKFQ8lYNHPwGT dJC7qymshlNMjqYVc0vy2uvEqgwxChQbQnHkRgkGUhqqScJxB+e3x74UraVac9xPNoh5 joN/1llmSTwfmcCRv2KfPBI4OCCTUEngdSiiA0M5e4XMEXcdBnMyQZhWTL/INh58FT0m 6bby3+6f8iAu3moFgzcaEQRZAaeg4XxJQPttwo8ezzvghvbHNyE4nu3NdLyxiA5HCiXv bFv//K0SfWNEqYWHFAxIG33E37TbY15L5oEcaubRrDJC8pXy5FpetMtMllz7ycpMvDOQ mjOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aWp/iwox"; 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 6-20020a05621420e600b0062dec1c9bb8si725266qvk.513.2023.06.20.04.15.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:15:59 -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="aWp/iwox"; 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 1qBZDp-0006GH-TO; Tue, 20 Jun 2023 07:08:29 -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 1qBZDl-00069L-IL for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:25 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDj-0004L7-Gu for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:25 -0400 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-982a88ca610so546771166b.2 for ; Tue, 20 Jun 2023 04:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259302; x=1689851302; 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=QRqjQC8v/J/3z0IiE+GLS9BAOlnmnUcZezvum6TPI3k=; b=aWp/iwoxUbkQolVQKW6qGvPmtiWB/WaMvGJvQaoaJUJXr2aRSCbSXU/LPxwFV8lLTS /M5D3laZG6F95r6RJP7kHJ2jYlEBCxIKHLWS+Dl+cxq+ETau5ofZaeadoskTY7rT63mp OclFYSl6GK9j/JvgLaEN15/zR607mB6L+FIePPygL4P5kSG7rDAJEIsZ2ji/iDVlZuAm B+ZAm4fAPBB0ChlkMzsoTBQpRQ2lcrtTCfqX9boJADTspm6d0aiYkNGiOAOY+zNtFv8W ocPabNcOjMN5pCSJv4ROaMtI32+6HwZK/hTKH4y+pBNsT7UaNLywZIxBanBIQqz02sXx OBpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259302; x=1689851302; 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=QRqjQC8v/J/3z0IiE+GLS9BAOlnmnUcZezvum6TPI3k=; b=KeeIUdZATi13wrCMcWTgKNHWF+or/JwGYrQmC4ymi3txLSe4j0EpH04spuFAuzkEXs wtpc45X687HnmgcaeAl7KXkUx1aFkhJz57Obf8Jiq345NZismtfx3RaMnzfnBzOR3jaB un49WAMjd34xGsvt42dvKTtm5K0f9+ncZkvi1Mw20bt2N7qLZc/DtErorzOkVMPzru59 Y5Kh4Qdm4MNE9FvVVzW6yelkS/Ixi8eRwpxn+/r3jipqPbVBQlFuO8Cx6XTr6be3Iu66 Gq5sUiLs3YznU+DyBCVUcav974GUQAsz8LvxgzcKRf1jUo1DstSOfMbXlNlArxGOG+dZ FNMg== X-Gm-Message-State: AC+VfDw2ykqlgr3aRwNdi7f+Da0OfjaYYnwFPHOBcZzEbTNi5m+b8zc9 2ImB2FnKMCw1Dl3Rfy4uUpdN8aD4rhgxvaCVkXKyFbKO X-Received: by 2002:a17:906:f84d:b0:965:6a32:7de6 with SMTP id ks13-20020a170906f84d00b009656a327de6mr7917240ejb.30.1687259302192; Tue, 20 Jun 2023 04:08:22 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 15/37] target/riscv: Use aesdec_ISB_ISR_AK Date: Tue, 20 Jun 2023 13:07:36 +0200 Message-Id: <20230620110758.787479-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62b.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 This implements the AES64DS instruction. Signed-off-by: Richard Henderson --- target/riscv/crypto_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c index b072fed3e2..e61f7fe1e5 100644 --- a/target/riscv/crypto_helper.c +++ b/target/riscv/crypto_helper.c @@ -213,7 +213,12 @@ target_ulong HELPER(aes64es)(target_ulong rs1, target_ulong rs2) target_ulong HELPER(aes64ds)(target_ulong rs1, target_ulong rs2) { - return aes64_operation(rs1, rs2, false, false); + AESState t; + + t.d[HOST_BIG_ENDIAN] = rs1; + t.d[!HOST_BIG_ENDIAN] = rs2; + aesdec_ISB_ISR_AK(&t, &t, &aes_zero, false); + return t.d[HOST_BIG_ENDIAN]; } target_ulong HELPER(aes64dsm)(target_ulong rs1, target_ulong rs2) From patchwork Tue Jun 20 11:07:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694482 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247019wrm; Tue, 20 Jun 2023 04:16:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6B0bSZxu1KACC+tJs0StqtJtFDuXpfsDyQeXEjHoI7hGcOkb5TMSxqf3wr/LULZ50E2MgY X-Received: by 2002:a05:6214:c6f:b0:5e9:2d8c:9a06 with SMTP id t15-20020a0562140c6f00b005e92d8c9a06mr16385265qvj.39.1687259776532; Tue, 20 Jun 2023 04:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259776; cv=none; d=google.com; s=arc-20160816; b=RrApuleMj8DHYKVParqUmat4p/RSbmeEXpZ0DIN9eKsCSC2+SLEqI9PypNDDBu3d2b 7hHqcvehmbk1PTVHvSzba2OYGmOJgnD8Kpsl6n3hdXBQhM6slENUj7+54dWZWptoe0XS fswsarKmZA+O0yPucQyuuXvf0PMr3crGZu3i73kSE54qT2m0EXVuvArmnMkCCV2vgqoX apWem2TPpmgXEt/M9c5a8Z7s82Cyyo+LZQgcpl9luUFI7QkPsA7/hRPraIrk9QGpS4x0 i8QrlRLv+CsIQ8Vtlh8E+VdwI0M1KMZ/YtrC93xfF+j6Ukkgc8rccz+RSCqkFqtPOlXP BQJQ== 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=A7xfy/db8RS4fR9dmE4f+gptt8VWgaldKCFJ1ZLH2+Q=; b=XNiBQ4hOYHcqvXTjnMUUEB8rtEw1vCxCGt4VrZqa2reB78Z6XJMGLyAPY7RdGahexE kManeiE+kFPk4Uma07WFYWkGCzFPu3LbdOUdjw1tkO5Lk3Ze9tSU+au1B8bqOWpaue/M SCGOOyPScv1FXEzyc06Ffkr27rnSVaYfynDdMudT4cPIej33hQLHPDvj2YBBDXIC6qkf 3u06aQoaftCfpEhsxXlUO9FTy4Fc15oKKtXUV1AfSL9Pqd4IYG5s7i9LAGPWhYAhoSvn wHsfCmICNjDcdZxnqX2qsODln3VHQMBwbzokRpEyn7bkwHwqQen5T4szyOugXOg9Fhgh OJTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m1+WbrWX; 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 q11-20020ad45cab000000b0062def41b844si704896qvh.495.2023.06.20.04.16.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:16:16 -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=m1+WbrWX; 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 1qBZDp-0006Ex-B1; Tue, 20 Jun 2023 07:08:29 -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 1qBZDm-0006Bl-Q7 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:26 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDk-0004Lt-Lc for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:26 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-988c495f35fso235850766b.1 for ; Tue, 20 Jun 2023 04:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259303; x=1689851303; 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=A7xfy/db8RS4fR9dmE4f+gptt8VWgaldKCFJ1ZLH2+Q=; b=m1+WbrWXfJAGOYrABKYcNAGXNlQA/v/R3Q64WYVpZs1tHV5B8+JOCPBW+vc5ZlcE0K cIVUsCVahhV8pN1WXGTEb4pLCYjf56M/FZ8mIRUIMQKsATNtUX88UcNSJIlCrP4w4Lro Kr7l8PWPvF5XrUsPQNHz3NVQ2kYW4Zb1srCCcJDtAP8hUmP+58bloreYfarCUKD2634O aE+KOwidrwS4y1i4IobjUHwV/26zAHA4IJZg47jxWCQhx6f2nPJtn1P2Tq+jZZi+TEZS biLqsXJD+qM4oRgfXqgyzf0WnGakAs61GGkbyfHD8KLzFUFpaUrrk3jkWWnm/o2nZmN1 bTMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259303; x=1689851303; 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=A7xfy/db8RS4fR9dmE4f+gptt8VWgaldKCFJ1ZLH2+Q=; b=hCMAztSnjkq4yIFqrzE+y/sDFdp6yNj0WUeENSKMoqncX0d+eneztbz4cTVn5C3Rb9 YqTKT5y7Uy0yhBVyA8LUQ2QNPDZY6tm7G7k945/jiJNd0jlwoCFz59wt7bjYolbRBVb8 PocOwP6K25F8quK8OxIUgKl84L0YRpuAfd7zI01IbYXuT19HBk5Rysye3LBbH/jcSrmV CVPvHJUzsCleHw5sX6JaRpx4swqypgIDLoN5sfqkciqeqPMfdFMMxFcYF1Lic1wENFL0 suL6zDZbNm0eeKPeAB98aVwq8B5fEJqNgLFMLgzH2eR9vM12z14t/OAF8GDFaraQcXde Sokw== X-Gm-Message-State: AC+VfDxDAPKNO+qzOr2Sm8zDMyXNePt2+B5Z5Gd0B7tutM8YkexGYrJe PTho4LQ+dqtI8p5RQDZrW64ACPskQOca9rPtpkghcdIa X-Received: by 2002:a17:907:d0f:b0:975:942e:81e7 with SMTP id gn15-20020a1709070d0f00b00975942e81e7mr13199399ejc.37.1687259303361; Tue, 20 Jun 2023 04:08:23 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 16/37] crypto: Add aesenc_MC Date: Tue, 20 Jun 2023 13:07:37 +0200 Message-Id: <20230620110758.787479-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62e.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 Add a primitive for MixColumns. Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- host/include/generic/host/crypto/aes-round.h | 2 + include/crypto/aes-round.h | 18 ++++++ crypto/aes.c | 61 ++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/host/include/generic/host/crypto/aes-round.h b/host/include/generic/host/crypto/aes-round.h index c9b9d732f0..1b82afc629 100644 --- a/host/include/generic/host/crypto/aes-round.h +++ b/host/include/generic/host/crypto/aes-round.h @@ -9,6 +9,8 @@ #define HAVE_AES_ACCEL false #define ATTR_AES_ACCEL +void aesenc_MC_accel(AESState *, const AESState *, bool) + QEMU_ERROR("unsupported accel"); void aesenc_SB_SR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h index f917339104..df252ac76d 100644 --- a/include/crypto/aes-round.h +++ b/include/crypto/aes-round.h @@ -20,6 +20,24 @@ typedef union { #include "host/crypto/aes-round.h" +/* + * Perform MixColumns. + */ + +void aesenc_MC_gen(AESState *ret, const AESState *st); +void aesenc_MC_genrev(AESState *ret, const AESState *st); + +static inline void aesenc_MC(AESState *r, const AESState *st, bool be) +{ + if (HAVE_AES_ACCEL) { + aesenc_MC_accel(r, st, be); + } else if (HOST_BIG_ENDIAN == be) { + aesenc_MC_gen(r, st); + } else { + aesenc_MC_genrev(r, st); + } +} + /* * Perform SubBytes + ShiftRows + AddRoundKey. */ diff --git a/crypto/aes.c b/crypto/aes.c index 3d24781858..d1ef4c19c2 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -28,6 +28,8 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "qemu/osdep.h" +#include "qemu/bswap.h" +#include "qemu/bitops.h" #include "crypto/aes.h" #include "crypto/aes-round.h" @@ -1250,6 +1252,65 @@ static const u32 rcon[] = { 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ }; +/* + * Perform MixColumns. + */ +static inline void +aesenc_MC_swap(AESState *r, const AESState *st, bool swap) +{ + int swap_b = swap * 0xf; + int swap_w = swap * 0x3; + bool be = HOST_BIG_ENDIAN ^ swap; + uint32_t t; + + /* Note that AES_mc_rot is encoded for little-endian. */ + t = ( AES_mc_rot[st->b[swap_b ^ 0x0]] ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0x1]], 8) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0x2]], 16) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0x3]], 24)); + if (be) { + t = bswap32(t); + } + r->w[swap_w ^ 0] = t; + + t = ( AES_mc_rot[st->b[swap_b ^ 0x4]] ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0x5]], 8) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0x6]], 16) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0x7]], 24)); + if (be) { + t = bswap32(t); + } + r->w[swap_w ^ 1] = t; + + t = ( AES_mc_rot[st->b[swap_b ^ 0x8]] ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0x9]], 8) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0xA]], 16) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0xB]], 24)); + if (be) { + t = bswap32(t); + } + r->w[swap_w ^ 2] = t; + + t = ( AES_mc_rot[st->b[swap_b ^ 0xC]] ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0xD]], 8) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0xE]], 16) ^ + rol32(AES_mc_rot[st->b[swap_b ^ 0xF]], 24)); + if (be) { + t = bswap32(t); + } + r->w[swap_w ^ 3] = t; +} + +void aesenc_MC_gen(AESState *r, const AESState *st) +{ + aesenc_MC_swap(r, st, false); +} + +void aesenc_MC_genrev(AESState *r, const AESState *st) +{ + aesenc_MC_swap(r, st, true); +} + /* * Perform SubBytes + ShiftRows + AddRoundKey. */ From patchwork Tue Jun 20 11:07:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694461 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244778wrm; Tue, 20 Jun 2023 04:11:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6r6yhxJuycoNEyCeqSjemp6idrHtQhf4ZNmfOh0nSkbrZ4QeOmho09Hke8zcC3bWEh2tTe X-Received: by 2002:a05:620a:4390:b0:75b:23a1:362a with SMTP id a16-20020a05620a439000b0075b23a1362amr3725452qkp.59.1687259465698; Tue, 20 Jun 2023 04:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259465; cv=none; d=google.com; s=arc-20160816; b=A4QyAqEoNbvWsforHs+Oe0NZ5lrsAizPeAcCz0anV7OUthUNXFGdc/WAGftDMsedP7 ZmlYKzKJO27Eik8dnqWtFIzO3Ln4EdUBF0lvHD+kcY/wTChsQZH8/mHz/jM/gYQaPzEQ m3IMqtDH1a2zVPNs+KAEsLK5451/EvSfOfid/NVh4qK5wVePT1CkpsGk3Uw8or+A3LjV gmTdUvlenGAuCFjj1Jdkg2wVPSiQ8vAaRmJiGxaG4/C3d7S+3hC6mwQ3FO0ISyxlkhXf 4PUVonvWGdaGwDBmVyx+l8Kx0y1YXVhXw/DrZVbzdUQjpppmUjO3PjayNnJTsYrYlpkA z9dw== 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=N6iXZSXnCLQtjnIuP74mgzpVObleAywaFeG7GQpsIEc=; b=q58OIWl8PYnNLHCxgeinTsg4QjhnqZzw8hJTJEMk5x0Og5PA1EtcE6fu3k0rZOQg+U FGWc9KqpoCbcXPvDmuRsl2XVoKVFPOprOIptvjqzXCuBAVsgy+L2I0OASO95zL5YxQcl XbQDYy4W3oy4maw5CA/v5DG9wyfrCLZiRbVQJZxJ2N+RIvTY/RoYtJqfGBYmomkVUSpU K/b2SmtTVrcctFz19kcqaQPksUi12v4lPswYZNWQEIbO+FKbIvt8sIqTp19wrogDUCpY RQ8ju80VESfcihXP0vQd8RKsnQQIzuvX64EC1t/BfH6WexANIHjvZaoQFmcDBCdwJrOG 8Rog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mMudJ280; 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 k20-20020a05620a143400b007622260f3f8si85526qkj.413.2023.06.20.04.11.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:11:05 -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=mMudJ280; 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 1qBZDr-0006Ik-1V; Tue, 20 Jun 2023 07:08:31 -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 1qBZDn-0006Dh-SE for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:27 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDm-0004N0-A1 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:27 -0400 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9891c73e0fbso143570166b.1 for ; Tue, 20 Jun 2023 04:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259305; x=1689851305; 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=N6iXZSXnCLQtjnIuP74mgzpVObleAywaFeG7GQpsIEc=; b=mMudJ280WURUhhZmKay2iYZ9h9vgrmttnAvWPMP/4jlcK60Upjlc49YAB+87E9KHWF Sqp0bOS76WYhZqFArpqWbrwhR8COmtBNTvd3jMn7qj+XSbl4ScaYtOU67wf3Ee9Z/IXf UerTlc1F1XhT8XrVFkTke9w/rGYAwksa/2/FXxCqBnXPe3qiqdajFslIAentfo/Y/XPt gSD+ygd1xwjNyVk3NXGslRjljuLNCaGXAIwEeK3i+orClKp3Yiu7dZ2U9+a87d1jIQev qWVaTTB0hvxlSsXqRLtQaYOGNJPYtqPuFw1rBor8wNi+uxsM+epTjAzs8hfIZI+otkOS fgDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259305; x=1689851305; 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=N6iXZSXnCLQtjnIuP74mgzpVObleAywaFeG7GQpsIEc=; b=kjqIk38SoAzvEeMiXfJBd1JGkcnK8dZAXJf9hEsQTTcl24qGUrFEIzwSBwZ8rKgFaG odS0POMmGtUGeg8UFvGdtgWhvEvDnhi2aqlfgPWm2s/Dg8xxFe2xvsCWMWEQKgcRMHW6 p1HVdBE+qT/Wi3nQmHn+4Jux9U0XQZvx1trOTDdKcLd/3ubXsH4bn4W3zkiJnVjcqsZs sGZkq8bG3onQ7GmZbkf7+o38/0VRa+KWimuVGU14YYKxGqOAEoeh460FzZ3Oh8R/bPve Yvpg8BjkuAhzYzwUgZ9B3hcCv5MIGY0+Vy+hCIJSIaITSkqIZwILVND0mrTexJW/CQyu WBhQ== X-Gm-Message-State: AC+VfDyvrg1P9iyMi+izRgLyJ0p1AHKQHwoDN5wbfX3RZsbS/qiCY+9M XxUgFQrF+hAvpJT5ZBypi4IV3IBksiRTW+cZz6uYQ2nX X-Received: by 2002:a17:907:7ba0:b0:989:4b:e69e with SMTP id ne32-20020a1709077ba000b00989004be69emr2732973ejc.4.1687259305002; Tue, 20 Jun 2023 04:08:25 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 17/37] target/arm: Use aesenc_MC Date: Tue, 20 Jun 2023 13:07:38 +0200 Message-Id: <20230620110758.787479-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62b.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 This implements the AESMC instruction. Signed-off-by: Richard Henderson --- target/arm/tcg/crypto_helper.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index d2cb74e7fc..1952aaac58 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -124,7 +124,20 @@ void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t desc) intptr_t i, opr_sz = simd_oprsz(desc); for (i = 0; i < opr_sz; i += 16) { - do_crypto_aesmc(vd + i, vm + i, AES_mc_rot); + AESState *ad = (AESState *)(vd + i); + AESState *st = (AESState *)(vm + i); + AESState t; + + /* Our uint64_t are in the wrong order for big-endian. */ + if (HOST_BIG_ENDIAN) { + t.d[0] = st->d[1]; + t.d[1] = st->d[0]; + aesenc_MC(&t, &t, false); + ad->d[0] = t.d[1]; + ad->d[1] = t.d[0]; + } else { + aesenc_MC(ad, st, false); + } } clear_tail(vd, opr_sz, simd_maxsz(desc)); } From patchwork Tue Jun 20 11:07:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694487 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247350wrm; Tue, 20 Jun 2023 04:17:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rvq+D+euckDpWrpo7ObonwZT+1NpEwikKkFcB6y4bjv2JviKXuwqv/sll8KlFYfF2LjB9 X-Received: by 2002:a05:6214:130b:b0:623:42c5:612f with SMTP id pn11-20020a056214130b00b0062342c5612fmr14462742qvb.49.1687259820302; Tue, 20 Jun 2023 04:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259820; cv=none; d=google.com; s=arc-20160816; b=RFTtKZHVZN5bm/CKV81Fj99BQnGq4Vbr7+gEunwfOgwqYtLlbFYef9CsSKaFpWXbgg TLsaFxp6PkhEpzUiJv0I+OKgG+hiVECZKy6t4bku3Ucl+IJAg/xu+cB+sqLs9qI6ZAn4 edrpjICtjTjJKIbW6xhz6wqSJ7VIsBhTr/Iku0dSIHoslq/CpQFHUEREvsVS+CCO4RcA QafNZZml6pL0naNlTNWfd9KVAMQpZgnRP3vK6IkcSjgMTTZwojtMll47hdUvlMizo9+z MTMNcGq6TtrEZniqJyXljsWXomKJK4QD8Sg6hwTe+56HL+igjl7f1v1TrYUhlWGTxCq5 qFfQ== 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=SiJKh9OddvMER1urjRI8ROm1oVZkVAu8kaqi4NJ0AwE=; b=oebh/Ph1bX4yAwt3iqy+K6uegc177vBLw4tf4vLzhF6FtNRX3qgE7LAtn9/w9Oz9hX HXHuuTGNieE3E7G9B1QqpBo0gmLsOsIbN4HRCNeSIRoezQean1TvbMCC/ejRnDp8UtfZ CLGnJBIdUgU0naG7NQZ42DR011UIcOcA0gaHps0SmGmXeg6gkTaKd11vU1hHXLQ/YO7Q QS3expc1ddPYXeSCCwOrhJ2AdXNhoxVBPOwHT0ICd1PIKH4HEAKDv44P8dWE2SN4sQqr NTG0LaUpG+tScYnZee4z1lEdaYVTdI8PQ8T9j1uJ319hztQEqeKJLdH14WI5DsEBOX07 09RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PB36B7SE; 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 jz12-20020a0562140e6c00b0062febb17f3dsi723938qvb.525.2023.06.20.04.17.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:17:00 -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=PB36B7SE; 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 1qBZDs-0006Kb-GW; Tue, 20 Jun 2023 07:08: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 1qBZDp-0006F9-Cw for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:29 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDn-0004Nl-HW for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:29 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-986d871a9beso591159166b.1 for ; Tue, 20 Jun 2023 04:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259306; x=1689851306; 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=SiJKh9OddvMER1urjRI8ROm1oVZkVAu8kaqi4NJ0AwE=; b=PB36B7SEdItAgBXCjw+qZCcY3cUxIf+ce08VbPqQS89g/RPh3rGq2OVoSc0oK8D9UW pA9/kA8s7+8pmVjxjC3zzwBOiWJr8BHdLgRNGwD1YCU44Kba4BB+kfS4SeAvAnfGSIIt rNOyWkx36Z1kYwfrzJxIiHXBS0Kxcmcowh4OZZmlJJZLP8Zqfeq1UPmdp9DRL24JOPv+ XMKH04/i3n9qtu7mt9QMrETWiFbG26IGFVcv2qRwesAJ96ObZ/yEnD2cmhCVN79Aoxp+ ISrQl/bgBokfEKZpTLsuHPBXUy2Ra4/+KU6Cx5OHW5tdDzJNCsqawGXOnojiqe29pB72 fJ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259306; x=1689851306; 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=SiJKh9OddvMER1urjRI8ROm1oVZkVAu8kaqi4NJ0AwE=; b=HKLWTHfP+HbX3wNGVUPM0iUiTat7myCJle2K0njFURfHEA+6TfQ/VdP9j3RqI/xDII 5F1YmqAPhBI80qCEPh8KW5o2f82tlv73KTg9C0BrDX4XanSi5p/NuW2lu6A6fvgEw0qz 4NYQsYSEoqXFiHrqqGZQvfwlV+lJDv2gXCmGmCuxIZsRzE5MSEXZpplIOBZgL1omaCZP 7d5Xi8ky+ISWV7/x2rA/BjiqXcyfvWHgvIFfGnrYHqBH+YBoWKsFaiDxPpT4bLDb4zAy cHglDr5zKufNVYnDFPTrQWXja1Z6nJdM9BShAgGytguNgXcHpck6NkErQmo9cvO86o4S nQvw== X-Gm-Message-State: AC+VfDxahwMnFiT9hE4Y5wrv3ix6niEsq9+ISqCu5qPXRlnpZ7b6GBi7 DQJJK3eTwfvH68EgCzK+kZbjx8MGsjVxZ7xFnD0owYDc X-Received: by 2002:a17:906:fe4e:b0:96f:c46f:d8fe with SMTP id wz14-20020a170906fe4e00b0096fc46fd8femr10620729ejb.27.1687259306084; Tue, 20 Jun 2023 04:08:26 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 18/37] crypto: Add aesdec_IMC Date: Tue, 20 Jun 2023 13:07:39 +0200 Message-Id: <20230620110758.787479-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x629.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=unavailable 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 Add a primitive for InvMixColumns. Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- host/include/generic/host/crypto/aes-round.h | 2 + include/crypto/aes-round.h | 18 ++++++ crypto/aes.c | 59 ++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/host/include/generic/host/crypto/aes-round.h b/host/include/generic/host/crypto/aes-round.h index 1b82afc629..335ec3f11e 100644 --- a/host/include/generic/host/crypto/aes-round.h +++ b/host/include/generic/host/crypto/aes-round.h @@ -15,6 +15,8 @@ void aesenc_SB_SR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); +void aesdec_IMC_accel(AESState *, const AESState *, bool) + QEMU_ERROR("unsupported accel"); void aesdec_ISB_ISR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h index df252ac76d..e1a9c24cca 100644 --- a/include/crypto/aes-round.h +++ b/include/crypto/aes-round.h @@ -59,6 +59,24 @@ static inline void aesenc_SB_SR_AK(AESState *r, const AESState *st, } } +/* + * Perform InvMixColumns. + */ + +void aesdec_IMC_gen(AESState *ret, const AESState *st); +void aesdec_IMC_genrev(AESState *ret, const AESState *st); + +static inline void aesdec_IMC(AESState *r, const AESState *st, bool be) +{ + if (HAVE_AES_ACCEL) { + aesdec_IMC_accel(r, st, be); + } else if (HOST_BIG_ENDIAN == be) { + aesdec_IMC_gen(r, st); + } else { + aesdec_IMC_genrev(r, st); + } +} + /* * Perform InvSubBytes + InvShiftRows + AddRoundKey. */ diff --git a/crypto/aes.c b/crypto/aes.c index d1ef4c19c2..31028609d6 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1356,6 +1356,65 @@ void aesenc_SB_SR_AK_genrev(AESState *r, const AESState *s, const AESState *k) aesenc_SB_SR_AK_swap(r, s, k, true); } +/* + * Perform InvMixColumns. + */ +static inline void +aesdec_IMC_swap(AESState *r, const AESState *st, bool swap) +{ + int swap_b = swap * 0xf; + int swap_w = swap * 0x3; + bool be = HOST_BIG_ENDIAN ^ swap; + uint32_t t; + + /* Note that AES_imc is encoded for big-endian. */ + t = (AES_imc[st->b[swap_b ^ 0x0]][0] ^ + AES_imc[st->b[swap_b ^ 0x1]][1] ^ + AES_imc[st->b[swap_b ^ 0x2]][2] ^ + AES_imc[st->b[swap_b ^ 0x3]][3]); + if (!be) { + t = bswap32(t); + } + r->w[swap_w ^ 0] = t; + + t = (AES_imc[st->b[swap_b ^ 0x4]][0] ^ + AES_imc[st->b[swap_b ^ 0x5]][1] ^ + AES_imc[st->b[swap_b ^ 0x6]][2] ^ + AES_imc[st->b[swap_b ^ 0x7]][3]); + if (!be) { + t = bswap32(t); + } + r->w[swap_w ^ 1] = t; + + t = (AES_imc[st->b[swap_b ^ 0x8]][0] ^ + AES_imc[st->b[swap_b ^ 0x9]][1] ^ + AES_imc[st->b[swap_b ^ 0xA]][2] ^ + AES_imc[st->b[swap_b ^ 0xB]][3]); + if (!be) { + t = bswap32(t); + } + r->w[swap_w ^ 2] = t; + + t = (AES_imc[st->b[swap_b ^ 0xC]][0] ^ + AES_imc[st->b[swap_b ^ 0xD]][1] ^ + AES_imc[st->b[swap_b ^ 0xE]][2] ^ + AES_imc[st->b[swap_b ^ 0xF]][3]); + if (!be) { + t = bswap32(t); + } + r->w[swap_w ^ 3] = t; +} + +void aesdec_IMC_gen(AESState *r, const AESState *st) +{ + aesdec_IMC_swap(r, st, false); +} + +void aesdec_IMC_genrev(AESState *r, const AESState *st) +{ + aesdec_IMC_swap(r, st, true); +} + /* * Perform InvSubBytes + InvShiftRows + AddRoundKey. */ From patchwork Tue Jun 20 11:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694468 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245818wrm; Tue, 20 Jun 2023 04:13:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79g058VIuIjI4NkPWATOXrp9sYZokpv23iCSnY+FSCDwI6y915rf+mO+Rdll/oVn2jt6/r X-Received: by 2002:a05:620a:228b:b0:763:ade2:74e9 with SMTP id o11-20020a05620a228b00b00763ade274e9mr1590030qkh.66.1687259606069; Tue, 20 Jun 2023 04:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259606; cv=none; d=google.com; s=arc-20160816; b=sulz2tPcv43eYlrwo9h32lXHtW1Z2xIjshmx0DNjHTOnFlUv5GdWYJqfgJoZyxsv10 nwFFsN5i6k6vWxInpH7bfUE04wMjCOnZp+KeFFLVykXztz+V3OZMPGDqNU9LiVp/7BN6 /qmiEIolsg0hMZfXLUp8TDzolvN1jf+BuPRh4CMmdh6CbUK1ZhA34RUWm+g8SFlIcO5E hGzrt9nepDhULLqJpPnXFmqHl/wsapWDQJt5IAcscnuZr2W9uyh0Gasg8KIUfDfHRx6n nfMBYfNNeeY9FKm/HkYhicT2axzpwqdGR3v0F20XVTO0U1OpvUaRBNY91FVUxzJ/lOoC EImA== 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=+lOYUQGr/W2hN41A+MbMW4B7XkhWFliC6iC1qe2q7c8=; b=CJrU24ZhMBp8NyOJdnNNF682mWVcpcwvcbOdciNeD7551RDnMND7D9DhnZXIwGjrwS g13pR+rPshOcYnB2q5AV9/DIqfIZOH4b5nNyOrmj62Yen7JPpv0A6yqxdP3q6+Lm8GS/ dRza9SlOAKnwStYjEoedSyLVj9knyGtW/Y+KVaQPx/jzDJ8JkCFrXeVnCfIog0On05xv TdocswAfo9vBxj9+26iStEogqo7rj1EQQ4uOq0dRBOnWDl5FKfMXZ+H9jwTua0jRRUU0 M1o9XTLa4yClabRXykdF4KqWinwuRQLJoCA5vBW0SNdS+Eh6tuiATxcunn0XC1+KEWDa c6zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=otR5FyBF; 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 d28-20020a05620a167c00b0075f5b184d4dsi687772qko.569.2023.06.20.04.13.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:13:26 -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=otR5FyBF; 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 1qBZDu-0006M3-Al; Tue, 20 Jun 2023 07:08:34 -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 1qBZDs-0006KZ-Ew for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:32 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDo-0004Oa-QP for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:32 -0400 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9741caaf9d4so558700966b.0 for ; Tue, 20 Jun 2023 04:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259307; x=1689851307; 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=+lOYUQGr/W2hN41A+MbMW4B7XkhWFliC6iC1qe2q7c8=; b=otR5FyBFmDpDB3KOv+EmuXpJDlYSj9cbY9u/cCcPJs95SB0XfUIJbynjfqWAxOrcLg fcqQcLXDXW0KJHiyjEa3MPMqcNi3Nfqh/lY0BdkzlMGpCJp1kimEU9qsIUvpbc7ZPYzU GkyuyqU2AxvV3FDvmru8vMh4ljqUEsnow08jzCAUpmAjuM9l11pFxEQP9H6H4jXn/ma8 RoAXNOhAckj12oXu3jjgNbIGqQqhrV60bIGZTfoX8RvT4i7NRSF6YzKEwetCPPWEgSh0 a+ySe9cgCz/vtwFtqSSzo4Xr4nhBil+ypJV8tmEJEqbObZbdnmiYO6EBSLigvXCQJ6Js Nvcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259307; x=1689851307; 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=+lOYUQGr/W2hN41A+MbMW4B7XkhWFliC6iC1qe2q7c8=; b=BvUe1SruznI1IClOWiM3HNXeZ/CHYr39Mowd6PYJ6E3N36kCvTFlk/8M5fIV8DmGa0 jeWAhZifKbwM1VfoOhuJl/IKE6SMu2ZrTFviYNY1UNTYap/0NZ03CLuQQURBDeP5of0R xsQ57VplxQWs+FsZTh/uq//vyk65GDrTekggOyvlGkLOerQmfJnON7IfbH/YfzQphCEe 6YgPKjEAVhrBHl4igZYTtwNKpGXesMqnFtyJHejMRgxWJG6lHXpA51180JXnhVnqMY1P X4MmYQR3NHkxKyOEbiVgsIVdUmJAO7n1K4bw1HwS+ksDDdBVMVrGymhh6yyl4/ZsjFLQ V8QQ== X-Gm-Message-State: AC+VfDzTR+1HTzOB2GrHpoE+7PDTivAWcYk89ZTQcCujfCNAqBUW5mhg RyCTfETFJPH7HXE/HW1ItqAYNtD4LPfjRu0KF4wa5k4Q X-Received: by 2002:a17:907:746:b0:962:46d7:c8fc with SMTP id xc6-20020a170907074600b0096246d7c8fcmr11699590ejb.21.1687259307466; Tue, 20 Jun 2023 04:08:27 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 19/37] target/i386: Use aesdec_IMC Date: Tue, 20 Jun 2023 13:07:40 +0200 Message-Id: <20230620110758.787479-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x631.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=unavailable 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 This implements the AESIMC instruction. Signed-off-by: Richard Henderson --- target/i386/ops_sse.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index 0a37bde595..893913ebf8 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -2215,15 +2215,10 @@ void glue(helper_aesenclast, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) #if SHIFT == 1 void glue(helper_aesimc, SUFFIX)(CPUX86State *env, Reg *d, Reg *s) { - int i; - Reg tmp = *s; + AESState *ad = (AESState *)&d->ZMM_X(0); + AESState *st = (AESState *)&s->ZMM_X(0); - for (i = 0 ; i < 4 ; i++) { - d->L(i) = bswap32(AES_imc[tmp.B(4 * i + 0)][0] ^ - AES_imc[tmp.B(4 * i + 1)][1] ^ - AES_imc[tmp.B(4 * i + 2)][2] ^ - AES_imc[tmp.B(4 * i + 3)][3]); - } + aesdec_IMC(ad, st, false); } void glue(helper_aeskeygenassist, SUFFIX)(CPUX86State *env, Reg *d, Reg *s, From patchwork Tue Jun 20 11:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694490 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247702wrm; Tue, 20 Jun 2023 04:17:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XJTnyOvvE9mxniAXqGt+PPxiJ7mTTYC83EwWDvWmliOQjWVL/8XK6l40/f37mzU+bioxp X-Received: by 2002:a05:622a:14c6:b0:3f5:39a7:1b9e with SMTP id u6-20020a05622a14c600b003f539a71b9emr12889766qtx.56.1687259870336; Tue, 20 Jun 2023 04:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259870; cv=none; d=google.com; s=arc-20160816; b=JbAVFoY3EBp8cnCTWIQOvr8Bl6KilW8dKDZuxz20Q3YdEf8bTZFSlRnGZuTTH5UHHZ R2nhzrq+T2TwnYQ1ovv2QJ6pX/sSO2vuhCjuau/srOHxu91+vVGHxeacpJgYsBN5otRE blT+E2ggHiT8fp7UovmHRPlQH9uIEIoyFtLiQ8PsZQOQ3yrb+F8trLObEGF+tXxDKtpo rrpUcuafIZOtx0rR6hoHlYJCtvE7roWjQW3GRlg/eNs0gq5jHndpfqiOZXHiFREx4BGi 8QlexWJyL9qt7FBbb/p6YeRfsaOhwOK+1z+lGXHDwPtDAjfZy8EG2h1ZVgXOnEGSo8xy Dsjg== 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=F8c22mTwcbWMs129JigZzKtfDDKQP2XGxgtoSuBUoiE=; b=LpUMbEHZobB7dIdp2lc5LiPXLNH0xhLqjbkxGFfj8hCqpI5vqV+n4yOwwZzL0Zb9oW G+TKrlApE5l9oBJ6bztuitmtbwG60tJFJ0+sgmax/uh3eEPFfYkzYRsTsJi8oU+ynpcM ARrKh2mK+31AhVuHqFezplBJgg6CqVvNBlsoz0OMmO4pEjUhb5Egm15atWK1tqhVdTfM NPEKfyJdQlw+HzFIL3VRxB8ET4oRBfXD7ZTuzT70pRmCV3RF/5FqKOfkI4YEfVIEg9OA zN5Uw944guis3rC9YiIU8Drh9LC2f6MJPeWwp01X67T5GuLzIi/dRMi0k7V59BIJORtI 1++w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pSW2jGWC; 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 b4-20020ac85bc4000000b003f52ed15c6esi675145qtb.683.2023.06.20.04.17.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:17:50 -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=pSW2jGWC; 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 1qBZDv-0006Nb-50; Tue, 20 Jun 2023 07:08:35 -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 1qBZDt-0006L3-DI for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:33 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDp-0004PE-TI for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:33 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-98746d7f35dso571535866b.2 for ; Tue, 20 Jun 2023 04:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259308; x=1689851308; 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=F8c22mTwcbWMs129JigZzKtfDDKQP2XGxgtoSuBUoiE=; b=pSW2jGWC7cy2tlM5GqSFsYGBfxsPtlVB4p1yLFb8QtE+6JTXrR9Z9YsD77svtkLyv1 3PRpZLXSNJ0ySP5HQ0zuV4a1RArnbsh1WekZbP0DRIbMzYov9jP9JPnmnobWfkYlBGok TwQPDjrr+wXWG9+HvnDGLlMwjH4aQrtZ9gdranoXXJ9HmpMxrowL07AxEgDRy/Z6E+mD NzyHdR0vEpV8U4lDZFf3C3nIimDj9SknY9c31rCL4vD7xWfvmpMkYMI08z6ERuQuRJi2 Ya1IcFBCLjalyygHQnyQw+0RHlCkgeWRdb96U08LYzaGIWOuA0runag6TfE+fuEWa17K xnWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259308; x=1689851308; 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=F8c22mTwcbWMs129JigZzKtfDDKQP2XGxgtoSuBUoiE=; b=cXLoNbIwoFk+MpMJOyQrqm+TAttPyp2UzH4IeHlQxel+DYeFdIESzGPFtEej2b/HNh AfDuskcnz/ZI5LjLUYN7XcjYNRaDcG3KFwuifGsO6IX5iUj4Zi6kVXvzKJ8z7Cy6lCyD IR2zeYk1UQLF1p1/s9Q7kGQ05F3g5buE14vVu9EsXmmMBoldbXVM9MOQ7s1SorFhx/85 Dsiq9eZuPaoOukVIfzYgpeEiumFVreC8gP27klNVfZOo8NVwvew9/kiZtDFDlOUdEHus bjc45yB6mh9wjuFHoXTM1T1J13W4A/efVWQGiMmjzIJ5eitgJ4vm+rBJIIDiRMDIVPuk YBgQ== X-Gm-Message-State: AC+VfDwYyBw5PiMBvI7Jor2ami+0w3OOt0s4U34EjaoMj3F4lQI7rTdu pjv71/S4w6V7IRsudr9YKoAUxMcPkUpQDxWi+ndoBYPn X-Received: by 2002:a17:907:9810:b0:96f:bcea:df87 with SMTP id ji16-20020a170907981000b0096fbceadf87mr12597242ejc.42.1687259308582; Tue, 20 Jun 2023 04:08:28 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 20/37] target/arm: Use aesdec_IMC Date: Tue, 20 Jun 2023 13:07:41 +0200 Message-Id: <20230620110758.787479-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x636.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=unavailable 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 This implements the AESIMC instruction. We have converted everything to crypto/aes-round.h; crypto/aes.h is no longer needed. Signed-off-by: Richard Henderson --- target/arm/tcg/crypto_helper.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index 1952aaac58..fdd70abbfd 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -14,7 +14,6 @@ #include "cpu.h" #include "exec/helper-proto.h" #include "tcg/tcg-gvec-desc.h" -#include "crypto/aes.h" #include "crypto/aes-round.h" #include "crypto/sm4.h" #include "vec_internal.h" @@ -102,23 +101,6 @@ void HELPER(crypto_aesd)(void *vd, void *vn, void *vm, uint32_t desc) clear_tail(vd, opr_sz, simd_maxsz(desc)); } -static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, const uint32_t *mc) -{ - union CRYPTO_STATE st = { .l = { rm[0], rm[1] } }; - int i; - - for (i = 0; i < 16; i += 4) { - CR_ST_WORD(st, i >> 2) = - mc[CR_ST_BYTE(st, i)] ^ - rol32(mc[CR_ST_BYTE(st, i + 1)], 8) ^ - rol32(mc[CR_ST_BYTE(st, i + 2)], 16) ^ - rol32(mc[CR_ST_BYTE(st, i + 3)], 24); - } - - rd[0] = st.l[0]; - rd[1] = st.l[1]; -} - void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t desc) { intptr_t i, opr_sz = simd_oprsz(desc); @@ -147,7 +129,20 @@ void HELPER(crypto_aesimc)(void *vd, void *vm, uint32_t desc) intptr_t i, opr_sz = simd_oprsz(desc); for (i = 0; i < opr_sz; i += 16) { - do_crypto_aesmc(vd + i, vm + i, AES_imc_rot); + AESState *ad = (AESState *)(vd + i); + AESState *st = (AESState *)(vm + i); + AESState t; + + /* Our uint64_t are in the wrong order for big-endian. */ + if (HOST_BIG_ENDIAN) { + t.d[0] = st->d[1]; + t.d[1] = st->d[0]; + aesdec_IMC(&t, &t, false); + ad->d[0] = t.d[1]; + ad->d[1] = t.d[0]; + } else { + aesdec_IMC(ad, st, false); + } } clear_tail(vd, opr_sz, simd_maxsz(desc)); } From patchwork Tue Jun 20 11:07:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694485 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247152wrm; Tue, 20 Jun 2023 04:16:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6bQ74kH9PTVdopMYXUZ+9NLXc+MWtNbi3S2R+BpuE8PTp1YSHeKRieCewAxPVJiasLnJux X-Received: by 2002:a05:6214:f01:b0:62f:ef74:a304 with SMTP id gw1-20020a0562140f0100b0062fef74a304mr16996436qvb.8.1687259794255; Tue, 20 Jun 2023 04:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259794; cv=none; d=google.com; s=arc-20160816; b=V2CHCNQgaAYDzgTEDakzxpdnMloPcEDwuXzBQhA+yDARQZyU77bZT9fCnRUrg3nLnD MVWY3dhYqVzWcOZkeIcslB3lAhHtROES1lxhX4dRPswrFXKSpp2lvea4xoQqI7zCDDUi 4Z6p5u5hjaOtEaVJG6Y4uwtEcHz+2jZm9KVqZ+4Q3f0CeVpWnG9nlz2LNWeCpGZWDpXp G1wrf6sh8UXpBDsKy4HXHriFm5EgpSjWfu7+4wKe26R9ByTC/LJXcGnqcKodPasCpYo2 /IsjctDi1x2gTGyRNArMQgdHfaXHefQ6vWisq0ZU19HZCBTOlgupRTo060W3JKGCju9s trDw== 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=4pOjdTU6VTsEkj/YPCvRrXcIKg2xairdxfu8316FBss=; b=NGJN6DbicAMOIl7QNERM14t+CjkVvxKYlh+JANZkOqSdy3M1ZJeKZIY9+HCM1dbcY5 +NxW8Wo/YOh0VobkL9cZX0mxawtT5TDU6Ui0CkGYTjOXB5W4fpG2XvsSgWS7gaxbxTvc j3U3iU2IZGMeGQ1D0Jtr1w4LmF/ICwoq4hUyIVyvEmjQMTytiAx87fXHUkq8XvKTIamm am3UVRwZI2d+GX987jMerMvs/+EPacpJm2JIfdxBvnVG++0WZqyR2BiOevciSiF394Ul 9gfz8j/LDon6M850qrBJY/96uBx/I+LjtYlW4RccfTbdnlNxTAOuBvFalxt6vxeF3gtm uTLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hYiqw96J; 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 im5-20020a056214246500b0062dfad6c53bsi721532qvb.289.2023.06.20.04.16.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:16:34 -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=hYiqw96J; 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 1qBZDv-0006Oh-Ue; Tue, 20 Jun 2023 07:08:35 -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 1qBZDu-0006La-3G for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:34 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDr-0004Pu-09 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:33 -0400 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-988a076a7d3so331313066b.3 for ; Tue, 20 Jun 2023 04:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259309; x=1689851309; 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=4pOjdTU6VTsEkj/YPCvRrXcIKg2xairdxfu8316FBss=; b=hYiqw96JSEdcqpEPp3u5DEbaGKLEdjTy+QYbCk4Zo6bvKleWnKhKLFc+MQ/8O1pc/h SpnCzIsLz3NzW9mM5r4MipbYOb+a0t5PV+sWRxBdwEHNz4MPDyLulOTLkqC5dTxPk1pC e1SXfkgOppUTo05lShREFAmak8QM092AXruxsz6sJSJQR/zwiNKMyI7k3XTbAirO6y/L uk/pRe2kpoDcWxuR0GNl30FUlEkTtN0pNndgrP3DuOHWA/zncnJOt+il3WUMhmEWMAhn 8B1099REepqbrXsSRQGEbZ04UF+++VM7TJb1CTB4Q1hjw0EH6/A5WP0d2f3i8/KAlVXu eGOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259309; x=1689851309; 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=4pOjdTU6VTsEkj/YPCvRrXcIKg2xairdxfu8316FBss=; b=YYLtUDyjUfhWOBO/nlYHZDU6BRghZ44IrxH3HxWkIaFfqdhEjbPt67j2c+aFYCN/uY Ga3khl8s2aXk56ubWv5WQBnEHroviLpR1NonNIQDn5rdV0LV4X83bDitDDP2nD9xNBG4 SonvHmZ6QGwGjB9zYBFz9JohTFJ3B1ZcsnCqLmU0OVTgYrnlvNHi3Ak4drUjiRWfWmTT BeEekiEdL1XUMQ7C0zsggk2Dvk3jJooGICUYkjzxrtiJBF2pppuoeMLDe2QX/dhMdFqi ZIZrF/YgDvE7jXAgltTMSwQI7BZAeBO4mepAHod+gBKMqHxG9TFkuy7T7pt8CfHTL1YQ m59w== X-Gm-Message-State: AC+VfDxExrt7Z1v6NbS2Yq27psohE4pWi3XdGqH2TYI1dHPa7DqzLeZJ OYbdAMogqwzP8nlqOGxuO9xRPw6jpHsY+zpHNR/7NNAl X-Received: by 2002:a17:907:72c1:b0:96f:a891:36cb with SMTP id du1-20020a17090772c100b0096fa89136cbmr11715525ejc.0.1687259309674; Tue, 20 Jun 2023 04:08:29 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 21/37] target/riscv: Use aesdec_IMC Date: Tue, 20 Jun 2023 13:07:42 +0200 Message-Id: <20230620110758.787479-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x630.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=unavailable 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 This implements the AES64IM instruction. Signed-off-by: Richard Henderson --- target/riscv/crypto_helper.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c index e61f7fe1e5..505166ce5a 100644 --- a/target/riscv/crypto_helper.c +++ b/target/riscv/crypto_helper.c @@ -272,17 +272,12 @@ target_ulong HELPER(aes64ks1i)(target_ulong rs1, target_ulong rnum) target_ulong HELPER(aes64im)(target_ulong rs1) { - uint64_t RS1 = rs1; - uint32_t col_0 = RS1 & 0xFFFFFFFF; - uint32_t col_1 = RS1 >> 32; - target_ulong result; + AESState t; - col_0 = AES_INVMIXCOLUMN(col_0); - col_1 = AES_INVMIXCOLUMN(col_1); - - result = ((uint64_t)col_1 << 32) | col_0; - - return result; + t.d[HOST_BIG_ENDIAN] = rs1; + t.d[!HOST_BIG_ENDIAN] = 0; + aesdec_IMC(&t, &t, false); + return t.d[HOST_BIG_ENDIAN]; } target_ulong HELPER(sm4ed)(target_ulong rs1, target_ulong rs2, From patchwork Tue Jun 20 11:07:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694456 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244447wrm; Tue, 20 Jun 2023 04:10:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7WqryZTYaPwsh37ZJzUU8wQkNLKLhCa6OU+YdrijcVSmb2ogs9jcLZm622mtdKl0nDsqyn X-Received: by 2002:ac8:5a46:0:b0:3ff:3018:8d9c with SMTP id o6-20020ac85a46000000b003ff30188d9cmr619660qta.17.1687259418140; Tue, 20 Jun 2023 04:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259418; cv=none; d=google.com; s=arc-20160816; b=P3EGQM9LGLbO374OBt0aXj9F/Y+iBVFJZxhWOGBlUtxak7aysyw0I3dL4K2bZOrJZy fqVp7foDJKbN1yccaG2L0JPbu0t7UVFdSlcs+cAT+Fga5f++71oOGM6MUCVs8hU3+CbC PLelLBz4X/kkYJqnzRr4d+O80Nbz5U7ik6T3VSBoW42qdfp+SardB1B4ZsFIebinh23i EjUSTpdLhtzaUGpSQF8rGjQ7t8NEykLPjl5ij3vwe/Z1rJ+0x2kxPkFamPFGqXXR5z1X 5o9Y99ptF/cYUo9R/SCs5iRHo6VSx+rhRV7PcXGFIktsx5qVBghb8t8zfbrtP4HhjDB0 FEUA== 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=37v87OvAxenj0irSs1EemrWAhShq/0s61Y9O5yLeJgY=; b=0dnamxDuarY94mlO10WWYCulbW1gih4Jis0BHhtKL+sby5reO7pMwKtc1v+UqzrpIB Ih6hRgIQmZ0mqL5B0l2V1acv/NzpT3qPp0fBtzdnWsRph6bHhrYf/2DDeq1xzB/95zxo 2SDqecW3mk6OjOlZIQ91ohOdAgTLaZOFOHyF2CFhklRYfonR68ZroEnIkXnYoVvMbwWx jAV2uXgZP4RA+0FLOJRKVvMrKlsiLteXu8Pt7/+cTQzSl5ScOT6OINZA0z/pM0elvVmy l51eVKA6cniP8ubQeTSVTVJaCY3GEylNuHmiiNJYnSZI0f/98LDUBoT/cmI1MC3GxtLr Hang== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D4+8i4Rj; 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 f18-20020a05622a105200b003b9bf110a36si636428qte.719.2023.06.20.04.10.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:10:18 -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=D4+8i4Rj; 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 1qBZE1-0006Wv-Lt; Tue, 20 Jun 2023 07:08:41 -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 1qBZDv-0006Ng-B2 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:36 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDs-0004QI-39 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:35 -0400 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-98802908fedso415285066b.1 for ; Tue, 20 Jun 2023 04:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259310; x=1689851310; 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=37v87OvAxenj0irSs1EemrWAhShq/0s61Y9O5yLeJgY=; b=D4+8i4Rjvpi/hZGd2oKlpqWVgN23cHT1Z25RuKe2Spd2KmU160fG8Noy3v8prkJuTI GkEZF1OVKHrq42kYkVpPinncfAV+ClHedzWAFbFoom7/A8+6kgsXSYVm7FjHrk9MwB0h SWOkrMFkDNNSr6LpT0oiEq27GW6mpkK2KoheJVP+Dyy4w5qvbRAPUqH6HqT707+Dl3F3 WfXnaQy0NaXjAeovd1xvrKZIsbWgUGdt2kPDNlXHseRKPlfUNBFKumXySNGbEPSLaY6v 25swpq4jd+PAnBEvpZQDHHI8S3I2tasOeJcFDkM/2TEiAof/a92Sh7alTdl49C/nvHge Mzgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259310; x=1689851310; 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=37v87OvAxenj0irSs1EemrWAhShq/0s61Y9O5yLeJgY=; b=dHRSo4rXEAjfC69v7Z/a97MrL9OD7643i71zSzBFZ3AV+A/Z1e+JYy6+tbhV4U0VJV Js7BEQwFRBbq/n2ClkZ+Bq0ht71Q6aZ4rJtAsmVY0rAp709SupPouL1V0aWrFhnsWpsR b5HQ0Y62xXe0qZ/i6/INOF56F3VUXvXFdaH1muYrwAK6WPSHaat6Uk+sN1ne+iVvRpLy jL8l087ZhRBnLOePQPxNsEh137aN1OLaNA/y7JSNmq2yfOK3xlSQO/I9299eWpLlIqlb xbJTnGzMHPp1bL10Z8Jzfb2lOG97lOx+2F5GYaghVXsRZ5QO9Vb+T0cK2jY9vyHXci85 0G7g== X-Gm-Message-State: AC+VfDzcWeRLDSL9kOxTQDY0cEDpgfiZRd8b1mWVY/lf+r1vUz0FWOpy ivXaTUmkxUxNd+GdoV4fbpapvIVPS4ueZBAyQ3XdiAmW X-Received: by 2002:a17:907:8687:b0:973:91a5:bff1 with SMTP id qa7-20020a170907868700b0097391a5bff1mr10958173ejc.68.1687259310738; Tue, 20 Jun 2023 04:08:30 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 22/37] crypto: Add aesenc_SB_SR_MC_AK Date: Tue, 20 Jun 2023 13:07:43 +0200 Message-Id: <20230620110758.787479-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x630.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 Add a primitive for SubBytes + ShiftRows + MixColumns + AddRoundKey. Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- host/include/generic/host/crypto/aes-round.h | 3 + include/crypto/aes-round.h | 21 +++++++ crypto/aes.c | 58 ++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/host/include/generic/host/crypto/aes-round.h b/host/include/generic/host/crypto/aes-round.h index 335ec3f11e..9886e81e50 100644 --- a/host/include/generic/host/crypto/aes-round.h +++ b/host/include/generic/host/crypto/aes-round.h @@ -14,6 +14,9 @@ void aesenc_MC_accel(AESState *, const AESState *, bool) void aesenc_SB_SR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); +void aesenc_SB_SR_MC_AK_accel(AESState *, const AESState *, + const AESState *, bool) + QEMU_ERROR("unsupported accel"); void aesdec_IMC_accel(AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h index e1a9c24cca..6c744b299d 100644 --- a/include/crypto/aes-round.h +++ b/include/crypto/aes-round.h @@ -59,6 +59,27 @@ static inline void aesenc_SB_SR_AK(AESState *r, const AESState *st, } } +/* + * Perform SubBytes + ShiftRows + MixColumns + AddRoundKey. + */ + +void aesenc_SB_SR_MC_AK_gen(AESState *ret, const AESState *st, + const AESState *rk); +void aesenc_SB_SR_MC_AK_genrev(AESState *ret, const AESState *st, + const AESState *rk); + +static inline void aesenc_SB_SR_MC_AK(AESState *r, const AESState *st, + const AESState *rk, bool be) +{ + if (HAVE_AES_ACCEL) { + aesenc_SB_SR_MC_AK_accel(r, st, rk, be); + } else if (HOST_BIG_ENDIAN == be) { + aesenc_SB_SR_MC_AK_gen(r, st, rk); + } else { + aesenc_SB_SR_MC_AK_genrev(r, st, rk); + } +} + /* * Perform InvMixColumns. */ diff --git a/crypto/aes.c b/crypto/aes.c index 31028609d6..c0350c0b76 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1356,6 +1356,64 @@ void aesenc_SB_SR_AK_genrev(AESState *r, const AESState *s, const AESState *k) aesenc_SB_SR_AK_swap(r, s, k, true); } +/* + * Perform SubBytes + ShiftRows + MixColumns + AddRoundKey. + */ +static inline void +aesenc_SB_SR_MC_AK_swap(AESState *r, const AESState *st, + const AESState *rk, bool swap) +{ + int swap_b = swap * 0xf; + int swap_w = swap * 0x3; + bool be = HOST_BIG_ENDIAN ^ swap; + uint32_t w0, w1, w2, w3; + + w0 = (AES_Te0[st->b[swap_b ^ AES_SH_0]] ^ + AES_Te1[st->b[swap_b ^ AES_SH_1]] ^ + AES_Te2[st->b[swap_b ^ AES_SH_2]] ^ + AES_Te3[st->b[swap_b ^ AES_SH_3]]); + + w1 = (AES_Te0[st->b[swap_b ^ AES_SH_4]] ^ + AES_Te1[st->b[swap_b ^ AES_SH_5]] ^ + AES_Te2[st->b[swap_b ^ AES_SH_6]] ^ + AES_Te3[st->b[swap_b ^ AES_SH_7]]); + + w2 = (AES_Te0[st->b[swap_b ^ AES_SH_8]] ^ + AES_Te1[st->b[swap_b ^ AES_SH_9]] ^ + AES_Te2[st->b[swap_b ^ AES_SH_A]] ^ + AES_Te3[st->b[swap_b ^ AES_SH_B]]); + + w3 = (AES_Te0[st->b[swap_b ^ AES_SH_C]] ^ + AES_Te1[st->b[swap_b ^ AES_SH_D]] ^ + AES_Te2[st->b[swap_b ^ AES_SH_E]] ^ + AES_Te3[st->b[swap_b ^ AES_SH_F]]); + + /* Note that AES_TeX is encoded for big-endian. */ + if (!be) { + w0 = bswap32(w0); + w1 = bswap32(w1); + w2 = bswap32(w2); + w3 = bswap32(w3); + } + + r->w[swap_w ^ 0] = rk->w[swap_w ^ 0] ^ w0; + r->w[swap_w ^ 1] = rk->w[swap_w ^ 1] ^ w1; + r->w[swap_w ^ 2] = rk->w[swap_w ^ 2] ^ w2; + r->w[swap_w ^ 3] = rk->w[swap_w ^ 3] ^ w3; +} + +void aesenc_SB_SR_MC_AK_gen(AESState *r, const AESState *st, + const AESState *rk) +{ + aesenc_SB_SR_MC_AK_swap(r, st, rk, false); +} + +void aesenc_SB_SR_MC_AK_genrev(AESState *r, const AESState *st, + const AESState *rk) +{ + aesenc_SB_SR_MC_AK_swap(r, st, rk, true); +} + /* * Perform InvMixColumns. */ From patchwork Tue Jun 20 11:07:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694462 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244809wrm; Tue, 20 Jun 2023 04:11:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6c5n6GEud+EXgDj6PeFr2PHfhCJtSCSYWuQFv3w/OX4lro3dztqFdAbj21LXcDg576p2kG X-Received: by 2002:a05:620a:ed3:b0:75d:4de8:aec0 with SMTP id x19-20020a05620a0ed300b0075d4de8aec0mr9897181qkm.3.1687259471264; Tue, 20 Jun 2023 04:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259471; cv=none; d=google.com; s=arc-20160816; b=gPZmWIWPp+rR+Or0St76kcEZPt1tuZlW3X5RRkxx1cG9L62xOO5ncceqMuKQGM3/5n 9f1m1842hvOzzpbLBaOA0ZUt7MGKroXF5Qs7x9Puo8epdMRNagGppDczzNU0lNdwZ6Ko TFTwXfId/3/i20u5tmSjXAt1zn3ezNTOFvRMQuHZrPaNaDDLoJaDkQ6saHiWUTSSXIQ9 3TMFwfulZyxLuLhv+5zTD+/5z5AXCJApBn1w7/kYGpaQlqPQHay2K56tx9OxmgQDmDJj KMF+c322lX7LNnKiDHgcCNH7brJiqtepz/qM45CQ1LqBQC7wfJOuSroQ1KTvvGrd8xNr +JaQ== 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=+os3nHQ/ZmARewYX8s5fRYkcgS0NtfZNFjYHPGkpaM4=; b=g6vm8jkg/oHTbIGtXP3MLUXcSQ22u3aaXLVidJP9hF7DOA5gvI9Dn3ES275nZOFVlp nfDtfnS5GqxxhqAbb+JgReV2Axs88nuWqX7eaPU0QurrFkevC9ecgMHTn886CdP7zQbz sFsNn7bfFn67o4ciWTRakXgxsh1uDwDoIPVkgQTTanbERzV3gggw49aDpE0dbJpObuhQ eKsxRaUHV2QqEG/B3CGTLAjCuD5VlsJOOQccF/vTRBJHipjS4ckoV4G39cK0/s0OJw2J Fkjn7B/GCFpqMrWeBpUtXUYdJ/QHdPokduB3q2jSnwntPPNuUsexeYYqcruM9D8ioG8Y 0x4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zfwlUnoT; 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 dw4-20020a05620a600400b0075b15f99a5csi748258qkb.99.2023.06.20.04.11.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:11:11 -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=zfwlUnoT; 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 1qBZEP-00072h-Aa; Tue, 20 Jun 2023 07:09:05 -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 1qBZE6-0006fJ-7s for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:46 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZE3-0004Qy-9b for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:45 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-987a977f62aso369013066b.1 for ; Tue, 20 Jun 2023 04:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259312; x=1689851312; 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=+os3nHQ/ZmARewYX8s5fRYkcgS0NtfZNFjYHPGkpaM4=; b=zfwlUnoT+9JYRJvMcXFhJoA7pLYnBP6H3iplCQEVsslkAUnW+LsRlFYN/x7yYDqRuc ruU/2SksY61jTarLwbbvFWlAkPuSSpBjsqq4937hH07bWqpahgahlUUFWAaatvk2KTBt EkSkShmKZqHVsn5j55bv0hG5UOirLvq1cwzIuN4enGmx7mCE1fwTXgmQ3kGCEfYlai9z vll1pdSqOZC55Y0rxJh5UJCt9PIP7Se6qWA9Pp4ztzSRn0eThRL4YZ0aYvLjbVgLR+pe 9vtRkAQvrukhnUcAP7gkdju53yqLevZmMbbAloDcm2cIUI9ICTR+kH+CWtLHdur39Uz8 dZDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259312; x=1689851312; 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=+os3nHQ/ZmARewYX8s5fRYkcgS0NtfZNFjYHPGkpaM4=; b=hkF7+0cmYYxGbn08GDF5ulYBmgdmRycKItGhoCnqKshoscE0mey+bkaM6OHrIZ1pBG MdASZOHdp8kiAPF+RukwJhRDTipNMbfaoEmykksN87T5bYiKXEsJJYnuaPlcgwRDS5yh 5VeY+ijDFGp3phR0hnTSojy3gueXAtAXG6+2KsRR3f36eHfbJDljKqNxrlblTcuiTugg 88dswH1KrCxlgo5XKN3QpGwWBnstSKgiMbU/1fN9xoi14BbnHALgBH5LiRwma+Fr3vQH 0e+xGc7fy+w3EpQFy2Icbjvpvk0Ro9KDM4qw2wpRSzVJijsTUiw6LspH977P+Rd7wm52 OEWA== X-Gm-Message-State: AC+VfDxszlOzbanM0F2yRypyo9Q/e+Uje2hxhMGieiV39qbq3coi1wyk uI5LIk1TW0qj7gYjA6IP5Z/ForUiWSQ9TBvXu+D1qM7Z X-Received: by 2002:a17:907:7b96:b0:982:3e2a:91a8 with SMTP id ne22-20020a1709077b9600b009823e2a91a8mr11045159ejc.72.1687259311971; Tue, 20 Jun 2023 04:08:31 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 23/37] target/i386: Use aesenc_SB_SR_MC_AK Date: Tue, 20 Jun 2023 13:07:44 +0200 Message-Id: <20230620110758.787479-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62e.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=unavailable 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 This implements the AESENC instruction. Signed-off-by: Richard Henderson --- target/i386/ops_sse.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index 893913ebf8..93a4e0cf16 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -2188,16 +2188,12 @@ void glue(helper_aesdeclast, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) void glue(helper_aesenc, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) { - int i; - Reg st = *v; - Reg rk = *s; + for (int i = 0; i < SHIFT; i++) { + AESState *ad = (AESState *)&d->ZMM_X(i); + AESState *st = (AESState *)&v->ZMM_X(i); + AESState *rk = (AESState *)&s->ZMM_X(i); - for (i = 0 ; i < 2 << SHIFT ; i++) { - int j = i & 3; - d->L(i) = rk.L(i) ^ bswap32(AES_Te0[st.B(AES_shifts[4 * j + 0])] ^ - AES_Te1[st.B(AES_shifts[4 * j + 1])] ^ - AES_Te2[st.B(AES_shifts[4 * j + 2])] ^ - AES_Te3[st.B(AES_shifts[4 * j + 3])]); + aesenc_SB_SR_MC_AK(ad, st, rk, false); } } From patchwork Tue Jun 20 11:07:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694465 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245412wrm; Tue, 20 Jun 2023 04:12:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XxblPJdE2ANeXCpNYKFEXFVlUPw5woj88enYPoJ8OwhfSOKB3FXjScR8ENduPme7HE9rk X-Received: by 2002:a05:622a:1b8c:b0:3fd:e091:3fe4 with SMTP id bp12-20020a05622a1b8c00b003fde0913fe4mr12320107qtb.58.1687259549733; Tue, 20 Jun 2023 04:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259549; cv=none; d=google.com; s=arc-20160816; b=DhNWPDOCN44qh9/Qk5DVlJLNVMVNF6ql3tKzeoKtoquSoE5aILqMif+bm4/lFJiJxo /y4COteILnsWvEWeUM88rPE6pAHhg158SZ2tmIcpBkgcwIFXsa5ptOMbvH234/eMU7iS V43TXH8EzjjBwRXF7FV7YsxJkbe3ErHk2zlyiyP0sRDPRpqqRrGBRWgmcaL/dCFO6HOK ReMdmfzlLQkF+Vvzr/SC5EbCKG3tblZXQyi38WS08hnO0p1ghaySQ9htNJVz03cw1PpQ AIv48Xi8FCL6jUlz5SXpzbPikeRFfBBEfCkVu+vkO0LE7H/+OUcgtHjCHtfwXrX4qi1V cCdA== 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=5yB3KjFB+U9E0IGbPxBILX7NHTWOiWyWbVzWyod1A2Y=; b=VEtDJGi6+fP/K3J4Es7Z8iifBOMNynBFMsScHdbkpaIRmEdpgflESize8XhTj9e5Vh a0Wh1GwI1VOxbwKy1eCYRp8MTbqRgZx3VqUVMbLGl/wc7RE0SkeWD/7+uZNDWE9zONwY C6rePhd5ljFAQELDHitz8JkjSV761qzD2jmriZGu3PeOhKPIaPN/xuaukr58JlYrj0yw qD9DGBssj4xygnX3TA/AZ/M8XxdCUTKr386jVG47UXbK5s5cvYUOSSLXbRb2qgmCFJWO pYd7CW/fTQxWZtcvx7Y+d3Dk3yBHDR3DVN3YEJIDHGn3kAgR3qEOqjgE6+b/N8KCfMvC C+ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vIDZqQ+4; 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 a9-20020a05622a02c900b003fded3017d6si647489qtx.551.2023.06.20.04.12.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:12:29 -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=vIDZqQ+4; 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 1qBZE2-0006Zg-E8; Tue, 20 Jun 2023 07:08:42 -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 1qBZDx-0006RB-M0 for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:37 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450: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 1qBZDu-0004Rc-KC for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:37 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-987c932883bso520335966b.0 for ; Tue, 20 Jun 2023 04:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259313; x=1689851313; 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=5yB3KjFB+U9E0IGbPxBILX7NHTWOiWyWbVzWyod1A2Y=; b=vIDZqQ+4qe8OfzkAge7xCSI/gHQxa6IjBuJ2+qDZVO1bE+E4n5NoZ0KruDEvQ/iu4H vqsE9jdY584U3DIW4vSlMxtm8XPltTRgLUdvLmLZ/sqsK9qvXVhhbwQEAig9P6m/NWp8 uhzXLFSJ3deDlq/aanAN4OMHQyj/O5T2rOD+fU5eDi1qqE25XM+LGwERs8f85PXNDSPB aLAEwfL/p6/0/1tOAPrCz4z5NFo74oQWGj8iOrrniysdXeW0Hult1A8QBAjWsYaa9m/L Q8TKjkEX2PUtQRVUxQ6VBdkC6TGjtOj9nHGAuzw4aoVYev5Qe8gfUjYDgBa+Z3WngMEE WRPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259313; x=1689851313; 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=5yB3KjFB+U9E0IGbPxBILX7NHTWOiWyWbVzWyod1A2Y=; b=d98COWajZSMmOWMo21TpCNEMesk0S4vQNW5hcFUUtYpcl1z2HFQwioK+WrEaJb+xwq fBtzqafIQ/DuPM371uhfNQJxuc7DwbwXOZdHKh/zzDF8KUs9NPIx5/Pj8FacReDjvwqq 2BcA7omds+NGNIem1r0aXx5qqZwSUT6P3lllip9NApe/c7XQTPYq+Q9nQx1/k2HbGkDd YNMf9WfnWmsgXqqHck1RCsmvHUPDPHm8BmxlRc+F/PREwNo3++ns1nA6TpwpV/DXsSVa jtOaRP2avc32rROFzeSuFjmiT2sTb2vel9BvgUYns40dcd6cTSQ8yh5zsewzY4vI21VU r5og== X-Gm-Message-State: AC+VfDwxeePa8KJcLZj1le7aCFs00huNG+Lm2I7/IpJEHc8QMQxK7Ykx X8gTfuBECKOxH8pumFgH7u0fvdz2CqgQoNtQp2JailN0 X-Received: by 2002:a17:907:7f14:b0:989:1f66:e44f with SMTP id qf20-20020a1709077f1400b009891f66e44fmr1620173ejc.11.1687259313240; Tue, 20 Jun 2023 04:08:33 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Daniel Henrique Barboza Subject: [PATCH v3 24/37] target/ppc: Use aesenc_SB_SR_MC_AK Date: Tue, 20 Jun 2023 13:07:45 +0200 Message-Id: <20230620110758.787479-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 This implements the VCIPHER instruction. Reviewed-by: Daniel Henrique Barboza Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index 15f07fca2b..1e477924b7 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -2933,17 +2933,11 @@ void helper_vsbox(ppc_avr_t *r, ppc_avr_t *a) void helper_vcipher(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) { - ppc_avr_t result; - int i; + AESState *ad = (AESState *)r; + AESState *st = (AESState *)a; + AESState *rk = (AESState *)b; - VECTOR_FOR_INORDER_I(i, u32) { - result.VsrW(i) = b->VsrW(i) ^ - (AES_Te0[a->VsrB(AES_shifts[4 * i + 0])] ^ - AES_Te1[a->VsrB(AES_shifts[4 * i + 1])] ^ - AES_Te2[a->VsrB(AES_shifts[4 * i + 2])] ^ - AES_Te3[a->VsrB(AES_shifts[4 * i + 3])]); - } - *r = result; + aesenc_SB_SR_MC_AK(ad, st, rk, true); } void helper_vcipherlast(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) From patchwork Tue Jun 20 11:07:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694470 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245960wrm; Tue, 20 Jun 2023 04:13:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iikMdyT4Kkp9o2iOh5LscGRBK0q789BTQ/JvE4XS90sbX1kxxD3CixhD0KcT6mQKRwoWG X-Received: by 2002:a05:6214:c6f:b0:623:71d0:95 with SMTP id t15-20020a0562140c6f00b0062371d00095mr17466669qvj.42.1687259626345; Tue, 20 Jun 2023 04:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259626; cv=none; d=google.com; s=arc-20160816; b=ZRhKbyw2Feub2k63G4UDrOLmfgXfHLs134wa+2EHXJfy9IFrQnDvwjC62JxGebUJdZ 0VIst6sYJedyTV2z59fiCs/4ZBEBwWGhvC/EqoDGpfzZpsNv/B63hi/vtOCtpQC/GvpS +wJcRyDO/4v2Dm7IFUCPRw6kgX32WEp27EFcsUP8nQfb1elKbaho4guDY6lS5mgrGU7L PgXW77/Jnw5F47x6G0Q8oLne8OzFfvRi0JWD6+p7MedDe6Qe6vhJ3BwsiCvAHdJas8Uk OAHSNWgg2czWHpuiR2GZatl4uSJO0Mk4pDJLvgCdAapMlVcFKz8G8ouXp2tcuXGHyi/e sMPw== 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=D0I8unuNO+OjgsLA/5Ao4N4ndudI6wjx6PBNe+Du5WM=; b=md8ge/jkyxHUmZjPRn2vRzQuRP6i7swl1AAo8M5wNcaSphGaqJVMh7BItQPHo+2HFa FZ8x9cBebYWHDYx4Rp2GrBO0+SLC2Fb7Ah/lDQPxik2M8pqpVwnUaAKwflJUd4PxyBCA q9uq8GgR/n2EgBwt9DUid0wfglRnCjbyfDHhXx/+ZjERpOjMTOR1IAdVs8ayL2yIhIG5 V5VNryCY+OYdVn26iLTNsefmJZBdvphggLhzV4DkkCOG6AGm2cPjlH4h62TmvKS+bYK4 hjUz8OFj5LRjGlzjSNndgmdRLWXkve7FmgodUKYIE8EQorpi5nWnsjFgDLdbJ2fBfORo TD3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H/355eKP"; 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 s3-20020a0562140ca300b006258e11de50si730690qvs.134.2023.06.20.04.13.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:13:46 -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="H/355eKP"; 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 1qBZEM-0006wm-73; Tue, 20 Jun 2023 07:09:03 -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 1qBZDz-0006Rs-0P for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:39 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDv-0004SO-JG for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:38 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9889952ed18so348515766b.3 for ; Tue, 20 Jun 2023 04:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259314; x=1689851314; 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=D0I8unuNO+OjgsLA/5Ao4N4ndudI6wjx6PBNe+Du5WM=; b=H/355eKP2OudGaREb0Jf8k9xBqLbZssn38xZhnZVnrPhbtra2DVNG2Jt1pZ6bZl5qS 42CvHW2GmSUIrIBR80eaVaFBTrAey1A7XCNpWCDlj1auIisZIXixWwSWwhJRzLHepGlY 0nqsi8KeIIg5KLo+nnmzd8YB5wAJIZWmbR6V5+gR0p6FORLrgPkOf+nIf7aFGOgGFVcG UkKhkiEyiR4U58h4PI8iVEOdIkzZQAPGkOf0SOzOQ36UBq6HqEwOvh2vs2Tqrt86SuSW AqwORZXGJXFbcbDa/2RCOVqxIGx9+H02SUVpVZAmyRxV4yWa/mlZxXqDc2NAkvw/QvwQ EgQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259314; x=1689851314; 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=D0I8unuNO+OjgsLA/5Ao4N4ndudI6wjx6PBNe+Du5WM=; b=QJ7ndqlHckqrDrWJCHEsF45mlAD8jNI2LvSojicpGmSZoMDt+Gs6LazSn9iO4V8+zW v9p1lgi8gF43+LZCPz2iaJomN3ts0QJoc1q1njCiEzIFjbuy0s8JedXe8ks86NXz163V HUFUqIiydm7e43qW84jw2cEpB1ljI002yeVx2xtaRm35h/A8qF+jLU7bElTu4RvWBsh3 /SBTfTH5HEXNC4nMEYhzvVxPO09dQmo5gq3VgleIJvWbRheJ0sZJ/PZIc652CDeKC6b7 Y9Azgx/S0hTJQeR8QLEBUEO3Omyts/TTEGuo5EKDhRzO8JmlQ9PjYpx1TzC1FKU8DR5b dvfw== X-Gm-Message-State: AC+VfDzaPIZ3wjZhyfl2TgvRsp49R7B3mxnS17fkfN6671zweXOKYgh2 jtRGPj5XNfSFvRD/oYJodc2r+buj48WKJBnBWPzdKhTQ X-Received: by 2002:a17:907:844:b0:982:9dc1:a434 with SMTP id ww4-20020a170907084400b009829dc1a434mr11166400ejb.19.1687259314270; Tue, 20 Jun 2023 04:08:34 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 25/37] target/riscv: Use aesenc_SB_SR_MC_AK Date: Tue, 20 Jun 2023 13:07:46 +0200 Message-Id: <20230620110758.787479-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x629.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=unavailable 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 This implements the AES64ESM instruction. Signed-off-by: Richard Henderson --- target/riscv/crypto_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c index 505166ce5a..c036fe8632 100644 --- a/target/riscv/crypto_helper.c +++ b/target/riscv/crypto_helper.c @@ -198,7 +198,12 @@ static inline target_ulong aes64_operation(target_ulong rs1, target_ulong rs2, target_ulong HELPER(aes64esm)(target_ulong rs1, target_ulong rs2) { - return aes64_operation(rs1, rs2, true, true); + AESState t; + + t.d[HOST_BIG_ENDIAN] = rs1; + t.d[!HOST_BIG_ENDIAN] = rs2; + aesenc_SB_SR_MC_AK(&t, &t, &aes_zero, false); + return t.d[HOST_BIG_ENDIAN]; } target_ulong HELPER(aes64es)(target_ulong rs1, target_ulong rs2) From patchwork Tue Jun 20 11:07:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694467 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245646wrm; Tue, 20 Jun 2023 04:13:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Ojzm/Pfk16lrcC8Qs27aT05mEujcZyW+hmZqxwyyn7lmUqsPFRsw/hbw5lZvPj2YlPLEk X-Received: by 2002:a05:620a:3e8b:b0:75d:5398:fc70 with SMTP id tv11-20020a05620a3e8b00b0075d5398fc70mr11069594qkn.38.1687259583805; Tue, 20 Jun 2023 04:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259583; cv=none; d=google.com; s=arc-20160816; b=s9xq6Q2euklNChS2VMXYa6DMi3iYaNWlQNb210tsPfVa/rPcxKfQU7tyaq1mqYpwW9 MIhNq876iKcRpCI6vBMk2aCI6Yw58mt1un1/i9P4AaXKIVX7+LJsAG6RQnP0kytkBc2r jb+Gt1C7xXkBMoZUlnlcByXcNLTx5ILyfCrzQyG1sI9+0uxJquabGZs9YFerL1wOqGXF VTx3vpx9D3aQhqCL2AWKVP2YL8HovZ5h3LUsLFCCMMkGzTRkx8al8EiaGjFVyHDxIE8O zECoO9fpwl06tj26eJ4FtIqKu/+3DFElTy6UtQwC0hvjSZakjnrV0SejASLDGVd4bpMd nNrQ== 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=VkkdZVWfvLDeeOXE0iU3FgNXPD+nxdYVaySYHBaRhYI=; b=TZyWWTq+ohG5a38OijJ80edssNRd+R9JaYj4G8ZmEDMg1YmmuScR75Ap0H1O1d0UYg pUf8nIGCQ03bJfjlSbW/yDcxaQdk3lK8ow+XhVFOIVhw/QU/9lLFFQoc2acTVATV3AEO rKKhdiXIw0Rbm9ojCGN2sB+cBw1j1N8bQ4xUTeHHdjN+PqDByFcJQnOUcjubTPKbj5VG FBUHMfYQ0NMuedPHTDU5xGMRAcHzONXL+RdkkQkD3VXqY2zl/kzPKXQohjn9djyyPfxP XYPsDXEYBLa+7R+MOxNdYOoeMvQ0xi7pSOwpdedXpngbeSLykivalWPTwJdeUDyAJwNY /5LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v+68CWZ0; 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 r30-20020a05620a03de00b007621513a86csi702662qkm.619.2023.06.20.04.13.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:13:03 -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=v+68CWZ0; 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 1qBZE2-0006ZY-Ee; Tue, 20 Jun 2023 07:08:42 -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 1qBZDz-0006Rt-EG for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:39 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDw-0004T1-RX for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:39 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-985b04c46caso685453366b.0 for ; Tue, 20 Jun 2023 04:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259315; x=1689851315; 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=VkkdZVWfvLDeeOXE0iU3FgNXPD+nxdYVaySYHBaRhYI=; b=v+68CWZ0mxTURbAjJjr9WXf0VivFSux3nXotwqNt3rXb+A8wWswiTLXgN4iM0Xg+Vr upMruGdr3TYboXy5pxPvEY4C4IWcwfx1q0j6sAjqywhBVhK00bgopOkY6GzeigrSFRzk sndpLA0zXxyMCUOub3fzNkVaC/y6jzX7YJXlpVElDiGO8gaVU76x0AHU9DKjirfwDitK IhtukiNV177+SZc63MY3JL7pnQG2qgpycYsvdH9Ea3yjzYj/ZMLH7uwAE+wsOCA8gOs4 H8ThmXlct+11dgfEHPQrfC7FtpVcTdeh9vgT5+lFbKkALLQ5sNFe4oNkpTYpXz6uXg1d 1CJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259315; x=1689851315; 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=VkkdZVWfvLDeeOXE0iU3FgNXPD+nxdYVaySYHBaRhYI=; b=WAImc6M9UoBRJxiXnc+fEMvNQtnCeS+scx9znzS7xsaOgno5FMV+l1Wm8u/MhWxuRy /ZFvvaW03sGmFOfQa2CI4qCxzwN4NiCu8IwnI4PfaKqdl7WLgICGdI48iJvOQkJWSVhG LQURXWYdz+GwulGuDpwSapcc0sjNaB03eYJeNjLwWgLlNalHalChEaNno5O7PqJHw1Hi kgqWCHwH5smsFpV7yoBElnnGXQY44g1gYZip6J9AD5vpw6zHd8jRfZKR8RgaunV0cIos RemFrOplcsdzTgW7DPfk/TTjSDT2Jw1RQjrtwnV46Re/3a2Qc4JOvGIHx2SAfD9DVT6r 1yCQ== X-Gm-Message-State: AC+VfDxux+YW+kO7zmzoRAHAZbf2gakKv06gtUvS3okvDn+Qwsh18vvk 4wVmTwL+Hj54wMttvbR++/dGyJ2uWN9HZdT5FSL8gIsg X-Received: by 2002:a17:907:25cc:b0:989:450:e57b with SMTP id ae12-20020a17090725cc00b009890450e57bmr2331559ejc.7.1687259315398; Tue, 20 Jun 2023 04:08:35 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 26/37] crypto: Add aesdec_ISB_ISR_IMC_AK Date: Tue, 20 Jun 2023 13:07:47 +0200 Message-Id: <20230620110758.787479-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x635.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 Add a primitive for InvSubBytes + InvShiftRows + InvMixColumns + AddRoundKey. Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- host/include/generic/host/crypto/aes-round.h | 3 + include/crypto/aes-round.h | 21 +++++++ crypto/aes.c | 58 ++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/host/include/generic/host/crypto/aes-round.h b/host/include/generic/host/crypto/aes-round.h index 9886e81e50..db8cfe17eb 100644 --- a/host/include/generic/host/crypto/aes-round.h +++ b/host/include/generic/host/crypto/aes-round.h @@ -23,5 +23,8 @@ void aesdec_IMC_accel(AESState *, const AESState *, bool) void aesdec_ISB_ISR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); +void aesdec_ISB_ISR_IMC_AK_accel(AESState *, const AESState *, + const AESState *, bool) + QEMU_ERROR("unsupported accel"); #endif /* GENERIC_HOST_CRYPTO_AES_ROUND_H */ diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h index 6c744b299d..68cec14950 100644 --- a/include/crypto/aes-round.h +++ b/include/crypto/aes-round.h @@ -119,4 +119,25 @@ static inline void aesdec_ISB_ISR_AK(AESState *r, const AESState *st, } } +/* + * Perform InvSubBytes + InvShiftRows + InvMixColumns + AddRoundKey. + */ + +void aesdec_ISB_ISR_IMC_AK_gen(AESState *ret, const AESState *st, + const AESState *rk); +void aesdec_ISB_ISR_IMC_AK_genrev(AESState *ret, const AESState *st, + const AESState *rk); + +static inline void aesdec_ISB_ISR_IMC_AK(AESState *r, const AESState *st, + const AESState *rk, bool be) +{ + if (HAVE_AES_ACCEL) { + aesdec_ISB_ISR_IMC_AK_accel(r, st, rk, be); + } else if (HOST_BIG_ENDIAN == be) { + aesdec_ISB_ISR_IMC_AK_gen(r, st, rk); + } else { + aesdec_ISB_ISR_IMC_AK_genrev(r, st, rk); + } +} + #endif /* CRYPTO_AES_ROUND_H */ diff --git a/crypto/aes.c b/crypto/aes.c index c0350c0b76..53696e8953 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1518,6 +1518,64 @@ void aesdec_ISB_ISR_AK_genrev(AESState *r, const AESState *s, const AESState *k) aesdec_ISB_ISR_AK_swap(r, s, k, true); } +/* + * Perform InvSubBytes + InvShiftRows + InvMixColumns + AddRoundKey. + */ +static inline void +aesdec_ISB_ISR_IMC_AK_swap(AESState *r, const AESState *st, + const AESState *rk, bool swap) +{ + int swap_b = swap * 0xf; + int swap_w = swap * 0x3; + bool be = HOST_BIG_ENDIAN ^ swap; + uint32_t w0, w1, w2, w3; + + w0 = (AES_Td0[st->b[swap_b ^ AES_ISH_0]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH_1]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH_2]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH_3]]); + + w1 = (AES_Td0[st->b[swap_b ^ AES_ISH_4]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH_5]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH_6]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH_7]]); + + w2 = (AES_Td0[st->b[swap_b ^ AES_ISH_8]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH_9]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH_A]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH_B]]); + + w3 = (AES_Td0[st->b[swap_b ^ AES_ISH_C]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH_D]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH_E]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH_F]]); + + /* Note that AES_TdX is encoded for big-endian. */ + if (!be) { + w0 = bswap32(w0); + w1 = bswap32(w1); + w2 = bswap32(w2); + w3 = bswap32(w3); + } + + r->w[swap_w ^ 0] = rk->w[swap_w ^ 0] ^ w0; + r->w[swap_w ^ 1] = rk->w[swap_w ^ 1] ^ w1; + r->w[swap_w ^ 2] = rk->w[swap_w ^ 2] ^ w2; + r->w[swap_w ^ 3] = rk->w[swap_w ^ 3] ^ w3; +} + +void aesdec_ISB_ISR_IMC_AK_gen(AESState *r, const AESState *st, + const AESState *rk) +{ + aesdec_ISB_ISR_IMC_AK_swap(r, st, rk, false); +} + +void aesdec_ISB_ISR_IMC_AK_genrev(AESState *r, const AESState *st, + const AESState *rk) +{ + aesdec_ISB_ISR_IMC_AK_swap(r, st, rk, true); +} + /** * Expand the cipher key into the encryption key schedule. */ From patchwork Tue Jun 20 11:07:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694486 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247192wrm; Tue, 20 Jun 2023 04:16:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Uvra62ZBKSbqzx6vPKWxmE2YnKpPlPOIQ2ccQvGge3+O7x1iOJ56o21eoVZ8FzNntIhDp X-Received: by 2002:a05:620a:1a19:b0:760:88e9:c890 with SMTP id bk25-20020a05620a1a1900b0076088e9c890mr12551565qkb.45.1687259799555; Tue, 20 Jun 2023 04:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259799; cv=none; d=google.com; s=arc-20160816; b=uHfHBgCyahzWPzCS31T/Hw3NHe0tF8ldnZ5+uTzRV2MOKZEaOyxb8Ah5wEiRxgonkD H8y+M3h+PegnIkcKkd0oUZYGNQdHfd1o6WfqlTg34R3CSMVhp/DOSq1beDymX+VetuGq upqQMTk9jvXOgT8DKNIOXf7LCh9Ior6fIvi3aTmHucXqDOwVipe+uPtu/J8ulERgDBnc QKGUfKti8rFHflhL7bcOb/+yo4QkF4CI5i5jBWaBFey8lYxo8PPX0s6LV7gXz01LOXaW sgL8GgCL8ItzFOVIpYrqU85Bsb/saaPJVRORojAELbBpy/tbBkt5PPJ4VcGr+zLzhesx Wupg== 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=5CADGmxGJYg/RjV/FHciOOU7jKKLgdI+xydvPDVf6m0=; b=XY+dUNXBR8xI0TuCC1ou+/ZcZ7mBMGR+uXDAauaGh9EJ8fep+n0Nv9kIZOmVhLo4LJ L+ae+wAky4T0m11gTCgo8g1zNd72kcu3DC5SofWhtpfWDCJeyDbT/Aw98XOkZTVyXhQI uAr8Kzon8R8F3JW9F+q0aS43V4LHvTmkozy4VfSF8GtthQaFlhBULlgl7wZ+rY5S2SRo XvJOfTja8dEU4W87ES2TllArH0pLttOO0bCiftSrU09okGkmu/KSAIawsY2TxLNuwnXk 3q37gNxo9ju2Y1rKHn3tnylTc5Rw3GUcOmbWSMB+DA7pvuUxWUblHJvJwXeEx2p4BvEZ TfGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kmaRhTun; 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 x20-20020a05620a14b400b0075772297496si720274qkj.353.2023.06.20.04.16.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:16:39 -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=kmaRhTun; 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 1qBZEQ-00074h-8u; Tue, 20 Jun 2023 07:09:06 -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 1qBZE0-0006Wl-PZ for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:41 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDx-0004Tl-OQ for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:40 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-988a5383fd4so396210066b.0 for ; Tue, 20 Jun 2023 04:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259316; x=1689851316; 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=5CADGmxGJYg/RjV/FHciOOU7jKKLgdI+xydvPDVf6m0=; b=kmaRhTunpRHqu1Dxjhr36m8NW55YJQUI6E24JzAolRKCJ35LpPhQf30r99LGvF8UCQ mNcm17XOmsbPi32rbeNhCgieHOp/mgosexsP2OCzlxXU6xVPO3MYdAKiVPF09flgVnW8 /jyEQbc7KkxudMIOEkMwb0oiUb5E0kxvCXHd/yl0oKdE6USR5STpdBtrSlE+zHI/kjV5 WG5XQ7AJENxMmQNlGbd+Fgpxkxg9ZupJb40+WkHLNbgCnKuirfI/uRrKYkFPJPeVXVwE YHA1ppKN/4WBZQVUHgRrDtP21N8cIlkr5UADvnTJYxC8nm3F6Wzb3bsQmvXyvuGDG7Sn fS3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259316; x=1689851316; 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=5CADGmxGJYg/RjV/FHciOOU7jKKLgdI+xydvPDVf6m0=; b=LiJANhXM9uZSRQWXy4VXTKv5+aPLXsWvvGynj1XQWGfQSCASVF4gXLo+j91LYQD2jc H2ksrN+jxBBIESv5Kz8ccmAkICcW4F/Aya1unHWQyJwX1GdcFBjNNAe9ZOGYmnhLSphW SkUx6pG7vC4vzIGx9z/nu5PP/bqCB9Req88T/6pvBADHb/mJVmTKhHY4PPPSSkFmbcMr pf1x5oyICN+yEQax9FjF4SJXr4eXb5Gn/cVHzZ/PrYcVemYWMYC4VJMx6ZOlzrWqGPof qeVFx5dyDXbIGaMEMEfZoFvpymUxeWguP12t8kAJTfkhuXsZ3mCif1+RIqENGyRAsyIV 9MmQ== X-Gm-Message-State: AC+VfDyrJf8XZ9wmK6lXllglDm9pZOpkHe/RzCfvWg4yMUzCk/VwFTtf LkvisFNaJ24HwbLKPsmMfKofVqUEol3MpsIrFx7/XPVe X-Received: by 2002:a17:907:3ea4:b0:978:8979:c66c with SMTP id hs36-20020a1709073ea400b009788979c66cmr17803113ejc.18.1687259316435; Tue, 20 Jun 2023 04:08:36 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 27/37] target/i386: Use aesdec_ISB_ISR_IMC_AK Date: Tue, 20 Jun 2023 13:07:48 +0200 Message-Id: <20230620110758.787479-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x632.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=unavailable 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 This implements the AESDEC instruction. Signed-off-by: Richard Henderson --- target/i386/ops_sse.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index 93a4e0cf16..a0e425733f 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -2162,16 +2162,12 @@ void glue(helper_pclmulqdq, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s, void glue(helper_aesdec, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s) { - int i; - Reg st = *v; - Reg rk = *s; + for (int i = 0; i < SHIFT; i++) { + AESState *ad = (AESState *)&d->ZMM_X(i); + AESState *st = (AESState *)&v->ZMM_X(i); + AESState *rk = (AESState *)&s->ZMM_X(i); - for (i = 0 ; i < 2 << SHIFT ; i++) { - int j = i & 3; - d->L(i) = rk.L(i) ^ bswap32(AES_Td0[st.B(AES_ishifts[4 * j + 0])] ^ - AES_Td1[st.B(AES_ishifts[4 * j + 1])] ^ - AES_Td2[st.B(AES_ishifts[4 * j + 2])] ^ - AES_Td3[st.B(AES_ishifts[4 * j + 3])]); + aesdec_ISB_ISR_IMC_AK(ad, st, rk, false); } } From patchwork Tue Jun 20 11:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694491 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247703wrm; Tue, 20 Jun 2023 04:17:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67LevFoJFHIPrmzX7LKPEiu6xbV5+p6LkmephWLuCcqomAMFXhRIj82NQeiYlNppKc5U7k X-Received: by 2002:a05:6214:1c0a:b0:62d:ddeb:3770 with SMTP id u10-20020a0562141c0a00b0062dddeb3770mr18274440qvc.0.1687259870455; Tue, 20 Jun 2023 04:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259870; cv=none; d=google.com; s=arc-20160816; b=ijFgF8lA2bjGFdJB5JIPXq2fNM+3/DZ7OJRtx3Ms6tZgdiag5m3k0zWSF+mo87d0bE ykIM3fycdXD0nHCZoj98gAx44Zk3QNk/jnc8XsSHOc3xBph1v6wtty/AST19fYJGJC9G bw9QylfYkvGEbw8LnIOqA7g8u3r9YaCGC8N4H++bl4oW461OhLWZfWD+KVSriF/7snFI FviyMCR7DnpgF4kjDHaZJuazL6kkg91+tj5faQ30hvKKcNrTNlzCUob3pSfccLpsYpHb zObfE8wqKIIDASp1yYE7ulzChL0EeiqAI0aeFnotlE6ZTtc7tHFdp7mmD1HYCYYYqzOt 6bSg== 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=M7z3XVBK0XuXSTZ82FoV8jlvhCwFhDqWNnV/JcekGnU=; b=K7PCwPF6pcxTHkdon+EEJZQti8ZpQkPgnKK2AS8aeG1C5u4eA01e0lP4NCATkRmEAr WI3CJJxruJD7ohnstIftmLOYE27c4uCX0jQt62NZZnOKMy230E/UYxZE5uN21G7VaBp6 NZNenv4ZkKLKp+TQRP3kmt/KhG3/4va9klbAOdhKLN5UXJ0JBrOCfkZFrlxoKjzNJVxw MWyTL6EQFwvJ4Pdbyx1obDvXumLdUOnJ1o0NNLUepIkGse5SQ2n6aaLZgHvUtlRFBQlk 6aWLtN6E+qgcdh9cT4LPEb6wF4fq6m3iVdPzfPy5FRD97fpKyX3aMJJmK6kpbN9PG2X6 dgsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UNvDFUOc; 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 eo13-20020ad4594d000000b00623897deb67si744795qvb.194.2023.06.20.04.17.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:17:50 -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=UNvDFUOc; 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 1qBZER-00079D-60; Tue, 20 Jun 2023 07:09:07 -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 1qBZE1-0006Yc-VQ for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:42 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDy-0004UU-TW for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:41 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-988aefaa44eso307774666b.2 for ; Tue, 20 Jun 2023 04:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259317; x=1689851317; 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=M7z3XVBK0XuXSTZ82FoV8jlvhCwFhDqWNnV/JcekGnU=; b=UNvDFUOcZlKZJCNu9yftaPk4hl/pSvMxYuK8Ew0rbAwGgMztrwd8lq9kM47qR2VX5a 4olD845dc0K7z9v8oh7FzxeWLVVSit4C2v4fg6vxnHDeeNBS6T3JyL0v9LDaXdxijEJr p5XpqlOLAjEhh6XoPENCXGXiO3AFmgBBZWTfQjEOFK7qRDtlF6R5f8hhyYn7lSpf9gmf rn2fYUJ3f/dzCExrxF6xkjI/dQMtT2EP9B97gQ47901N1TlPgbeNduC+33mAO4HDg4/6 pyHcC88rVL8bvKjtQPJetMZZDUQR52OeRtFNIbuUtSUFvK75AW0BZEWnU8E1wnfrtinn soWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259317; x=1689851317; 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=M7z3XVBK0XuXSTZ82FoV8jlvhCwFhDqWNnV/JcekGnU=; b=MR6XZM0WXDX+OzSBoLeli8llYNnnl13FcDddODDG9I5qoL3mF2ZDxXvGPI05XpesGf aEX794p9s0AKAs8OBnmeOJ8P6dg9+FdPZu6zfj1lsC2oD2vChWk6/0bzP8yICwOZpyNj sG5dvDyIGdCedKKBmHG8UjWdhK6XMiypoHqRkSnyh1dhpecmn8Wr9jYmTmjiCMQxO43Y 6mDngEchFEHyI0cvGoJfSnyayeqZzwtdEUWsV6L2Y0TpyjJigvycw1LcRNuL7jkJKWnr z5X+8Wl/alKMKo61ThnL9ce+XAWYjdTlEQEzb0D5gourX+P1gsQx6KYkJPbIUUVb4c/U kcoA== X-Gm-Message-State: AC+VfDzFVzRrgHcQoTYprk9gPt3901+SN+SCYXWSJun+Ct+RzZeHaXUj KX3kbfNzmUGaWIWyEXHk9PFALdvRzO1Wsaeu5MUFRv2i X-Received: by 2002:a17:906:a402:b0:977:eed1:4510 with SMTP id l2-20020a170906a40200b00977eed14510mr9021441ejz.21.1687259317625; Tue, 20 Jun 2023 04:08:37 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 28/37] target/riscv: Use aesdec_ISB_ISR_IMC_AK Date: Tue, 20 Jun 2023 13:07:49 +0200 Message-Id: <20230620110758.787479-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x635.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 This implements the AES64DSM instruction. This was the last use of aes64_operation and its support macros, so remove them all. Signed-off-by: Richard Henderson --- target/riscv/crypto_helper.c | 101 ++++------------------------------- 1 file changed, 10 insertions(+), 91 deletions(-) diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c index c036fe8632..99d85a6188 100644 --- a/target/riscv/crypto_helper.c +++ b/target/riscv/crypto_helper.c @@ -104,98 +104,8 @@ target_ulong HELPER(aes32dsi)(target_ulong rs1, target_ulong rs2, return aes32_operation(shamt, rs1, rs2, false, false); } -#define BY(X, I) ((X >> (8 * I)) & 0xFF) - -#define AES_SHIFROWS_LO(RS1, RS2) ( \ - (((RS1 >> 24) & 0xFF) << 56) | (((RS2 >> 48) & 0xFF) << 48) | \ - (((RS2 >> 8) & 0xFF) << 40) | (((RS1 >> 32) & 0xFF) << 32) | \ - (((RS2 >> 56) & 0xFF) << 24) | (((RS2 >> 16) & 0xFF) << 16) | \ - (((RS1 >> 40) & 0xFF) << 8) | (((RS1 >> 0) & 0xFF) << 0)) - -#define AES_INVSHIFROWS_LO(RS1, RS2) ( \ - (((RS2 >> 24) & 0xFF) << 56) | (((RS2 >> 48) & 0xFF) << 48) | \ - (((RS1 >> 8) & 0xFF) << 40) | (((RS1 >> 32) & 0xFF) << 32) | \ - (((RS1 >> 56) & 0xFF) << 24) | (((RS2 >> 16) & 0xFF) << 16) | \ - (((RS2 >> 40) & 0xFF) << 8) | (((RS1 >> 0) & 0xFF) << 0)) - -#define AES_MIXBYTE(COL, B0, B1, B2, B3) ( \ - BY(COL, B3) ^ BY(COL, B2) ^ AES_GFMUL(BY(COL, B1), 3) ^ \ - AES_GFMUL(BY(COL, B0), 2)) - -#define AES_MIXCOLUMN(COL) ( \ - AES_MIXBYTE(COL, 3, 0, 1, 2) << 24 | \ - AES_MIXBYTE(COL, 2, 3, 0, 1) << 16 | \ - AES_MIXBYTE(COL, 1, 2, 3, 0) << 8 | AES_MIXBYTE(COL, 0, 1, 2, 3) << 0) - -#define AES_INVMIXBYTE(COL, B0, B1, B2, B3) ( \ - AES_GFMUL(BY(COL, B3), 0x9) ^ AES_GFMUL(BY(COL, B2), 0xd) ^ \ - AES_GFMUL(BY(COL, B1), 0xb) ^ AES_GFMUL(BY(COL, B0), 0xe)) - -#define AES_INVMIXCOLUMN(COL) ( \ - AES_INVMIXBYTE(COL, 3, 0, 1, 2) << 24 | \ - AES_INVMIXBYTE(COL, 2, 3, 0, 1) << 16 | \ - AES_INVMIXBYTE(COL, 1, 2, 3, 0) << 8 | \ - AES_INVMIXBYTE(COL, 0, 1, 2, 3) << 0) - static const AESState aes_zero = { }; -static inline target_ulong aes64_operation(target_ulong rs1, target_ulong rs2, - bool enc, bool mix) -{ - uint64_t RS1 = rs1; - uint64_t RS2 = rs2; - uint64_t result; - uint64_t temp; - uint32_t col_0; - uint32_t col_1; - - if (enc) { - temp = AES_SHIFROWS_LO(RS1, RS2); - temp = (((uint64_t)AES_sbox[(temp >> 0) & 0xFF] << 0) | - ((uint64_t)AES_sbox[(temp >> 8) & 0xFF] << 8) | - ((uint64_t)AES_sbox[(temp >> 16) & 0xFF] << 16) | - ((uint64_t)AES_sbox[(temp >> 24) & 0xFF] << 24) | - ((uint64_t)AES_sbox[(temp >> 32) & 0xFF] << 32) | - ((uint64_t)AES_sbox[(temp >> 40) & 0xFF] << 40) | - ((uint64_t)AES_sbox[(temp >> 48) & 0xFF] << 48) | - ((uint64_t)AES_sbox[(temp >> 56) & 0xFF] << 56)); - if (mix) { - col_0 = temp & 0xFFFFFFFF; - col_1 = temp >> 32; - - col_0 = AES_MIXCOLUMN(col_0); - col_1 = AES_MIXCOLUMN(col_1); - - result = ((uint64_t)col_1 << 32) | col_0; - } else { - result = temp; - } - } else { - temp = AES_INVSHIFROWS_LO(RS1, RS2); - temp = (((uint64_t)AES_isbox[(temp >> 0) & 0xFF] << 0) | - ((uint64_t)AES_isbox[(temp >> 8) & 0xFF] << 8) | - ((uint64_t)AES_isbox[(temp >> 16) & 0xFF] << 16) | - ((uint64_t)AES_isbox[(temp >> 24) & 0xFF] << 24) | - ((uint64_t)AES_isbox[(temp >> 32) & 0xFF] << 32) | - ((uint64_t)AES_isbox[(temp >> 40) & 0xFF] << 40) | - ((uint64_t)AES_isbox[(temp >> 48) & 0xFF] << 48) | - ((uint64_t)AES_isbox[(temp >> 56) & 0xFF] << 56)); - if (mix) { - col_0 = temp & 0xFFFFFFFF; - col_1 = temp >> 32; - - col_0 = AES_INVMIXCOLUMN(col_0); - col_1 = AES_INVMIXCOLUMN(col_1); - - result = ((uint64_t)col_1 << 32) | col_0; - } else { - result = temp; - } - } - - return result; -} - target_ulong HELPER(aes64esm)(target_ulong rs1, target_ulong rs2) { AESState t; @@ -228,7 +138,16 @@ target_ulong HELPER(aes64ds)(target_ulong rs1, target_ulong rs2) target_ulong HELPER(aes64dsm)(target_ulong rs1, target_ulong rs2) { - return aes64_operation(rs1, rs2, false, true); + AESState t, z = { }; + + /* + * This instruction does not include a round key, + * so supply a zero to our primitive. + */ + t.d[HOST_BIG_ENDIAN] = rs1; + t.d[!HOST_BIG_ENDIAN] = rs2; + aesdec_ISB_ISR_IMC_AK(&t, &t, &z, false); + return t.d[HOST_BIG_ENDIAN]; } target_ulong HELPER(aes64ks2)(target_ulong rs1, target_ulong rs2) From patchwork Tue Jun 20 11:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694464 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245411wrm; Tue, 20 Jun 2023 04:12:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67JTbQlfel7y+fNigGwSwcEG/+cVi2jkeYyB4pO8NkKzzw/PEia7daSzLznq+5alGaCINr X-Received: by 2002:ac8:7d0e:0:b0:3fb:425f:d4e6 with SMTP id g14-20020ac87d0e000000b003fb425fd4e6mr16010503qtb.6.1687259549632; Tue, 20 Jun 2023 04:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259549; cv=none; d=google.com; s=arc-20160816; b=PYbBRPq3Y71VPfQAJCB9dldxyaOcaSjCG6lEg97WxEY6s0cZxAtVL22eEX3qJxrTjc dhyWW4HWCuBACbWgNhKi0tQzWvcwZVFk45l8tZ9EWDakYJ3w/DkhqegEjYlrgnFeonPF TYBl5fX28KBpQgOsIu7wSv18MSJqA0gmRR0SqgKGwoKnac1NrVGDCieYDU+y2icVqnbN WABsZF8D5eYRezgKB+gxyTLihQP7c/jdpVWo8UiwG/smOAIARCUiaBRiY9SUB1XjlDaD pE1WYpZDGKp+RdYqWh9r64r7hJh6QWIPRUviahZ8BOqqVmoPjQN2riClglQehu/U6O+/ i3rQ== 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=wGlC/81ss1Jj94uQ0vf5KkBvhLt8Sw0gG5elkpKjdEk=; b=c3qKWSmXAOOaWb5hVZ9oHfBl0CfSSYW4nuEJ9rbQUJ2wFXJM9z0o3Zg9XEI9zxRXnA +SXm5UdSxVbRGvmYlYu6EEF5lhjNYnXKZg52iw2MzoykawGV/Gjpz6i/9+pNHuK8pPdQ Pq1RoRwle0LQCLh7PTlSrBuhv4TNN8CQhMAfvOL/lBqIj0QTtNCcAprTsYsmi7MlXMj2 CzKr+o/fjds6MgwyfJrB5yzjJ/VOOVhKZFeQDiSYCTl0KeeKjgdCvqehxMhTEzCO7fC/ jYch9PsIzA8R6g0WzOeOhWbhL445WmMjnRP6FbkBizAjDcPnaq7AvI58R93nfJ3FAhUK aGQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M+U36JOb; 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 e9-20020a05622a110900b003f4e4c15f87si675046qty.92.2023.06.20.04.12.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:12:29 -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=M+U36JOb; 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 1qBZEA-0006lH-7U; Tue, 20 Jun 2023 07:08:51 -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 1qBZE3-0006bz-FB for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:43 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZE0-0004V9-EU for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:43 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-982a88ca610so546806866b.2 for ; Tue, 20 Jun 2023 04:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259319; x=1689851319; 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=wGlC/81ss1Jj94uQ0vf5KkBvhLt8Sw0gG5elkpKjdEk=; b=M+U36JOb+hdpql7wKTS5xxcjO6q0z3C42moEd/BzLzNsbtb4qHxKWGxDyv6EwrIQuj ji5JLF+DAhfp+DDQ87TKXtNICqMAQ5aeVb3p29odObllS3aS8tG1joJ4YYlt/iadjEhk VX80kJjB//wSXh0shC18870/fQL8uQEqYGcIgigKiPCQap7AGDvomy2itvTzYpeJvagy +ryEew+VVBTsrscb45I1AMk5yns40t/nJQQ64RYQfu7KmpR3kc6Vb8QYhiMp7H0VvpQx DZMLro7AsLxXzhl9fajRg+wRI/R7g+w88yyHHtOqnCWoE78LvQ/UgLbvx43uo0QWurXT 37xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259319; x=1689851319; 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=wGlC/81ss1Jj94uQ0vf5KkBvhLt8Sw0gG5elkpKjdEk=; b=D43bMAtdsK7s1+B9f1pJBRYm41nd2xppybMbK2A+GJT9fisf8/6wSLL3tbiYqb1a0N 9vinc6U6sBohJ3v4yFoQQWaWMbF9JtHuZ13QTa8EeEudMcGCbbde5HHCFIfhbiByGktE mh7BYG+Ec9SqMdXmdA4Lr+6Bwe10fl5alYJ7JTvOAmIT+qfPCiZsw0a35Lzy9pNDzWIi 0oE+loqkHnmshE5wTtaayRjaCtPmNjC/wlPyM5ELsDuY/gcSFt2JLAdbez//krsKtGx6 +zeucJrclaAV42SsgLMu85huZiLolUuufavyoo8mm9GDoL0WlKhSd6D+hvVc2DT1x1nD cQuw== X-Gm-Message-State: AC+VfDwMPf2yaepoCy+DNeh3gqgF+mIobzwYdDWaM/f/WhPR5tlqI6hZ +28zicKZJi4Y2jrGoKRESrgziEepDrdhpjf9iHrBoxTn X-Received: by 2002:a17:907:a412:b0:989:d9d:d90f with SMTP id sg18-20020a170907a41200b009890d9dd90fmr1541158ejc.67.1687259318985; Tue, 20 Jun 2023 04:08:38 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 29/37] crypto: Add aesdec_ISB_ISR_AK_IMC Date: Tue, 20 Jun 2023 13:07:50 +0200 Message-Id: <20230620110758.787479-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62f.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=unavailable 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 Add a primitive for InvSubBytes + InvShiftRows + AddRoundKey + InvMixColumns. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- host/include/generic/host/crypto/aes-round.h | 3 +++ include/crypto/aes-round.h | 21 ++++++++++++++++++++ crypto/aes.c | 14 +++++++++++++ 3 files changed, 38 insertions(+) diff --git a/host/include/generic/host/crypto/aes-round.h b/host/include/generic/host/crypto/aes-round.h index db8cfe17eb..1b9720f917 100644 --- a/host/include/generic/host/crypto/aes-round.h +++ b/host/include/generic/host/crypto/aes-round.h @@ -23,6 +23,9 @@ void aesdec_IMC_accel(AESState *, const AESState *, bool) void aesdec_ISB_ISR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); +void aesdec_ISB_ISR_AK_IMC_accel(AESState *, const AESState *, + const AESState *, bool) + QEMU_ERROR("unsupported accel"); void aesdec_ISB_ISR_IMC_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h index 68cec14950..ffd8ec6fa8 100644 --- a/include/crypto/aes-round.h +++ b/include/crypto/aes-round.h @@ -119,6 +119,27 @@ static inline void aesdec_ISB_ISR_AK(AESState *r, const AESState *st, } } +/* + * Perform InvSubBytes + InvShiftRows + AddRoundKey + InvMixColumns. + */ + +void aesdec_ISB_ISR_AK_IMC_gen(AESState *ret, const AESState *st, + const AESState *rk); +void aesdec_ISB_ISR_AK_IMC_genrev(AESState *ret, const AESState *st, + const AESState *rk); + +static inline void aesdec_ISB_ISR_AK_IMC(AESState *r, const AESState *st, + const AESState *rk, bool be) +{ + if (HAVE_AES_ACCEL) { + aesdec_ISB_ISR_AK_IMC_accel(r, st, rk, be); + } else if (HOST_BIG_ENDIAN == be) { + aesdec_ISB_ISR_AK_IMC_gen(r, st, rk); + } else { + aesdec_ISB_ISR_AK_IMC_genrev(r, st, rk); + } +} + /* * Perform InvSubBytes + InvShiftRows + InvMixColumns + AddRoundKey. */ diff --git a/crypto/aes.c b/crypto/aes.c index 53696e8953..2676faa962 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1576,6 +1576,20 @@ void aesdec_ISB_ISR_IMC_AK_genrev(AESState *r, const AESState *st, aesdec_ISB_ISR_IMC_AK_swap(r, st, rk, true); } +void aesdec_ISB_ISR_AK_IMC_gen(AESState *ret, const AESState *st, + const AESState *rk) +{ + aesdec_ISB_ISR_AK_gen(ret, st, rk); + aesdec_IMC_gen(ret, ret); +} + +void aesdec_ISB_ISR_AK_IMC_genrev(AESState *ret, const AESState *st, + const AESState *rk) +{ + aesdec_ISB_ISR_AK_genrev(ret, st, rk); + aesdec_IMC_genrev(ret, ret); +} + /** * Expand the cipher key into the encryption key schedule. */ From patchwork Tue Jun 20 11:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694466 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245479wrm; Tue, 20 Jun 2023 04:12:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4h5RmXugnzsq08i0k2GCSvT9b9foj3TEjMN79f+ZnxXdJlgVtUhkmEzEe7V/2xeZ+4pvs/ X-Received: by 2002:a05:6214:e6b:b0:628:335a:174d with SMTP id jz11-20020a0562140e6b00b00628335a174dmr4276583qvb.36.1687259558657; Tue, 20 Jun 2023 04:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259558; cv=none; d=google.com; s=arc-20160816; b=qhvssjkQHc0ob7GRvZoX29zuY5txEkQPWIp1MZ38ClqTjpc2+26EnxZbJL7sLH797C slmCPrnDmEUlRTQrjCI/3u5PEgLi5rwIl2nV/FknB7gFvb4/tL8IcvNMk8MuGdXObGzF bVBTcjd9T8LfkeDBFnWNPpoNQ+s19wk5l8eSd28/1ZYufj50s4qy2BIV7ie3w2jjq1W3 myUjP5ntXQLN2aVvhXxkuVzqbB9mqJ0myC3hNl4gGhruwbrmoN/XpFNGu51IVMCWeJkR 1VW2kzubBfyuGmCtVrjHAB5cyigvOZTvohifKVhTX3C/vbL2drqr4x5QCXbgg6E47nPb llSw== 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=NQsBpcgKVgYp7fXYDQVN06TvKGcdOIek7QQgIG6AozQ=; b=jeEgZTt19fjFCTqYOuJslhdrlgV9jqFFKRKOPDVJVXnKos5rA8GhfJCshyU4M9fORa As9mB13EedHXS4mBYrsdqYC7lKkyc5YXQxZNqC4GrR4UEt/iNkzpK7dx1/6n3ZsSHKkA Eyn+5eYJFKos2DMG6kJxGh3g9eRIzsighwz3Qe1wU+mEaxq1aQQgVg6S8HIQAZRwq/uc 3h2Fbz8kN8IOmKWkquLwrmRHwkguv0rFhqLJjkHESBNtp0hqjfyGMgMGtmtSPF0XPPsv peaqjxvZpIPcL7j4XJXtGY24CM2pd0SNw5x0GJbFB2/zwf7U7wLpwnxuQnDqkG3zIKVL gwxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h+JtSff8; 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 j3-20020a05621419c300b0062617a404casi705094qvc.417.2023.06.20.04.12.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:12:38 -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=h+JtSff8; 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 1qBZEK-0006ue-4m; Tue, 20 Jun 2023 07:09:02 -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 1qBZE4-0006eB-QF for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:45 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450: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 1qBZE1-0004W4-Pq for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:44 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-988aefaa44eso307780466b.2 for ; Tue, 20 Jun 2023 04:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259320; x=1689851320; 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=NQsBpcgKVgYp7fXYDQVN06TvKGcdOIek7QQgIG6AozQ=; b=h+JtSff8IYkVKAcdBJf7nEaauxjEKByEkA110g78iFFmEc8P88p9doYhiOONWqCcFF xm/3Vb8SYXwAfPgZFMyJVv3lSmtNlZY498Uy0Rh4I/7maeDJSwf9eqODmg2H6R/seoGC 0YjJmjDadmgalAGubcLCT6jb5csT0tPJRPH7l+HxOJbLdAyGZR4ay2wV3cFuLsXbr1Un I4Ge2roiVIikapF7jiZ0gVu7qD1WPJP48dbjBz3AUkAtdjwpVDsTKkCc27eYx4Gz5wk/ Ydgl/fKkYhxHtcIIA1b12UyHbDUsZyk5Rc4yY3dVQiioe0Hu6eC6Z3MjGGu3m3fvjXKa Ck+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259320; x=1689851320; 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=NQsBpcgKVgYp7fXYDQVN06TvKGcdOIek7QQgIG6AozQ=; b=kSjyhZSRLK5OeCNI2pSZVaO172Uzd77clcortDVBj8FLkSlP3lquIlSmeyKdbLZbrP ptDSraFqFWiZAhU1rX9l48oXz3OkBRR8KD+pPYEi19xArVcuqklJsDIzWPeIgKHm11/I iq6ARFuTx3R8QeK90z6iAppkNNEJJWrcbv4dM/KJoZjnhkbVrgQKOD6r/6MLCpBEE37o 0fPSanYORT8EkZ0tTFgbZB4oG46n0Ay6vryRqS9j3wmRrVdIk1tUgo1ZMulkzkZ2CrQ7 u2iJN4mOugw5yHRE4RfOeZpJ8KTzEn5olnbgfLbULcI8komaQRF/0GA1LMYibrHLKECo tGBg== X-Gm-Message-State: AC+VfDzpyxSd34rryxAiFhIGeMuhAZaFDVE3b4U6CVeKHHzz8He2xpTt lVjqk2H8z8Pbz5ITA0gXtyuQ9FTrCzw+vkXjUKDwFyps X-Received: by 2002:a17:907:36c6:b0:974:1d8b:ca5e with SMTP id bj6-20020a17090736c600b009741d8bca5emr10362897ejc.14.1687259320379; Tue, 20 Jun 2023 04:08:40 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PATCH v3 30/37] target/ppc: Use aesdec_ISB_ISR_AK_IMC Date: Tue, 20 Jun 2023 13:07:51 +0200 Message-Id: <20230620110758.787479-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-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, 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 This implements the VNCIPHER instruction. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel Henrique Barboza Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index 1e477924b7..834da80fe3 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -2947,22 +2947,11 @@ void helper_vcipherlast(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) void helper_vncipher(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) { - /* This differs from what is written in ISA V2.07. The RTL is */ - /* incorrect and will be fixed in V2.07B. */ - int i; - ppc_avr_t tmp; + AESState *ad = (AESState *)r; + AESState *st = (AESState *)a; + AESState *rk = (AESState *)b; - VECTOR_FOR_INORDER_I(i, u8) { - tmp.VsrB(i) = b->VsrB(i) ^ AES_isbox[a->VsrB(AES_ishifts[i])]; - } - - VECTOR_FOR_INORDER_I(i, u32) { - r->VsrW(i) = - AES_imc[tmp.VsrB(4 * i + 0)][0] ^ - AES_imc[tmp.VsrB(4 * i + 1)][1] ^ - AES_imc[tmp.VsrB(4 * i + 2)][2] ^ - AES_imc[tmp.VsrB(4 * i + 3)][3]; - } + aesdec_ISB_ISR_AK_IMC(ad, st, rk, true); } void helper_vncipherlast(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b) From patchwork Tue Jun 20 11:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694459 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp244704wrm; Tue, 20 Jun 2023 04:10:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7qotFdhSIXiqcP0ySqd6M1Pt01AT/VAtKM6s2yoBd1en8DudR/MIyD5YSEWppvWCettd6s X-Received: by 2002:a05:622a:1883:b0:3fd:e12e:56cf with SMTP id v3-20020a05622a188300b003fde12e56cfmr12832795qtc.46.1687259453102; Tue, 20 Jun 2023 04:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259453; cv=none; d=google.com; s=arc-20160816; b=ucDiIuzzIh7F6fH1DneiABHRW3VtdJsq8W2ofyy1spN4zFz2rKkopMk5bFqZwjDkDi MA3FgtVcn7XISdyR+4dvhWCQyBZ7EfFH3RahxweEPDEGOu6yzfYRyTO35eOZOP10QUp2 vht2wPVogHcYokYDA0KTmMmsF2UYZ4fTc4AfnMrAw0LmL+8FvQHXM3VdTzFsa+4cS/rR YexMfbJAdiV4PLphcQ4MpNwW5v/yyM0l4Hk0MK/Y3qj912nzjFeYxzJaWUqa06+HlmL9 K6iZiV3upJAPvv9JJXYeU5KAV/IyLuWe2qFBb+1RDVUpK/MV7zEmgkzXdauPDaDbRQyf 2okA== 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=pgBAxhQFeKhLP03OUtk50UQNjg0nvOfEcQqaZaYFTpk=; b=NOm6rcF4Nl72/fA3zotZzCdBOIaLGFtgB9MxQ5SNK9kLVd8poJxtDT20DI4Fsyvwyh 4TXvOQxHm5O89UNyUQpCjbWPk0qq4dJp+1qCy2L+1UWq+aaNV9ivBZkUODXGNMXVCepg tKJ6kAKHhNndep0BNZvwY9t5NIau0N3KtV0obShJX35oGXkTtL6RCN3Fl6wPqnO26jBc MgYF+TO7xLUhzlGyydgzXxMz5P7nw+oEDDSB9l67xVi2GNzmSgNjSDzw9XV6wkFLPoHK Ap/8WFdqQdg0L1T/wCAfVGMUfvpUS97WI58JkngxykJ62L/UfWRW8dd09sVs0zySqBAH XXOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZkfN037y; 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 o16-20020a05622a139000b003fdecc72a28si677319qtk.354.2023.06.20.04.10.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:10:53 -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=ZkfN037y; 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 1qBZEV-0007QI-AO; Tue, 20 Jun 2023 07:09:11 -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 1qBZE6-0006f5-3h for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:46 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZE2-0004Wg-VV for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:45 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-98934f000a5so62458866b.2 for ; Tue, 20 Jun 2023 04:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259321; x=1689851321; 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=pgBAxhQFeKhLP03OUtk50UQNjg0nvOfEcQqaZaYFTpk=; b=ZkfN037y/+U2htybBOOvy/v3rCEnN9UKqdSt/X+C2ZCIVev89oHc/+f/Koj5JocIRf bbCOPyNaXWk+9HyVC4vgtjIVo8X7bwTUc+S+5kecJ6XFZTzmU/SLQwp/4lMpUNOiZ3dm cw+8Zm1bzCZBwDEHJp5gELfwN/BkA3fa7rVAaR7DKwPopEJWoBpZItSRBPiaqvbcRsfb QyrJTe2uorG2B3pMNoKRbWtXp+sgtrytiqX364nx6Lkr1octUFkGxEwsxg7/zTIzVanj 9E5hfcgdALjsOBgUxSin5nm9yUdZlauGVxZKSNBxuianbliv47coRwAVcebcQmm8wUSQ 2mBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259321; x=1689851321; 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=pgBAxhQFeKhLP03OUtk50UQNjg0nvOfEcQqaZaYFTpk=; b=Mgna1YsfexbRWKU3/DzdksGw7MJH+kyEwoLuZODMne3sc5IlAXcuNusRxFXxngQ2LD fUak8ew5l9mJClFAK292McQYeo5Y2XfdB26LQJMRksQpqbA1vWDXc8VVXLi4UB1Zn12i 0WZ5m6B6KxgOdPTzk5AxKa0aDDDRE1PMxis04Mq9+ee8Z0IW/XFiqlBD4McqqeFhzaaw jQeO9LXZsFCkp9Zokst9zKz5Ct0LSdsHujo3sxSwZl/+gd5HJ/lgVH4Oeao5h6myXbCf rV4q/Jc4bovPO41aP+DaU+wOh5muYW+136Z9QmiEJE/l0mLUmIhkeoOz8fODo2al68ez M0ag== X-Gm-Message-State: AC+VfDyPCNu7Sh5qCGPZRnIWhnMHEMNtFx5/RNY34hb2Fza+Jn5DV0ya KWiQkbVsqZXlQgc7zCT0fZJNkTEFTLaELStvQsgE3qEq X-Received: by 2002:a17:907:7b96:b0:973:9f60:c57e with SMTP id ne22-20020a1709077b9600b009739f60c57emr13116579ejc.2.1687259321619; Tue, 20 Jun 2023 04:08:41 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 31/37] crypto: Remove AES_shifts, AES_ishifts Date: Tue, 20 Jun 2023 13:07:52 +0200 Message-Id: <20230620110758.787479-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62f.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=unavailable 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 These arrays are no longer used, replaced by AES_SH_*, AES_ISH_*. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- include/crypto/aes.h | 4 ---- crypto/aes.c | 14 -------------- 2 files changed, 18 deletions(-) diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 24b073d569..aa8b54065d 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -30,10 +30,6 @@ void AES_decrypt(const unsigned char *in, unsigned char *out, extern const uint8_t AES_sbox[256]; extern const uint8_t AES_isbox[256]; -/* AES ShiftRows and InvShiftRows */ -extern const uint8_t AES_shifts[16]; -extern const uint8_t AES_ishifts[16]; - /* AES MixColumns, for use with rot32. */ extern const uint32_t AES_mc_rot[256]; diff --git a/crypto/aes.c b/crypto/aes.c index 2676faa962..9795ae8614 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -131,13 +131,6 @@ enum { AES_SH_F = 0xb, }; -const uint8_t AES_shifts[16] = { - AES_SH_0, AES_SH_1, AES_SH_2, AES_SH_3, - AES_SH_4, AES_SH_5, AES_SH_6, AES_SH_7, - AES_SH_8, AES_SH_9, AES_SH_A, AES_SH_B, - AES_SH_C, AES_SH_D, AES_SH_E, AES_SH_F, -}; - /* AES InvShiftRows, for complete unrolling. */ enum { AES_ISH_0 = 0x0, @@ -158,13 +151,6 @@ enum { AES_ISH_F = 0x3, }; -const uint8_t AES_ishifts[16] = { - AES_ISH_0, AES_ISH_1, AES_ISH_2, AES_ISH_3, - AES_ISH_4, AES_ISH_5, AES_ISH_6, AES_ISH_7, - AES_ISH_8, AES_ISH_9, AES_ISH_A, AES_ISH_B, - AES_ISH_C, AES_ISH_D, AES_ISH_E, AES_ISH_F, -}; - /* * MixColumns lookup table, for use with rot32. */ From patchwork Tue Jun 20 11:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694483 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247036wrm; Tue, 20 Jun 2023 04:16:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kq+HH1OAotmHLq1WWpkhK//Dszrkn2icpzJctC35ICBSq8ZtmJcQsznkjTaQXfs37Z9ke X-Received: by 2002:a05:622a:1392:b0:3fd:ea62:bc3b with SMTP id o18-20020a05622a139200b003fdea62bc3bmr10412102qtk.33.1687259778146; Tue, 20 Jun 2023 04:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259778; cv=none; d=google.com; s=arc-20160816; b=zoaRaUNtrIcBHz7qvBXknToTZiBgtOae+VaLbYXhMm9gxx1Fucm3fCAeK3frVLJQvK DMNlbgOpRR6jWYvMUEhL7b1pnlvKCnI/EDemmOrDWD2Ogj/xO8yJD/01kt57XL0waJjo mc8RqT2NyrqdydFQ/4JgyAqYELdV0SMsfY/fkBJWHyS///iOwLEHSgjBGfkUV7EfSR17 UvWRqncH/2g3qh5LmqBA9DV/FrHO0JFghSQA/cCyUCdXqsDGSkcPl7VcuXpnYxHFvH4a fZHlW1WuUX4blJvcMPF6BJ7VQ7vTFVumaBg0kieE6bcepRfcy/8NW7yJUTAQ0YwxMgmB j3Yg== 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=SPTofI9JsvJrrcptDf/DV5w5SQH9XzTd4Au47XuO2js=; b=EJnBrQVL2PjM5+hbXD2Z9845bgo1ZRa6OWNNACWt/AH6xtnMbgclFuyJscI1fQuJFD ceVBzkHJ/ZRcE/psg74sSUeyzJUpM/G1Lcqk3Wu36BtQnsprUBPv/Lv8D06u89gBS7iQ SylsgRK2n/joBmNhscWCyXFjdiJF632FocMR9GrrlpmZGYWSzcW2ebCVyyL93VdwQm9l /LXV5iaMYZtNxeqEu5hSoPB8mGF4JyYmsJMy+rrxYcVZUyflDAY7yWyLhkd5M4c+jz98 t8AnZskdGdfcmngLU7TfpKueK07m4Wl7GIwiiAGROL0AUkoMKJzH+flI/GJo4tZOUD2+ yQGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gPIFjYXT; 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 z13-20020a05622a028d00b003f41b7430c1si680663qtw.608.2023.06.20.04.16.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:16:18 -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=gPIFjYXT; 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 1qBZEQ-00078a-Vx; Tue, 20 Jun 2023 07:09:07 -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 1qBZE6-0006ft-Ff for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:46 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZE4-0004XL-5R for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:46 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-9887ebe16d0so334651466b.2 for ; Tue, 20 Jun 2023 04:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259323; x=1689851323; 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=SPTofI9JsvJrrcptDf/DV5w5SQH9XzTd4Au47XuO2js=; b=gPIFjYXTMHbhLGRAx822xADv/NBe6+4/86riiKtDe9ZVPuEMKaykUORVhCgZC2Bmgd aoEtrzDGVdF0AHSvY7kmg136hh6RlVLhXluWyyYKdwpS1VazATY9bbDdOtqBKnMMfDbg 6Bgugp9qIEHR885O2kYH0FOSvRx34h093Qjb7uN58K58LGIolwEs8J7Ljd4w66gGnVS0 qOeX5xSTkkfWQwGTpFX+egH++nAyFOBylBOb+2xwca9IFwJPiR+Nqw2oYHMpiBHnklNg cvPjVahcWu+0P2kwQcueCaNDt0DxZWEwfHAtB7hSaDgBjw3T7MR7wHhjzwcVm1xP9SRZ CyUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259323; x=1689851323; 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=SPTofI9JsvJrrcptDf/DV5w5SQH9XzTd4Au47XuO2js=; b=U9a3Ei8Wz3rh0QGV7tAGxTBMMGjGzc7PQdvRZFXyfdYYGWknZf+Pi/pJyX9Nuh1Q0l 7jDjkKCdsuuL8SYvvDPx7CInRJ4FjvKKkMUJWVy9dyd2tle0EcxHurvA2BIiIqDPJEm2 ++b5emO+pKwgQL1CqGlxUEkxm1YtfykzFZkrWau8YC1rzKM823mRuKimOaQeoGWTFcaH C6jFV7LMy67rzJFVgWZiRs2IBBt+Zj3rkB+uXxlYfeUEwjrThnL9YCEyJbF3ik1GXNJk DXkf/+sR6VvXHJ/WgRIATdMJumYAcwbtZ2SXSLlV8TSxWIKKbyKGX6cIC31yP3f+03T3 NMMg== X-Gm-Message-State: AC+VfDy1s5dse0ZHhvegnaUnB2lVt9qzTXbkerydqThF2WuDREz2R4Fu o7BdFhLUydrJ4I5DYjHa7qknauCKVWSEghKZIDcjbW1m X-Received: by 2002:a17:907:2d28:b0:982:6bba:79c5 with SMTP id gs40-20020a1709072d2800b009826bba79c5mr11745289ejc.72.1687259322836; Tue, 20 Jun 2023 04:08:42 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 32/37] crypto: Implement aesdec_IMC with AES_imc_rot Date: Tue, 20 Jun 2023 13:07:53 +0200 Message-Id: <20230620110758.787479-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62a.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 This method uses one uint32_t * 256 table instead of 4, which means its data cache overhead is less. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- crypto/aes.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 9795ae8614..307c27947c 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1411,39 +1411,39 @@ aesdec_IMC_swap(AESState *r, const AESState *st, bool swap) bool be = HOST_BIG_ENDIAN ^ swap; uint32_t t; - /* Note that AES_imc is encoded for big-endian. */ - t = (AES_imc[st->b[swap_b ^ 0x0]][0] ^ - AES_imc[st->b[swap_b ^ 0x1]][1] ^ - AES_imc[st->b[swap_b ^ 0x2]][2] ^ - AES_imc[st->b[swap_b ^ 0x3]][3]); - if (!be) { + /* Note that AES_imc_rot is encoded for little-endian. */ + t = ( AES_imc_rot[st->b[swap_b ^ 0x0]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x1]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x2]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x3]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 0] = t; - t = (AES_imc[st->b[swap_b ^ 0x4]][0] ^ - AES_imc[st->b[swap_b ^ 0x5]][1] ^ - AES_imc[st->b[swap_b ^ 0x6]][2] ^ - AES_imc[st->b[swap_b ^ 0x7]][3]); - if (!be) { + t = ( AES_imc_rot[st->b[swap_b ^ 0x4]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x5]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x6]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x7]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 1] = t; - t = (AES_imc[st->b[swap_b ^ 0x8]][0] ^ - AES_imc[st->b[swap_b ^ 0x9]][1] ^ - AES_imc[st->b[swap_b ^ 0xA]][2] ^ - AES_imc[st->b[swap_b ^ 0xB]][3]); - if (!be) { + t = ( AES_imc_rot[st->b[swap_b ^ 0x8]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x9]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xA]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xB]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 2] = t; - t = (AES_imc[st->b[swap_b ^ 0xC]][0] ^ - AES_imc[st->b[swap_b ^ 0xD]][1] ^ - AES_imc[st->b[swap_b ^ 0xE]][2] ^ - AES_imc[st->b[swap_b ^ 0xF]][3]); - if (!be) { + t = ( AES_imc_rot[st->b[swap_b ^ 0xC]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xD]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xE]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xF]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 3] = t; From patchwork Tue Jun 20 11:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694472 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246145wrm; Tue, 20 Jun 2023 04:14:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kcRg3lKtO1QMKHcgdR7rmGnhRvy/P4cId3F9lpw61EehVpbpzWXpGyDdZC1EKZhvR4jB4 X-Received: by 2002:a05:6214:2622:b0:628:42e1:f373 with SMTP id gv2-20020a056214262200b0062842e1f373mr15033892qvb.59.1687259655762; Tue, 20 Jun 2023 04:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259655; cv=none; d=google.com; s=arc-20160816; b=hZZCLKlvIbDvNvdw0AtrInDfOhIargX6eHoJVL79zV8q/Y2R1CMDr1D3aBRE53bNBL uemdD+ZRmuCX3vEkFMEkZFNGUzn8v2PQUEm+eksng+k9DLMhor6u6UuLFvITj6QdG7Hg Syr8SJBQsTHXtCIhKNKRW7JfXEredwoSnAkSzpNqgRDagPH+Mc6IY4Gh1KyyE31iCttZ VpwBCLiGKC8XlmmRdjl8V69zXGSzankZOc6JPZrRF7M+IVlSadWmolODocu4gharDD1X JJvE1U001xcrIrTLyPdntkt31O0QijagN4WGhb1ip2rw3IaCMsQnjGt8zUcymPtEKvGs sj9A== 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=cwUuX0zKYulHXjb/fOXJ8OD0i/qvC/4E4K0aaRnvYj0=; b=sl6Og1ZJK/PXeX1sSl2OVXKvaSEDVkIfuh57F2k8qEJt6/d2Kdy+llE5MsIdy1vni+ 8tl11H8qbJEo1KzWu0klqWrEeiLvwMz2uyNAvsfSN2ZfRb2XpdmAvoJMcSpkvN0wXY4K eN9/WkS1NR/FMspYkO7clXXrcvFHH1gTUnow+q9IuCVva2vLTvabIHOvq+VsbCX50mnu ARAEQ9Pd/S/V5NZLjEs+NRMNuzk800xZUclnyqZYXzJhAD0/KTasi/CSA8BjC1sJl3t/ XcMCHpPIqgToEukgnrtv3MvLJ1h3m8nU3pCy8T+2fc4lVLVKq05FO+MbebfRzoowMIxG eVnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YX525etV; 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 g11-20020a0562140acb00b006262cd1f8besi715982qvi.442.2023.06.20.04.14.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:14:15 -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=YX525etV; 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 1qBZET-0007H7-0z; Tue, 20 Jun 2023 07:09:09 -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 1qBZEI-0006uM-6I for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:00 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZEE-0004Zf-3I for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:57 -0400 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9829a5ae978so717218766b.2 for ; Tue, 20 Jun 2023 04:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259333; x=1689851333; 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=cwUuX0zKYulHXjb/fOXJ8OD0i/qvC/4E4K0aaRnvYj0=; b=YX525etVCKzIK0lq0syYCr1b/EjzfjdQ3JQKKMbrGOVrRUBj9O/thrJoG5baxNutXJ kSDSv5ZJKNB8yed55h+LFgTPUe5L9p809aCqLSLbrrXnPHpHyq/MyudLR0wfQkrzu5As 4mbvXF2nY43SohqJdZhHRbwnpriOjjJ67ItU5plUvBfKLXV1XzWvjKfU5H8d4ZfdL2lt iqk5+pbj7LGr5kEg6PCMb3ipToz10vaUVfOMqEZC8+2mcx0pYRs9TY0A98M683uDwDCE aI8mHf6DwvauqrAevZKrpy22adLeV69FdpbYaRpBcTlmG3L0xeJj0L5/wW5LHokHtcWb U7vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259333; x=1689851333; 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=cwUuX0zKYulHXjb/fOXJ8OD0i/qvC/4E4K0aaRnvYj0=; b=hyXUTFtb2KrKthiHrtUOi2bGvMZl05C8wJAM6wUiat71dnURDqfEoPteowqlTyNj9s i2MYDdhjoBdHZjg0BGi63fcQ+IuWLsWQ7PLvcQioYWilHSBYaa2yf9wPSdnM16O8rWIm h2HQEJpDtUZRHI5v/hMlmEXVO9eDI3RCBvEqOxVGXdcl9I8nwJZHYKU5dnVzvXO5azqu mVh+3TJc9lC5x6/vXxoEmzzwa35G3ZhePCr4QjCInkQvmu9zVJSFKtPOXUXDyMZ+Wbpv UQMMh/I3MmLevebI+u1BBYNh66RLqvbT25iN/7l+E+m91t4KlfKDZ0zHTGmNJUbELo6q QnCQ== X-Gm-Message-State: AC+VfDxAf+EtKNiESYmGDRP9jnpIOug07J9WiiXoSxfV6J4Rvc6Y8WqM JeBBWcnwKp4pOLevYgjIsA88PSgAGvK0M0u1gCMrTpv3 X-Received: by 2002:a17:907:7f1e:b0:989:1f66:e42f with SMTP id qf30-20020a1709077f1e00b009891f66e42fmr1612832ejc.62.1687259324041; Tue, 20 Jun 2023 04:08:44 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 33/37] crypto: Remove AES_imc Date: Tue, 20 Jun 2023 13:07:54 +0200 Message-Id: <20230620110758.787479-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62b.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 This array is no longer used. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- include/crypto/aes.h | 7 -- crypto/aes.c | 264 ------------------------------------------- 2 files changed, 271 deletions(-) diff --git a/include/crypto/aes.h b/include/crypto/aes.h index aa8b54065d..99209f51b9 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -36,13 +36,6 @@ extern const uint32_t AES_mc_rot[256]; /* AES InvMixColumns, for use with rot32. */ extern const uint32_t AES_imc_rot[256]; -/* AES InvMixColumns */ -/* AES_imc[x][0] = [x].[0e, 09, 0d, 0b]; */ -/* AES_imc[x][1] = [x].[0b, 0e, 09, 0d]; */ -/* AES_imc[x][2] = [x].[0d, 0b, 0e, 09]; */ -/* AES_imc[x][3] = [x].[09, 0d, 0b, 0e]; */ -extern const uint32_t AES_imc[256][4]; - /* AES_Te0[x] = S [x].[02, 01, 01, 03]; AES_Te1[x] = S [x].[03, 02, 01, 01]; diff --git a/crypto/aes.c b/crypto/aes.c index 307c27947c..897d4c8d2b 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -291,270 +291,6 @@ const uint32_t AES_imc_rot[256] = { 0xbe805d9f, 0xb58d5491, 0xa89a4f83, 0xa397468d, }; -/* AES_imc[x][0] = [x].[0e, 09, 0d, 0b]; */ -/* AES_imc[x][1] = [x].[0b, 0e, 09, 0d]; */ -/* AES_imc[x][2] = [x].[0d, 0b, 0e, 09]; */ -/* AES_imc[x][3] = [x].[09, 0d, 0b, 0e]; */ -const uint32_t AES_imc[256][4] = { - { 0x00000000, 0x00000000, 0x00000000, 0x00000000, }, /* x=00 */ - { 0x0E090D0B, 0x0B0E090D, 0x0D0B0E09, 0x090D0B0E, }, /* x=01 */ - { 0x1C121A16, 0x161C121A, 0x1A161C12, 0x121A161C, }, /* x=02 */ - { 0x121B171D, 0x1D121B17, 0x171D121B, 0x1B171D12, }, /* x=03 */ - { 0x3824342C, 0x2C382434, 0x342C3824, 0x24342C38, }, /* x=04 */ - { 0x362D3927, 0x27362D39, 0x3927362D, 0x2D392736, }, /* x=05 */ - { 0x24362E3A, 0x3A24362E, 0x2E3A2436, 0x362E3A24, }, /* x=06 */ - { 0x2A3F2331, 0x312A3F23, 0x23312A3F, 0x3F23312A, }, /* x=07 */ - { 0x70486858, 0x58704868, 0x68587048, 0x48685870, }, /* x=08 */ - { 0x7E416553, 0x537E4165, 0x65537E41, 0x4165537E, }, /* x=09 */ - { 0x6C5A724E, 0x4E6C5A72, 0x724E6C5A, 0x5A724E6C, }, /* x=0A */ - { 0x62537F45, 0x4562537F, 0x7F456253, 0x537F4562, }, /* x=0B */ - { 0x486C5C74, 0x74486C5C, 0x5C74486C, 0x6C5C7448, }, /* x=0C */ - { 0x4665517F, 0x7F466551, 0x517F4665, 0x65517F46, }, /* x=0D */ - { 0x547E4662, 0x62547E46, 0x4662547E, 0x7E466254, }, /* x=0E */ - { 0x5A774B69, 0x695A774B, 0x4B695A77, 0x774B695A, }, /* x=0F */ - { 0xE090D0B0, 0xB0E090D0, 0xD0B0E090, 0x90D0B0E0, }, /* x=10 */ - { 0xEE99DDBB, 0xBBEE99DD, 0xDDBBEE99, 0x99DDBBEE, }, /* x=11 */ - { 0xFC82CAA6, 0xA6FC82CA, 0xCAA6FC82, 0x82CAA6FC, }, /* x=12 */ - { 0xF28BC7AD, 0xADF28BC7, 0xC7ADF28B, 0x8BC7ADF2, }, /* x=13 */ - { 0xD8B4E49C, 0x9CD8B4E4, 0xE49CD8B4, 0xB4E49CD8, }, /* x=14 */ - { 0xD6BDE997, 0x97D6BDE9, 0xE997D6BD, 0xBDE997D6, }, /* x=15 */ - { 0xC4A6FE8A, 0x8AC4A6FE, 0xFE8AC4A6, 0xA6FE8AC4, }, /* x=16 */ - { 0xCAAFF381, 0x81CAAFF3, 0xF381CAAF, 0xAFF381CA, }, /* x=17 */ - { 0x90D8B8E8, 0xE890D8B8, 0xB8E890D8, 0xD8B8E890, }, /* x=18 */ - { 0x9ED1B5E3, 0xE39ED1B5, 0xB5E39ED1, 0xD1B5E39E, }, /* x=19 */ - { 0x8CCAA2FE, 0xFE8CCAA2, 0xA2FE8CCA, 0xCAA2FE8C, }, /* x=1A */ - { 0x82C3AFF5, 0xF582C3AF, 0xAFF582C3, 0xC3AFF582, }, /* x=1B */ - { 0xA8FC8CC4, 0xC4A8FC8C, 0x8CC4A8FC, 0xFC8CC4A8, }, /* x=1C */ - { 0xA6F581CF, 0xCFA6F581, 0x81CFA6F5, 0xF581CFA6, }, /* x=1D */ - { 0xB4EE96D2, 0xD2B4EE96, 0x96D2B4EE, 0xEE96D2B4, }, /* x=1E */ - { 0xBAE79BD9, 0xD9BAE79B, 0x9BD9BAE7, 0xE79BD9BA, }, /* x=1F */ - { 0xDB3BBB7B, 0x7BDB3BBB, 0xBB7BDB3B, 0x3BBB7BDB, }, /* x=20 */ - { 0xD532B670, 0x70D532B6, 0xB670D532, 0x32B670D5, }, /* x=21 */ - { 0xC729A16D, 0x6DC729A1, 0xA16DC729, 0x29A16DC7, }, /* x=22 */ - { 0xC920AC66, 0x66C920AC, 0xAC66C920, 0x20AC66C9, }, /* x=23 */ - { 0xE31F8F57, 0x57E31F8F, 0x8F57E31F, 0x1F8F57E3, }, /* x=24 */ - { 0xED16825C, 0x5CED1682, 0x825CED16, 0x16825CED, }, /* x=25 */ - { 0xFF0D9541, 0x41FF0D95, 0x9541FF0D, 0x0D9541FF, }, /* x=26 */ - { 0xF104984A, 0x4AF10498, 0x984AF104, 0x04984AF1, }, /* x=27 */ - { 0xAB73D323, 0x23AB73D3, 0xD323AB73, 0x73D323AB, }, /* x=28 */ - { 0xA57ADE28, 0x28A57ADE, 0xDE28A57A, 0x7ADE28A5, }, /* x=29 */ - { 0xB761C935, 0x35B761C9, 0xC935B761, 0x61C935B7, }, /* x=2A */ - { 0xB968C43E, 0x3EB968C4, 0xC43EB968, 0x68C43EB9, }, /* x=2B */ - { 0x9357E70F, 0x0F9357E7, 0xE70F9357, 0x57E70F93, }, /* x=2C */ - { 0x9D5EEA04, 0x049D5EEA, 0xEA049D5E, 0x5EEA049D, }, /* x=2D */ - { 0x8F45FD19, 0x198F45FD, 0xFD198F45, 0x45FD198F, }, /* x=2E */ - { 0x814CF012, 0x12814CF0, 0xF012814C, 0x4CF01281, }, /* x=2F */ - { 0x3BAB6BCB, 0xCB3BAB6B, 0x6BCB3BAB, 0xAB6BCB3B, }, /* x=30 */ - { 0x35A266C0, 0xC035A266, 0x66C035A2, 0xA266C035, }, /* x=31 */ - { 0x27B971DD, 0xDD27B971, 0x71DD27B9, 0xB971DD27, }, /* x=32 */ - { 0x29B07CD6, 0xD629B07C, 0x7CD629B0, 0xB07CD629, }, /* x=33 */ - { 0x038F5FE7, 0xE7038F5F, 0x5FE7038F, 0x8F5FE703, }, /* x=34 */ - { 0x0D8652EC, 0xEC0D8652, 0x52EC0D86, 0x8652EC0D, }, /* x=35 */ - { 0x1F9D45F1, 0xF11F9D45, 0x45F11F9D, 0x9D45F11F, }, /* x=36 */ - { 0x119448FA, 0xFA119448, 0x48FA1194, 0x9448FA11, }, /* x=37 */ - { 0x4BE30393, 0x934BE303, 0x03934BE3, 0xE303934B, }, /* x=38 */ - { 0x45EA0E98, 0x9845EA0E, 0x0E9845EA, 0xEA0E9845, }, /* x=39 */ - { 0x57F11985, 0x8557F119, 0x198557F1, 0xF1198557, }, /* x=3A */ - { 0x59F8148E, 0x8E59F814, 0x148E59F8, 0xF8148E59, }, /* x=3B */ - { 0x73C737BF, 0xBF73C737, 0x37BF73C7, 0xC737BF73, }, /* x=3C */ - { 0x7DCE3AB4, 0xB47DCE3A, 0x3AB47DCE, 0xCE3AB47D, }, /* x=3D */ - { 0x6FD52DA9, 0xA96FD52D, 0x2DA96FD5, 0xD52DA96F, }, /* x=3E */ - { 0x61DC20A2, 0xA261DC20, 0x20A261DC, 0xDC20A261, }, /* x=3F */ - { 0xAD766DF6, 0xF6AD766D, 0x6DF6AD76, 0x766DF6AD, }, /* x=40 */ - { 0xA37F60FD, 0xFDA37F60, 0x60FDA37F, 0x7F60FDA3, }, /* x=41 */ - { 0xB16477E0, 0xE0B16477, 0x77E0B164, 0x6477E0B1, }, /* x=42 */ - { 0xBF6D7AEB, 0xEBBF6D7A, 0x7AEBBF6D, 0x6D7AEBBF, }, /* x=43 */ - { 0x955259DA, 0xDA955259, 0x59DA9552, 0x5259DA95, }, /* x=44 */ - { 0x9B5B54D1, 0xD19B5B54, 0x54D19B5B, 0x5B54D19B, }, /* x=45 */ - { 0x894043CC, 0xCC894043, 0x43CC8940, 0x4043CC89, }, /* x=46 */ - { 0x87494EC7, 0xC787494E, 0x4EC78749, 0x494EC787, }, /* x=47 */ - { 0xDD3E05AE, 0xAEDD3E05, 0x05AEDD3E, 0x3E05AEDD, }, /* x=48 */ - { 0xD33708A5, 0xA5D33708, 0x08A5D337, 0x3708A5D3, }, /* x=49 */ - { 0xC12C1FB8, 0xB8C12C1F, 0x1FB8C12C, 0x2C1FB8C1, }, /* x=4A */ - { 0xCF2512B3, 0xB3CF2512, 0x12B3CF25, 0x2512B3CF, }, /* x=4B */ - { 0xE51A3182, 0x82E51A31, 0x3182E51A, 0x1A3182E5, }, /* x=4C */ - { 0xEB133C89, 0x89EB133C, 0x3C89EB13, 0x133C89EB, }, /* x=4D */ - { 0xF9082B94, 0x94F9082B, 0x2B94F908, 0x082B94F9, }, /* x=4E */ - { 0xF701269F, 0x9FF70126, 0x269FF701, 0x01269FF7, }, /* x=4F */ - { 0x4DE6BD46, 0x464DE6BD, 0xBD464DE6, 0xE6BD464D, }, /* x=50 */ - { 0x43EFB04D, 0x4D43EFB0, 0xB04D43EF, 0xEFB04D43, }, /* x=51 */ - { 0x51F4A750, 0x5051F4A7, 0xA75051F4, 0xF4A75051, }, /* x=52 */ - { 0x5FFDAA5B, 0x5B5FFDAA, 0xAA5B5FFD, 0xFDAA5B5F, }, /* x=53 */ - { 0x75C2896A, 0x6A75C289, 0x896A75C2, 0xC2896A75, }, /* x=54 */ - { 0x7BCB8461, 0x617BCB84, 0x84617BCB, 0xCB84617B, }, /* x=55 */ - { 0x69D0937C, 0x7C69D093, 0x937C69D0, 0xD0937C69, }, /* x=56 */ - { 0x67D99E77, 0x7767D99E, 0x9E7767D9, 0xD99E7767, }, /* x=57 */ - { 0x3DAED51E, 0x1E3DAED5, 0xD51E3DAE, 0xAED51E3D, }, /* x=58 */ - { 0x33A7D815, 0x1533A7D8, 0xD81533A7, 0xA7D81533, }, /* x=59 */ - { 0x21BCCF08, 0x0821BCCF, 0xCF0821BC, 0xBCCF0821, }, /* x=5A */ - { 0x2FB5C203, 0x032FB5C2, 0xC2032FB5, 0xB5C2032F, }, /* x=5B */ - { 0x058AE132, 0x32058AE1, 0xE132058A, 0x8AE13205, }, /* x=5C */ - { 0x0B83EC39, 0x390B83EC, 0xEC390B83, 0x83EC390B, }, /* x=5D */ - { 0x1998FB24, 0x241998FB, 0xFB241998, 0x98FB2419, }, /* x=5E */ - { 0x1791F62F, 0x2F1791F6, 0xF62F1791, 0x91F62F17, }, /* x=5F */ - { 0x764DD68D, 0x8D764DD6, 0xD68D764D, 0x4DD68D76, }, /* x=60 */ - { 0x7844DB86, 0x867844DB, 0xDB867844, 0x44DB8678, }, /* x=61 */ - { 0x6A5FCC9B, 0x9B6A5FCC, 0xCC9B6A5F, 0x5FCC9B6A, }, /* x=62 */ - { 0x6456C190, 0x906456C1, 0xC1906456, 0x56C19064, }, /* x=63 */ - { 0x4E69E2A1, 0xA14E69E2, 0xE2A14E69, 0x69E2A14E, }, /* x=64 */ - { 0x4060EFAA, 0xAA4060EF, 0xEFAA4060, 0x60EFAA40, }, /* x=65 */ - { 0x527BF8B7, 0xB7527BF8, 0xF8B7527B, 0x7BF8B752, }, /* x=66 */ - { 0x5C72F5BC, 0xBC5C72F5, 0xF5BC5C72, 0x72F5BC5C, }, /* x=67 */ - { 0x0605BED5, 0xD50605BE, 0xBED50605, 0x05BED506, }, /* x=68 */ - { 0x080CB3DE, 0xDE080CB3, 0xB3DE080C, 0x0CB3DE08, }, /* x=69 */ - { 0x1A17A4C3, 0xC31A17A4, 0xA4C31A17, 0x17A4C31A, }, /* x=6A */ - { 0x141EA9C8, 0xC8141EA9, 0xA9C8141E, 0x1EA9C814, }, /* x=6B */ - { 0x3E218AF9, 0xF93E218A, 0x8AF93E21, 0x218AF93E, }, /* x=6C */ - { 0x302887F2, 0xF2302887, 0x87F23028, 0x2887F230, }, /* x=6D */ - { 0x223390EF, 0xEF223390, 0x90EF2233, 0x3390EF22, }, /* x=6E */ - { 0x2C3A9DE4, 0xE42C3A9D, 0x9DE42C3A, 0x3A9DE42C, }, /* x=6F */ - { 0x96DD063D, 0x3D96DD06, 0x063D96DD, 0xDD063D96, }, /* x=70 */ - { 0x98D40B36, 0x3698D40B, 0x0B3698D4, 0xD40B3698, }, /* x=71 */ - { 0x8ACF1C2B, 0x2B8ACF1C, 0x1C2B8ACF, 0xCF1C2B8A, }, /* x=72 */ - { 0x84C61120, 0x2084C611, 0x112084C6, 0xC6112084, }, /* x=73 */ - { 0xAEF93211, 0x11AEF932, 0x3211AEF9, 0xF93211AE, }, /* x=74 */ - { 0xA0F03F1A, 0x1AA0F03F, 0x3F1AA0F0, 0xF03F1AA0, }, /* x=75 */ - { 0xB2EB2807, 0x07B2EB28, 0x2807B2EB, 0xEB2807B2, }, /* x=76 */ - { 0xBCE2250C, 0x0CBCE225, 0x250CBCE2, 0xE2250CBC, }, /* x=77 */ - { 0xE6956E65, 0x65E6956E, 0x6E65E695, 0x956E65E6, }, /* x=78 */ - { 0xE89C636E, 0x6EE89C63, 0x636EE89C, 0x9C636EE8, }, /* x=79 */ - { 0xFA877473, 0x73FA8774, 0x7473FA87, 0x877473FA, }, /* x=7A */ - { 0xF48E7978, 0x78F48E79, 0x7978F48E, 0x8E7978F4, }, /* x=7B */ - { 0xDEB15A49, 0x49DEB15A, 0x5A49DEB1, 0xB15A49DE, }, /* x=7C */ - { 0xD0B85742, 0x42D0B857, 0x5742D0B8, 0xB85742D0, }, /* x=7D */ - { 0xC2A3405F, 0x5FC2A340, 0x405FC2A3, 0xA3405FC2, }, /* x=7E */ - { 0xCCAA4D54, 0x54CCAA4D, 0x4D54CCAA, 0xAA4D54CC, }, /* x=7F */ - { 0x41ECDAF7, 0xF741ECDA, 0xDAF741EC, 0xECDAF741, }, /* x=80 */ - { 0x4FE5D7FC, 0xFC4FE5D7, 0xD7FC4FE5, 0xE5D7FC4F, }, /* x=81 */ - { 0x5DFEC0E1, 0xE15DFEC0, 0xC0E15DFE, 0xFEC0E15D, }, /* x=82 */ - { 0x53F7CDEA, 0xEA53F7CD, 0xCDEA53F7, 0xF7CDEA53, }, /* x=83 */ - { 0x79C8EEDB, 0xDB79C8EE, 0xEEDB79C8, 0xC8EEDB79, }, /* x=84 */ - { 0x77C1E3D0, 0xD077C1E3, 0xE3D077C1, 0xC1E3D077, }, /* x=85 */ - { 0x65DAF4CD, 0xCD65DAF4, 0xF4CD65DA, 0xDAF4CD65, }, /* x=86 */ - { 0x6BD3F9C6, 0xC66BD3F9, 0xF9C66BD3, 0xD3F9C66B, }, /* x=87 */ - { 0x31A4B2AF, 0xAF31A4B2, 0xB2AF31A4, 0xA4B2AF31, }, /* x=88 */ - { 0x3FADBFA4, 0xA43FADBF, 0xBFA43FAD, 0xADBFA43F, }, /* x=89 */ - { 0x2DB6A8B9, 0xB92DB6A8, 0xA8B92DB6, 0xB6A8B92D, }, /* x=8A */ - { 0x23BFA5B2, 0xB223BFA5, 0xA5B223BF, 0xBFA5B223, }, /* x=8B */ - { 0x09808683, 0x83098086, 0x86830980, 0x80868309, }, /* x=8C */ - { 0x07898B88, 0x8807898B, 0x8B880789, 0x898B8807, }, /* x=8D */ - { 0x15929C95, 0x9515929C, 0x9C951592, 0x929C9515, }, /* x=8E */ - { 0x1B9B919E, 0x9E1B9B91, 0x919E1B9B, 0x9B919E1B, }, /* x=8F */ - { 0xA17C0A47, 0x47A17C0A, 0x0A47A17C, 0x7C0A47A1, }, /* x=90 */ - { 0xAF75074C, 0x4CAF7507, 0x074CAF75, 0x75074CAF, }, /* x=91 */ - { 0xBD6E1051, 0x51BD6E10, 0x1051BD6E, 0x6E1051BD, }, /* x=92 */ - { 0xB3671D5A, 0x5AB3671D, 0x1D5AB367, 0x671D5AB3, }, /* x=93 */ - { 0x99583E6B, 0x6B99583E, 0x3E6B9958, 0x583E6B99, }, /* x=94 */ - { 0x97513360, 0x60975133, 0x33609751, 0x51336097, }, /* x=95 */ - { 0x854A247D, 0x7D854A24, 0x247D854A, 0x4A247D85, }, /* x=96 */ - { 0x8B432976, 0x768B4329, 0x29768B43, 0x4329768B, }, /* x=97 */ - { 0xD134621F, 0x1FD13462, 0x621FD134, 0x34621FD1, }, /* x=98 */ - { 0xDF3D6F14, 0x14DF3D6F, 0x6F14DF3D, 0x3D6F14DF, }, /* x=99 */ - { 0xCD267809, 0x09CD2678, 0x7809CD26, 0x267809CD, }, /* x=9A */ - { 0xC32F7502, 0x02C32F75, 0x7502C32F, 0x2F7502C3, }, /* x=9B */ - { 0xE9105633, 0x33E91056, 0x5633E910, 0x105633E9, }, /* x=9C */ - { 0xE7195B38, 0x38E7195B, 0x5B38E719, 0x195B38E7, }, /* x=9D */ - { 0xF5024C25, 0x25F5024C, 0x4C25F502, 0x024C25F5, }, /* x=9E */ - { 0xFB0B412E, 0x2EFB0B41, 0x412EFB0B, 0x0B412EFB, }, /* x=9F */ - { 0x9AD7618C, 0x8C9AD761, 0x618C9AD7, 0xD7618C9A, }, /* x=A0 */ - { 0x94DE6C87, 0x8794DE6C, 0x6C8794DE, 0xDE6C8794, }, /* x=A1 */ - { 0x86C57B9A, 0x9A86C57B, 0x7B9A86C5, 0xC57B9A86, }, /* x=A2 */ - { 0x88CC7691, 0x9188CC76, 0x769188CC, 0xCC769188, }, /* x=A3 */ - { 0xA2F355A0, 0xA0A2F355, 0x55A0A2F3, 0xF355A0A2, }, /* x=A4 */ - { 0xACFA58AB, 0xABACFA58, 0x58ABACFA, 0xFA58ABAC, }, /* x=A5 */ - { 0xBEE14FB6, 0xB6BEE14F, 0x4FB6BEE1, 0xE14FB6BE, }, /* x=A6 */ - { 0xB0E842BD, 0xBDB0E842, 0x42BDB0E8, 0xE842BDB0, }, /* x=A7 */ - { 0xEA9F09D4, 0xD4EA9F09, 0x09D4EA9F, 0x9F09D4EA, }, /* x=A8 */ - { 0xE49604DF, 0xDFE49604, 0x04DFE496, 0x9604DFE4, }, /* x=A9 */ - { 0xF68D13C2, 0xC2F68D13, 0x13C2F68D, 0x8D13C2F6, }, /* x=AA */ - { 0xF8841EC9, 0xC9F8841E, 0x1EC9F884, 0x841EC9F8, }, /* x=AB */ - { 0xD2BB3DF8, 0xF8D2BB3D, 0x3DF8D2BB, 0xBB3DF8D2, }, /* x=AC */ - { 0xDCB230F3, 0xF3DCB230, 0x30F3DCB2, 0xB230F3DC, }, /* x=AD */ - { 0xCEA927EE, 0xEECEA927, 0x27EECEA9, 0xA927EECE, }, /* x=AE */ - { 0xC0A02AE5, 0xE5C0A02A, 0x2AE5C0A0, 0xA02AE5C0, }, /* x=AF */ - { 0x7A47B13C, 0x3C7A47B1, 0xB13C7A47, 0x47B13C7A, }, /* x=B0 */ - { 0x744EBC37, 0x37744EBC, 0xBC37744E, 0x4EBC3774, }, /* x=B1 */ - { 0x6655AB2A, 0x2A6655AB, 0xAB2A6655, 0x55AB2A66, }, /* x=B2 */ - { 0x685CA621, 0x21685CA6, 0xA621685C, 0x5CA62168, }, /* x=B3 */ - { 0x42638510, 0x10426385, 0x85104263, 0x63851042, }, /* x=B4 */ - { 0x4C6A881B, 0x1B4C6A88, 0x881B4C6A, 0x6A881B4C, }, /* x=B5 */ - { 0x5E719F06, 0x065E719F, 0x9F065E71, 0x719F065E, }, /* x=B6 */ - { 0x5078920D, 0x0D507892, 0x920D5078, 0x78920D50, }, /* x=B7 */ - { 0x0A0FD964, 0x640A0FD9, 0xD9640A0F, 0x0FD9640A, }, /* x=B8 */ - { 0x0406D46F, 0x6F0406D4, 0xD46F0406, 0x06D46F04, }, /* x=B9 */ - { 0x161DC372, 0x72161DC3, 0xC372161D, 0x1DC37216, }, /* x=BA */ - { 0x1814CE79, 0x791814CE, 0xCE791814, 0x14CE7918, }, /* x=BB */ - { 0x322BED48, 0x48322BED, 0xED48322B, 0x2BED4832, }, /* x=BC */ - { 0x3C22E043, 0x433C22E0, 0xE0433C22, 0x22E0433C, }, /* x=BD */ - { 0x2E39F75E, 0x5E2E39F7, 0xF75E2E39, 0x39F75E2E, }, /* x=BE */ - { 0x2030FA55, 0x552030FA, 0xFA552030, 0x30FA5520, }, /* x=BF */ - { 0xEC9AB701, 0x01EC9AB7, 0xB701EC9A, 0x9AB701EC, }, /* x=C0 */ - { 0xE293BA0A, 0x0AE293BA, 0xBA0AE293, 0x93BA0AE2, }, /* x=C1 */ - { 0xF088AD17, 0x17F088AD, 0xAD17F088, 0x88AD17F0, }, /* x=C2 */ - { 0xFE81A01C, 0x1CFE81A0, 0xA01CFE81, 0x81A01CFE, }, /* x=C3 */ - { 0xD4BE832D, 0x2DD4BE83, 0x832DD4BE, 0xBE832DD4, }, /* x=C4 */ - { 0xDAB78E26, 0x26DAB78E, 0x8E26DAB7, 0xB78E26DA, }, /* x=C5 */ - { 0xC8AC993B, 0x3BC8AC99, 0x993BC8AC, 0xAC993BC8, }, /* x=C6 */ - { 0xC6A59430, 0x30C6A594, 0x9430C6A5, 0xA59430C6, }, /* x=C7 */ - { 0x9CD2DF59, 0x599CD2DF, 0xDF599CD2, 0xD2DF599C, }, /* x=C8 */ - { 0x92DBD252, 0x5292DBD2, 0xD25292DB, 0xDBD25292, }, /* x=C9 */ - { 0x80C0C54F, 0x4F80C0C5, 0xC54F80C0, 0xC0C54F80, }, /* x=CA */ - { 0x8EC9C844, 0x448EC9C8, 0xC8448EC9, 0xC9C8448E, }, /* x=CB */ - { 0xA4F6EB75, 0x75A4F6EB, 0xEB75A4F6, 0xF6EB75A4, }, /* x=CC */ - { 0xAAFFE67E, 0x7EAAFFE6, 0xE67EAAFF, 0xFFE67EAA, }, /* x=CD */ - { 0xB8E4F163, 0x63B8E4F1, 0xF163B8E4, 0xE4F163B8, }, /* x=CE */ - { 0xB6EDFC68, 0x68B6EDFC, 0xFC68B6ED, 0xEDFC68B6, }, /* x=CF */ - { 0x0C0A67B1, 0xB10C0A67, 0x67B10C0A, 0x0A67B10C, }, /* x=D0 */ - { 0x02036ABA, 0xBA02036A, 0x6ABA0203, 0x036ABA02, }, /* x=D1 */ - { 0x10187DA7, 0xA710187D, 0x7DA71018, 0x187DA710, }, /* x=D2 */ - { 0x1E1170AC, 0xAC1E1170, 0x70AC1E11, 0x1170AC1E, }, /* x=D3 */ - { 0x342E539D, 0x9D342E53, 0x539D342E, 0x2E539D34, }, /* x=D4 */ - { 0x3A275E96, 0x963A275E, 0x5E963A27, 0x275E963A, }, /* x=D5 */ - { 0x283C498B, 0x8B283C49, 0x498B283C, 0x3C498B28, }, /* x=D6 */ - { 0x26354480, 0x80263544, 0x44802635, 0x35448026, }, /* x=D7 */ - { 0x7C420FE9, 0xE97C420F, 0x0FE97C42, 0x420FE97C, }, /* x=D8 */ - { 0x724B02E2, 0xE2724B02, 0x02E2724B, 0x4B02E272, }, /* x=D9 */ - { 0x605015FF, 0xFF605015, 0x15FF6050, 0x5015FF60, }, /* x=DA */ - { 0x6E5918F4, 0xF46E5918, 0x18F46E59, 0x5918F46E, }, /* x=DB */ - { 0x44663BC5, 0xC544663B, 0x3BC54466, 0x663BC544, }, /* x=DC */ - { 0x4A6F36CE, 0xCE4A6F36, 0x36CE4A6F, 0x6F36CE4A, }, /* x=DD */ - { 0x587421D3, 0xD3587421, 0x21D35874, 0x7421D358, }, /* x=DE */ - { 0x567D2CD8, 0xD8567D2C, 0x2CD8567D, 0x7D2CD856, }, /* x=DF */ - { 0x37A10C7A, 0x7A37A10C, 0x0C7A37A1, 0xA10C7A37, }, /* x=E0 */ - { 0x39A80171, 0x7139A801, 0x017139A8, 0xA8017139, }, /* x=E1 */ - { 0x2BB3166C, 0x6C2BB316, 0x166C2BB3, 0xB3166C2B, }, /* x=E2 */ - { 0x25BA1B67, 0x6725BA1B, 0x1B6725BA, 0xBA1B6725, }, /* x=E3 */ - { 0x0F853856, 0x560F8538, 0x38560F85, 0x8538560F, }, /* x=E4 */ - { 0x018C355D, 0x5D018C35, 0x355D018C, 0x8C355D01, }, /* x=E5 */ - { 0x13972240, 0x40139722, 0x22401397, 0x97224013, }, /* x=E6 */ - { 0x1D9E2F4B, 0x4B1D9E2F, 0x2F4B1D9E, 0x9E2F4B1D, }, /* x=E7 */ - { 0x47E96422, 0x2247E964, 0x642247E9, 0xE9642247, }, /* x=E8 */ - { 0x49E06929, 0x2949E069, 0x692949E0, 0xE0692949, }, /* x=E9 */ - { 0x5BFB7E34, 0x345BFB7E, 0x7E345BFB, 0xFB7E345B, }, /* x=EA */ - { 0x55F2733F, 0x3F55F273, 0x733F55F2, 0xF2733F55, }, /* x=EB */ - { 0x7FCD500E, 0x0E7FCD50, 0x500E7FCD, 0xCD500E7F, }, /* x=EC */ - { 0x71C45D05, 0x0571C45D, 0x5D0571C4, 0xC45D0571, }, /* x=ED */ - { 0x63DF4A18, 0x1863DF4A, 0x4A1863DF, 0xDF4A1863, }, /* x=EE */ - { 0x6DD64713, 0x136DD647, 0x47136DD6, 0xD647136D, }, /* x=EF */ - { 0xD731DCCA, 0xCAD731DC, 0xDCCAD731, 0x31DCCAD7, }, /* x=F0 */ - { 0xD938D1C1, 0xC1D938D1, 0xD1C1D938, 0x38D1C1D9, }, /* x=F1 */ - { 0xCB23C6DC, 0xDCCB23C6, 0xC6DCCB23, 0x23C6DCCB, }, /* x=F2 */ - { 0xC52ACBD7, 0xD7C52ACB, 0xCBD7C52A, 0x2ACBD7C5, }, /* x=F3 */ - { 0xEF15E8E6, 0xE6EF15E8, 0xE8E6EF15, 0x15E8E6EF, }, /* x=F4 */ - { 0xE11CE5ED, 0xEDE11CE5, 0xE5EDE11C, 0x1CE5EDE1, }, /* x=F5 */ - { 0xF307F2F0, 0xF0F307F2, 0xF2F0F307, 0x07F2F0F3, }, /* x=F6 */ - { 0xFD0EFFFB, 0xFBFD0EFF, 0xFFFBFD0E, 0x0EFFFBFD, }, /* x=F7 */ - { 0xA779B492, 0x92A779B4, 0xB492A779, 0x79B492A7, }, /* x=F8 */ - { 0xA970B999, 0x99A970B9, 0xB999A970, 0x70B999A9, }, /* x=F9 */ - { 0xBB6BAE84, 0x84BB6BAE, 0xAE84BB6B, 0x6BAE84BB, }, /* x=FA */ - { 0xB562A38F, 0x8FB562A3, 0xA38FB562, 0x62A38FB5, }, /* x=FB */ - { 0x9F5D80BE, 0xBE9F5D80, 0x80BE9F5D, 0x5D80BE9F, }, /* x=FC */ - { 0x91548DB5, 0xB591548D, 0x8DB59154, 0x548DB591, }, /* x=FD */ - { 0x834F9AA8, 0xA8834F9A, 0x9AA8834F, 0x4F9AA883, }, /* x=FE */ - { 0x8D4697A3, 0xA38D4697, 0x97A38D46, 0x4697A38D, }, /* x=FF */ -}; - - /* AES_Te0[x] = S [x].[02, 01, 01, 03]; From patchwork Tue Jun 20 11:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694473 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246153wrm; Tue, 20 Jun 2023 04:14:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5NWspvDsK1ygQyHXkSycqcnxAYt8N7yHxEIgB8puVkGLYOdQi+c41Wzlq3RbPUeC0GjOlt X-Received: by 2002:a05:620a:1a87:b0:763:b8f6:33dc with SMTP id bl7-20020a05620a1a8700b00763b8f633dcmr451359qkb.37.1687259657474; Tue, 20 Jun 2023 04:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259657; cv=none; d=google.com; s=arc-20160816; b=DUHljo1EQuA+L99fC8ZSqSNH/yGVQ3O7BuYaLE8wTEt/pl6mJZWqpdFXq0E8xb7rFT essWGpTh+pCHhtOoNIuctfAYHPR3UmLAbuwPs77PBUOLQwJ6XABbQqik/8OsE7ajCd+C DIvcm6iOKsrIsj4oyUFQCLEgyl+1/xRYaGXrI8l/PrszxYN9nsSNeDhBuCavtrjdr9dk V7KUfWySE6x2m96eY1SUuLpiVvE882Xe35Bb9LZgvbPZydlZZ7H9kts+sEEMvMO1sVQI FU79dlH+KrtCfWQJmeIpNXbiKo6ucCP4FiKcR7dtUseo42Z2Cpp5l/2rwhcH3QIqFxhc gItA== 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=5fV4OH2+18aXYcOc6vzuDdaAN0nZgBSsc3xuSrFTnRA=; b=Q+sIjuCMofR5QDSpshNSSURs3SKyYTSCN1UtZu7QBnN97RTiucMnKD5aA/yj9m8ytv prOS1IYMAQGmPchzaaSWLAx/eOBz2DDD1Vp0KbWyK21tJLIu3ne+Aj2C5VXFZbOD5xei KgYg4DDmt2Uf5ISfqLQg7sMhg8gChKj1z6TgfyPpYQFNiLXuHl16cF1fVl4GXRF77B2+ I1PFA0ZV68Iyiw0Kb4qCPyIPq+RAvvfxqVqk0a7+afaPQhDgjRcKTkAieEmNtNUTcmGR 9HmOoAs2zOZbHJVg9XRC/u52mHaN4lb/gRptoVLXWX2z8Lt6QFGhF/wT6JxVq8NkiISg P19Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rFE2MwXv; 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 u18-20020a05620a121200b00760952f5f01si668598qkj.723.2023.06.20.04.14.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:14:17 -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=rFE2MwXv; 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 1qBZER-0007C8-Uk; Tue, 20 Jun 2023 07:09:07 -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 1qBZEL-0006wX-3y for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:02 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZEH-0004ah-UD for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:00 -0400 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b46cad2fd9so40951871fa.1 for ; Tue, 20 Jun 2023 04:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259334; x=1689851334; 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=5fV4OH2+18aXYcOc6vzuDdaAN0nZgBSsc3xuSrFTnRA=; b=rFE2MwXvQa1681uCCUizvlhZLz4Mp13N+6vtUJ1lC8hahpydw6Kb65HCQUELfNjEYu kSrkNMp5WYys9HSF64qyJ77VUOk54KV8QvlntgANHm5LlnaWiJenXAZ5Var0RBpuxtwc 4mLIyOsmvFyxF4nbQ6n4TYIjpTUk0ggYmZU34LaW1ZtUg48OqVwxbXAxT8K9yhJG3oWu Vi0TAMliZ+UDHekFa1/mJwJCYi6iRLUqImfKzmwJfKfKKzai+Ag513SB4nAKL4O8rNJT 7VrXKg2sYHQ2ZiInrGMhXi42QrerRgRuaKz0O2dRuWEnBNwQKgmNTYBfXjTs2a85mGlO JAUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259334; x=1689851334; 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=5fV4OH2+18aXYcOc6vzuDdaAN0nZgBSsc3xuSrFTnRA=; b=LWz28UPCAxRz5blV1FcaHWrwhyiFuhb1VCLjcR4uff6R9swYBlSJ3ZZz3iEmetImRy pvwHre3x3Ar+6Evf2HKCU994lqc6PhDlzzS0GrA+sa1lOSmHRJ2hQK7TfT1ru1sGgk9T T/dRgrAQyJpR2+KFd8RgM9JesWR5/m7Wre6iyriW+Y+Qz+zEw5wkIwTcXc5UEAiaan+v kUS3eVsprRIcER/gwhYHBoQQx8tHQNm5XLVGz68srHEJnJ6RBs1MZzDP9TzUQirAbYJE bPlwtiiCaCi0+mEw1pneKvlrXnr19hep8yvNfFLJxxyL7HK3sN/GXyR+WS6qtAtVuDE/ 5ueg== X-Gm-Message-State: AC+VfDzMHmma4DWIb6h1/TxN1q3E9e7deaUPokaKKTjgNuZnzLXXVUTJ MHfMA93RMJyw3xceyY6fiM0Bsfer32UIERYISjc+lNpQ X-Received: by 2002:a2e:95c2:0:b0:2b3:43e6:4335 with SMTP id y2-20020a2e95c2000000b002b343e64335mr7661164ljh.11.1687259333925; Tue, 20 Jun 2023 04:08:53 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 34/37] crypto: Unexport AES_*_rot, AES_TeN, AES_TdN Date: Tue, 20 Jun 2023 13:07:55 +0200 Message-Id: <20230620110758.787479-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::229; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x229.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 These arrays are no longer used outside of aes.c. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- include/crypto/aes.h | 25 ------------------------- crypto/aes.c | 33 +++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 99209f51b9..709d4d226b 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -30,29 +30,4 @@ void AES_decrypt(const unsigned char *in, unsigned char *out, extern const uint8_t AES_sbox[256]; extern const uint8_t AES_isbox[256]; -/* AES MixColumns, for use with rot32. */ -extern const uint32_t AES_mc_rot[256]; - -/* AES InvMixColumns, for use with rot32. */ -extern const uint32_t AES_imc_rot[256]; - -/* -AES_Te0[x] = S [x].[02, 01, 01, 03]; -AES_Te1[x] = S [x].[03, 02, 01, 01]; -AES_Te2[x] = S [x].[01, 03, 02, 01]; -AES_Te3[x] = S [x].[01, 01, 03, 02]; -AES_Te4[x] = S [x].[01, 01, 01, 01]; - -AES_Td0[x] = Si[x].[0e, 09, 0d, 0b]; -AES_Td1[x] = Si[x].[0b, 0e, 09, 0d]; -AES_Td2[x] = Si[x].[0d, 0b, 0e, 09]; -AES_Td3[x] = Si[x].[09, 0d, 0b, 0e]; -AES_Td4[x] = Si[x].[01, 01, 01, 01]; -*/ - -extern const uint32_t AES_Te0[256], AES_Te1[256], AES_Te2[256], - AES_Te3[256], AES_Te4[256]; -extern const uint32_t AES_Td0[256], AES_Td1[256], AES_Td2[256], - AES_Td3[256], AES_Td4[256]; - #endif diff --git a/crypto/aes.c b/crypto/aes.c index 897d4c8d2b..c63c48db38 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -154,7 +154,7 @@ enum { /* * MixColumns lookup table, for use with rot32. */ -const uint32_t AES_mc_rot[256] = { +static const uint32_t AES_mc_rot[256] = { 0x00000000, 0x03010102, 0x06020204, 0x05030306, 0x0c040408, 0x0f05050a, 0x0a06060c, 0x0907070e, 0x18080810, 0x1b090912, 0x1e0a0a14, 0x1d0b0b16, @@ -224,7 +224,7 @@ const uint32_t AES_mc_rot[256] = { /* * Inverse MixColumns lookup table, for use with rot32. */ -const uint32_t AES_imc_rot[256] = { +static const uint32_t AES_imc_rot[256] = { 0x00000000, 0x0b0d090e, 0x161a121c, 0x1d171b12, 0x2c342438, 0x27392d36, 0x3a2e3624, 0x31233f2a, 0x58684870, 0x5365417e, 0x4e725a6c, 0x457f5362, @@ -306,7 +306,7 @@ AES_Td3[x] = Si[x].[09, 0d, 0b, 0e]; AES_Td4[x] = Si[x].[01, 01, 01, 01]; */ -const uint32_t AES_Te0[256] = { +static const uint32_t AES_Te0[256] = { 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, @@ -372,7 +372,8 @@ const uint32_t AES_Te0[256] = { 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, }; -const uint32_t AES_Te1[256] = { + +static const uint32_t AES_Te1[256] = { 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, @@ -438,7 +439,8 @@ const uint32_t AES_Te1[256] = { 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, }; -const uint32_t AES_Te2[256] = { + +static const uint32_t AES_Te2[256] = { 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, @@ -504,8 +506,8 @@ const uint32_t AES_Te2[256] = { 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, }; -const uint32_t AES_Te3[256] = { +static const uint32_t AES_Te3[256] = { 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, @@ -571,7 +573,8 @@ const uint32_t AES_Te3[256] = { 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, }; -const uint32_t AES_Te4[256] = { + +static const uint32_t AES_Te4[256] = { 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU, @@ -637,7 +640,8 @@ const uint32_t AES_Te4[256] = { 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU, 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, }; -const uint32_t AES_Td0[256] = { + +static const uint32_t AES_Td0[256] = { 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, @@ -703,7 +707,8 @@ const uint32_t AES_Td0[256] = { 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, }; -const uint32_t AES_Td1[256] = { + +static const uint32_t AES_Td1[256] = { 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, @@ -769,7 +774,8 @@ const uint32_t AES_Td1[256] = { 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, }; -const uint32_t AES_Td2[256] = { + +static const uint32_t AES_Td2[256] = { 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, @@ -836,7 +842,8 @@ const uint32_t AES_Td2[256] = { 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, }; -const uint32_t AES_Td3[256] = { + +static const uint32_t AES_Td3[256] = { 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, @@ -902,7 +909,8 @@ const uint32_t AES_Td3[256] = { 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, }; -const uint32_t AES_Td4[256] = { + +static const uint32_t AES_Td4[256] = { 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU, @@ -968,6 +976,7 @@ const uint32_t AES_Td4[256] = { 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U, 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, }; + static const u32 rcon[] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, From patchwork Tue Jun 20 11:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694469 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp245923wrm; Tue, 20 Jun 2023 04:13:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5h5N2q6D6B6bCVPBeA7MX2uN0X6LwYzPZFf6yDVJpKBY4KSx3WT4zCC8P03gN2K3U+kqP/ X-Received: by 2002:ad4:5f05:0:b0:626:29db:7fe5 with SMTP id fo5-20020ad45f05000000b0062629db7fe5mr15452209qvb.60.1687259620697; Tue, 20 Jun 2023 04:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259620; cv=none; d=google.com; s=arc-20160816; b=H2iWigfuKSpiqPJ7RVKB+pn54Y48d4jngRz5tYOpGKGa+DcScVCqA85UzV4EWrqt3y KqL+4w7iKS/yOarsTpjkMCXFkb+SDKTOaxLKlg8XdoS2TiJng2y11qljUNnQT+MfY7IT wcXLY/LBHxgZWNm29FCVwnrRVxy+gQWUvX5c53czVNtBiAiuu/uqsHrSqNaSVAYL6Xal ss2TfdXxGpB6bDyKjgIfy2jIq9Q9j5RpjbL7y0Ex856Xd+5f2k+St/9oMJZ2Bw//3p1I H6lXGhKnkZGxM49B1qmo/RhSSdwhSETxVy953C3oVi3EbcCbWXrQy5dxd3ofgtKzuVr/ 5QTg== 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=jsF8E0JGJalzWmrX5g2tSojnQQtbBHl3guSmbqu5fKQ=; b=wf4s0vyZuL86KJGtEXzpT3smigMLlkVA+3ZG4fUTDwq2wrtoPgvWALWjAB1fMAwx8s /fBorzxe53yoT5lvz47kxkCNcXqSY4SOS2Un9l3mz+Nq0MNayszGo2fMNsjAQjcC3fIo 2eMntBfCfLTtoznufQdGwqpVhNmv8FAsxy0in7SFyKNsDHb7jMRkK6Hk6HemeEBPPV+r xwAjaZheCxr7/w+jqLANhlSfsLYLyjxn5kcLtw/riD07b4tcpP1naBWod+GZyP4hxE/d mWgR3+lja9kOit+gZSG18+5jmgdtrv0rdJDM6kTBUrH5ICzanp59hx942QL+rxEGMScP HvpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Q/UTq0kd"; 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 4-20020a0562140d0400b0062610c33883si733943qvh.1.2023.06.20.04.13.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:13:40 -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="Q/UTq0kd"; 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 1qBZET-0007IW-Lo; Tue, 20 Jun 2023 07:09:09 -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 1qBZEJ-0006uj-Vx for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:00 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450: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 1qBZEH-0004al-Fp for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:59 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-983f499fc81so555936766b.3 for ; Tue, 20 Jun 2023 04:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259335; x=1689851335; 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=jsF8E0JGJalzWmrX5g2tSojnQQtbBHl3guSmbqu5fKQ=; b=Q/UTq0kdtbnCYodK/wj+qgRoKkALYsH2SC3iY7uRVe9kFL9eKwmwUSdoOc2N3G4f7F 9FwMiCBCHZtgeFWb5/romBmKRuRFMzo5vAQhL1fdvyKF2tOkopGu6HlFjWn0mpf/+oE3 jOjhjzBimmscIUkbjaj3lvYsK+fJd0vhYT/WFcza1f7GuYFEvsbzSHyl/kKwSS/RvmXX DP353FPncRZhox0DSl40NEfmy/ZGExz0meTopqsvg2DND7s/zMARW/xTVA9P7mqckB26 u2Fjn+27sOXwU/DKm14XMGph6uoehRm8FZgtDB5Z2m3zYRLpHcg7kdmmAG1P+toccr10 DLeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259335; x=1689851335; 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=jsF8E0JGJalzWmrX5g2tSojnQQtbBHl3guSmbqu5fKQ=; b=PO4d7MGg+WqMoiJBasDWWDNepyv7+9v0LKmowBPMDffD1trJLU4NMrtnmvAxMn9VaP XU6pavCF8dxLf39pjLKnNkTtkzUE5isxu5ihRvARubOX1mcWlbyMZ2xlCtYVSwAlhEWf Pha6PsTvfl0wM04CYOlUnfg2JcJgUXgC1BDnR52XCmSfyA5wS8Om0OxL/MuUsdzAd9GO 6Y1BiH6e6yf1FxR32QWl/UEBgZimGthlXJlcgC3CzUBXuyzuh6hN60vM0Xy6XCBEDAH8 kkaSZu9Q6t3D51kUFno+VAnVOEQ5Q7QyaS25lH7+JY7iAGLKKzZeexQPcb7SvSUFw/Vm 5jbA== X-Gm-Message-State: AC+VfDwEZ40veDnGZcUCDLhcW5/lpEZKCaOWJ8dbO3A3d22gTuKY64NI 5Kj8ZQ5ybcnW15viAlhY3Z8We5SvBfcrxBXYQlndTGDq X-Received: by 2002:a17:907:6e07:b0:988:eb17:d053 with SMTP id sd7-20020a1709076e0700b00988eb17d053mr4265624ejc.67.1687259335355; Tue, 20 Jun 2023 04:08:55 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 35/37] host/include/i386: Implement aes-round.h Date: Tue, 20 Jun 2023 13:07:56 +0200 Message-Id: <20230620110758.787479-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-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, 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 Detect AES in cpuinfo; implement the accel hooks. Signed-off-by: Richard Henderson --- host/include/i386/host/cpuinfo.h | 1 + host/include/i386/host/crypto/aes-round.h | 152 ++++++++++++++++++++ host/include/x86_64/host/crypto/aes-round.h | 1 + util/cpuinfo-i386.c | 3 + 4 files changed, 157 insertions(+) create mode 100644 host/include/i386/host/crypto/aes-round.h create mode 100644 host/include/x86_64/host/crypto/aes-round.h diff --git a/host/include/i386/host/cpuinfo.h b/host/include/i386/host/cpuinfo.h index a6537123cf..073d0a426f 100644 --- a/host/include/i386/host/cpuinfo.h +++ b/host/include/i386/host/cpuinfo.h @@ -26,6 +26,7 @@ #define CPUINFO_AVX512VBMI2 (1u << 15) #define CPUINFO_ATOMIC_VMOVDQA (1u << 16) #define CPUINFO_ATOMIC_VMOVDQU (1u << 17) +#define CPUINFO_AES (1u << 18) /* Initialized with a constructor. */ extern unsigned cpuinfo; diff --git a/host/include/i386/host/crypto/aes-round.h b/host/include/i386/host/crypto/aes-round.h new file mode 100644 index 0000000000..59a64130f7 --- /dev/null +++ b/host/include/i386/host/crypto/aes-round.h @@ -0,0 +1,152 @@ +/* + * x86 specific aes acceleration. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef X86_HOST_CRYPTO_AES_ROUND_H +#define X86_HOST_CRYPTO_AES_ROUND_H + +#include "host/cpuinfo.h" +#include + +#if defined(__AES__) && defined(__SSSE3__) +# define HAVE_AES_ACCEL true +# define ATTR_AES_ACCEL +#else +# define HAVE_AES_ACCEL likely(cpuinfo & CPUINFO_AES) +# define ATTR_AES_ACCEL __attribute__((target("aes,ssse3"))) +#endif + +static inline __m128i ATTR_AES_ACCEL +aes_accel_bswap(__m128i x) +{ + return _mm_shuffle_epi8(x, _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15)); +} + +static inline void ATTR_AES_ACCEL +aesenc_MC_accel(AESState *ret, const AESState *st, bool be) +{ + __m128i t = (__m128i)st->v; + __m128i z = _mm_setzero_si128(); + + if (be) { + t = aes_accel_bswap(t); + t = _mm_aesdeclast_si128(t, z); + t = _mm_aesenc_si128(t, z); + t = aes_accel_bswap(t); + } else { + t = _mm_aesdeclast_si128(t, z); + t = _mm_aesenc_si128(t, z); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesenc_SB_SR_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + __m128i t = (__m128i)st->v; + __m128i k = (__m128i)rk->v; + + if (be) { + t = aes_accel_bswap(t); + k = aes_accel_bswap(k); + t = _mm_aesenclast_si128(t, k); + t = aes_accel_bswap(t); + } else { + t = _mm_aesenclast_si128(t, k); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesenc_SB_SR_MC_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + __m128i t = (__m128i)st->v; + __m128i k = (__m128i)rk->v; + + if (be) { + t = aes_accel_bswap(t); + k = aes_accel_bswap(k); + t = _mm_aesenc_si128(t, k); + t = aes_accel_bswap(t); + } else { + t = _mm_aesenc_si128(t, k); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesdec_IMC_accel(AESState *ret, const AESState *st, bool be) +{ + __m128i t = (__m128i)st->v; + + if (be) { + t = aes_accel_bswap(t); + t = _mm_aesimc_si128(t); + t = aes_accel_bswap(t); + } else { + t = _mm_aesimc_si128(t); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesdec_ISB_ISR_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + __m128i t = (__m128i)st->v; + __m128i k = (__m128i)rk->v; + + if (be) { + t = aes_accel_bswap(t); + k = aes_accel_bswap(k); + t = _mm_aesdeclast_si128(t, k); + t = aes_accel_bswap(t); + } else { + t = _mm_aesdeclast_si128(t, k); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesdec_ISB_ISR_AK_IMC_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + __m128i t = (__m128i)st->v; + __m128i k = (__m128i)rk->v; + + if (be) { + t = aes_accel_bswap(t); + k = aes_accel_bswap(k); + t = _mm_aesdeclast_si128(t, k); + t = _mm_aesimc_si128(t); + t = aes_accel_bswap(t); + } else { + t = _mm_aesdeclast_si128(t, k); + t = _mm_aesimc_si128(t); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesdec_ISB_ISR_IMC_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + __m128i t = (__m128i)st->v; + __m128i k = (__m128i)rk->v; + + if (be) { + t = aes_accel_bswap(t); + k = aes_accel_bswap(k); + t = _mm_aesdec_si128(t, k); + t = aes_accel_bswap(t); + } else { + t = _mm_aesdec_si128(t, k); + } + ret->v = (AESStateVec)t; +} + +#endif /* X86_HOST_CRYPTO_AES_ROUND_H */ diff --git a/host/include/x86_64/host/crypto/aes-round.h b/host/include/x86_64/host/crypto/aes-round.h new file mode 100644 index 0000000000..2773cc9f10 --- /dev/null +++ b/host/include/x86_64/host/crypto/aes-round.h @@ -0,0 +1 @@ +#include "host/include/i386/host/crypto/aes-round.h" diff --git a/util/cpuinfo-i386.c b/util/cpuinfo-i386.c index ab6143d9e7..3a7b7e0ad1 100644 --- a/util/cpuinfo-i386.c +++ b/util/cpuinfo-i386.c @@ -40,6 +40,9 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) info |= (c & bit_MOVBE ? CPUINFO_MOVBE : 0); info |= (c & bit_POPCNT ? CPUINFO_POPCNT : 0); + /* Our AES support requires PSHUFB as well. */ + info |= ((c & bit_AES) && (c & bit_SSSE3) ? CPUINFO_AES : 0); + /* For AVX features, we must check available and usable. */ if ((c & bit_AVX) && (c & bit_OSXSAVE)) { unsigned bv = xgetbv_low(0); From patchwork Tue Jun 20 11:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694488 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247413wrm; Tue, 20 Jun 2023 04:17:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VvwR63GNpIHqVCjYGenKZs5c3zkIrqwGdOuHctK7gWQhF7Q8JJorKqSKh6Wv1JWflxn/o X-Received: by 2002:a05:6214:d42:b0:626:1fe8:bba4 with SMTP id 2-20020a0562140d4200b006261fe8bba4mr18180927qvr.10.1687259831602; Tue, 20 Jun 2023 04:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259831; cv=none; d=google.com; s=arc-20160816; b=VJDIVM6JaYHeUAIYGsjvRCcHRfvm/Q/0hhex3OCfMP6Bv4FHKfqEXDNjthp/0zMcGG mDUSSIqlp3se5NTQsdulxOSVIvbuMBZ2ci7YIRK8mwxDfwAFBUcWnWYsRs46MCLozwqI hq0ckuJWqd9DsPwTc5h7VkN0HavtsLAWKPBVTwK82rs2cZslLDqSIB13U7aW5jXGqs+M DNeclycbAtWKg/Go4Z/t012lZGj0qCC3+idGCZWB57ZWhUofBz6GegzhIgKdfvHwnivF ybxtcW0BsOd8cWyDV6NpwqMlyhr7p3WCO+rzrCq1BB8ig5ip+3CNgp9BX3VulvBKrv4y rzwQ== 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=sKqdML8OOkd/9MMr9Zrb0tAOr3XFy13fJxMhSqc0LZI=; b=FdmyPpr1Ni2uht0RVKs+OgSf2M7yJAfE1H7D23iN6quDMI2432ZaffNTDae1supXgp fehluNnPKresSTpZ25/1jyat6eSzBSrYGgYPT1dbbHYWBi0Davok81gf4Ae+5djmcpuS 4LMpQTJ5kLBQbjimiu18Upg2oxGJhTiWcjOFep58I+bcQT7fOjaUyj51nuaRe8BfnhNt ZPaJ+Px3mdg+8YFIL6SbNpUaciqssFtnii2U7Nx26RYl+h9uf1jx5IpuIeiUQfi9XYJn 0gGKYrnxXDFTgVYLIljV+ZuNFcZi5BhBqJrzwLXOPa7eDIswCD1SoTm6PvEFZGXYZcvd bUzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ELwUDv5P; 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 kc24-20020a056214411800b006300919e082si738979qvb.367.2023.06.20.04.17.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:17:11 -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=ELwUDv5P; 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 1qBZEW-0007TY-Rs; Tue, 20 Jun 2023 07:09:12 -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 1qBZEL-0006wb-LZ for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:02 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZEI-0004bL-0f for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:01 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9883123260fso330081166b.0 for ; Tue, 20 Jun 2023 04:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259336; x=1689851336; 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=sKqdML8OOkd/9MMr9Zrb0tAOr3XFy13fJxMhSqc0LZI=; b=ELwUDv5PrCQIKircfrZnTPz1RM06etL3xXHpVWYrPsRExcEjeLMzO9EAfU6RInKoyE axkL5J8sdCbz1g4AskWVltkKepuEf9O29sUSfSrRUtyFn12mz+aSCDqd+4gGVzm0Dwns 0QkH8T3Ii+0gCHjb8NiVlIS5iQfc/8UZtZcvX/aEzlDAMnVvKaghM3tp+2dbTifz3U6C JoQlRfi/PWHud5U3qX/C8K8mt3qKMtW4b1I+VWdK+3QqV3EIeg1vquM3pKVAwygXmjl1 fo6ld/A+oFoc4ksngfi2X4vx3SVJJe5fK1d9m4EuYOlfEo78qk+PMUv8tHjibgG91xLp ukQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259336; x=1689851336; 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=sKqdML8OOkd/9MMr9Zrb0tAOr3XFy13fJxMhSqc0LZI=; b=aPoryYwVUMW0q1ltAeskEllPTR9olsxgxXBmNVRM79eDvWJX3P2eJ1oAyfYAKFCcNe y9luSuuTd+NPKscp75WZx7VoeqCp9N6a6FcWV5dWfx7xqJ2PKSLguFZuBpLQbjp6gvjR SKcTcKL7GEbOPZ0qUL26HaF9M7L0nj8/GIv6uv9Rg3qhcOdpfdYUO1+QJ1/VTyIUtl+N hD4Iakhc2X+QXcaBlkul6pde7YGpJu6143UTy+6V6PLB0YSRLv9GFjtrvgg4CQwjyej9 pZw/XdB/dNPAGy51jdQLhx478f71T/yk1P7wXafFnVpeVFHuO0X5UL7HJ3w7FPjmQOru 1hRg== X-Gm-Message-State: AC+VfDzWZI3oGtEDX+BeGT5svwzUipNhBU0pROCx9ZavBQuEdrjnZfwh 7vukXRffFa8ACREjuLtIpG2npiMxrZakZZ+7whwjQk09 X-Received: by 2002:a17:906:fcb7:b0:96f:5902:8c4d with SMTP id qw23-20020a170906fcb700b0096f59028c4dmr7993713ejb.27.1687259336611; Tue, 20 Jun 2023 04:08:56 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v3 36/37] host/include/aarch64: Implement aes-round.h Date: Tue, 20 Jun 2023 13:07:57 +0200 Message-Id: <20230620110758.787479-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x629.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 Detect AES in cpuinfo; implement the accel hooks. Signed-off-by: Richard Henderson --- meson.build | 9 + host/include/aarch64/host/cpuinfo.h | 1 + host/include/aarch64/host/crypto/aes-round.h | 205 +++++++++++++++++++ util/cpuinfo-aarch64.c | 2 + 4 files changed, 217 insertions(+) create mode 100644 host/include/aarch64/host/crypto/aes-round.h diff --git a/meson.build b/meson.build index 6ef78ea278..a1e5f3c06d 100644 --- a/meson.build +++ b/meson.build @@ -2667,6 +2667,15 @@ config_host_data.set('CONFIG_AVX512BW_OPT', get_option('avx512bw') \ int main(int argc, char *argv[]) { return bar(argv[0]); } '''), error_message: 'AVX512BW not available').allowed()) +# For both AArch64 and AArch32, detect if builtins are available. +config_host_data.set('CONFIG_ARM_AES_BUILTIN', cc.compiles(''' + #include + #ifndef __ARM_FEATURE_AES + __attribute__((target("+crypto"))) + #endif + void foo(uint8x16_t *p) { *p = vaesmcq_u8(*p); } + ''')) + have_pvrdma = get_option('pvrdma') \ .require(rdma.found(), error_message: 'PVRDMA requires OpenFabrics libraries') \ .require(cc.compiles(gnu_source_prefix + ''' diff --git a/host/include/aarch64/host/cpuinfo.h b/host/include/aarch64/host/cpuinfo.h index 82227890b4..05feeb4f43 100644 --- a/host/include/aarch64/host/cpuinfo.h +++ b/host/include/aarch64/host/cpuinfo.h @@ -9,6 +9,7 @@ #define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */ #define CPUINFO_LSE (1u << 1) #define CPUINFO_LSE2 (1u << 2) +#define CPUINFO_AES (1u << 3) /* Initialized with a constructor. */ extern unsigned cpuinfo; diff --git a/host/include/aarch64/host/crypto/aes-round.h b/host/include/aarch64/host/crypto/aes-round.h new file mode 100644 index 0000000000..8b5f88d50c --- /dev/null +++ b/host/include/aarch64/host/crypto/aes-round.h @@ -0,0 +1,205 @@ +/* + * AArch64 specific aes acceleration. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef AARCH64_HOST_CRYPTO_AES_ROUND_H +#define AARCH64_HOST_CRYPTO_AES_ROUND_H + +#include "host/cpuinfo.h" +#include + +#ifdef __ARM_FEATURE_AES +# define HAVE_AES_ACCEL true +#else +# define HAVE_AES_ACCEL likely(cpuinfo & CPUINFO_AES) +#endif +#if !defined(__ARM_FEATURE_AES) && defined(CONFIG_ARM_AES_BUILTIN) +# define ATTR_AES_ACCEL __attribute__((target("+crypto"))) +#else +# define ATTR_AES_ACCEL +#endif + +static inline uint8x16_t aes_accel_bswap(uint8x16_t x) +{ + return vqtbl1q_u8(x, (uint8x16_t){ 15, 14, 13, 12, 11, 10, 9, 8, + 7, 6, 5, 4, 3, 2, 1, 0, }); +} + +#ifdef CONFIG_ARM_AES_BUILTIN +# define aes_accel_aesd vaesdq_u8 +# define aes_accel_aese vaeseq_u8 +# define aes_accel_aesmc vaesmcq_u8 +# define aes_accel_aesimc vaesimcq_u8 +# define aes_accel_aesd_imc(S, K) vaesimcq_u8(vaesdq_u8(S, K)) +# define aes_accel_aese_mc(S, K) vaesmcq_u8(vaeseq_u8(S, K)) +#else +static inline uint8x16_t aes_accel_aesd(uint8x16_t d, uint8x16_t k) +{ + asm(".arch_extension aes\n\t" + "aesd %0.16b, %1.16b" : "+w"(d) : "w"(k)); + return d; +} + +static inline uint8x16_t aes_accel_aese(uint8x16_t d, uint8x16_t k) +{ + asm(".arch_extension aes\n\t" + "aese %0.16b, %1.16b" : "+w"(d) : "w"(k)); + return d; +} + +static inline uint8x16_t aes_accel_aesmc(uint8x16_t d) +{ + asm(".arch_extension aes\n\t" + "aesmc %0.16b, %1.16b" : "=w"(d) : "w"(d)); + return d; +} + +static inline uint8x16_t aes_accel_aesimc(uint8x16_t d) +{ + asm(".arch_extension aes\n\t" + "aesimc %0.16b, %1.16b" : "=w"(d) : "w"(d)); + return d; +} + +/* Most CPUs fuse AESD+AESIMC in the execution pipeline. */ +static inline uint8x16_t aes_accel_aesd_imc(uint8x16_t d, uint8x16_t k) +{ + asm(".arch_extension aes\n\t" + "aesd %0.16b, %1.16b\n\t" + "aesimc %0.16b, %0.16b" : "+w"(d) : "w"(k)); + return d; +} + +/* Most CPUs fuse AESE+AESMC in the execution pipeline. */ +static inline uint8x16_t aes_accel_aese_mc(uint8x16_t d, uint8x16_t k) +{ + asm(".arch_extension aes\n\t" + "aese %0.16b, %1.16b\n\t" + "aesmc %0.16b, %0.16b" : "+w"(d) : "w"(k)); + return d; +} +#endif /* CONFIG_ARM_AES_BUILTIN */ + +static inline void ATTR_AES_ACCEL +aesenc_MC_accel(AESState *ret, const AESState *st, bool be) +{ + uint8x16_t t = (uint8x16_t)st->v; + + if (be) { + t = aes_accel_bswap(t); + t = aes_accel_aesmc(t); + t = aes_accel_bswap(t); + } else { + t = aes_accel_aesmc(t); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesenc_SB_SR_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + uint8x16_t t = (uint8x16_t)st->v; + uint8x16_t z = { }; + + if (be) { + t = aes_accel_bswap(t); + t = aes_accel_aese(t, z); + t = aes_accel_bswap(t); + } else { + t = aes_accel_aese(t, z); + } + ret->v = (AESStateVec)t ^ rk->v; +} + +static inline void ATTR_AES_ACCEL +aesenc_SB_SR_MC_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + uint8x16_t t = (uint8x16_t)st->v; + uint8x16_t z = { }; + + if (be) { + t = aes_accel_bswap(t); + t = aes_accel_aese_mc(t, z); + t = aes_accel_bswap(t); + } else { + t = aes_accel_aese_mc(t, z); + } + ret->v = (AESStateVec)t ^ rk->v; +} + +static inline void ATTR_AES_ACCEL +aesdec_IMC_accel(AESState *ret, const AESState *st, bool be) +{ + uint8x16_t t = (uint8x16_t)st->v; + + if (be) { + t = aes_accel_bswap(t); + t = aes_accel_aesimc(t); + t = aes_accel_bswap(t); + } else { + t = aes_accel_aesimc(t); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesdec_ISB_ISR_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + uint8x16_t t = (uint8x16_t)st->v; + uint8x16_t z = { }; + + if (be) { + t = aes_accel_bswap(t); + t = aes_accel_aesd(t, z); + t = aes_accel_bswap(t); + } else { + t = aes_accel_aesd(t, z); + } + ret->v = (AESStateVec)t ^ rk->v; +} + +static inline void ATTR_AES_ACCEL +aesdec_ISB_ISR_AK_IMC_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + uint8x16_t t = (uint8x16_t)st->v; + uint8x16_t k = (uint8x16_t)rk->v; + uint8x16_t z = { }; + + if (be) { + t = aes_accel_bswap(t); + k = aes_accel_bswap(k); + t = aes_accel_aesd(t, z); + t ^= k; + t = aes_accel_aesimc(t); + t = aes_accel_bswap(t); + } else { + t = aes_accel_aesd(t, z); + t ^= k; + t = aes_accel_aesimc(t); + } + ret->v = (AESStateVec)t; +} + +static inline void ATTR_AES_ACCEL +aesdec_ISB_ISR_IMC_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + uint8x16_t t = (uint8x16_t)st->v; + uint8x16_t z = { }; + + if (be) { + t = aes_accel_bswap(t); + t = aes_accel_aesd_imc(t, z); + t = aes_accel_bswap(t); + } else { + t = aes_accel_aesd_imc(t, z); + } + ret->v = (AESStateVec)t ^ rk->v; +} + +#endif /* AARCH64_HOST_CRYPTO_AES_ROUND_H */ diff --git a/util/cpuinfo-aarch64.c b/util/cpuinfo-aarch64.c index f99acb7884..ababc39550 100644 --- a/util/cpuinfo-aarch64.c +++ b/util/cpuinfo-aarch64.c @@ -56,10 +56,12 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) unsigned long hwcap = qemu_getauxval(AT_HWCAP); info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0); info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0); + info |= (hwcap & HWCAP_AES ? CPUINFO_AES: 0); #endif #ifdef CONFIG_DARWIN info |= sysctl_for_bool("hw.optional.arm.FEAT_LSE") * CPUINFO_LSE; info |= sysctl_for_bool("hw.optional.arm.FEAT_LSE2") * CPUINFO_LSE2; + info |= sysctl_for_bool("hw.optional.arm.FEAT_AES") * CPUINFO_AES; #endif cpuinfo = info; From patchwork Tue Jun 20 11:07:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694477 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246614wrm; Tue, 20 Jun 2023 04:15:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/VV4hX9+YwqTfZA3rdWQ1BsvCAan1FHTn/mlVy4PAHRdsUKm/18LNNXky3FbKJIwfzEqr X-Received: by 2002:ad4:5765:0:b0:630:e9d:ed2f with SMTP id r5-20020ad45765000000b006300e9ded2fmr9904636qvx.17.1687259722016; Tue, 20 Jun 2023 04:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259722; cv=none; d=google.com; s=arc-20160816; b=SpfPEIdq414IhF0h8wQusDFe2wGegr7L8/seIIqPI5XirsgxK2fowWk3b06NX3nKMb scHNnzteGrcd6J1ZI3/i6Fi4fbCESBzRsG9QIrYFKqWxG+ubhLVffaI9KSfto/hElPV9 zGkdhru40eLzZ/dFguEag0F/jnKlMclcUMATMph/SK16pQQYrXwwy8nywRJ0QjUhCTV4 qlegKTQc7zhVbHtjzR483PnQZzUix4f8sdAClVsWwYtOHT+7RkRbj7QAXHOMpiHcdlnL 1VLSeqrMObELEOE23+OiuoRiYO3BXE5PGq09hGBYRAMqNllSLrSCV5aEVqTRTd3ZrfMZ b3bg== 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=tquFfTdtw0sVSZbN7ZybV+/6BBhwf96oST0EwHIj8d8=; b=gO5K1q6su+96lNw7nP6T3Z3zscgkXN7DTK8IzNSWrR/VzQKQnIL77/xDW/89VO/Q7+ +tiwl0eBrlLn3ysOTINC187oKil+0Cd2ON72zupHwelA4GqYab5CwjCaZWA8J/AK9iNQ IHlzRxS5BQiIsKPEMjSAhetvSxBG55lR4Ld12c6Z+nNVaGTk7o1UlcissNbo9r3VsC5D rOktte84usa+ETVpvfArJoUxURw8MIvJ37j/zXbdVa7g7s4+grT6nyc4ZM4aoHEaqll4 1FqIJPqFDl5Og0Q9kcEoTg7Mu2fJYKTPeB6+Mv7lNrr/qZ8jU95br5FZvbaqAdBQuRDn EnCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ktmUMiVX; 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 q2-20020a05621419e200b0063020a21b9csi726548qvc.271.2023.06.20.04.15.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:15: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=ktmUMiVX; 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 1qBZEY-0007XJ-V9; Tue, 20 Jun 2023 07:09:14 -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 1qBZEV-0007Rk-Ov for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:11 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZET-0004bx-Pj for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:09:11 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-988b204ce5fso262966266b.3 for ; Tue, 20 Jun 2023 04:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259338; x=1689851338; 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=tquFfTdtw0sVSZbN7ZybV+/6BBhwf96oST0EwHIj8d8=; b=ktmUMiVXF7RRURH3EoJFqZ7X3QrVQOFCmFuvT6EtCxZB6bwGP7/qPNANv4MS1gcc0p AENG4p70wpm21HZViGJBLCpKqWqf/SD+8D0iYDjT4/H8oc/AeYRu53isM89lxtCUzxXR PfBA1yPpTJLeTgaR/yQ5//hD2P55JrQRD2kLbZps+zG7TZ3CdigXLBbEY7WVpkpiLRmv o+ZQtUiydw5S40Xz5vGfq5AxnaY5cWkEm6ljhcD5j9F+nklIfzVPlsLRhR3Au3uIXy9t g0gfWLTAznhEFOyOfVij41LXlsp+NWXJOtoXhYGZj69M/klhfLeKSO6Lb6cxPER3hQzE 5QLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259338; x=1689851338; 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=tquFfTdtw0sVSZbN7ZybV+/6BBhwf96oST0EwHIj8d8=; b=KrF+wrKCVpLFp4jVr4YtPAzRmz2LTcd5a1uyxtjQFUtWBTpqHUtYTVnAFptFgdUtSb G6bYKDnt8SsBGlC4HhBfB7vhbrx2E5cOjW5BHPM2QWhd0PKOHDnPRitfP7cvQC/+N5E6 rAzYWY9klCSS8gLEa2fJnmwNbFwM3a5aw3BiTWnAbkGhkhxroiyX0e+Olv2/MNc8t8t2 f+Z79wi8XXal6RwbBpy9qCDMVs+YJqnhPNMn+z08nZTlRb3HrhuhKYCg59kGzYBqSTIT vBe+9C4H9PbmWq9d5kz17ZsMjxdMz+oGycad2DpUnk2ky7bX+OsHueliNicHDlNW9DR8 61iw== X-Gm-Message-State: AC+VfDxfvIYU6qu0H4G3bmFBAHMPqqWRCPocWFc9p0ax8/pzj2Pb1FZL KXSmY8TsOAwecO26IcSGwhZ0rbyI2YrjS3ZEcRQdpm8d X-Received: by 2002:a17:907:6ea0:b0:961:800b:3f1e with SMTP id sh32-20020a1709076ea000b00961800b3f1emr13757763ejc.73.1687259337954; Tue, 20 Jun 2023 04:08:57 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Daniel Henrique Barboza Subject: [PATCH v3 37/37] host/include/ppc: Implement aes-round.h Date: Tue, 20 Jun 2023 13:07:58 +0200 Message-Id: <20230620110758.787479-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62e.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=unavailable 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 Detect CRYPTO in cpuinfo; implement the accel hooks. Reviewed-by: Daniel Henrique Barboza Signed-off-by: Richard Henderson --- host/include/ppc/host/cpuinfo.h | 1 + host/include/ppc/host/crypto/aes-round.h | 182 +++++++++++++++++++++ host/include/ppc64/host/crypto/aes-round.h | 1 + util/cpuinfo-ppc.c | 8 + 4 files changed, 192 insertions(+) create mode 100644 host/include/ppc/host/crypto/aes-round.h create mode 100644 host/include/ppc64/host/crypto/aes-round.h diff --git a/host/include/ppc/host/cpuinfo.h b/host/include/ppc/host/cpuinfo.h index df11e8d417..29ee7f9ef8 100644 --- a/host/include/ppc/host/cpuinfo.h +++ b/host/include/ppc/host/cpuinfo.h @@ -16,6 +16,7 @@ #define CPUINFO_ISEL (1u << 5) #define CPUINFO_ALTIVEC (1u << 6) #define CPUINFO_VSX (1u << 7) +#define CPUINFO_CRYPTO (1u << 8) /* Initialized with a constructor. */ extern unsigned cpuinfo; diff --git a/host/include/ppc/host/crypto/aes-round.h b/host/include/ppc/host/crypto/aes-round.h new file mode 100644 index 0000000000..8062d2a537 --- /dev/null +++ b/host/include/ppc/host/crypto/aes-round.h @@ -0,0 +1,182 @@ +/* + * Power v2.07 specific aes acceleration. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef PPC_HOST_CRYPTO_AES_ROUND_H +#define PPC_HOST_CRYPTO_AES_ROUND_H + +#ifdef __ALTIVEC__ +#include "host/cpuinfo.h" + +#ifdef __CRYPTO__ +# define HAVE_AES_ACCEL true +#else +# define HAVE_AES_ACCEL likely(cpuinfo & CPUINFO_CRYPTO) +#endif +#define ATTR_AES_ACCEL + +/* + * While there is , both gcc and clang "aid" with the + * endianness issues in different ways. Just use inline asm instead. + */ + +/* Bytes in memory are host-endian; bytes in register are @be. */ +static inline AESStateVec aes_accel_ld(const AESState *p, bool be) +{ + AESStateVec r; + + if (be) { + asm("lvx %0, 0, %1" : "=v"(r) : "r"(p), "m"(*p)); + } else if (HOST_BIG_ENDIAN) { + AESStateVec rev = { + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, + }; + asm("lvx %0, 0, %1\n\t" + "vperm %0, %0, %0, %2" + : "=v"(r) : "r"(p), "v"(rev), "m"(*p)); + } else { +#ifdef __POWER9_VECTOR__ + asm("lxvb16x %x0, 0, %1" : "=v"(r) : "r"(p), "m"(*p)); +#else + asm("lxvd2x %x0, 0, %1\n\t" + "xxpermdi %x0, %x0, %x0, 2" + : "=v"(r) : "r"(p), "m"(*p)); +#endif + } + return r; +} + +static void aes_accel_st(AESState *p, AESStateVec r, bool be) +{ + if (be) { + asm("stvx %1, 0, %2" : "=m"(*p) : "v"(r), "r"(p)); + } else if (HOST_BIG_ENDIAN) { + AESStateVec rev = { + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, + }; + asm("vperm %1, %1, %1, %2\n\t" + "stvx %1, 0, %3" + : "=m"(*p), "+v"(r) : "v"(rev), "r"(p)); + } else { +#ifdef __POWER9_VECTOR__ + asm("stxvb16x %x1, 0, %2" : "=m"(*p) : "v"(r), "r"(p)); +#else + asm("xxpermdi %x1, %x1, %x1, 2\n\t" + "stxvd2x %x1, 0, %2" + : "=m"(*p), "+v"(r) : "r"(p)); +#endif + } +} + +static inline AESStateVec aes_accel_vcipher(AESStateVec d, AESStateVec k) +{ + asm("vcipher %0, %0, %1" : "+v"(d) : "v"(k)); + return d; +} + +static inline AESStateVec aes_accel_vncipher(AESStateVec d, AESStateVec k) +{ + asm("vncipher %0, %0, %1" : "+v"(d) : "v"(k)); + return d; +} + +static inline AESStateVec aes_accel_vcipherlast(AESStateVec d, AESStateVec k) +{ + asm("vcipherlast %0, %0, %1" : "+v"(d) : "v"(k)); + return d; +} + +static inline AESStateVec aes_accel_vncipherlast(AESStateVec d, AESStateVec k) +{ + asm("vncipherlast %0, %0, %1" : "+v"(d) : "v"(k)); + return d; +} + +static inline void +aesenc_MC_accel(AESState *ret, const AESState *st, bool be) +{ + AESStateVec t, z = { }; + + t = aes_accel_ld(st, be); + t = aes_accel_vncipherlast(t, z); + t = aes_accel_vcipher(t, z); + aes_accel_st(ret, t, be); +} + +static inline void +aesenc_SB_SR_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + AESStateVec t, k; + + t = aes_accel_ld(st, be); + k = aes_accel_ld(rk, be); + t = aes_accel_vcipherlast(t, k); + aes_accel_st(ret, t, be); +} + +static inline void +aesenc_SB_SR_MC_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + AESStateVec t, k; + + t = aes_accel_ld(st, be); + k = aes_accel_ld(rk, be); + t = aes_accel_vcipher(t, k); + aes_accel_st(ret, t, be); +} + +static inline void +aesdec_IMC_accel(AESState *ret, const AESState *st, bool be) +{ + AESStateVec t, z = { }; + + t = aes_accel_ld(st, be); + t = aes_accel_vcipherlast(t, z); + t = aes_accel_vncipher(t, z); + aes_accel_st(ret, t, be); +} + +static inline void +aesdec_ISB_ISR_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + AESStateVec t, k; + + t = aes_accel_ld(st, be); + k = aes_accel_ld(rk, be); + t = aes_accel_vncipherlast(t, k); + aes_accel_st(ret, t, be); +} + +static inline void +aesdec_ISB_ISR_AK_IMC_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + AESStateVec t, k; + + t = aes_accel_ld(st, be); + k = aes_accel_ld(rk, be); + t = aes_accel_vncipher(t, k); + aes_accel_st(ret, t, be); +} + +static inline void +aesdec_ISB_ISR_IMC_AK_accel(AESState *ret, const AESState *st, + const AESState *rk, bool be) +{ + AESStateVec t, k, z = { }; + + t = aes_accel_ld(st, be); + k = aes_accel_ld(rk, be); + t = aes_accel_vncipher(t, z); + aes_accel_st(ret, t ^ k, be); +} +#else +/* Without ALTIVEC, we can't even write inline assembly. */ +#include "host/include/generic/host/crypto/aes-round.h" +#endif + +#endif /* PPC_HOST_CRYPTO_AES_ROUND_H */ diff --git a/host/include/ppc64/host/crypto/aes-round.h b/host/include/ppc64/host/crypto/aes-round.h new file mode 100644 index 0000000000..5eeba6dcb7 --- /dev/null +++ b/host/include/ppc64/host/crypto/aes-round.h @@ -0,0 +1 @@ +#include "host/include/ppc/host/crypto/aes-round.h" diff --git a/util/cpuinfo-ppc.c b/util/cpuinfo-ppc.c index d95adc8ccd..7212afa45d 100644 --- a/util/cpuinfo-ppc.c +++ b/util/cpuinfo-ppc.c @@ -48,6 +48,14 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) /* We only care about the portion of VSX that overlaps Altivec. */ if (hwcap & PPC_FEATURE_HAS_VSX) { info |= CPUINFO_VSX; + /* + * We use VSX especially for little-endian, but we should + * always have both anyway, since VSX came with Power7 + * and crypto came with Power8. + */ + if (hwcap2 & PPC_FEATURE2_HAS_VEC_CRYPTO) { + info |= CPUINFO_CRYPTO; + } } }