From patchwork Sun Jul 9 13:59:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700822 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740808wrs; Sun, 9 Jul 2023 07:02:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlEwn2SAroYZiOTmbYOjmoRPmTe1OFFqqAGUekj2ZE50GZzxoWuDIBClTy9b6Rtt2tWFRWtw X-Received: by 2002:a05:620a:3721:b0:75b:23a1:3ee with SMTP id de33-20020a05620a372100b0075b23a103eemr9283913qkb.4.1688911329002; Sun, 09 Jul 2023 07:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911328; cv=none; d=google.com; s=arc-20160816; b=DDbRxIx7YVaV+LR361djDpuPOluiN4titsq9AupecT9+j0X/yNU+yC7fwLpQAh82w9 wBva9KZvIk7s3vQ5Tz2qiJZHbO2CM+kiotp6i2ToOoFnetU55sGs0Tkg0r4QJapX4LMl WCsGfkD4jD/JDL/58OGAszD8HGd5MNBsxTkESzoY513vA7WoPSKNONzB+OK8fxvBjXD6 vaq9bigj1FAuk+SkLZygO0PQi2HoLkfz6sdb6KumV9qrWWv0cY7OAHJZp84fS4XUIkvX EcIrHAXIDGaGrG8YOf33fo6jG93pEJPLzJlNqMGJ8SRQgKjJU+EAdGv67BB6X6rNJOiV dM4A== 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=; fh=3qdrlAICycY7VgU0cI4E0duimIwv/aNBV7oZD6cPLQA=; b=vY/57VvIsJ4vO5M3hd2sJxbWirm3qhEYMFUCeVG3UVi3ydGflqg3B/tvvXWa5Yni8U ASoCMbJX8ni/HJHRuFggpGKbjfhb/8nOr2EBo+VsX2oEG+McY3X//hVzSS2Zskq6/va3 x8rUrzmmFYuJzQrsjtar4+DznAPLPru9JGecTdCAch8uvLX+NjgHbXaEk6lKlozskqRq FN02A/BhOUUgcflFKeNV/dUs5Od24JC5dzWLwCGB+6Wue4xVsc1DL3lQkQcl02Nk0dgx t6isvJ7Tp9HOktnjU/swIiApsq4qPP16THJZRzTsI9fefii0jw/i0JFjqtbAf1zDpSx5 ATnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VqvRT1F+; 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 s10-20020a05620a254a00b00767d04f2884si387003qko.625.2023.07.09.07.02.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:02:08 -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=VqvRT1F+; 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 1qIUxo-0000iT-VF; Sun, 09 Jul 2023 10:00:36 -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 1qIUxL-0000OV-1X for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx5-0000MM-Lu for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:06 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-31441bc0092so3414365f8f.1 for ; Sun, 09 Jul 2023 06:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911188; x=1691503188; 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=VqvRT1F+i/5xHsSJL/KPigvFw8aSwRURXBe+UrVukj/w5zMo3xYtg+N4uACWaAMgfz SCxjFhhfpYoIwX2pIj91rkgB1pZj+5SZPeyfEpStgSVDUp/gnsWovzmQJVtl4mrul6Uo AsjVdUDS1VTwppCkMmRo4pg9PQ38CWtQWxQs4jrpUpShhz3heoYbK+DDt99iin+UudXM Rvmxrh5lNZq4WY6CkFaIsNwDwvd5ENhuesyjnuoRQEmHk66qTmCkrA44xAsjqdTsaA3q 2SPgdY8FNdVyGpBQ2rk+m+e82b857UT0HjbYz28oHePqCYMvr/UQaAWI/2o5MGRxqUBZ aaGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911188; x=1691503188; 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=WC9wxbrs/b8KlD0ed6rSepDIy7ncb2cGikI/rPbP5gjqoTlIBAZ75kNAO7ghXnRcNm htsBhbrJ6oP3SlAcNK4eVFBVNTiF3KscMH++YnxFIkvHoogt9q8odDbJy89cOX3OaVth eD7Wg3uY/ZQpM9swk9lBfqtzMYEFyoIfp1hYK/PuE1UTw8mZMSNmGKdosneVJNdjpdSN SMF4vyz2c2DQhl7vQ1DbvUVTjGeAo4n8ghY/ltRZ76EKbwgCrNEFXjtxpBFHCPdJADCX Ne7I3jcic8nXPd9pjDqZxtT9m2ZsYQiD0WnS7fOwLHbwIbtmDvLJ/mLNnJln9TffjU9p 73QA== X-Gm-Message-State: ABy/qLa0KAiPsH1JT4W01X7zX4G6ulYn4RY6Wsh6wVl/W53dXqKGWfqi nsxuANKumCWeXr2++yIQvH6O6lXeP+BDou2H7wNgyA== X-Received: by 2002:a5d:6501:0:b0:313:e456:e64a with SMTP id x1-20020a5d6501000000b00313e456e64amr7991895wru.21.1688911188162; Sun, 09 Jul 2023 06:59:48 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PULL 01/37] util: Add cpuinfo-ppc.c Date: Sun, 9 Jul 2023 14:59:09 +0100 Message-Id: <20230709135945.250311-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42f.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, 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 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 Sun Jul 9 13:59:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700826 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741562wrs; Sun, 9 Jul 2023 07:03:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlFvQKWrUh75tUFDxP7E6NSnnMaca4IV45MYtslZd6onjda3hNzkw0Vjq68IuihX2R3yxTBV X-Received: by 2002:a37:58c3:0:b0:75d:54fc:47b1 with SMTP id m186-20020a3758c3000000b0075d54fc47b1mr9141336qkb.54.1688911409161; Sun, 09 Jul 2023 07:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911409; cv=none; d=google.com; s=arc-20160816; b=xp3PXhG02/zHP51ejX6Ou+rq2Trgibv5mCZtLa588cnRsvAZKcEBS72mgZ3BO3fWpG AlSB6W4BWkseQich2T/WvkZXOQLwpzIH6rZW5Sz68A8vfQEliABp8uNj1/Izw5kBgfoc BhRz25l7kXhPjJI2pvCIkk6saKNrBtCMTgfl+y7sIxx62GCu0VqBHHBimiKpPoCsXHNB m3kvUAX+hHdPeAQ793ZvUrRZ5zvml82jCbXYXEdW7Lm3bWJh49cMPa2RaorDEodcCnJA ph0iuf/E8+4j8suIvIaWKJO0t2pILrLs5WHNFfmAjONWAtA23xdAspuybQ+CswgiDA5s SxoQ== 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=PHrPJPS+mlRVkDvCLAEYdPQN/uxz8IaF+SaQf2EtYVY=; fh=ZuLSLtzpwbOj79Lm6HQkAzCl7AYBeBRT4Q/1zeFcrQg=; b=aeRDjbltx+bGJxVd5VNbG5XLkXmNOgIOTj3WmFBDdirm3FcSQ4rQ9jodv023zzzEPQ 0krMKtsY4VormNzc4lCJdjA9T5OTulAFNlSXKEkZ22T9a3T+Cm/LwtVr1k1XNnIgJ91W N99CPxC0c9rzQnVt00UKjRlNvyCCJtg8tBOQ5Q035HKL9tPa0aOSRjrNA8H5LF7c3whz BTehz2r4pAx/YTJ2Ykn2qCiJkWZIuv2LKO/0B9e4Ofu8SMxnskML29gy7T1OvB+yOOQi eqBmkoyLRrkEjId27KHyYVx4JYLasNPt9BYqNG+XjWzCQnInrcVMJqcb5zNe2GawLdW+ 79SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HraWOVJT; 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 i24-20020a0cab58000000b00636cf63b2a8si4673603qvb.360.2023.07.09.07.03.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03: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=HraWOVJT; 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 1qIUxU-0000SK-Qo; Sun, 09 Jul 2023 10:00:16 -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 1qIUxA-0000JG-FL for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:56 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx5-0000MP-Oe for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:56 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fc0aecf15bso8774545e9.1 for ; Sun, 09 Jul 2023 06:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911189; x=1691503189; 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=PHrPJPS+mlRVkDvCLAEYdPQN/uxz8IaF+SaQf2EtYVY=; b=HraWOVJTxcVL3g0niiNGnuXfVf9hLeZv8i1fXsZmVkE4Z5SNE9WbYOSe0HT1ykELZW 85a4nP1q6Bu7XjUxA/ctwKY9NBGy10Dk6Ov3a5uYzaTEK37i81i37jfe/JSWQAfUfuG0 7AVuSyq1O5PL9pJWgMnPtZanxmKgxv451RWfuU2PPFMaUCdPsgTWA4CFhX3INEu0L2/v XziQNpbV1wfBjk/ks3HC+x9suAM8ZTr5nPhsH1mSBDoKFqmNnSD62F/FFzmbZdQWy92M 1amociK0+I36qEueloatBH9U5V991BMNIbGsYmqfZbtSzML5KZjtrCZogAhHeH6ypP/P H+vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911189; x=1691503189; 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=PHrPJPS+mlRVkDvCLAEYdPQN/uxz8IaF+SaQf2EtYVY=; b=hNrExgfW/ELbAHyQ9sJrYytIiMYWYrWa5XEU1Ht/NKi1MO2Cv9U1m9Lptttg4eaedm 1/vNFo1W/j4UNIGKyzDPuegJUQZ6IbuVGepIsHFX8TmJVvDYQ0ckKYPD7V2YvZ4fT5WI OacVE+Lw/Y+BcEkO39zc7If+IshA5EpGBjbju+duef8EaXDJi0O6FmbEXO60sE30krKp aJ81Qv6aYPR00opDMl9+KGI084P7JwhN2JFxFVcs/Q0w0JcDF7bfSdcSjrg++V+VFhuE j3LYFyq/SRouNFUjLMOT9Fv2z8Bk5RMgkFjk8YU3L79qdW9WzI+gLFTX9agXZLVK2oyq TQQg== X-Gm-Message-State: ABy/qLYXIIFe03MsorcC3jqmTFb5gozZ+Hxq6AJfysuv90WGxRbVJzZK v0iN42V5G1NdpdWv6y4G+wl5DOb0WdIii1ZiXO9NvQ== X-Received: by 2002:adf:edc8:0:b0:313:ffdd:a707 with SMTP id v8-20020adfedc8000000b00313ffdda707mr8508554wro.35.1688911189131; Sun, 09 Jul 2023 06:59:49 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 02/37] tests/multiarch: Add test-aes Date: Sun, 9 Jul 2023 14:59:10 +0100 Message-Id: <20230709135945.250311-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x334.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 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 | 81 +++++++++++ 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 | 3 + 9 files changed, 518 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..6a0ef77e7b --- /dev/null +++ b/tests/tcg/riscv64/test-aes.c @@ -0,0 +1,81 @@ +/* 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; + + /* aes64es rd, rs1, rs2 = 0011001 rs2 rs1 000 rd 0110011 */ + asm(".insn r 0x33, 0x0, 0x19, %0, %2, %3\n\t" + ".insn r 0x33, 0x0, 0x19, %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; + + /* aesesm rd, rs1, rs2 = 0011011 rs2 rs1 000 rd 0110011 */ + asm(".insn r 0x33, 0x0, 0x1b, %0, %2, %3\n\t" + ".insn r 0x33, 0x0, 0x1b, %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; + + /* aes64ds rd, rs1, rs2 = 0011101 rs2 rs1 000 rd 0110011 */ + asm(".insn r 0x33, 0x0, 0x1d, %0, %2, %3\n\t" + ".insn r 0x33, 0x0, 0x1d, %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; + + /* aes64im rd, rs1 = 0011000 00000 rs1 001 rd 0010011 */ + asm(".insn r 0x13, 0x1, 0x18, %0, %0, x0\n\t" + ".insn r 0x13, 0x1, 0x18, %1, %1, x0" + : "=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; + + /* aes64dsm rd, rs1, rs2 = 0011111 rs2 rs1 000 rd 0110011 */ + asm(".insn r 0x33, 0x0, 0x1f, %0, %2, %3\n\t" + ".insn r 0x33, 0x0, 0x1f, %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..4b5f7f98aa --- /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 0606dec118..617f821613 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -74,6 +74,10 @@ ifneq ($(CROSS_CC_HAS_SVE),) 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 f2ee7a4db7..fdf757c6ce 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..42993549cb 100644 --- a/tests/tcg/riscv64/Makefile.target +++ b/tests/tcg/riscv64/Makefile.target @@ -9,3 +9,6 @@ TESTS += noexec TESTS += test-noc test-noc: LDFLAGS = -nostdlib -static run-test-noc: QEMU_OPTS += -cpu rv64,c=false + +TESTS += test-aes +run-test-aes: QEMU_OPTS += -cpu rv64,zk=on From patchwork Sun Jul 9 13:59:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700815 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740042wrs; Sun, 9 Jul 2023 07:00:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlElJ3xaLOEpfxFzZHKmkt+WYAWE4NUUK/UGjltNcM9NU3MezTBx3Geyb6P/5/hvS2zT0SRn X-Received: by 2002:ac8:5b10:0:b0:400:987c:bf5c with SMTP id m16-20020ac85b10000000b00400987cbf5cmr9204170qtw.18.1688911240300; Sun, 09 Jul 2023 07:00:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911240; cv=none; d=google.com; s=arc-20160816; b=GVwg+79GXKwpz46CZQUT4w4Iqgip6rUyIx0CeRTc/PPZhH43X+bbJIPFQSkX09pFM3 rj0PyuNWDwGJs++0zhWQkQiB5DBesPHtLj8BtvfWTLEusvs+TkU2Cn9/Hr6n/zlPRpn4 iIVi+TEIAh9+cYIDmvJz2qk+x9FzcHa11WTR6dQ8Bq53rNBOLwrbbHycdW/CllLmx4PA bIeMx5+980Eclb9mwOSKuiOCoNXFE8zYIuSG2h7lOMW57NIeBqzXH/v/a6OmLylUMZ0s 55rWUvwFfNSL6qj1uUroCVnZbzzA737G8KO01bIuKiKGp0w/HjusGZBr9JhMF5oqANcX p1bg== 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=; fh=4+sHc5gSB+vLQ14VCh2E8zYmyDBpEZkIg4SetDCy+NM=; b=bPpVB1xrfe/QuN987Ex8w6GkTNSG3YaCmz1wyw/O+RfZ5MjExRf9OLwGfOpuo8noZ+ nDbUsEt98RinBe8OWm+KUIuf0XpVArtV69a5fKKM68bAfrbw0/mAA2ZrCWmnGZ1yQlyY ZrvyciHUiprAiHIn4Y+0N9/YMZIndXmzs3E90yEbGAhfrLN3KBsUAssSIkuF0jRyJuXQ FCeXxOVA/HUTE1WGiTZZXNphjxk+OSGISMI2pLOiHkODaFd7dB6LZ4bodswcf2xa/oan BZ2OBVaKTX3F/njJG0w2/6MESH9rFHuBpL+8n8knb83LzQ4kBPRqPm2OQypC6Zk5s/Jt /tTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=niduhaLJ; 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 u16-20020a05622a14d000b004008fd5b693si4674433qtx.724.2023.07.09.07.00.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:00: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=niduhaLJ; 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 1qIUxN-0000O3-IB; Sun, 09 Jul 2023 10:00: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 1qIUxA-0000IS-5x for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:56 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx6-0000MW-UT for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:55 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3090d3e9c92so4314076f8f.2 for ; Sun, 09 Jul 2023 06:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911190; x=1691503190; 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=niduhaLJUfo0gO86j7Zi0XdeCAGfe0P20hORKIBxB+MGAAh+nhjh41EtJQhDVo95km 4GlUiSbsBzJYOOx4vc0OB81I5m7PPLhEdc175kL6eX/ebWhKp8b3Ld3+sP1VRkvoYH3Y /m+dZrSGaCltdrt3E/7mgq/y7RmCg2mwyogg62xur9PIpDZwlHGfb+H1Ihz83AH87lQd sUmHrF/NPP9FXol8X+JbGfdRD1WT+628N/IQ8lG22b6q1M5CRHwx1yhPvrb0DSNm9UCR FbrXhrdNrKInUFiKFpLRjiteXVb4j4pJPg4eNPw2n0ip++mhKWiOQ57+EfYoH3w51vf2 9yfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911190; x=1691503190; 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=lxMdSo+LYjxeTKyTIUGIpTzVtLxM/PyLd7aNO3wbIRjXzIzYUiwEKM0z6Uy0ZMro5h tbMLkR9PjZvQQzKcj9D6uqg2mifqV5wL0b9TPz1VtuwAmF91J4QM4mEFCUYTaihPGLlj EVgSfXJbTpe2Jf035DaK0SXvpubP8pEVRZEscF0AuhPwEx6IodShvC9ayqHgJgwezxwu eq0xamcvQy4ttMDN9FNgyxqZ/+E93B/m5sVsFdqtOBteKsQ6iTXO+r2e8npxYtbNKqkp gilmAK5iAWGwEyASVbSZnfi2mGjpyJNEygwPpC7rsbs3D5YDtoHtsI0GcsIOPHh2TZ1d uSNg== X-Gm-Message-State: ABy/qLaV9pxT0TFhHSVZgExvHgcC4WqRbGh1U+seo0KCYrG78+58w760 zWDE/B7pGY4c1s+d9vX7ADtKgCsiKCE6z0CHpYem/A== X-Received: by 2002:a5d:4909:0:b0:314:545b:4f3 with SMTP id x9-20020a5d4909000000b00314545b04f3mr9493964wrq.36.1688911190078; Sun, 09 Jul 2023 06:59:50 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 03/37] target/arm: Move aesmc and aesimc tables to crypto/aes.c Date: Sun, 9 Jul 2023 14:59:11 +0100 Message-Id: <20230709135945.250311-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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 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 Sun Jul 9 13:59:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700820 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740451wrs; Sun, 9 Jul 2023 07:01:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlF2EeBqoUNXYxE17qFvXu8UXvV6HxT7Hx1RDFkKZh1P0lEUmMz8SXC5v/HeE9TD0EGaF3Nb X-Received: by 2002:a05:620a:4608:b0:765:5c3a:26d6 with SMTP id br8-20020a05620a460800b007655c3a26d6mr15854854qkb.12.1688911286833; Sun, 09 Jul 2023 07:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911286; cv=none; d=google.com; s=arc-20160816; b=LFr4ODkAhnWsT1HBAKXKRBuvqn7S/ieq4JrUoJfkKp/QF4JJen6viO6jfhoP4NTqzL qcs44xVJyT3q8Jv1Nc3kkHo/a2Bkh3MwnpysxpieCddah5JDNAXnxmLJzEizUDI8MjLV ooaGWLtziAv/BMDC0qb+Znv+kKsmugHiEGKWFPwj4TR00xSVqTMvuCqqLjk5azG0H/ri pJOsqBMoy6fk8kJ3B+ImDoSTg8BvE5oT3dYvrJ3Eam6RAtusgTYNHj1VRo3/uRHC32QN vRLwLHqcBh/VJgYBf1MM4A7wEG/2j3TSeQRcFH2TXRBaKmiSEKhxaFwQ8PVqMTOvQ3fr B41A== 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=gLgfXZyf9aATX9TfQItUdKukGg6cdQDyWQ8EagJh33A=; fh=4+sHc5gSB+vLQ14VCh2E8zYmyDBpEZkIg4SetDCy+NM=; b=kkS7ogmC9+EOfNkTOUStntCfzSJXLCHDo+KjKJVCMnRnai0X/mysoDHsEb/W4uCAQM PZJa1L7X3pYx561Aegbc7GH0nBuZiKuB48Di8a5nnfv2Hbq+6Ni67x3DDH+DC2r746eY +jvajSsUXuOK4x3KnxqOX6/pcPiO4OtypC3bWeriuIZDj2qqLkKWI6xuD9ttTdjGTAhk Ftb1AKly9mU+gMZrs8pgFneIlKXkSIswR2BpU9SkTEHEPHAfeo/qg57Prch7dSJvsyqr vMNou7O71BGgLUgIKydT1uAYV4gzos7DcKTm8OALJZwC6BEHRCQM0C97WB71PGthF0gm RxlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RXcbdHlp; 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 x16-20020a05622a001000b003f4ecb4085bsi4677948qtw.289.2023.07.09.07.01.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:01: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=RXcbdHlp; 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 1qIUxB-0000L6-DS; Sun, 09 Jul 2023 09:59:57 -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 1qIUx9-0000Fa-EO for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:55 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx7-0000Mc-9g for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:55 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3144bf65ce9so3656608f8f.3 for ; Sun, 09 Jul 2023 06:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911191; x=1691503191; 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=gLgfXZyf9aATX9TfQItUdKukGg6cdQDyWQ8EagJh33A=; b=RXcbdHlpK9Er6yTyJfRDGUnb17ZmAkVa3t3W6p3t8wTuAypGbqegPgPyaDnKvh0uyx hK/QC5NAoUqheeEdO6coEbF0UbfAN18aXOzopDRHRJTuVHc9uSGJ8DMfMWW3iAgtusyn 4GFa9MSOD22v2J17/I3s+OnJWI2fyhLCPs1koVLKvMCFiPiH+syeJWtLIGcrb41gAAoq gVvJpwEggInGAYeXWxPZ7gAKaikJcq1VB1AJL7uPNjbhpkr/s1Yu6kiJ0BUGrPNDdvGr zRlo9JC8hkKDLpaKzOTkkEhJLo+uAnkT036CIKAqLSpy2b0HJ8MZTejvveLUsGO2mTAc VKWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911191; x=1691503191; 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=gLgfXZyf9aATX9TfQItUdKukGg6cdQDyWQ8EagJh33A=; b=BXlJITHDOT65Vk2+p4W+BvEjBXHDrBMIiZh88gwa72c1D7UnIMOt7GrIobmULPjPfW Kcquir1voDWrAF8HF9rG7p6rEdl3QgiwzmIYS/sTePv9g5db1bZBp5fk5+0w7parEpiy Gba42fnoV+6aeR0eR7fQD8nFJxSwzTTJiXwECRtmws/XyFcXQCjpJuECQKA+hCViBpmu mcrMkVIuytX1Ro+h4mRHO3p4RxjE9iAR6oBrBwc0NkxBpGd+OLvfL972YFsKyUaiF2M/ QRV8QJGXchuC6PEKiiCWo/6ID7sal4rsIaqQ8sBKhp88k+lx3BctWcTw/h+N878Np22i QdNg== X-Gm-Message-State: ABy/qLbxDE66LemnbtuM2LiiB1llv9jVZ4tWaQsQnFWA475UGaIMnRau Uvx6Cfsboe3L9ZxFwnsNizN3LsUjsEDaY5sTzpuK9A== X-Received: by 2002:a5d:66c9:0:b0:313:f990:c631 with SMTP id k9-20020a5d66c9000000b00313f990c631mr8340848wrw.44.1688911190964; Sun, 09 Jul 2023 06:59:50 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 04/37] crypto/aes: Add AES_SH, AES_ISH macros Date: Sun, 9 Jul 2023 14:59:12 +0100 Message-Id: <20230709135945.250311-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42c.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 macros will constant fold and 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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 67bb74b8e3..e65c97e0c1 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -108,12 +108,24 @@ const uint8_t AES_isbox[256] = { 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D, }; +/* AES ShiftRows, for complete unrolling. */ +#define AES_SH(X) (((X) * 5) & 15) + const uint8_t AES_shifts[16] = { - 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11 + AES_SH(0x0), AES_SH(0x1), AES_SH(0x2), AES_SH(0x3), + AES_SH(0x4), AES_SH(0x5), AES_SH(0x6), AES_SH(0x7), + AES_SH(0x8), AES_SH(0x9), AES_SH(0xA), AES_SH(0xB), + AES_SH(0xC), AES_SH(0xD), AES_SH(0xE), AES_SH(0xF), }; +/* AES InvShiftRows, for complete unrolling. */ +#define AES_ISH(X) (((X) * 13) & 15) + const uint8_t AES_ishifts[16] = { - 0, 13, 10, 7, 4, 1, 14, 11, 8, 5, 2, 15, 12, 9, 6, 3 + AES_ISH(0x0), AES_ISH(0x1), AES_ISH(0x2), AES_ISH(0x3), + AES_ISH(0x4), AES_ISH(0x5), AES_ISH(0x6), AES_ISH(0x7), + AES_ISH(0x8), AES_ISH(0x9), AES_ISH(0xA), AES_ISH(0xB), + AES_ISH(0xC), AES_ISH(0xD), AES_ISH(0xE), AES_ISH(0xF), }; /* From patchwork Sun Jul 9 13:59:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700816 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740088wrs; Sun, 9 Jul 2023 07:00:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlF7dUBRuFU9uI8IBD/l9mduHDSPExHeasAvFZDIJmfh+BV/hkz0uw6C5HScqhC3cFbVK5HF X-Received: by 2002:a05:622a:94:b0:400:9831:5a36 with SMTP id o20-20020a05622a009400b0040098315a36mr13678900qtw.5.1688911245070; Sun, 09 Jul 2023 07:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911245; cv=none; d=google.com; s=arc-20160816; b=MNmtm9w2LbNtnfEMB4RFmOKgU38zVFJvjaf/ns7l+PywWilvLWn8pAZ6XAd69r3vY5 6dIv8UvSeWNmnAI0h1y9PV8zSc/8jniCkl957t0ybASWJlr/SCl02+S/OukFpJdkJu2q h04EMACSc+Hbfv9bB7kMStegqxRoRAs35XvJsTojRQg3zYKs3xKvbbDveBlC8p1PpB8q T9/MpP3G3lxNhT9D6MSuzoYOWaboCvD+YcIznDvkLE/RI7ithq9tjYOVY8u4vz70KYwj Cb+A9XxIVYLMtq80C35eb8IZSV7+kMBSMVQ/wM8G0dyScj8V5SpSsym87DIcu3FtZebu kB5Q== 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=+2eq+Rqw2tfVQv+qv2fSzwIl0ZvbKdHuhOb40v3Ga3s=; fh=NDeJ2wqT+fijtWONfLVnciqd4z0YwE/p9OnFcWQIM00=; b=kv5Jrp/3Gg1VbZ31hFBFJpSbHX0iFsKCOjNYkdblwkHvgsK8EEWF2sX0rcyaJbIhO4 jOeTa7hmaB9k33cXthZELZqZvayA5HPXfjSmKNFzYPEa9+uS3MSW8rP/T9Z+a5sokG84 /I6cvXdJBTdYtuHtVEFefIpOPhmwi+XQBrI4byiXhJQlp+Q1uACsu3kDltUOLy1uKiNl kEbGJ2LzcIcczhmnxbcb4IB6pBSMmt/w96t6CX7zXtr6ttLykJpFohvm5bsZD+lKmuHs +cxG9VPOVlc8RDNs9LJLpP7Rl2BjWJK/TAmGmucRV2hVCYY/xQqPZ6hP8cfp9sUMXdN7 5iSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zXyuraHE; 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 n16-20020a05622a041000b004039f045e4esi2536534qtx.166.2023.07.09.07.00.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:00:45 -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=zXyuraHE; 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 1qIUxC-0000Li-6g; Sun, 09 Jul 2023 09:59:58 -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 1qIUx9-0000Fy-Jj for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:55 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx7-0000Mg-1O for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:55 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3128fcd58f3so3853091f8f.1 for ; Sun, 09 Jul 2023 06:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911191; x=1691503191; 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=+2eq+Rqw2tfVQv+qv2fSzwIl0ZvbKdHuhOb40v3Ga3s=; b=zXyuraHEhPzw5B6DmZwWd4lK1xjoH0SDCY1bMk2DBEnFyc9UN+qAaaIdDqijGmG1Bx GJoXEaesDwNjS0dRYg8o+s3Hf2O/UmtvKOe3oMjoJMYNn6l9abt/itIwDsu4v6hjjIMq /RVtJjsyYW/dmS8rgLcC5iyVfYcL8+6Y6RIkO0qxGTHLcSd1g7REntlCQXi1FNgs2+xd OvMGNESgZ6Enble65Xx0scScifNybSxiaE0HjKdn2J+0wgBHuXdBBEhxD+/ljFOu3ncB ElBc99v2S4n41blhPorsckVw+OmG90rzHGgapyQWkHcQuI6DWUeB58/dgby2j9JCk2q+ x8BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911191; x=1691503191; 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=+2eq+Rqw2tfVQv+qv2fSzwIl0ZvbKdHuhOb40v3Ga3s=; b=ExwF2+euCHPJBqvBwtp2wUEr4QJtlH3QgCccH+j+QEn6qyWkaBDGBZdn8c5h+JR5o+ iIkYmYcyeT+1ieXWtL1XKOyubKFt3bwzpwf8j9MWCVBLxG24qrxQ1uSfz/79EZu/foXr IH3lP2vZUkQB3wnekhadjLh2gT7Gg4jQecjawLJLlzG6K9PpTLoT6KczGB9nU7EmI0ni qYT8oRJUU/rOapUXfhMFnJiacn3M6hxWtAZcIPfipyTSDiAK2ypihgcE77HblNo9u5u1 nyjchJ4F8fNAq03RrV6cJhugBmpbM/ic+MxvPSMzikh3jrd5yi1nIMG8Fnt9egOAuc68 y/yw== X-Gm-Message-State: ABy/qLb6CLIPp6uw6Zx46kmmaPQMSOGQ7kQirCDfEJBJYeWxp2u7YXq4 u/Rq7oe1jyl7WKQt7yJ2DzPAALNxROuPxTcoKIQ7Cw== X-Received: by 2002:adf:f74e:0:b0:314:13d8:8ae7 with SMTP id z14-20020adff74e000000b0031413d88ae7mr8240453wrp.26.1688911191764; Sun, 09 Jul 2023 06:59:51 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 05/37] crypto: Add aesenc_SB_SR_AK Date: Sun, 9 Jul 2023 14:59:13 +0100 Message-Id: <20230709135945.250311-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x436.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. Acked-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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 d422ce50e3..1817cfc62f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3224,6 +3224,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..b85db1a30e --- /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[2]; + 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 e65c97e0c1..408d92b81f 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; @@ -1215,6 +1216,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(0x0)]]; + t.b[swap_b ^ 0x1] = AES_sbox[st->b[swap_b ^ AES_SH(0x1)]]; + t.b[swap_b ^ 0x2] = AES_sbox[st->b[swap_b ^ AES_SH(0x2)]]; + t.b[swap_b ^ 0x3] = AES_sbox[st->b[swap_b ^ AES_SH(0x3)]]; + t.b[swap_b ^ 0x4] = AES_sbox[st->b[swap_b ^ AES_SH(0x4)]]; + t.b[swap_b ^ 0x5] = AES_sbox[st->b[swap_b ^ AES_SH(0x5)]]; + t.b[swap_b ^ 0x6] = AES_sbox[st->b[swap_b ^ AES_SH(0x6)]]; + t.b[swap_b ^ 0x7] = AES_sbox[st->b[swap_b ^ AES_SH(0x7)]]; + t.b[swap_b ^ 0x8] = AES_sbox[st->b[swap_b ^ AES_SH(0x8)]]; + t.b[swap_b ^ 0x9] = AES_sbox[st->b[swap_b ^ AES_SH(0x9)]]; + t.b[swap_b ^ 0xa] = AES_sbox[st->b[swap_b ^ AES_SH(0xA)]]; + t.b[swap_b ^ 0xb] = AES_sbox[st->b[swap_b ^ AES_SH(0xB)]]; + t.b[swap_b ^ 0xc] = AES_sbox[st->b[swap_b ^ AES_SH(0xC)]]; + t.b[swap_b ^ 0xd] = AES_sbox[st->b[swap_b ^ AES_SH(0xD)]]; + t.b[swap_b ^ 0xe] = AES_sbox[st->b[swap_b ^ AES_SH(0xE)]]; + t.b[swap_b ^ 0xf] = AES_sbox[st->b[swap_b ^ AES_SH(0xF)]]; + + /* + * 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 Sun Jul 9 13:59:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700837 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742280wrs; Sun, 9 Jul 2023 07:04:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlFtzbnWm8iTqUa/ghwDrcin7RxP24EFxEst0vcSO2argrhv3uGTbQPQcqqJbvLDiznx9TN+ X-Received: by 2002:a37:2c81:0:b0:767:3f2a:cfe7 with SMTP id s123-20020a372c81000000b007673f2acfe7mr8586165qkh.56.1688911491511; Sun, 09 Jul 2023 07:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911491; cv=none; d=google.com; s=arc-20160816; b=GfX6tZcR0xrlPpo0ozQYnCazaiC/TiuJwCK+6sHBxnGhasPr2KGUkhvleRnoB40RMa jRkvjqdEwYs75BL/y+1UxbNTQFnDc4WcJlloKkFgPEy1lzn8+DNd59qMXdl3Po+W4BYc AITQg/s2ZVw7VedXpvjQtVYx4BwsiLp04LkeK6NOFBqL/iBmjOofVePVZeC9g8dndx1T DUxmpngEs+CDJwdIazHO9lmxgscxKmeuYpxvQRtNe/X0Twj0MywLc9XeXNmescfMoiQ7 xwEmjYK74BplYt2SouhR33o9MBmX7G4piqp/oxek80Xy42Ue63L3BD+t9PrZDf/EAiPN scoA== 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=TOF0YX3biOvYXBmYgvIyMISz7K/doCgseRX4BopoSYk=; fh=NDeJ2wqT+fijtWONfLVnciqd4z0YwE/p9OnFcWQIM00=; b=XML6r24tCes5GQVKmkVdtksPZtj7LJ3A4QlAbDnlwPW0aAo8qyl/5AtiGebfg8WHfn g5PoQPZQ8oVCV2DO1Cw3wuejC46Lk4juXYik6U4fuHk8YMvl5EzqbN+kA0v1dJYlp3Uj iU+I2S5fix1hUfW015IbZReZHT4A6a41baXAhGxC64NKmLa/d8GhCKVE/deEcZIuazn6 sQ4WfcVvin6hYmG6934xqylhrfE8rsni4IrzyYnIG/DsRrs6xtmzepBSZ9zLnVGgASjy sCqvs+dvO1gUSUBn7zGJhdcNQZ6OfIrsitH+2z1zTuWBZEG7JvmfGz4S8e/Baz2mlTkL 3arA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f08Z9gWd; 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 ow8-20020a05620a820800b007655a4d2ab0si4739006qkn.85.2023.07.09.07.04.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:04:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f08Z9gWd; 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 1qIUxW-0000T8-Jt; Sun, 09 Jul 2023 10:00: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 1qIUxA-0000K2-UF for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:56 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx7-0000Mk-ST for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:56 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbd33a57ddso36453795e9.1 for ; Sun, 09 Jul 2023 06:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911192; x=1691503192; 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=TOF0YX3biOvYXBmYgvIyMISz7K/doCgseRX4BopoSYk=; b=f08Z9gWdkij8P8089LPhohEkOUYXudqWQkpFnKEDzG2176Jjv+WOPHRDIe8EcK8elp aOpHkYQPXlyj06FGBhqqqhIVmUWo3XreVEuMV/xgJWZK5czx00F/x9erPiVn8eD+F8+e QQugMhGwiZzZ3ggJslVGYvvv7wpmrTNVj0zr5I6SO8kJriCWFOZYhGoMPb0gqEn/M5S5 u4cz2aH1HWZBsLc+ofWmJTnAsHxCounZeadd9z/c9CLxHVM3yf+Th+drvtONOi0QOh7j BGmJUd9twxN4X7IIywRpmt5njAia9iwaVtwP8LlgM5Uqjk2MFdxtfNFnT/ABv629JFwQ rLMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911192; x=1691503192; 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=TOF0YX3biOvYXBmYgvIyMISz7K/doCgseRX4BopoSYk=; b=i4aYxFWFJwFrUjLrkTWzBLCseP532fVWxkCMAKCiupIT1Ea2OGO+4MGwufKWlrLL77 kRiXgwIqhMotlmMXA8kfyhq5Ftkhl3wtsabLGv+fY3Qbtv2ggBZjky1cixWCVd+9SQcj r+f+annlAnrc9k/1lhaQTx9yO9bLhTQQrQ9lsblr0uy1ntiQahJicvFVUDlolRaNT36i e7sKStbtZ1Fe3sPkL31XEoX5T7u+jGQC3EqqDg4Uzs6NhxYKgoL+V4PZtj+C//9pteMV Funvd94efxl/wnxU0+kSjTJKWO99OZCKKHY8OMn/omx33ajdqA/2EPZM7uiku4WTw2p6 jZ+Q== X-Gm-Message-State: ABy/qLa0t8rrwg9TV9gin4KXoioyj3iji/FGvha9vvn4UiOk40gf9V2t 89A+l47JBAONXXOGctSSZTzBOgSj++gtK3LE/eEKwg== X-Received: by 2002:a05:6000:1cc2:b0:311:9a5:2d63 with SMTP id bf2-20020a0560001cc200b0031109a52d63mr7200703wrb.42.1688911192600; Sun, 09 Jul 2023 06:59:52 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 06/37] crypto: Add aesdec_ISB_ISR_AK Date: Sun, 9 Jul 2023 14:59:14 +0100 Message-Id: <20230709135945.250311-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.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. Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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 b85db1a30e..dcf098b97b 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 408d92b81f..90274c3706 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1261,6 +1261,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(0x0)]]; + t.b[swap_b ^ 0x1] = AES_isbox[st->b[swap_b ^ AES_ISH(0x1)]]; + t.b[swap_b ^ 0x2] = AES_isbox[st->b[swap_b ^ AES_ISH(0x2)]]; + t.b[swap_b ^ 0x3] = AES_isbox[st->b[swap_b ^ AES_ISH(0x3)]]; + t.b[swap_b ^ 0x4] = AES_isbox[st->b[swap_b ^ AES_ISH(0x4)]]; + t.b[swap_b ^ 0x5] = AES_isbox[st->b[swap_b ^ AES_ISH(0x5)]]; + t.b[swap_b ^ 0x6] = AES_isbox[st->b[swap_b ^ AES_ISH(0x6)]]; + t.b[swap_b ^ 0x7] = AES_isbox[st->b[swap_b ^ AES_ISH(0x7)]]; + t.b[swap_b ^ 0x8] = AES_isbox[st->b[swap_b ^ AES_ISH(0x8)]]; + t.b[swap_b ^ 0x9] = AES_isbox[st->b[swap_b ^ AES_ISH(0x9)]]; + t.b[swap_b ^ 0xa] = AES_isbox[st->b[swap_b ^ AES_ISH(0xA)]]; + t.b[swap_b ^ 0xb] = AES_isbox[st->b[swap_b ^ AES_ISH(0xB)]]; + t.b[swap_b ^ 0xc] = AES_isbox[st->b[swap_b ^ AES_ISH(0xC)]]; + t.b[swap_b ^ 0xd] = AES_isbox[st->b[swap_b ^ AES_ISH(0xD)]]; + t.b[swap_b ^ 0xe] = AES_isbox[st->b[swap_b ^ AES_ISH(0xE)]]; + t.b[swap_b ^ 0xf] = AES_isbox[st->b[swap_b ^ AES_ISH(0xF)]]; + + /* + * 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 Sun Jul 9 13:59:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700833 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741863wrs; Sun, 9 Jul 2023 07:03:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGuq/AAz/HsTtDHRuMnB66uaPaIAD6lN1S40/C4VEeADZbCG7faevcGSeqFfmZkrAnWLxqJ X-Received: by 2002:a0c:db8d:0:b0:634:7c34:6c6f with SMTP id m13-20020a0cdb8d000000b006347c346c6fmr9880692qvk.13.1688911438492; Sun, 09 Jul 2023 07:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911438; cv=none; d=google.com; s=arc-20160816; b=klmWjhA/sdefuYtM/WBM1WNQskwPMeij1gyEyTIA4+nbEj+MsNxRWsZsvagWwyKCW5 M3IMfHhrg6cMYx/eoPQqob2B9oi5+T/19Z6TgiY8SyVauNCnMRwkqJJeTkt3X05HjQN4 t0DBWJMURX6AFoJcvTAK6ZIe74/Aacc7LJAP7sNcIDQh6Re3K2FL7r4u7N0bXfJuPJKX a0+IGI8KcPdU4T+Zkt7DCkS5XTB5dL53aMQiUYRLlprRAKWOpoZJFokv4Y3Fql9tejuv 1pdM2sB9vwVIGhKE7bW8xwUBBoGN4yvKV3u9C8X6BH6/fCf7PrGOYGlvX59PwJyX3rWm 8yfg== 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=OqJ8/74xslZqAPWuseMNlVx/dmpNm7/AQh+6yi6QQ/Q=; fh=NDeJ2wqT+fijtWONfLVnciqd4z0YwE/p9OnFcWQIM00=; b=ytS/IroIQr59511eueClTS/BR2z2tgO7rkxpBvMwVLshCN++t9vAS9efpyaA5cyOkW UKX5VahMsQA97Jfa51H/nVYYVmc3Pw6swY98tzyr9VV8wbMhc2MSwe295ElzBg5BKyId EleWK35P5o6whcq8IidKCmIV9rMjGjB/B4btiWrKKQ2HW6hQZHj/5DhtEwOdhAgPB1nV ZktDd3D5BUwLl8MNh3lhhU5sFOa1O5Zi09yJQlo7CQ0U7bcl0L3YvFwSzoy9UyEDIdJd i3V+fLcJ58N8U0jJsYvFXqrVr2EJsR7TN2ngeyT9kkYmFjDbuKwbSW8DNQSP0ek3Qm5F fNYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Chqmz1iD; 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 f8-20020a05620a280800b00767cd8d1659si708041qkp.548.2023.07.09.07.03.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03:58 -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=Chqmz1iD; 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 1qIUxW-0000T2-9X; Sun, 09 Jul 2023 10:00: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 1qIUxA-0000KG-V6 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:56 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx9-0000My-1Y for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:56 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3090d3e9c92so4314124f8f.2 for ; Sun, 09 Jul 2023 06:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911193; x=1691503193; 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=OqJ8/74xslZqAPWuseMNlVx/dmpNm7/AQh+6yi6QQ/Q=; b=Chqmz1iDwCeT7ZJzh2IEpMbgA7A/F+hYIW30CVw96oIG/EsovgwrYLGJOf3l+4Ff6G oItmokdDqSg6ZlwMAlCJtxjXlrgVDXc9GbfNdyDbuoL3WMTp2agv+mbYr7EnM4qWwqCH Ojbz9NOo7F44b8ZvriJb7jBuas3gdBgvzL/AhGToWXHljcFWUUR4D9qHIB0LINMBAsfX VGPGXKx6WcAffLIcpPkLVMOQZ5me9t5JZ9V8LdixqDTJgcGFjtBXmrUBdkglQVtCpPCE uBPRymTacaS0IFSzsiHOPDFcJt1Jxa6Eo4tRx8Wt+92MN7G8kqSBNR/kVm2RtTigYOaE SHpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911193; x=1691503193; 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=OqJ8/74xslZqAPWuseMNlVx/dmpNm7/AQh+6yi6QQ/Q=; b=Y8aRSfEiaiOaqY8a28YP3Dd5/PF8GEjI3tuYW9xoOyoyrTR910vUskerNcvI0gPAtH SVpZF+c9n+d5vv/7SwWizPBIkdyqtTTcWC619rnSTq2KqkjkDqnx2uYiYBYk9RjwBKP+ 6htNzhlNhtOBlCHTEK3naaBPRCNKAn7OXciFHdfTQelSUCFEAz5oLfjugAAsyHjTqDP9 PcWVwUL1pDPaEsbngbit8wTgMsGCYYXHAfmlBoE6p5HEyTZ+9mOwoskZ7c5fIeaHELSV FnWj5XRvgTxRyzKSxMsOGoh30/C5d2BHAItVAUMpTscAliMCEvF5Bs+uPOjgGCj0ceCM YBog== X-Gm-Message-State: ABy/qLYRAYpXCh6ZA/fbtiqFKz6elcYAz+lJz3hMc85bVaF1bbrI7IYx KmhyBrYOulbT69n4vDvqaf9VSM3brveGpsKjRS+KxA== X-Received: by 2002:adf:e844:0:b0:314:3b1f:8ea2 with SMTP id d4-20020adfe844000000b003143b1f8ea2mr11057948wrn.6.1688911193462; Sun, 09 Jul 2023 06:59:53 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 07/37] crypto: Add aesenc_MC Date: Sun, 9 Jul 2023 14:59:15 +0100 Message-Id: <20230709135945.250311-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x435.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. Acked-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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 dcf098b97b..7d2be40a67 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 90274c3706..ec300cda0c 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" @@ -1216,6 +1218,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 Sun Jul 9 13:59:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700825 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741193wrs; Sun, 9 Jul 2023 07:02:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlFzRvnL8eQdvC6D60uQWeE8bMZiSaBwH/STwPfJsHBtD0PqT6vNJkLOzdfn5vU73fcfSI4I X-Received: by 2002:a05:622a:3c8:b0:403:3859:d20a with SMTP id k8-20020a05622a03c800b004033859d20amr11848543qtx.24.1688911370579; Sun, 09 Jul 2023 07:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911370; cv=none; d=google.com; s=arc-20160816; b=M6mjp/aen4uD6dwrYCxxkubQjme6/B+9xml9JLcwSQKIyXP57vGROpjbU7WLIAEFR6 srImFPV81YEaQlGeAZirD+Kvxeg2sopTTHi8gLT1hc6syXZuHtNmDMeWs+0fGuEji81Q uMLG16vVT+TgJcjMk7opJVBIW+Ap9DRNuKzpSv6of56j79SoZJFO0c1pTZ1+zz1Wzyxt L5YuOKddwWmbHvu8TLBdlo79Iek5bCUUUMhlVdC8Qb48QmRlpStEaKl54L9E/0WHT8vP /gIMK7FCvnsvh4CznomVh/C6NAk79rqnbnrakC0OuWH4xWSgo90zm6QC+NBTWQNNvxeK 1tog== 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=1lNVmzIrZ20vaRM4z3bBKO9neuQ8i1reH4ftvygdvPI=; fh=NDeJ2wqT+fijtWONfLVnciqd4z0YwE/p9OnFcWQIM00=; b=sPkhGXb3y48iL6ln9u72WrpRxeE84Qvt+crM9fx7xIqaAt6U+faQEa38kIhYps3ybn M6Ma9nuPSm4rfMgTFaAHFgdKgiQYC5Ml7I0TrTrZl+J4x6RevqMh6Pxd3oM8ulPnhUXX 8m6usGao50XfE1GLWocMG/xe+ET8mpvzXtnswg30yuFvlHLKQx15BHzllm2tU80e/4Sk h9WhhWY5kAXw02XRCZrykh77Eqyhb0dVmIrF3Na09ZO5PNtJ9qLLQHsxBFnxM1ypK2v3 FDUHVPLCyuaX3j+Id2hhdY/QOViJbzAO2/aIhw7CgwETj29KoI9wXBzm5j2yBnQfDmSy hiSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ylW6zMUZ; 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 x8-20020ac85f08000000b00401e1c92d1csi4617194qta.586.2023.07.09.07.02.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:02: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=ylW6zMUZ; 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 1qIUxY-0000TZ-43; Sun, 09 Jul 2023 10:00: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 1qIUxB-0000LC-Ff for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:57 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUx9-0000N2-P3 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:57 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-31297125334so2719193f8f.0 for ; Sun, 09 Jul 2023 06:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911194; x=1691503194; 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=1lNVmzIrZ20vaRM4z3bBKO9neuQ8i1reH4ftvygdvPI=; b=ylW6zMUZJDPODhE3mjOZt0HFrZeDCOvVVrSD+eWDuCSjVaFtg2uuEZvRG9q9cagbGz xrsRwHezE60v7YyPtaH31lzGPIReo0Jl5MkAM+9Nt43hFTtCkg8yYz5NofL+oiAkWwxN T6UbSfJ8d6ED4LCiEERZkt6PdEVCgdZt+HJeD5FI4FtNhQ1MnU9zhwD+HgCOIwNdsX+s Vq0cXvOHGWGHOp+c2512wuY0SU/jScX3EyXDC/4kaILGMGs7F+yDHXca+Y1Y2CoHrVoF 9zE+wKvY8ISdwgEt5CfU1FCoEVwTYiUCMtInZpyNLl7htFuaVC1slp4XXiZfd2qnXUrV ZLgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911194; x=1691503194; 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=1lNVmzIrZ20vaRM4z3bBKO9neuQ8i1reH4ftvygdvPI=; b=df9P41OTDwZtcG6WLBy4wgQQiacj+AoYG2/pU+jB+MvtW742GSuGZKEDhgvKDiJR9m 00zAvaAq+zdPbFiwNftFquEGfMl0QHPkJdAibpiQDdeNS0LJadmQ0XlqGAXx2T7dbd8K wWjuDT4BpOuPx+DLzEcD/GhMXiXPjp4CkYsZ3YHALtuMNQA2v4tv1oZXhnkVVs+xeO++ 7+b6g5jopgu4YzCgoDo78/eNa49lyb0Q6b8TMQOjTSgkPBiiRKvCFzL344RKxWWuAaEU fUVYH/itnqXox+QhjwTEhDaEAOj/tFfyTj3GcxKAmHW/r8KrcAUqiXRObczRrbI2jp+L g6bQ== X-Gm-Message-State: ABy/qLYefEoat2pa/DbttpNdAyvw9bFEJ1Ml5AyAmBIzMnTzvKYZk0KX I5BOgczDUpdiZm3YxVdsj7p9/H2fV5RhtBWMI01qdg== X-Received: by 2002:adf:fd44:0:b0:313:ebf3:850b with SMTP id h4-20020adffd44000000b00313ebf3850bmr11883810wrs.2.1688911194224; Sun, 09 Jul 2023 06:59:54 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 08/37] crypto: Add aesdec_IMC Date: Sun, 9 Jul 2023 14:59:16 +0100 Message-Id: <20230709135945.250311-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 InvMixColumns. Acked-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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 7d2be40a67..7be2cc0d8e 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 ec300cda0c..6c05d731f4 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1322,6 +1322,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 Sun Jul 9 13:59:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700847 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4743100wrs; Sun, 9 Jul 2023 07:06:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlG6IOL9eRGly8MOIIVtRLVeW+7eMfhMeJ8FnCzSPTBmrmVZC0Yxk4VOD31ysUsOAKcfL1Yt X-Received: by 2002:a05:622a:180b:b0:403:a0c6:46d1 with SMTP id t11-20020a05622a180b00b00403a0c646d1mr6654319qtc.19.1688911588617; Sun, 09 Jul 2023 07:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911588; cv=none; d=google.com; s=arc-20160816; b=QjzeYLoN51/GQe8hVl7bjr6zMlIXZYuxE1fAzpWLbEMQDFfBBJVw4NVJBh9SLgUOvU EMLhZc/nxdZzB61NDGhCd4eMxdQ5b7mQ5sGaRGi/RjCXluSn37IA8QdbKA+ADCcaFvdD oxaipdaaMGjt0Qor3bPThuqub26q878Pv7nzCP5XdMmk1rfCJ0oWZZpjGSouypZbN60z Z74M5SCEgK0Rm0tXMpiLxdZEPjcDFPuMSiEkNwG/cLJ1uJB0rAEbtfwhg8BBOOXVBFbF UXAOODTngheuYFC5Zvzf7h+RtAgHfnOC+z+uTTAcsEOu63EvEbD7aHQuFZ1RsuGb28To tz6g== 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=ne/prNzqsLfpjp4V0V8cndvcCHzJQtvFp1sqS4i2NnA=; fh=NDeJ2wqT+fijtWONfLVnciqd4z0YwE/p9OnFcWQIM00=; b=TEEIYct8W40r6+h5C6M83yHt7+KpZtth4y4ohMAb9FiN2Kx/lEHIUxsXsQnamhakhA X5lObNK8Ldn3w6+1RlmWK01uu26m7vP2u+g147ecEYFTpXgA+cvDJQ0h/YIHy8bkQ4ZT nCBOl4ve4mP79ODNQOchFPWCnpC9uoIw/CJEcQh1DL674Hk0p7ceJO5U8KQPV1yi4sFo T5oM52h0cIW/IIiLRuKLQ8wOXelTNMNyAZkH2cbVpq+wwkeBjupoCBa9NQdr2WmTybZ6 d3CsLg+cpWt4qeIzemVILUPoN3JuGy8uhto3EzdWdT4BJ9Q2OkPECR2DlYAInHaQaobL BLLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ocgf9GiN; 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 c17-20020a05622a059100b00403aa87aadesi531070qtb.98.2023.07.09.07.06.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:06:28 -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=Ocgf9GiN; 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 1qIUxe-0000Uo-2S; Sun, 09 Jul 2023 10:00:26 -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 1qIUxC-0000Ll-78 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:58 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxA-0000NF-JZ for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:57 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fbd33a57ddso36454185e9.1 for ; Sun, 09 Jul 2023 06:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911195; x=1691503195; 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=ne/prNzqsLfpjp4V0V8cndvcCHzJQtvFp1sqS4i2NnA=; b=Ocgf9GiN0SPnhFKh/7bqI8mCeIhBpkekSd1LD7aiSDsjHLdAzc+I1wbe/+7xLVhDTO b8SI8mUo8bRhYhn7MYNKOMd+gg/ASIM8yuOkPdtd3A8sC8vzOKjZbdBj1J3Hp+xvD1AZ c5ccW441ZDbHKsYfv8cmLyT3VsgWiyOhDfbsumcCXL+4Yg3SkjQN4ILhoOgOlQmb2b/t 1vH0ZxLJiij4wgRm+nx8UhkccWPT0eg0ZV4b84Sj18dDimzNpncQc4tN/0K4ptXBbf7i gYU2Sow7BpvIsGgGNAV9/aMYq0gv5dOKCt5EzQPsh+jKUEjWRNe0Jd+gqUz3M3pY3t/D vXrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911195; x=1691503195; 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=ne/prNzqsLfpjp4V0V8cndvcCHzJQtvFp1sqS4i2NnA=; b=gDo+9osY6YHLabLCn8yMkgNkX26symk5iU0mkbLdO15xK8WcXR+/JqiPFSu7JQRRea uzYd+Qa36fVcvUisPqvBy4kSENKpUzEJ73y4WUR65VaBBtf/UoleFc8Gxqifk74tB8HI 0VohtlRncaKcCgnBedcWyiqeOHlKgqOGoZNV25CNHmGqvv6ktZP1a8siALObw0L+14Uc gqCSExT340KDkhgWpTqLO1wB8oyGbfjGG2CBPvukAwKGwRgScxO/GZZyCcbtkKSEd7dY 5dlgD2j5ADxIA7p6lW74iYuFQ0fgttKnMhg3OdSuduCpB1gXjFxw3Lr7f2t+Q5fr7x7n 4vmg== X-Gm-Message-State: ABy/qLZ1qPbxANBw8xtaBFFHKofNihMYkySA4/gk/zherUi+fK7tB5WA iL9ho1Mebg8I1X0vUvIt/E/No2RADC/9jbxAqYB+Bw== X-Received: by 2002:a5d:6b47:0:b0:314:152d:f8db with SMTP id x7-20020a5d6b47000000b00314152df8dbmr7030411wrw.58.1688911195035; Sun, 09 Jul 2023 06:59:55 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 09/37] crypto: Add aesenc_SB_SR_MC_AK Date: Sun, 9 Jul 2023 14:59:17 +0100 Message-Id: <20230709135945.250311-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x333.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. Acked-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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 7be2cc0d8e..03688c8640 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 6c05d731f4..a193d98d54 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1322,6 +1322,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(0x0)]] ^ + AES_Te1[st->b[swap_b ^ AES_SH(0x1)]] ^ + AES_Te2[st->b[swap_b ^ AES_SH(0x2)]] ^ + AES_Te3[st->b[swap_b ^ AES_SH(0x3)]]); + + w1 = (AES_Te0[st->b[swap_b ^ AES_SH(0x4)]] ^ + AES_Te1[st->b[swap_b ^ AES_SH(0x5)]] ^ + AES_Te2[st->b[swap_b ^ AES_SH(0x6)]] ^ + AES_Te3[st->b[swap_b ^ AES_SH(0x7)]]); + + w2 = (AES_Te0[st->b[swap_b ^ AES_SH(0x8)]] ^ + AES_Te1[st->b[swap_b ^ AES_SH(0x9)]] ^ + AES_Te2[st->b[swap_b ^ AES_SH(0xA)]] ^ + AES_Te3[st->b[swap_b ^ AES_SH(0xB)]]); + + w3 = (AES_Te0[st->b[swap_b ^ AES_SH(0xC)]] ^ + AES_Te1[st->b[swap_b ^ AES_SH(0xD)]] ^ + AES_Te2[st->b[swap_b ^ AES_SH(0xE)]] ^ + AES_Te3[st->b[swap_b ^ AES_SH(0xF)]]); + + /* 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 Sun Jul 9 13:59:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700829 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741831wrs; Sun, 9 Jul 2023 07:03:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlFSDNreXd5G24eB+CIUklCIEy54LCv2GsEHfJCAXiqJV/1MEQ2RV4CcCtA7gD8JOhc3qFSP X-Received: by 2002:a05:620a:404e:b0:767:3fa7:2ae9 with SMTP id i14-20020a05620a404e00b007673fa72ae9mr10917488qko.12.1688911434228; Sun, 09 Jul 2023 07:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911434; cv=none; d=google.com; s=arc-20160816; b=tglSn059DnxgClE50qSaAREg/wHpn4yYJ0yih+rBritbmO9UbaY01YcLXj8+kFlL9Q rBF5F9Q+OHKSB8WGTQA0JsHkCX0Ch0AqBpQOqZEaHQsGQ8tX5P/atBvRyECz62A4xbAP 4MsgdlwaerPUJoZa6Trv6XF80thWZJplvTQDnA0Xyw/foKVHCaIrnJ9+kMel+yv8B9u+ 0OtyP7BvTAO0ImAHPYLVcXNha42WkZxpDrd0ZoE8DZKkPO1kLsVKra+0rgtd/4KhyznQ tlr+JD9dgCFhisE7mvP0c5YJ0HoEyoW4eq8UlPH8YQbBzla8RzUFoSbGkFuWawZrBXD3 t/ng== 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=bjel77SnKNWNctLdWi3qeIHBWb+IXzPkj8iWkSio4Cw=; fh=NDeJ2wqT+fijtWONfLVnciqd4z0YwE/p9OnFcWQIM00=; b=snaIaIeqQA+Cg7ulT9bf0bT2lJsp23STOkIWmnIePBXq6K+yEgMDwpLO/87+rpjjRK Xq0oWMXGmfDb4DLPWjSploOYix1q61gNp75aPwn1mWAjMmBnwq4PefXyf5ZzeDSbH0R/ xQfmQ6wOyX2YQkng72KaA1S4PLa/WT6TBd5kOu24wAIPSZZx6Z35fs9oRUarc4bwKltt eOAIPMTRokUIuYaOB0uh4fo59ympepdQlhUH3mebnAuYvq7AjJxJ8xXVR2m43qAXlnF3 u/aNVinyrsLe5/q2Q4vj9ofT5KCbcRm3I3RaRI2Kr49zrwM12c6NoS9hxyfBL1/OARm0 /q1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="hSHJK8/N"; 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 ow33-20020a05620a822100b00763a8f6aa25si4592578qkn.542.2023.07.09.07.03.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03:54 -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="hSHJK8/N"; 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 1qIUxj-0000eD-7T; Sun, 09 Jul 2023 10:00: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 1qIUxD-0000Lz-3I for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:03 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxB-0000NU-C3 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:58 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-31441bc0092so3414429f8f.1 for ; Sun, 09 Jul 2023 06:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911196; x=1691503196; 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=bjel77SnKNWNctLdWi3qeIHBWb+IXzPkj8iWkSio4Cw=; b=hSHJK8/N3Z2VqaMhULS72fi0dDicfbINs2n7iDtqL9LS0DomH68QDO1XNLu5GXnaiz a5Bo3xUuhFK2ILWrG88L9rsWAZdipMmCz0VEgKlXDt6G0Zu4xVrBy5f6CZl13GMV+MgL pZDYeScvr5GSuA/M/Epku+/6qAQN0FAa+vEfU72548fKM4UOXuR6ClXIylfSG8Tg//X5 WVAXGgCKrZN9ga+nbAi8xWSazMSwtMKI689tyY+l1e30C7nf6AmJL54uFCMxaBArqawM XRmtR7QwkYVfiuv1nvyXusHjVl1f9fhq4hNgaZ7M1vtuccQTo96Bat8ul9wyYZtv4iqN Oyyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911196; x=1691503196; 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=bjel77SnKNWNctLdWi3qeIHBWb+IXzPkj8iWkSio4Cw=; b=HUapNtRFie3Sv2xglAaTX9ps0JUMxOD1mu+zIXEVoCbUi2g14ThgLZUvNemAJMi4Jg dMRvdyer7jQQNv+/962g0xd0UVr95ptPirxeE7PRxk4kizm4TEBGI4z8dRB9YqDkGX0K 8xV6An4zMYgcfcxZYThfOxTefHzz6e4X1OLCfO9wE1unIIH6OzqHY7rEuUIqCAcrAw79 Wu5UDOWsu8VO4mGuZ232L1knFLEREdFk5WjVMbwfMezxtO7/dUwDUeG2RRplJkC80CQw 9PS2AQL6BnuvuvUrppEvEzPh8P1/WZQ3ThVFhLyIZtywd+TCK95evt0wjG2Oslcb1g47 frhg== X-Gm-Message-State: ABy/qLYv/quUHk7io3QOx7z7nvb0656NzdOU9YgDFM2ypDdBWSfHadzQ tqapHeEKEFHY/HpBhzX2v1HElB7IX9nXDfU6IqCESg== X-Received: by 2002:a5d:4603:0:b0:314:11ab:11a0 with SMTP id t3-20020a5d4603000000b0031411ab11a0mr7415291wrq.34.1688911195834; Sun, 09 Jul 2023 06:59:55 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL 10/37] crypto: Add aesdec_ISB_ISR_IMC_AK Date: Sun, 9 Jul 2023 14:59:18 +0100 Message-Id: <20230709135945.250311-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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. Acked-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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 03688c8640..9996f1c219 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 a193d98d54..c2546ef12e 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1484,6 +1484,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(0x0)]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH(0x1)]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH(0x2)]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH(0x3)]]); + + w1 = (AES_Td0[st->b[swap_b ^ AES_ISH(0x4)]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH(0x5)]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH(0x6)]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH(0x7)]]); + + w2 = (AES_Td0[st->b[swap_b ^ AES_ISH(0x8)]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH(0x9)]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH(0xA)]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH(0xB)]]); + + w3 = (AES_Td0[st->b[swap_b ^ AES_ISH(0xC)]] ^ + AES_Td1[st->b[swap_b ^ AES_ISH(0xD)]] ^ + AES_Td2[st->b[swap_b ^ AES_ISH(0xE)]] ^ + AES_Td3[st->b[swap_b ^ AES_ISH(0xF)]]); + + /* 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 Sun Jul 9 13:59:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700848 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4743120wrs; Sun, 9 Jul 2023 07:06:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFm9itJBk1DADkdAjhWPsOmubBdC8/9YEaUfZEQiRdugzmwIy77suJpI5pItbqdF7CLAUHr X-Received: by 2002:a05:620a:3b11:b0:767:13cd:e179 with SMTP id tl17-20020a05620a3b1100b0076713cde179mr7977091qkn.62.1688911590102; Sun, 09 Jul 2023 07:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911590; cv=none; d=google.com; s=arc-20160816; b=0EP3s/6gqBW7Glvmotdo/ztd1akbAFcfpU/faPR7qMI6abbW7lA+I7+Zf7dchSCfr5 ZYTX78KAE7Nspqp5TZVaBvr/DWZVLyQ3NY+ptEz128TDCVWURX2VgHOgH6Cue3xTTMvg Wt/TLzplwCi351LzBTp7s9MyAP3YxRzqMGQMZYa3AUIfdeDufLnMVwMj/3ct6Qprk3Kb Ri6ciJLNENlZveGyO/FYQuRctcvVjNagFI32XmZEeqtCRQW7BVbtpqEvjsoe6GgZEUmd 587s0LmeIkecfmBaVi90YUJYqW/pJjTJZrOOgrcBerPZ8kl87WeIbg7fSlzaBgJ2rvwF TyrQ== 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=/QBtvBQSI1Tt7HA/Hos/l3dVZOAq+hVRSg1lIqyT39k=; fh=4+sHc5gSB+vLQ14VCh2E8zYmyDBpEZkIg4SetDCy+NM=; b=i0e/8ciPnYF0/MeZ1FG/8w47wiHnnHBfUWVw0Po5BbXJD0Y4oyYu0apTKZ+ot1jyoF 27DF/mz2pbiB58dtlN5nq+LpZGzXad8O+Hpe0SLDNmEblQ7eMwnqk/wJjaMGgciLDTBc t4s2zxdi6AbL4R8nVB2Q2e6HUZ5Amza4/jCnYwJTvbtLz5p8b/CeXQwNnuFUmEGrWX+E qi4lJuiYSC6sdaD5yw50Njsuxjo7055u9MfrrJcpH5jOI+UKCMOKP4wKovkQ1e72QlNP 7zg98e9VlMDkyzv+DuVWT8Z2/ZM+I1UoU5Krs2segyU9KyJ2MJXoXo6ESObAIcAN0aAd 6IUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nim3ZUS1; 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 w16-20020a05620a445000b00767ce346790si623531qkp.95.2023.07.09.07.06.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:06:30 -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=nim3ZUS1; 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 1qIUxj-0000dn-0q; Sun, 09 Jul 2023 10:00: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 1qIUxD-0000M0-IS for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:03 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxB-0000OC-T7 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 09:59:59 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3144bf65ce9so3656685f8f.3 for ; Sun, 09 Jul 2023 06:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911196; x=1691503196; 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=/QBtvBQSI1Tt7HA/Hos/l3dVZOAq+hVRSg1lIqyT39k=; b=nim3ZUS1XeICVakl4L5RemQWh/+JDiMtJWcLQuzHt/+VcNpt1zclXaKc1jGSOfEl6c T79+IdOGLhBa8BZKeTlUW9PjC+C2ITlxYm1TLIrSwazUexnv/gs7c/6FHHQPo4ZQ4CIC mfoTSRaB8SMWkd+zD3/95o2u6pViKsqraX2TXcMaeHbQHVRkISTpIfArEJRYXBXISNry SwciYhEV/w7ZTW+jqKOBEauwm+ugWiWd4VtslsciYQqKz53vOMvsLZz32yIHWVwVLkiw D1+ESVp7GOUAxvniDLYVQMt3u86l7Ey21AskCUfjknJIIhkO8oe3FYv2zdAS0m2MSIs6 dnTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911196; x=1691503196; 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=/QBtvBQSI1Tt7HA/Hos/l3dVZOAq+hVRSg1lIqyT39k=; b=Tnv5+5PrBaUf/AzxzA2xKPjOm+DSE+NYt4LciITUDaWXkNqES5OTGBbkeC6KexjdxM QybvyFGzPROeWzxnzvuhc2C07azh9lVLut4mQpNlWlWI2jRFdJizOGU+aN1/8qsMCpUb mwNrEUtCqByTkNLjPx0TjxocRO0YP8FRvr4kQceledrPz00jwNt/8TefH2UHibMGvNSt WHxm8unYNAxug52KPHFQHgRumhrtSPn3bz5SAgIfZQ0cuZO+slfhFMFxNqKgxxOWNpjz 93dNdei9xbOGT4pFk7F1l68pRa+v5fOaAXRUfZNJ3hx9AGdSNZGmHk189bufBtqk7tO4 mmYQ== X-Gm-Message-State: ABy/qLbHQZdz2lvfaa0M7WFSfc7x0qROx/fvsVRdmGvEiLgffC1/9KaO kItZGmTwgWlNWdWLdeCaiZT2zpPSBBJ+1TEyBRQORA== X-Received: by 2002:a5d:66c9:0:b0:313:f990:c631 with SMTP id k9-20020a5d66c9000000b00313f990c631mr8340997wrw.44.1688911196704; Sun, 09 Jul 2023 06:59:56 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 11/37] crypto: Add aesdec_ISB_ISR_AK_IMC Date: Sun, 9 Jul 2023 14:59:19 +0100 Message-Id: <20230709135945.250311-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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 + InvMixColumns. Acked-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 9996f1c219..854fb0966a 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 c2546ef12e..c765f11c1e 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1542,6 +1542,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 Sun Jul 9 13:59:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700849 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4743121wrs; Sun, 9 Jul 2023 07:06:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlHpkOwmydhw14SaM8o9xm4dkoOwQAMuS+t3dpI9RKnBEKitsT9oF++MkR7rX/Vp3Gdr4FCV X-Received: by 2002:a05:620a:d88:b0:767:a4b8:8d4 with SMTP id q8-20020a05620a0d8800b00767a4b808d4mr10254885qkl.0.1688911590186; Sun, 09 Jul 2023 07:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911590; cv=none; d=google.com; s=arc-20160816; b=sY8FZaWPfCKOvsSj1KRrkUtw53CdmjsF8fLTIZ6vbiWIxOF1zaqqmpOvN4d8yZDcs3 zlq8wNeiHR9fop5UubbH8Cg7sS9oahOYTyKKMw3LeJGlQUf+O2EVr7pl5P+86h9BU8rK yeQmJ+JGqwpnRWU9q/q7WNR0mPgOSb6ZCMRiwx9Znh34wRf8BTv13eKorCfwUD+82H2Q ADleFl/6UzIljUrMFuqEsWVn/7bxn98P+FuQKPEjqWN5CvKQWV2bQdC8IUwqYsf9edLo B3ibnyqq3/d3gV8XxMECu9hCdGmxg8Ed9XU+zUsu48UI8JtvNqc5k/C6jISbXODH316r UGjA== 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:to:from :dkim-signature; bh=jsF8E0JGJalzWmrX5g2tSojnQQtbBHl3guSmbqu5fKQ=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=ehAU3zZoE5MrpXcK3h+2c4Z8vRTKmqyByDb9CAKzt5me9Zqv1caGcQTffF+hr/CY0b LgRN2ibk2rHZuVmQ3+ePbjU3v7/6+NjprF2KvlTbGPcN8wgj2PSCk9HjnpjKDQcxFdA/ onrrPaNJreqxk71FXHniECW7oDO9Eb49PQMsqhzgzoOB0nvt7oZ6vBTpFDAn/w8iJfTt Jm/qQSFyu192tcD1xp3rWFWEqd/v/5j9WG6L9Z7J0FwWyZZ07O2v5jlhixfcdKfpoipA eqEBETZpbF71NkvGd9NC3UHPT0eN361NMw2FarFQ/LUHmSJKVXCOw3hkWNpNq3dxDpWU dq+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vcwt2ECv; 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 k14-20020a0cb24e000000b005eee3411598si4489792qve.145.2023.07.09.07.06.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:06:30 -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=vcwt2ECv; 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 1qIUxe-0000Us-OR; Sun, 09 Jul 2023 10:00:26 -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 1qIUxG-0000Mn-LU for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:03 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxD-0000OQ-51 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:00 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fbc244d384so36509725e9.0 for ; Sun, 09 Jul 2023 06:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911197; x=1691503197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jsF8E0JGJalzWmrX5g2tSojnQQtbBHl3guSmbqu5fKQ=; b=vcwt2ECvHZsEh2bSx0j8m7NQSVHWcAImpPythtUcEHj3i0+++FZyXtwyztNur4o9n0 URNzA+87I4w2FfEeG5Jyic4tuvKao6XUtDGGIdTjgCH/pe0eYkBeJpnrZBr9TTAFjEUf HYpZoaqeumqOUYcEqqrjk3hZ0pBu+uhFz6ld7kSO8nhtNz3qDKMnGxSwAedfRe3PWjd7 hQ9ML/OHxsJbW8ClMf5i6OgbzatEgGZeuOPHoAKTfAf+joO/SUVq6Ud9AyRHcMmajJxP ZoV9zA3PscKQ9lXk+8LKKyPhHw9zxMIehlUxk6Frynn35cODs9atZZXLYTEYj4R6qPWT 9Ytw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911197; x=1691503197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jsF8E0JGJalzWmrX5g2tSojnQQtbBHl3guSmbqu5fKQ=; b=TpTe1QDidU2/w1JRdHnrIYzF2PWR6hr4p53qXxryc+y7wivy23mQtVgIdzZip7US2P f1JiYQxSKGMgm1bsKP03iTScdsToMcdAbveObSJawADQmCOYk8SAjF5UWjKJWVENhFSa /lomkHtGrwpcZZDLm8uZZyMDX2zCTGOGhlK19ePixEkho1LtbQFESBDuFCoDe7m5jw1T fRftIZozgnfam3FC3Mn9m6b6ItyXHNRsHjNuRRdPWo7zQrKxz05q6ptBf05rLdryNdW4 2Vb9YQJfXsGmLY6b9ymzoemcnw16Hf+3DIXq29/hRqTX4WAAuJRQ/Al66erJ0S/BVQRH ib7A== X-Gm-Message-State: ABy/qLY4QrsORYbeJnONOt8tto9W4iCtwqGbTBle4AKOvi6REcXSpkQ+ IG0iq8RB7id9qFYoDUiZJznXnR2SH3+cFkl7ERSjTA== X-Received: by 2002:a05:6000:92a:b0:314:c01:2e76 with SMTP id cx10-20020a056000092a00b003140c012e76mr7230204wrb.64.1688911197421; Sun, 09 Jul 2023 06:59:57 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 12/37] host/include/i386: Implement aes-round.h Date: Sun, 9 Jul 2023 14:59:20 +0100 Message-Id: <20230709135945.250311-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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 Sun Jul 9 13:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700839 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742390wrs; Sun, 9 Jul 2023 07:05:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFS8ANlpHTfXy23E4ZL/VdYwwfEpTJAj8ZpdqAxAvEr0Lgt7jtWQuCQsuevBS9UCfOpoVZ X-Received: by 2002:a05:622a:1483:b0:400:8493:83ad with SMTP id t3-20020a05622a148300b00400849383admr11960601qtx.15.1688911502132; Sun, 09 Jul 2023 07:05:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911502; cv=none; d=google.com; s=arc-20160816; b=gM7+BHhGMirb6jmLR0xLy26zjsI09GYfndBPgMV9pwLBRiv/KzZa6nG+WQbJtV5/QA ocrvOcPJ/NKnaQdUCzPep5U/bAv1cYfi0NBL/9cYQyClo0jS/gZ/m8s/Z8vxD9hG6FkP 7n4wyI/bFQkdNByzRZyFOKiPWQBe5oO8UHjbbO/9YdhdlJT8VRVHFE1gSmBwn8xpIUlB XfyszVCGkJ2y7GMoyGebzYH/t01jku8vetowCA+KwtF75f5+Wi0j9U8ReXSM2D43FVMK FoOoPnmpnfAG27wMeu1W1V5lNghsmZnAUl/SSLhuslQschlytiAujH9HflOmk7ZTr7Br aDtg== 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:to:from :dkim-signature; bh=rQM76z4rVFfGd1Monlw4rqjrIeX1bgxOaNzHCQOg/vo=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=lCLGPNOwJIQlTeOAmQyApxUR27VMaonPgl0b28270sfFPI+f1I+KZKYEfttvfJbC1h VveFajhWpdkRmvTCWz/ynzEmtddmDfnCpTPY1E4e1qkYk10aHNH9QacjQKtgYk8iF+2t 64+phQM1xYF24TOiQN9jhpGSuNbi9bpkOW2TBXrLLA0JiECrLEqoRqjQ9XqovAAqntNZ zh57eJRqPJitKTmbpX2eB2qCBOIC9OWK0FJmUKCLRmJTz9YtFayCGWkNF9+FXyU9J1vg NxjUxaJ5V3JwTMiZ3l3TuqEiBbRqDunXewB0dKX2BzJbYsOFxhb/1JBjm26vQofemc8D S1Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y1Nr3aeC; 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 z11-20020a05622a060b00b004032cc7e439si4599293qta.471.2023.07.09.07.05.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05:02 -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=y1Nr3aeC; 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 1qIUxj-0000f4-Ly; Sun, 09 Jul 2023 10:00: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 1qIUxJ-0000OT-VM for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:08 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxG-0000Oc-DS for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:05 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-314172bac25so3405012f8f.3 for ; Sun, 09 Jul 2023 06:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911198; x=1691503198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rQM76z4rVFfGd1Monlw4rqjrIeX1bgxOaNzHCQOg/vo=; b=y1Nr3aeCapmEc1j9ngADBQJpdE1MaHbQ8KYp8gg56AkW2ujXomTdYo0H8sJ0GUMA3y MuSzx0Y5+rCCciCwbHkQXkYmTJwKKOsvk72eDD+GvlAvznlSPh8DA44Qf8V2gQxtPljw SL8MMumVtpV8hQ6m9xAnxHkiYhhOlxdP2HJ3TqHmKee61MqdqPV93QHbyaScvo/EzyyV TC4KbFfvzNjghkHtYdjkd+QxQZu1c1QbgjB2ue4o2G3M+5pH1+Inwc0kRWcltIXUujyr z0MFw3Hsg2KPsQpb7u6ptKU4JrewS4Z1WsGwdTLOTPvx58B0MD7JE8argZK/Jsb0xSoi y2ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911198; x=1691503198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rQM76z4rVFfGd1Monlw4rqjrIeX1bgxOaNzHCQOg/vo=; b=byZbKWmAaU5lqqfnDFVqWtY2O9XxB5kczvQwuyfPEiXUPjZ0UG3ezmR69lsTAiwS4Q KtGdcE88KxDkzCXYFUPIaPiON2yGbPhjsI05tGFX2HkPKg3HUvY+ke7fy2yr8+4iuo+9 UI8xRfh2OR3+2bOvBK4FiSfwVlWDF8r23Oljwvp4QoLBKINV5SnNTp00V+HVNlAp6fKV lVan7+veazED8g6HyI3PmRHOutyHP8Fkco/rmI04ut/NEfLmAzPKFeVrozZAXxRpknV4 KrIV0a5LpEiQxUIqOoOsZV00kw0bSnLhcKjs8Xz4V5x/3gr9oSBbpewflbpw1tCueSlT Sf5g== X-Gm-Message-State: ABy/qLbKRF+lE7GSq0Ltbe7fsgM0+qx59auUaDRohtYgPDql3FTclXsF wCHiwxPDslCDaJeU0xxdgLnYX06D8FJ4JJo3+kk2hg== X-Received: by 2002:adf:ee4a:0:b0:314:11d7:c919 with SMTP id w10-20020adfee4a000000b0031411d7c919mr8370247wro.49.1688911198149; Sun, 09 Jul 2023 06:59:58 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 13/37] host/include/aarch64: Implement aes-round.h Date: Sun, 9 Jul 2023 14:59:21 +0100 Message-Id: <20230709135945.250311-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.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 c77faa0b6e..58413d44a5 100644 --- a/meson.build +++ b/meson.build @@ -2665,6 +2665,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 Sun Jul 9 13:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700814 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740044wrs; Sun, 9 Jul 2023 07:00:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXfTBfpsVqlqcIs2YNNMvvllBW7pdqfK6cA3KMHny8Vn8t8Qu2Owc9KLbfLYjw3xVqaJnV X-Received: by 2002:a37:f91e:0:b0:767:2530:543 with SMTP id l30-20020a37f91e000000b0076725300543mr9427792qkj.51.1688911240361; Sun, 09 Jul 2023 07:00:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911240; cv=none; d=google.com; s=arc-20160816; b=b4TW65in+MIYlPImg7hPNVePJcdxqx4v5oeBKkKyt3uDM1N0wpENdzRDht5Ms0rwjl BucbYG8bpv23oycxCnYbdt7hNXhNEU1CaEap0LfntpzMTWJdcoDkh+hJaCEJlwOFyEX0 JPfiVzjMPvUq95hHK6oS52ajH6+re1OhYUFbXB9XQay65TTYhJGexDoPswW1iS+WVOLK Bo9HN7PQSnbGtaU333Bho052G3LKjIkMh1wtaQLb9cseel4Ww7JhubV6gXVSNHPnrO69 LmGnz169kzJzNFUrtuB0ySV1Y0RuCd/OGAtSYPX5Aqcd7LukxK9m82Z3Pu9qDfmsJ2Jx 7efg== 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=; fh=WjXiPkZqMrJ4/ptsJscsiHQZVtbx4+L1JSVMINmKErs=; b=fGFjpiaDS7VPq5OtAwz7U3hDl3Hzi1a8o2m4KTUMaefwAOCGjHAXbtyA7d751tIYzv efJtX+69TubsQErPZk59fHpuPZqFrZLrXK2IHD/r7e7+hY40bkDKj46SKnIVhZM9LuQn hSFeddiVjq58SuSlso6Zf2cp72Zp6WXkLAYtBTEw+FODW5cj2lZPXJIPUJoDKf3yOFGd 9craOG+GOUdvVjk7OIloss8/k4SBQCpdfz/aEm+zLnk0OFBvQAHJUmSauVtGQK56PUgY liHV+zwggXeIt0JWnyKKOLoyneDvTo2xcjasE7EIoVDYpLoQua0amEnXh1uKCIeV/h4S D9kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MNrF4VG8; 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 h23-20020a37de17000000b007587e72f024si4752907qkj.660.2023.07.09.07.00.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:00: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=MNrF4VG8; 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 1qIUxb-0000Ti-Ug; Sun, 09 Jul 2023 10:00: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 1qIUxI-0000OK-Dw for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:07 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxG-0000Ou-De for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:04 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3142a9ffa89so4151631f8f.0 for ; Sun, 09 Jul 2023 06:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911199; x=1691503199; 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=MNrF4VG8xSwl2B0UFGLrSwL+OBjveX3LLs5HTF3HGdI+KOPemtqvJ6C3fq2buUjGgE xYFC5L48EzGJCYhyfMNVyCiCziCyzjYfWvh0buT4XgvtTsP68GbNEJ+kckurjsFSCX91 Q94L6We8TEW2ou8e0BCNSMgLGxtBKeHZXega/WW4eMsNo/kyD5DFzwxQY1tZrpmKfBa4 5Sl326PJZ1qdfMuR62QhUilCjWVd+07U9gNJsPzbKWlRcV9xJbP//xPy99usWETfSvCO 0tAIRYE8BuPQpYTvDZVLlztCfJpbOovoGOTz4keIGR5OPjonwhtfyjQ1rcQdBhVVFMcv 9+1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911199; x=1691503199; 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=SrjpS5WwwR7SrPl6bd0p6r4eAHPHYApDGq0WHN+1s+4rbMkei5t2EFpFkm9MTu0IMS G2bO2qgU3GEHFLEJZp9V/4dc9zLWW7c1FpZFTvTz5sB3ISBER/bn/ojqhHB7hlunqice gw5n/pgqZPnZ2j47wSINqO0s4D2yf88OVCK5QsqrQmm+5ae0biefD55BofbYj99wPgSE S6ZWtXQ+kNbKjQtrAUIFIDhcJbAtu1oO7qpjBNS0+RZ6wbMaDhzFRJ2ouqW1RZ/aurfr UTAhJHGU12l0dv3SE29o9SnTTVwbFj6yANNOMhAAV/hk7OIraF53uAX7fflPHCEIg14m wDSw== X-Gm-Message-State: ABy/qLa0q0jeu9BqyCLFKtpdI6KOW2RmdfpmqC2UWbv10FSppBVvx8rF Jb15WLYwAtHoCq+Q4VAccgLN2KviBjzryPe966RoAQ== X-Received: by 2002:a5d:6202:0:b0:30f:c195:2176 with SMTP id y2-20020a5d6202000000b0030fc1952176mr10268806wru.59.1688911199001; Sun, 09 Jul 2023 06:59:59 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Daniel Henrique Barboza Subject: [PULL 14/37] host/include/ppc: Implement aes-round.h Date: Sun, 9 Jul 2023 14:59:22 +0100 Message-Id: <20230709135945.250311-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42a.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 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; + } } } From patchwork Sun Jul 9 13:59: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: 700831 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741858wrs; Sun, 9 Jul 2023 07:03:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGUPvRz8n5+2UvVfIOLFsmpSgcDvfKzBasskAvlDnV5us5Pzhmvan7ivXbeqhzgqQ50YE6n X-Received: by 2002:ac8:5ac1:0:b0:403:ae78:1517 with SMTP id d1-20020ac85ac1000000b00403ae781517mr918847qtd.30.1688911438002; Sun, 09 Jul 2023 07:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911437; cv=none; d=google.com; s=arc-20160816; b=aIwmKniVdavcGrGiuOxjy6Uv3bCp4nJp3OskudEWZ5WxsbMc8Z4LhLyUVD8qFhel5Q ObsrVj/oeHoH6te9dMrT3F87xs0NvYQQKqkoquCV5VsTaisO78ZaAIRApCDbEHc3U+bd upc/mra5p4k6kPb0uah2+xknFSJy2b8YKgodmdjlpRLzG/t+T2jdqPL+gepYcFuG7xg/ LuMliT59s3k7niGGr3CUqcAR4kWpU5jcErDk9t1wnkumnDoUB1EMWyfWW7rHgMLj9/IQ GtstUJ5V3HdflDW0cbqZVFihDA4UwNF7EMV1qQM1w5xjNz6Y/B0Ly8rT31hcQisukyJh hycg== 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=; fh=3qdrlAICycY7VgU0cI4E0duimIwv/aNBV7oZD6cPLQA=; b=kOpvIFK/OzyTFc0VoLssN2ZPNF8/ro3+uW9oJvpZtYcs259BdGpsB+9VAwK45Mih7y YVWliqzeqIPIdwW+IF2EqNIMPoZOfC4prQOlD+SAxivYAx3zpqqinzAQyexMCE9CO34T vilZKYyVBrYVoxURFu/XofkRkkFFVfsEHD87MqvgRHN5shiAiAaCFaDfC+HDFUrvGn3P OVR9V6WKEHYYr0p0OnTdcHV4Y0sRseDmTqsj/mst6YFaMw1SkQn5Kqmo1JinIT2xZcM9 cjEyJifSkFwkf/4nVraAG5wfefxlfUgkwGMYK/QKDHYYLqczGE8H02kB0AnIHyd4QECX BJSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jYWTXnBL; 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 pe48-20020a05620a853000b00766e430ca7fsi4884799qkn.188.2023.07.09.07.03.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03:57 -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=jYWTXnBL; 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 1qIUxk-0000fq-Hh; Sun, 09 Jul 2023 10:00: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 1qIUxJ-0000OP-Jm for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:07 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxG-0000P1-EY for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:05 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3113da5260dso3407527f8f.2 for ; Sun, 09 Jul 2023 07:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911200; x=1691503200; 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=jYWTXnBLWwJ0lR7S2FvQFTwmNIuu5GIuh1oJJ2DQG6gH204ihMdS6g6JhizzJskyzg qW/h+yLTYlKkLXwblYslLgruWo/lypnzceze7iQlQCAnjgiR4bSftkbf8UQ8q1NA9V5T qqMotE0R65juOoaHdFbI9L3M07bSYwqXOxFnzWIaCx4JYo6ZdPkPh0qvuShbFtDYFXvD 11hKgoC0txgs9gpiabfscOlKiQA1N++hDqlXTPnCqK6V3VhJSTa9fG2S89X4DnfodHOj qVo+0wWAxMcwb8qV32rliObUPp5E2C3xDxbWfgcvff4HNXAnQ5MhKo9CHiPHqmVIzBFu wLDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911200; x=1691503200; 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=KVW+EyliWaKZrfwft6zsUqzgv7kGGd3gWgNf55PDfRA5ziXTYtuCG3QApr96XU+H9s Mf2OcryhmTnD6xKQRSPt8Iyuz3pYenN7m9SFALqi3EglB5vkxsaNOhMheERy7qb0j5SZ FgVqn+3TZLw/z3tR/trlMP2Kgvc/M5ZNwdrkS34sBE2NoPONiEICrYP2V1fZ2a7c3qN4 2XRzxUuqXJdFlEicxgtPAoiGzZlalSPTmXBTh0tO0k8g8LqZtbtgwlXppB7kgtKRmwa0 h/y+b3m1gU1RfnXFeJHsrijkXirP9xniTrg2y3NgdMP18P2BT6ySTq3qmtZebQjxxWNP ehoA== X-Gm-Message-State: ABy/qLZvdf1gC3siltxbxdvG2QvSmHMH8A4Dr+sxsC1QW/SzAEAlDXkj +lbg6IjZlsmltATa5f/g3WvgbMYMmdoOcCl9XZzqtw== X-Received: by 2002:adf:f60c:0:b0:311:1aee:4e1d with SMTP id t12-20020adff60c000000b003111aee4e1dmr8345676wrp.33.1688911199815; Sun, 09 Jul 2023 06:59:59 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.06.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 06:59:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PULL 15/37] target/ppc: Use aesenc_SB_SR_AK Date: Sun, 9 Jul 2023 14:59:23 +0100 Message-Id: <20230709135945.250311-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x429.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 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 Sun Jul 9 13:59: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: 700835 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742213wrs; Sun, 9 Jul 2023 07:04:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlENiQCzdyoI0J0ie1UKuqZmVe4a2Emdk0EFZTZImc0CMSL0a6jpa6wRMWKdDkPQlLowXE02 X-Received: by 2002:ac8:5b86:0:b0:400:7b48:3cb8 with SMTP id a6-20020ac85b86000000b004007b483cb8mr11526412qta.5.1688911482871; Sun, 09 Jul 2023 07:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911482; cv=none; d=google.com; s=arc-20160816; b=YPZrC859mXrI0DJYY+Ign+EtibapncWAWl1FQkz0NQDylQMYNVaEXYzdcbSQrAnrTx U/2Y+MqjL32mwpDAvyNEpIb/LcS66jmiuKTtiyjjRnYb86EA3Iy5GwG+mZ6Z4QeoljWI LHm7k46QfgweeAfHynVlyFEVlJpfrraobeD41ahFiin4TN1JNc4aqyCWrrgiZby8a19i KFZN5zenVY0mHzP1zbYR4Qgelq1jFq6kncvLC8fKS3QRR8YQtssVckx0zfurqhGikJLv jI58nfll12Nc0FmWngXM5S4Fe6nzrPODiZZRZ/vBrA6NDNWl19N+HaxLWGB8nbeWtRyk jS7w== 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=; fh=3qdrlAICycY7VgU0cI4E0duimIwv/aNBV7oZD6cPLQA=; b=Wa24l6PVzDevUhxGwJk2odSo9Q83orspXIDZ5dX/8k9TcZ+yOi92NSQLnHJMW1/V8a BkstKU0b4ifoRmjm0TjWO6v/nVuRian2Djews5AgMWDtzclCobZOEGlfiRPpdbXS+ZPD UjL75TPyuuZgpgYgBXoy1oTaGr/AkRAns1oLOblEnJfg9WIzmPt66Zvix6Q81d4CxgIG Ys9qqNofH2RLi1ht9zVq0ic6dnbNLTXREfbBfWCDUBsYpT5lKE/jXbesg2l9p3ZWm64g hRzB1qMqxwKOIg4gIErYKwudVaKOtONcE0VXG/7p8U44bG7WI4r9P5Ap9Z1kwyo+LDNk 2mIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eMV79sWi; 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 c1-20020a05622a024100b00403a4d46884si1326141qtx.273.2023.07.09.07.04.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:04: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=eMV79sWi; 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 1qIUxg-0000Uz-9H; Sun, 09 Jul 2023 10:00:28 -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 1qIUxI-0000OJ-6a for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:05 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxG-0000P7-Do for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:03 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-314172bb818so3864430f8f.1 for ; Sun, 09 Jul 2023 07:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911201; x=1691503201; 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=eMV79sWilJqua5a+Bz2Qdo/99TdCMp6DGijlsLIipFpOgMaW9riMtQmuRUpSiO0i+O lykQEA3LcGnTAxezM3CgZg9fQvP7Rx4NhXffw88IOCCJJIVytKN/M1m186sRXkIdKbVP bcMMe2NnRV+YeZvl/7fjv/TPRceM/c1cmRAVpPR5T+eiVDRpiDOPLZyOa7+Rsuqne5mj iAzoOAAQy1EjmVIxKKuZibw/U4elgRe4SWVehCvRDNSpPnTqd4dk5bNPVdGY9Lv1Ozxl rDmSUghofIP00f62m5UC67VM4Qgbo4MssN35coJ43LYQxCUjMWusADSKnqByDA+ZOaTs 0pSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911201; x=1691503201; 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=Q4q7kbcZ3GmD6yD2h/hZrj638ZOB0/2sN8nyYpO2P/pAonJq/UbKRaKl4uym3rpx/R bWXo488N7SjQpjsWAO+fw4fLc3CpQBpQDDwclKW1Hk4Pwducd9GTQCR3y2WaXcfLithu hwkviWYff5Ct9HlgYglhaHmMRua/g/xgrL6/o+7KnfOuQwR/z2gqSYPHv1vFc9AKmv7i yLgH5koZX/a3E8R5RXLoX+fF9+nTTQznEhQXucIiHtSnJKRuP9mJcDzPiEs/GooJ3Kqf Cb/Lydzh2JzP5hL1fliVfGIB2WmHYQjZiARUkwCg06BEdh/IMT73aGopgp8VFKLbAJG3 8Szw== X-Gm-Message-State: ABy/qLa/QT8AwodXQNwPTnfO13B6yz2+Q3l+bNBVnvp/XZj4udfaS8JX 0XkNJ8hRBM+1APxwIU3EJ02XzxKTt/dWo87cJ1pXoA== X-Received: by 2002:a5d:4305:0:b0:313:df09:ad04 with SMTP id h5-20020a5d4305000000b00313df09ad04mr8810952wrq.57.1688911200856; Sun, 09 Jul 2023 07:00:00 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PULL 16/37] target/ppc: Use aesdec_ISB_ISR_AK Date: Sun, 9 Jul 2023 14:59:24 +0100 Message-Id: <20230709135945.250311-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x430.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 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 Sun Jul 9 13:59: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: 700819 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740317wrs; Sun, 9 Jul 2023 07:01:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlGUpkqfU1r8SvSsm5c03me/uGc3YKFvTJ1Bb1TnxyXbZH7ytwR+Oq+gYXTZKzZLfIseZnnD X-Received: by 2002:ac8:7d91:0:b0:403:9c78:b90c with SMTP id c17-20020ac87d91000000b004039c78b90cmr6511830qtd.56.1688911270726; Sun, 09 Jul 2023 07:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911270; cv=none; d=google.com; s=arc-20160816; b=lS49WrHWsmJRwcc1mKOVWeFYvL6qmbxguWM3Krpt8w63JmspqTEpvoVxifgavObAXB t591n0S1/g917NCsK8N6DF7w+11kvoMWL2gHrQ5fhS6LTXZ394+HGaNHX4W74tJR6o1s oedFMLwFsSE2xIjEDjpDxBaiNRtrg2MOmNkaD6mcZHqJ61HODuWlbqE23n5NADi3IIpB 0YHIXVvSXFujT6GLry8epNXmK/7+86N8VVtFvN5acC69YsAga+MFWZ1aU+J537JkbHmv jK8OIh7m++FGOOGHUejV8acRcBiHK4wcMmIH6ISkiOjTvnvzL2lgxR1Er9qLZBhDOuyf 1dmw== 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=+Cz1+kZjkC5u47gB2bogcl1IkIjVlfgBFhqhPCwU85Y=; fh=3qdrlAICycY7VgU0cI4E0duimIwv/aNBV7oZD6cPLQA=; b=jPlwrwoG82okkHq9rZLtWFSpuTKz9C39UGlibi0Q9/VRZVNCNDZ30BuRdR1zf1pm+v S+KCxs6DltxG7o08q0Yo+gMlGTnMmQUIOZk/qeC6pIc3QQlLXCtpr5oFxOpoKoMPx/Ay aHxUSVaFumJmPElqE/S6+fcA3e8ghfST2D0aro5IbpjxdhS77LLxbaRr3NH3ZySTKi4X fbqs/b35Mln6Vry+79aPDl4tJJwWvzwaVRutFyaXHdaeOhQCqaWWpeVTY1BE1Fe1RSOY kswkY2gyBQySijG8tRouPxSsh/ghjNAI221m4JDll2tEkXksOqx+q+BKc/rg4ErnOTi8 5a5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ipXBaAA0; 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 y17-20020a05622a121100b00403a448056asi1424042qtx.401.2023.07.09.07.01.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:01:10 -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=ipXBaAA0; 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 1qIUxl-0000h3-8I; Sun, 09 Jul 2023 10:00:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIUxJ-0000ON-Hw for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:07 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxH-0000PP-Hs for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:05 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-313e742a787so2710322f8f.1 for ; Sun, 09 Jul 2023 07:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911202; x=1691503202; 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=+Cz1+kZjkC5u47gB2bogcl1IkIjVlfgBFhqhPCwU85Y=; b=ipXBaAA0216lsicNBvbsgtSTiPcTReEhGWDokJKpWpR7V2hYxxlkQS0kIcCwl/O4Xf 42LHz7CcHpRKWUq6nOhsVdEqjhhqdWSZuLV41QBXucINQ0ZLtoWWiC/FRgkGqXs2fsqx dDggWlOpz6eIpbpEYXPOf6NNLldJBu8G4TSRYTvb2yylgnPagyNEtR0liECBTJfuxlCL 5r5Ek+iN6fUhGyVNCNQmyNYXsMpSKZyOr0TDrqop6DR19hhJLvkfMFjTDuIQ1hl0/zrX rPGg2wCS3x+zMWIIA/+edioKDLDcvH1HsdAwg21apRSC5tXDrsP50mIpuuZ8oXUbDLz0 vSQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911202; x=1691503202; 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=+Cz1+kZjkC5u47gB2bogcl1IkIjVlfgBFhqhPCwU85Y=; b=M6ayQ5GNzp2n1Ks3deX8gYkSbJwggpiHWNYEVcQBnR1AXD3FA5J3BzuoFtWy1AJfWt HGfsbNMh/9Kl+KzO9pG6eLwdaXqYTKpQ4kYYprOKZTftjgpITd+Ip9E32i+etJ1UxD5P FXTQPQdY/iaZsGEfIWSiTFk8zzNWQ9eibFGP7+XogDpKbTjxS+Dygllh7a8f5U12mDQj 7o7ga+lZq6KTqGnbo4ahuXAq8TuCoY5zNxglB0C7tdpY2Y2d++dwjHzpCnWocBo0p0Qt 4BjShILOEyEFZH2rzyu9XkGrwQ4jzeVxUnSYtfga2k9tzYTAdPaWQj+G1uB7Oz6i/4mV nD8A== X-Gm-Message-State: ABy/qLYrJPU9J7b8br1/xY8wQu8cVTUqKWF9BeYcZAVSYdPK1UqNELZJ ZxdSrplQa8rWT77MIgrSEeFK97p3/zh3Nmpvb3xFdw== X-Received: by 2002:a5d:490a:0:b0:314:323b:9d3b with SMTP id x10-20020a5d490a000000b00314323b9d3bmr12558993wrq.32.1688911201832; Sun, 09 Jul 2023 07:00:01 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PULL 17/37] target/ppc: Use aesenc_SB_SR_MC_AK Date: Sun, 9 Jul 2023 14:59:25 +0100 Message-Id: <20230709135945.250311-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x435.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 VCIPHER instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59: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: 700834 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742094wrs; Sun, 9 Jul 2023 07:04:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlENoUoYOjfp3u7ve2LfPT0/nWk5wbI6r6CmtheK/7mIcAarzIQy2Y4ddn1y3VSkjnQ7jXGb X-Received: by 2002:a0c:9e81:0:b0:635:e81d:e57d with SMTP id r1-20020a0c9e81000000b00635e81de57dmr8239458qvd.55.1688911469497; Sun, 09 Jul 2023 07:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911469; cv=none; d=google.com; s=arc-20160816; b=f+L5Vsd2vuoWIfidr5/26aSpCIOYW9dTUnQcF3uBHfBKvNEK1hByiFSUSU1g9dcIad wSDcReWw4iGjSS+odHwt2ed7kjwCjoZh7HaggrJXvRNnBHT1EFmMqRqF2d/Uj95ZDMYf 4c1Gw8iMjMZ0mwjgikMDjiIlz7ZqnKSaPO2lJ9VENDnbqxMDOr2r3Iu7FDAQF9OFymPC cRfFaeACkBI0+taw74GmF8L2oVxA5dH2osW4EKRl6IN88k8ZnsKvRl420aeeaoNTzyVe Zvx4jT6E9XNldgkooQgVc4FGlk3CxqtEXkW1p11oFHk0/mcl49gzYZuTG10b/Z9jhBzW xzew== 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=; fh=3qdrlAICycY7VgU0cI4E0duimIwv/aNBV7oZD6cPLQA=; b=HJqUKOynJOaigMnJq0xdY6RRwegUWUkotf/Q/vFaWaUxXIjlTKWTih5OOqMPGUWK6C mg8f6g4scMFSZRgWltBUIDmK5xwcmH/9VO2geeqEHIFRlofCDB7FMuBjwhAo4qVXZgXE CvBEm5/v18fM2mszdkLhfxHtJ+6kt2G3rgp/l/ujHLbsnrnzdKXOO47AISz+i5bwaeyl Fp1GqhIdGgn5R7g9X3RSenfpoXsIK6ov1ds6rgW3eztElBYYR7mwerYIaYXK/B8ey726 SwcPTE2C5WMcv0Fq3vxlTrmsC4OlN9Yj/fCKmd5MLLpxDRC31xqDuY145gCrT6VW+K6U Fzig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wJ9onINF; 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 t19-20020a0ce2d3000000b0063631ab5dd9si4973256qvl.164.2023.07.09.07.04.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:04: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=wJ9onINF; 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 1qIUxh-0000Y8-CL; Sun, 09 Jul 2023 10:00: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 1qIUxL-0000Oh-Tw for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxJ-0000QT-9G for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:07 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbd33a57ddso36456895e9.1 for ; Sun, 09 Jul 2023 07:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911203; x=1691503203; 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=wJ9onINFxc3yk4A3u4B9mDcXrR6nMFw42mHpwRPCl1W+UwzExPrgB9ow9XcxVzaZ9b FYS9eL8R8X5rUulOm6cl08eO4Dx5XlVNc9EekRe8hYyKgIc+EiSyxwBDFzah2HwA5C5k /eGy3G9dgL7bhYm060fTFsvppAp6/xFGOWBawdEGzh7Nyz1VEF8Y5RwFcnPstZcvzPP5 u83Vg8g9jg7KSnia92imQZpy1mgvLUDYSKPr1ebhHXA9DtGXUbtWSNTk5QECJfTJUGPA j6vBjEdxN/C8Ch8MF+GnXJ8XD0X94Nv25CO1vcEICydWO/EInJeYn34thj7WhRkD3wWy ITUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911203; x=1691503203; 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=SWHFkbKdjo0PYXELNnxi2Tg+rK9sWFgjozvpY8idxVuBFOLRfG+4hAdu2kNLAHScwj 4ngmSOT7QOuSv8krvqlZz15C8oT5E8iROLalu+ZKoZxQBzddNSzmqNMl/vzcfh46icD2 XwA+4B9Zi0naXNM+X2NoxQaYm+JVtoFrE/5eOURpU3zQmaZU2M/xDjvYged3PzS4ng3T Y3msVgyAKU3InS4ZWcYeOAuJphQvcwcjln3mEDjEGg1/3zcixMsGgTacjBw52hIJ8afR PQpjSpgcYnZUdH2PlC5YAdBzxm+9GB4Cu6khXDbkKjrXLDP1a55RArRooCSAzSXyY8LJ uRuA== X-Gm-Message-State: ABy/qLZD2AVNDjMzmGGtKMNPs81kYISNNCbGc2A/b2w1wJMNS+hqUNy8 K2Ouk7CQKinVyQrj88BBzuEvUdJqSUGDkYKad5FzLg== X-Received: by 2002:a5d:614b:0:b0:314:7487:96a3 with SMTP id y11-20020a5d614b000000b00314748796a3mr6472113wrt.52.1688911202840; Sun, 09 Jul 2023 07:00:02 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza Subject: [PULL 18/37] target/ppc: Use aesdec_ISB_ISR_AK_IMC Date: Sun, 9 Jul 2023 14:59:26 +0100 Message-Id: <20230709135945.250311-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32a.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 Sun Jul 9 13:59: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: 700844 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742690wrs; Sun, 9 Jul 2023 07:05:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlHSS2nndvqrhEZUtvmYZ3+tOLBzjiDkcp0j9xIsSlK15FTjGRCEq3qTyEy7Zs6k5o+69Gi/ X-Received: by 2002:a05:622a:289:b0:403:780b:6138 with SMTP id z9-20020a05622a028900b00403780b6138mr13559423qtw.2.1688911539547; Sun, 09 Jul 2023 07:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911539; cv=none; d=google.com; s=arc-20160816; b=R+NMh90IyIeCkTqNvjnylJIqgA+jHDBMrCFh9dK+BVy/VZyA5XCpLFcyrApdNfu4vP Y1YtvDSiTuiSFCRUVkHM09DkpueuJ7/P58ivkLmQ4Ba4j3ndEbZ4gujJcrdlPAgUPVMg EeEtFtnb9yL926QUqXcaY3c2rwwkfIAM4138D4FqEweqqxhQasHKBR2OY/OEptvSTYvI syyjog2vxbzWuD0wJuEKweAuNSzJIbfCTWFC3ECmInBLYbsQluaqNOdLrE34krokywug UxNqRETOoXAJCsHAPW0QC92auOcBa08H4274+afFALmvZVIw9nPflXmjx+A4jV5dXzBA LX3g== 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=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=TBOMgayKw0KFbxxLrYPcFuF9fUoQFF5UStzykcxFgcANnLImYEvAICwbMW1O9I2l7M eKYnNIUvp+/5TjAeyO17m8PVGKM9tQFjjN+8jaZPzar6VRrPEJA/fGVc2i9fpT9vgbBr 2uoBKXAv0DEVG8ZzBPWec4w9hW/FIY1pjykp0petHDDQ+5geDPIcTlJVHVgYrYcXEcfs +7sa8pJm7no9w5PGx/g0nrjpqMcl+PFZQAX02fe8Enuuq4PjQ8tUq6rP1QDdMJ0pG4lq dx51pfxIHYOSrZOVObc3RzFqGRgGyuAY54+KI9mONcW4PWNzgXfzEK5NuBcVVsAz/Aiq ioKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y3DlOLOw; 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 e13-20020ac8598d000000b003ff46b1caf0si4647559qte.551.2023.07.09.07.05.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05: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=y3DlOLOw; 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 1qIUxg-0000V1-Ae; Sun, 09 Jul 2023 10:00:28 -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 1qIUxL-0000OX-7n for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxJ-0000Z4-M0 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:06 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-314313f127fso3667960f8f.1 for ; Sun, 09 Jul 2023 07:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911204; x=1691503204; 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=y3DlOLOwyui2TXeKftd9s256xDlgAe+guhi/Uz8RVcbDnz0SWCs55rPJU6NONqsywl PFUgajtCzbrxK80O7m7rWP+cOajeUlOqZrRcuASvk7/ATf72YX8xjAaHIWk+KEYx50oH iU9dd/wz98jtxSknKe1/SeKk10okkMYkPKuoKstu5+p3yH/bmb01Va7fac+VXk5duOgN wFPRRDxtIK5skPCAlDUaIq0wd4yzgp3G4FfjPlAhncCT/O+gI1HNKeArOgti/HFUyjf3 2Rq4aw8o7CJb+yrrKqI5hDTFuWKtMWnwtYWI+kut1Xa33s7BWg1UYjUhaIGPVAZg7cL4 i48A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911204; x=1691503204; 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=cfx4r7e0LIEbhZuKsNnp6tavPTudlZZEKaHbLegagXgczWIHHSlvTGMrwR0DfR4qTa CXwr4Jg00Wcq+6ume4nifIg9I7kR8pUMfB8Jrya5J3/Z4doTrjRp75glN1U+A7lUykRT HDuktoGgzR8X8ila3GpApXPNfUlxMrPHyTxc8UWstBb0ti434eplRZN4wQ3pl2ZbdbX6 GTIbirT4voFhwuqiIR+MIU1Eg9QzXl7A0oIJLwMvERouwaZ6vGffJCFsw1ZjQueydOCH RGJfOw6+94GfO8LzA0eHeCr7SjesxB+L47CahumjnRUwQ2KZpQDFKSQaYZrp6+639ipt wLVQ== X-Gm-Message-State: ABy/qLaZPJJoDAhbGiHYMys2mvxrwF0Ex762o9mZ81+VWaAEnFnTfkuV H7B+4d+1iK1KO2Ty5XxVCfFT91gKzFQAOUYhcdA+ww== X-Received: by 2002:adf:ee4a:0:b0:30f:af19:81f3 with SMTP id w10-20020adfee4a000000b0030faf1981f3mr8588557wro.41.1688911203577; Sun, 09 Jul 2023 07:00:03 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 19/37] target/i386: Use aesenc_SB_SR_AK Date: Sun, 9 Jul 2023 14:59:27 +0100 Message-Id: <20230709135945.250311-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42d.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 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 Sun Jul 9 13:59: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: 700818 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740249wrs; Sun, 9 Jul 2023 07:01:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlEu5+X8u5Mp9mUWIX1cqkB0A84YZzjfx9EYqJD4NjkwOe+B9NXZkl3vcPXmS3S9fAYES7Pi X-Received: by 2002:a0c:cb8e:0:b0:62f:f2fb:6915 with SMTP id p14-20020a0ccb8e000000b0062ff2fb6915mr8027721qvk.0.1688911260596; Sun, 09 Jul 2023 07:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911260; cv=none; d=google.com; s=arc-20160816; b=EoaG9/v4KmOF49XMu9DEORHry8sLJl3rTf+11PHicmbF2lY9RnD7br4sIvl0IXqxau PKLR0BncKrOLdekGn8Us5iBpHHAd8fYe/NmZSFkz657N6JJkujI5vEBk8LqPHSKLUoL6 UK1naBlvy1UkELdpphSWoFrAsPLF6gHe6J44Su8AXxqxjeuLQAadOKuGoNrcUMQSHfbL y0qi7uGCOXjnW7iGOKqR2lsait6uE8xNxjMBBWrrgKCWQpW8FWlzsn2g8gUlayg7pSzE ftu2t2sgn5zVr4dWtZwoO/YNfVl4vmGK1bM0q/arqVwBUSeCC2ljaR4HxLcNDVTS+dUQ lI/A== 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=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=D9PTiG90saj2LU1lj8YdOZyzV7DXCym0a8UELsJb+kg/X+0CBSCdsPcdrRBqTw94hx hZTFZwo6F6ijstqYrr8Y430WHSOkD1GjlodSVNYoju/uPtPpZ78lDZOGC9QiBKiKNFjQ Em8m/42t5a0rzY3Bbl1LWxTb8Hvii+X9yXNC54NkvbPpzQFfeeCrPwC59BY6pbQiLsC0 JhYs92fqAa2kX/KdvzNZUp3ZUT3sHK+l5E7Mg679JS43y4uawdeyghpYyr6xsTEcVDz0 UEbwJQEOIK5hIf/WuC2zLiZ+r+droDzph/hWS/h/zkwhN5SfjYa40f3siOoiqjGcAgCl w5pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IYEDiDUR; 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 x19-20020a0ce0d3000000b00635241eea9esi4816686qvk.202.2023.07.09.07.01.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:01: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=IYEDiDUR; 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 1qIUxX-0000TP-FV; Sun, 09 Jul 2023 10:00: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 1qIUxL-0000Og-PX for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxK-0000bb-05 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:07 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-313fb7f0f80so3552545f8f.2 for ; Sun, 09 Jul 2023 07:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911204; x=1691503204; 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=IYEDiDURjrjs7zpSjIPeWWWpKLHVJpEnYcgOvg03nQFuoUk0eQVqQ1faBF11GW+rny SV9VolhawGEVprWqVCmivAzpcGL8kbcD/xA8jYHV0+6hM8Yc47L84qg4MuWUa3+G5kR3 EHcGQXaAx+Vt1sDO7tO+y1j2PSWQMaO1Y5oBJhCRacMayiPkxghgxU7Kn8fzAc5SXX0u QqCUkuMxSxSv/3mfHzmmYqEJjV96pe9wNeULwhd/NrT2m+xSPVkfWFx8v0i2+E30dnqU 0VAqK9Mo393H04NQujU/4yBSDUWtgjgKXnfVzRQxdSTu+dEBFCScLw7nILrkWQd08RvG POPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911204; x=1691503204; 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=deEHoOKCs3VF7nKYJElfw+Dk7UzVzeW9DsSU4mcNrm5qVYedQVZhBnkQOs1KZdVDgE U3lXSkezuzpNiSdjb+IOHaO5L749bQUA6y/IGG+kPBPmr6vtRfxVO81LcDb82Q0TkyJt 4CYczE71DMuX6sb/KuDLzawkwQ8AkD3noGkyVEACU5IynvcMTIdtu0KzINqymR6hKzwf kQyCvk0JmMGqp74WBOZ7uCsxcDK2G5VzJUVFs0Q2hIk1D/4nGCyXaEdaChlxC5bkWSUq 2WJ0k/UjMu9V8COnyRnJcwfW1OaesOS+kieJ7ljLIZukLZuNwZ3ukwYhmsDwAqASAtvB at4A== X-Gm-Message-State: ABy/qLbGKolX5VvHUczIXnYVHZRrwOZWLG2IYBgeois+DPHmjydaFTUm ijL/GzSK71DbDolQhOpc4WJx41fq0/95nGmb0cS0rQ== X-Received: by 2002:a05:6000:104c:b0:313:e55f:b78c with SMTP id c12-20020a056000104c00b00313e55fb78cmr8081235wrx.21.1688911204546; Sun, 09 Jul 2023 07:00:04 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 20/37] target/i386: Use aesdec_ISB_ISR_AK Date: Sun, 9 Jul 2023 14:59:28 +0100 Message-Id: <20230709135945.250311-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42f.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 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 Sun Jul 9 13:59:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700832 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741864wrs; Sun, 9 Jul 2023 07:03:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHkHnyYWxJkBBEx3nkF6Y4VC4fZryfj+/kLcRGzk02LUiAwaIAX4nHnCBtjTycrqkZ0BR4r X-Received: by 2002:a05:622a:144:b0:403:63b5:3be4 with SMTP id v4-20020a05622a014400b0040363b53be4mr11783990qtw.27.1688911438523; Sun, 09 Jul 2023 07:03:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911438; cv=none; d=google.com; s=arc-20160816; b=Q1KfQifrMJuWBjPet5S2zWye3oV49VMBIiBx3QDJRUf/mcB7rZMxuRmMFqRS3CwT5j i9emsmG95G4ecpy1JnywgT9pqjONgY+rAzZG8F38WjSwV7It2I7b9vntCe3BIFpyQEgT ZV+1oAMioq1U3PCtBU+V0/Rm+mBnDGlSIKNYOfWNuYLnYNf8JjUwcpQRKOJd0YTGwz7P UbAx+0CdibWLKZHRP8Rq2vyuHLf4B/bHLMMxPLWkyT+f1KDo0W5Z5xtAwR6gqF5XjTFA HFQaVIFw0wd/ajONgdcfxHyICO+JCGFVNmwuK0v2Xyyy0Rbk8sboqzE22s5VSn4Xk+wL oMJA== 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=7ZmDZIvgGB2xxk9tqZEB+B+DCJxeJQyw+1f4RzekeQw=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=PtZwKJBmrRUScqevpFben2Z2UKvMzeEwpa7Tn+tiyiUIbimEOgOsjbzlhsbFKoXZgg VA+n7vgsKxHbeqxWAQJYw/yJlQFmFf9fQ0eVAjHByFhG9z3ZQ6nKEONtQ7oq5gWOsJ9x meyVhcIA0PvQ+sANz4YMI1GgeCEXAn92wsH3uUvjpOXHpZtgS1bpIErNOs6XDuflBHpV izvK5eQf0+JJpfw3fCZl/uq3fNjNBW0oyt5ksaeUkbs8aSqVq6577T0oZpI1kceJy1On JVk24rueki7K1pNsu2emLKs2JKvN/y7FNY5G5ukGvf8y5T/8HPqCxq9fPGRuR20MVDKg IQdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="XSq/s9hc"; 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 3-20020ac85743000000b003e4e85115casi4212596qtx.679.2023.07.09.07.03.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03:58 -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="XSq/s9hc"; 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 1qIUxj-0000fT-Ut; Sun, 09 Jul 2023 10:00: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 1qIUxO-0000Ou-9J for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxM-0000cG-2E for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:09 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbf1b82d9cso37691245e9.2 for ; Sun, 09 Jul 2023 07:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911206; x=1691503206; 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=7ZmDZIvgGB2xxk9tqZEB+B+DCJxeJQyw+1f4RzekeQw=; b=XSq/s9hc61HfxIgHfXZOfiUaviQW1tb3gXsFPZEAb66gPIkroyfktErhwQBuGFLkzs Xs9jStsYNJsaNxNC2wWIurBiQjQyIOTEFJ2oGFC4NxWA1N5+tgWP63hYujXX++cvZJxX jBVIs55+jMSxMBEYckphx+1keQ8GN3luaCdkxg8Bzlcn0tlkNp3Ej3mHk4Hlpk82MhVO WU0xttXHC+nbs0yFbSlvkYbA9tAdDhgZsuGypMDgIMzASnKtkev1FYpkV+O5uLWdno7v F2v7h41XjJwK9DonHN7fCLErQj9kq2A5+4S4Ec21zV/18CXMVji970WN5qQ7I4LVPZYu Adpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911206; x=1691503206; 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=7ZmDZIvgGB2xxk9tqZEB+B+DCJxeJQyw+1f4RzekeQw=; b=LX55G2AKm5yL8PLDTz/Flgd17GQNuj+hGHAKLU0XkpXnJSZUtJzgwqA6Zhrq5JAwGs 1olMDFCOSLrVBPsLP88OItxRhDL9WhoWtnnD1stOjlXxsugQNjD0rmA8vwVXTSj2YFsh FLyp4d25lGjZcIL59IyT1vU8C+jBkNjz8Msq658CGZho94UceOPFrh4WWTrta9QhtHW7 DmC5QqoTex04KGlAxidy4rdcMIu+i26sQu/rAme623Ts55GknPpMlHOLHyA6pbBcOURh l70lHtMx5IXPvaG4fBpdej5Yxtwlw5XGHyp/R+YGgq+ja7pGvsEWpaN74mY+Tenpsht6 AqWA== X-Gm-Message-State: ABy/qLatr/YNXD/fRJucApS4wxcFP6bsb/NUO6yst7InM+B7+p9qmVs2 M/OeAkGhvKU+2WW3bI3QNcxnvZbHodeU87GMIlr+lw== X-Received: by 2002:a05:600c:c8:b0:3fb:b05d:f27c with SMTP id u8-20020a05600c00c800b003fbb05df27cmr8106333wmm.34.1688911205651; Sun, 09 Jul 2023 07:00:05 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 21/37] target/i386: Use aesdec_IMC Date: Sun, 9 Jul 2023 14:59:29 +0100 Message-Id: <20230709135945.250311-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.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 AESIMC instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59: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: 700843 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742502wrs; Sun, 9 Jul 2023 07:05:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlHd01crmTQHyIVQcDrDgrBu/rzEUojDLHf8qvoRexk/KnhxM5z1ZVUc/EIW6sZNJKlAF5sk X-Received: by 2002:a05:622a:386:b0:400:9390:d129 with SMTP id j6-20020a05622a038600b004009390d129mr11193296qtx.36.1688911513608; Sun, 09 Jul 2023 07:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911513; cv=none; d=google.com; s=arc-20160816; b=uZ46CCcA+czYqs6fruLU3aFLjkpU2l/qh1POAl5As4HfRfhewIbMUoo7584eUuHFC1 5kZwTaCKJywFttemqeFWHq+kj/On4c+OcKu9qmvxPrPKHzWwFyP9+so3SSgcEF7xCb0p cwGRsgH0jKVpN2F3SPRXX5B6fvlOiDSIIToindSbCYqrjh4XTLmI4TAOnBcgrLvBUYdR hB0AO7FhfhFew6gR9lUrXzf2A3fZd7WyBvTxIANoRXTHwAf5Due7gcPzoqpKaofFcbWU tPP8+WGxhqwuAAHApncCYl5ud2Je2HzJs2tP1noqJ54sMbYeKTLSEiesiFodNgUVnv52 c0sA== 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=vBbRyJEaYCF6DplERXnYlyOqNcFvmMhKu7a8Ju7Ez3M=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=gI/Tb79U6Jhqw2LNP96tCeUSM+7+b1rXewktb1DjDdMEUsueMV/sJ3kBZdFrmEzcla VRS2m25N+njIxpNavFw8omQEA7lFvySnvXPoDca1Hhy8sgi554jR4RGhe8rFTaj6RErI XBgBbcKoTQQhYIdVKjasy0LFQm0rRg0x2GJbMXks7YxQrTNLeqUrL4GQRc1x9z/qBN8V uPF/3GMFhEulEGILOsRiP0RRtYBoL17qS7BLWjlVSRt9VkdG0l4SrZEt4KwipHjfgN2I JfL2bwZFrQ45dsG5tYYKSIMj3anf9DkA9VJ6lsolcDw2+D/i1CGObCNRixhHU+rXyVSk d4jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ChNG7oeB; 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 d24-20020a05620a137800b0075f02d4d588si4835088qkl.117.2023.07.09.07.05.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05: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=ChNG7oeB; 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 1qIUxe-0000Un-2l; Sun, 09 Jul 2023 10:00:26 -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 1qIUxP-0000Ow-9J for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxM-0000cN-3N for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:10 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3142ee41fd2so3551866f8f.3 for ; Sun, 09 Jul 2023 07:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911207; x=1691503207; 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=vBbRyJEaYCF6DplERXnYlyOqNcFvmMhKu7a8Ju7Ez3M=; b=ChNG7oeBvyoQpH6hcvOBCDY51pQZ7OC+1X1y41WQuo93cWHgTsIHuLW4ulySsd9dVP Ha/b8BaySVFZbLR5QvYL12sGGMw+9rYUhrX2Co0Ya27Jt52EunVuhH/yCNdlpi83OIVZ Jr9YyjD+i7t7mCaQ1vpOfQvQhiRpr8gT68SXak0XJR7ajQQejcLGDwEQAH31eVV82iXY zIvLI0kC7Ou3gBg++U6fPlAKZ5qJRc/fSCSPAvo9ETFwO+3ZIQ6jDYSEF1nzCmepWgmT rYnLg+04TZV8o7s0fAHPWUuwUSjDB/7P+CFgl5M4d4Lc5fdeNO7UzWOmFjV9fVZlALGv UN5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911207; x=1691503207; 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=vBbRyJEaYCF6DplERXnYlyOqNcFvmMhKu7a8Ju7Ez3M=; b=ERafas68AkDAbYFuZLFTU250Rn9vRPLCBhqqGoItrcAMxL+Gh1KhppvxPCD6SArWB1 aTHiUfndy61v5p2GsIE1eUtXhHBAWhOaPgAe30/B47yz4f6EJfzmPh9m3AmVj3jBfQj/ d3+ETCo+k7wr7/AgzBzm7G5BSfIY8oV6v0NmfQ2kfebuI/AhZtraN4FgmW85mEWycjnL gq1BQhA//5O3xQzJNZPbWJrb3qbULxY9zZFLdOVw59ox1a6n4u23DpPa+y+t21gv6XtT yCwWe5JHudEds+/0kzJSqmdXX6ApH/Yssz9CIENkWFsV30zA6AtBAw69tNf1BWdClGm/ M16Q== X-Gm-Message-State: ABy/qLZxcrgCz+4ijdrEJ8JABO7Da3TyzsjrnBNI6Rl6PCzrkzihzXfE FXrymK2GY0/U0gw4Cj5a5haclm77MDPrejwPUFSDFw== X-Received: by 2002:a5d:58cf:0:b0:314:77a:c2b2 with SMTP id o15-20020a5d58cf000000b00314077ac2b2mr7774527wrf.32.1688911206772; Sun, 09 Jul 2023 07:00:06 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 22/37] target/i386: Use aesenc_SB_SR_MC_AK Date: Sun, 9 Jul 2023 14:59:30 +0100 Message-Id: <20230709135945.250311-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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 AESENC instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700827 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741714wrs; Sun, 9 Jul 2023 07:03:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnzqJqQUPGjPHW70bCHs8kGT2U3DMm39dUp1RjZsFzH6wKOUVRF1VKll5ZV8JiywAvejGX X-Received: by 2002:a05:6214:c8c:b0:635:ee77:8d69 with SMTP id r12-20020a0562140c8c00b00635ee778d69mr17069447qvr.22.1688911423336; Sun, 09 Jul 2023 07:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911423; cv=none; d=google.com; s=arc-20160816; b=QdDjEo+z1yFSFF31f4AitVvTH9Ru6dXYowD4XGE0qXfApeqWoNCB/NSl709hbRfhqj Ejfa2motsvlMkltRdQ/bZdVRdqZSbIs4cAuB4x0Sm8T0OrS9weCeDETaoRChkKlTT+4A qNoCdv7+ZUdfsmvdVH5O16KWIlDbWiBMi3sYVjb2KBM93XyktJz65s9/TBZ9YsiFv50A VPbWcSHrVA378iYHTBz0c8WUT/TscCwbFGxIJJyihUtkFXHRh74RvoArZleHOFvs2MoK vbnviB49KJ51klMAyTvyUP6aXKs4f+r5/wmQ8jneLmmlEdL6iz6utUtz2G8v/KiS3Fau qPfg== 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=ineMFXHMMUsTtHLB4+TRmNQDsbNNDE8LTO9PLI3JgtY=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=utI7cE2Jowq4p6pF1BXuO2TYattWtPyn0MlMH8VgqSQyCKmXSLBbSCoWeQWZeknIvX KCRwTVZ72GpGwKOn01B0L/fgqbHIfyY+3RjZ1FdBksue9iczsmiaNcs4fnQSVCzHf7aV I9y/C4MHBIPCmcgUuQuPVLgt5cUI7VpyTcLVUMzYfrZFuFuxvU6jUEg4+VXs97VzO+21 w/t1ewgeOyuwApKvdM/saFZK6Ct/s9p3NPHfI3QhzGw7i8vXny/AE69ngccgdjWm2AQ8 ae42QT9tKR1OQF42QjzhkkAXoNRnlcTvueSCTc8rY++EUjVvm0dnmDbf2JqrFEYuQ+X4 ErVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LIL376Nn; 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 g21-20020ae9e115000000b007673d260cabsi5019956qkm.731.2023.07.09.07.03.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03:43 -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=LIL376Nn; 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 1qIUxh-0000YX-Gj; Sun, 09 Jul 2023 10:00: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 1qIUxP-0000P9-GX for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxN-0000d4-Bj for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:11 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbc656873eso47235425e9.1 for ; Sun, 09 Jul 2023 07:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911208; x=1691503208; 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=ineMFXHMMUsTtHLB4+TRmNQDsbNNDE8LTO9PLI3JgtY=; b=LIL376NngMbnjromVYy3xH1Oq1n7Up3N9FTKjY/aABCKs1ybOMrzr1UUzgvJLfFzFH tq0dOmEQtR5nLSpDLo7a/ryeQ82KCsc8aegr6YWHvEpbXz3N+b7xaAhhCG+vAQefDNdX rHK0GmaDwdFhjugZ4UYpTAK5kDW5cE5B1i6CeEM0fJr7bs1KChRxoMG3kQ3eVQ18w8ny maTV5dzAQCt5jN+vvLMSvuEpDW33Do2Pyzo0wJGj62MWCekuyEColAOKIjC3rORzIBIY /yLKgfDR6//xfhdBcae6byX54Tu5LekHarlQCvwPUakfjfffecMHbsSt1cdatwdpomb9 sing== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911208; x=1691503208; 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=ineMFXHMMUsTtHLB4+TRmNQDsbNNDE8LTO9PLI3JgtY=; b=E2JycU+5heetRLAdqpiJj7UFUpKJ/cPrTBfwKbjuo0/ClycKueQbGFyW6TT9IWmYZ+ R4AnOhaBC+oIkaXtSQ4g4QYchQPnT2sHsknNOa2Res3XKS4FrCl81fQa55Bp8eJBnzfe pijfJRRPy83yWgExU3waw9+DmN3d9rmrU6KCS04i+yIjNThAMaGo2Vv6eprjsxNuL72o mhJFic1BLq3rxN0aEUsBWbjNmUpNzrbXsZuLUlpy76fy/cmkC75kiCfnfPcSQ0rWG9T4 Fiizl2XFBnfC4ie/aI/Ktk8Vk/vpSIKHz8dqKCOpNB/uwLVpPnHNO1HNAgNxJj2iFa+5 qtag== X-Gm-Message-State: ABy/qLbhHsENy61ftggw9tTHwbKm+M/Xs2A8+OuoncRwjhuRDfijVduI 7JohTSi4iKilsokD/tdNfymNpT2QcGF2aeWJnkpJyQ== X-Received: by 2002:a05:600c:2105:b0:3fc:3e1:7105 with SMTP id u5-20020a05600c210500b003fc03e17105mr5790195wml.24.1688911207602; Sun, 09 Jul 2023 07:00:07 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 23/37] target/i386: Use aesdec_ISB_ISR_IMC_AK Date: Sun, 9 Jul 2023 14:59:31 +0100 Message-Id: <20230709135945.250311-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32f.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 AESDEC instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59: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: 700830 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741825wrs; Sun, 9 Jul 2023 07:03:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlGl69crKvOsC/ZTTg9QkQ7KxQJkpcGUoZVSEGCWt7JPJ0WvbzAMg+iE30Gwn8+LubNW4lHw X-Received: by 2002:a05:620a:192a:b0:765:3c4a:6237 with SMTP id bj42-20020a05620a192a00b007653c4a6237mr11272107qkb.16.1688911433847; Sun, 09 Jul 2023 07:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911433; cv=none; d=google.com; s=arc-20160816; b=EvaGaQJeloTaIulmO85JwaQFRbIlvKWNwrUPe6uyuzyWX003255BjZxykqaJiPh9Rx bXPU6tqCUOX+kMTidQwU+IWCpVrpr8l08FIc/EB6EWFgfbbgorsY/1WbS3I5XnBkT5l/ +KRiq6jNrTwNYS2MpYc8lcGjqawf86qheDqUCNFwXy9sevEsYk0fC6ARL8SyTlrPo98p q/7CqNBLj+tH9Rfm8DTrnMbLTfLiZMa8ywAcRc3fg4J6qry6qGOGQCJm11Bl8A5+c8Tf JX7ma64JWhYJvNWGnKhHg9KSffUT186ZUuUfvVqWz8yWtzFcMtw4SnZCumc60UDg2OP5 64uw== 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=O7ydnBYQ5OsAEU6obJ0/WYba/6nStgh78o+Q1/ZISH0=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=KAgY3ipsWAPW2EwmSf0Zq7tt0l+Rg4mnR6PmBL7QYEOdv3TbbtfhGWC+DpwKoYLpAd 2dFih5pjTBx/cI85ANa62k6vEktB14TG9u2G/WKIiDJypmrBvvZc8U/+WauY2NBKytQV m6F/6mnkuhrOmBPrgYzGlvcVK4f1klA57q3nUnGUFbDmXO8iydOtUa0wVxJ64lU36S3S Lwp3wYyQie8de0htrLicEfPCzwGbq6cXWCUEF3lc9o6Mk2nxG29xHsEOeXj49IeHUwpW XJyaio+55bymHd/OvcXZ3l144fq38xUH5daL/xu+8dJpV/6vxt7Td01Zw2NmLRR6steL +HOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mDgfQYy4; 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 s22-20020ae9f716000000b00766fd5f8611si4805759qkg.449.2023.07.09.07.03.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03: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=mDgfQYy4; 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 1qIUxt-0000qO-5J; Sun, 09 Jul 2023 10:00: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 1qIUxS-0000PL-4f for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxP-0000dU-DS for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:13 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742bso40005795e9.2 for ; Sun, 09 Jul 2023 07:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911210; x=1691503210; 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=O7ydnBYQ5OsAEU6obJ0/WYba/6nStgh78o+Q1/ZISH0=; b=mDgfQYy4k+1mekKLQkkodL13Xg3n0T9jGhrzELO75BuDKIK964uKIgm9AanACGdiku xMkCLWpe5k5FzMITWfW+o7RX8TO/VJBGpaZPid/FY8tVozzrP96tFR5DpAlK0dmTMBcM hv9gRSrklzxBLvVk+Uo+Z0OFQywbuMz+dfdgUTRzRfo5+Mi2VzQUAXyyS5QU7Tm5WjN6 BsCrw/mRo8NnPXbcqZ0Xv7Uw11mVUQxsRDk7AFZ1cbJLjNbTMCJP/YzyeHPfvl/v83xF RNKZAdNGfVaVpWvOFXjp1Q/AgMKLXxmJ8DMvBg0vawYpTVrtXloNg/nZ2maKwyjsg93v BCDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911210; x=1691503210; 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=O7ydnBYQ5OsAEU6obJ0/WYba/6nStgh78o+Q1/ZISH0=; b=GPSgwTI0gz+KOMj0j7G1gzGIOF66y5FmLS9MCcgZEvwzXEl+vd+OcQJT9faMv+MT3V ZpgbknvUYP/vMTyWnEma4+XVujcoE4LW3fB5qY2Pb6kZTdTIxuK1GbHHzxIIr2O4y/2B VT5ZQtiD4y3fO/bco+jObAZoaPtnIHx/nmAJI57Hjx+0fAXhIYhDSNTWvd7316lwUYyt eVTRyKGF2bXBFNm4TkQXF1HJfoK962gcfoVM2KqXd/6qpmf3VXypuRxKPhzZy6d/Aift N3K7aU1/M11/TUCVC8gnC3WzNcl+lz2sL3HgfS04iag4Znh3Ek6IT6CSPOgdUTQAzy62 BNzQ== X-Gm-Message-State: ABy/qLa+zY/ttjfk9xexO9wvMitoGDcsIbFHvGjgAS71q/xoEqVQZgQr 9Me5D8yfkBjjg5KLiGR2UszPPHWM8vlCdKh1j33ytQ== X-Received: by 2002:a7b:ca51:0:b0:3f7:2a1d:1b05 with SMTP id m17-20020a7bca51000000b003f72a1d1b05mr9417586wml.14.1688911208400; Sun, 09 Jul 2023 07:00:08 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 24/37] target/arm: Demultiplex AESE and AESMC Date: Sun, 9 Jul 2023 14:59:32 +0100 Message-Id: <20230709135945.250311-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32f.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 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 225d358922..8350a65f31 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 Sun Jul 9 13:59: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: 700841 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742414wrs; Sun, 9 Jul 2023 07:05:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlEBj+XZqVzzw+jtExZCqR3pcMZ6uzTgLfjI8R/CWnJR2mSYBI8tA4xHGBfvFGboA3f3RLLy X-Received: by 2002:a05:620a:4783:b0:767:2aca:7641 with SMTP id dt3-20020a05620a478300b007672aca7641mr9046338qkb.52.1688911504740; Sun, 09 Jul 2023 07:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911504; cv=none; d=google.com; s=arc-20160816; b=X0X3QqGX0rwlQYRXnflAgHNklnvrkB4yKdiUgKc8473ENHP9iJQ9K1OijQzCR1t61f OiYNcDJbHDeSY1U8Gy/y/34do6Zl9DkOEkxUInNx7x7ffTTpOnQ3PBCisgB/hX1GiWAr 4nVvTyXHCE/W78+BSO8K0X6tT4hp7xSzVMmkua4LLncDjzpbuXLeB+cbOePz64+tzeRG EVIHaRVU2kUx38P6vVth6LFu4+1ahvsI9rM6xfgmuZLVCtXlZleJ/QRi6cjh4sS/ZK9R DVHIcZdZBdOoPFr/GLaTpciKxU+qMNMjRC/b7gOM1ZviYDywuHY5TJYpSOC6dFnVueAh qgJQ== 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=WbTpqwootsmsPZFIj0kNAknK91pBd8Tm6VoiJxSZmAw=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=hjTXy6o1OcqvG41aX6bna9J9lSEQXM4MD6xuEL+VZ+EUKxskmXgxlWx/xCiDfjAJnd gfcLALZGDo0vIgxxRr4BfixNOsn8WxGcw38FjSH6W+u9cGZrWV9TRaYIvOlznuAFG7Jn 3Z6NsRS7Rax4aTg56uJ/tZ4ViOrndTZleWHWwJ6QtN2ZqDPn7IdrVdVXO1frzESZ8Px5 YeQ3nhkuMwo+/cYogvvYEMi4YdaZpZGfSlB8BcwcohHe+4deOESJRaewyZRU04RUEYQQ WFYIGb3nL1RMJqPLJg/PlFeU/AzYB2Tk9FOs+JFLOe1zxf1uRL0fEFsjm5fsXgWhjH/j BxSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DLH8AVOB; 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 s1-20020a05620a030100b00747a2434dbcsi4831922qkm.776.2023.07.09.07.05.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05: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=DLH8AVOB; 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 1qIUxk-0000gT-PZ; Sun, 09 Jul 2023 10:00: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 1qIUxQ-0000PH-JQ for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxO-0000dJ-E8 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:12 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fbea147034so35694255e9.0 for ; Sun, 09 Jul 2023 07:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911209; x=1691503209; 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=WbTpqwootsmsPZFIj0kNAknK91pBd8Tm6VoiJxSZmAw=; b=DLH8AVOB+Kbf2T9BvjL8HKP8Z4LuOpOXU8oxj3KLezrQOsU4Wft2YualdYKMPHYyuA 7DcXmsh+QZ/sKV8En9BjcGi4EORWKtIO7vLObXSCgUSBccF8cSpLa/yLobektUWR8Oyv iqxfaBXkzDzQHpclimc8mPicXeXE6ei0w+kwuW9dKS8YEvFmbchLdaicdpdD+RQ+p3bw TgeV4eYUIT0jzMMki8T2AxWVeR32EXefo6qj3ShGu7pkjia1DAe6IPCAJn87VenxZqye 0sbFmPbfQeDCmZUVpJ28jHYeb/EogNCvkcUHFeWAg2MLDGob04hHxtDGB/LhRc3kVy/h rOmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911209; x=1691503209; 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=WbTpqwootsmsPZFIj0kNAknK91pBd8Tm6VoiJxSZmAw=; b=Xxw4pZ+itXxX2txVJXtumtLMvGYEevurBmV4lP5McBiQsZYjd3Vjf//bM2AEGuEFxF AG1cYphtDlJSvynIJZPt5X46jH1mHKlEeQTDNbJkfz8WA+tXQ6VB0xacd/fXc/S9cAL5 WRIQEM+yUbCrskMe8tXh9GHeHvE4CLgu+3iF28IE3REVw3sx1VcO608us5t13VSudj9R FSyy6ZpmlOoOwsg/YqH9OdUpIZYilZxMj2hgz5sff/GtiQaVE8gG9TmcU1gV1C5twyRZ ZkCOQg0tNBm7kBY2gJRUFNE6M/kx+uq/4j1drqai4rTV09sUvgvX0jvwGQ7034yVWwtY ACjg== X-Gm-Message-State: ABy/qLYJGC+KJqobf0n/5MkEikzeeXyk7g3FgpuCH1xqaqP9qsLGiBTV wYhBcVs53kT4cjZUSXS0KVWU1taf9L3N7U013OByFw== X-Received: by 2002:a1c:4b18:0:b0:3fb:ab76:164b with SMTP id y24-20020a1c4b18000000b003fbab76164bmr8136449wma.13.1688911209192; Sun, 09 Jul 2023 07:00:09 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 25/37] target/arm: Use aesenc_SB_SR_AK Date: Sun, 9 Jul 2023 14:59:33 +0100 Message-Id: <20230709135945.250311-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32f.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 AESE instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700823 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741147wrs; Sun, 9 Jul 2023 07:02:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFp6eyaWenepAczNziCCdTwddQeGn18tzHa7qq7tuiVGY2A9QBtmn5D4crFRAolKFCNZj8B X-Received: by 2002:a0c:f394:0:b0:62b:3c25:5ae9 with SMTP id i20-20020a0cf394000000b0062b3c255ae9mr7553857qvk.65.1688911365531; Sun, 09 Jul 2023 07:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911365; cv=none; d=google.com; s=arc-20160816; b=zfWRKfELQjwixEuIuRqrdveZuvdUCf2t2GupqU+zo9rD2QTBLYqu/LAGOZ3Y5IFZTk VenXnQNa1SpuOpUVXMP3vUn19H0trgvklWNMpjappa6+XtgDt0SGy/6WvCx4p6z2YsZ9 cIxfWhSs9x0Iw2y5Sz9sgkRC4SBYYh6u35Z8EyLGx4O4oyd0iwiGrNW6WYnqHD8LvlyG 4VXvGFFLZTthdsjhvLgdteRHYvUdWcDeAAfki0TkN+ErL974U2EfWii1VofM7Ak+2ZGQ fE1sbZTzaaBP1o+8jyVFX/Rb546+Av/YsfGqsl5Ooe4e7l8ibFAJIgJ8zK6BIntKlujo 9b9A== 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=cKGE3OvFNd5jAIbGE9ocD3KdoxUzDMvYMbDIoK+kebA=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=TUrSMmamAAj6i+YoOo7PdBey+ACOSUuZ0ImEC7lJRAkGkk+6SDXPo8TK2oKSokv096 papXUKC44zIZFksa/l79Lgbk2vSYlNDtYzStMtoGJzxr+qpb8jidbkJOPhHgqK9M49wQ fyfswqhp8V/TlLDxtaZsk88Ut/Qca9iU9jg2Uuu5OAs29Vqdw5RtaEWpXJIb4Yl353r5 7DR86lqhc+lxI+IVUhtfS8nkFnHJEzVkqjm7J4JDSvAu6tTHWzK/ID43/k5TmuRn0Cd+ 3CiuSy8z7P3gpREvLsvtSDRYAwucM7oERakEDtZMTyHfuXJAivK+iCDV7+MKCJvIrIfN nstA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HRCjT0oc; 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 m6-20020ae9f206000000b00766ff1439e7si4594091qkg.741.2023.07.09.07.02.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:02:45 -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=HRCjT0oc; 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 1qIUxi-0000ba-85; Sun, 09 Jul 2023 10:00:30 -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 1qIUxR-0000PK-U3 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:14 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxQ-0000dS-Bp for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:13 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fbc5d5746cso41875015e9.2 for ; Sun, 09 Jul 2023 07:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911210; x=1691503210; 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=cKGE3OvFNd5jAIbGE9ocD3KdoxUzDMvYMbDIoK+kebA=; b=HRCjT0ocWashqocfuY2t+xUNBU6tYwvdEedjNAlRCNyfik8BN7dM6MMiL4WbyAjexz D2WHeJNk21Vi87ngO8aotsC9u5Zt19P2ggwzMM6oRf7HIEPUc4SEvwh4A+c2vl5bxNMt D/6rmQ0EmTggATLc9n17Rx4ydj//wUTP8aBgv03nC4G5r/argDCEOoQOlFBFWY1u3PoM XYHfMpU5X8U/889eieVlmgekgBpc83jbVOGvMrzmGIZ4aj5l9lZnIE+qC149iU8vQ+zm MOtPxVXLirkU8FcRTtu7mUhLoYDWCf1ppmeqqHyodlJwC5U+oV9zBaOAPE/wzN4uVde4 NS8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911210; x=1691503210; 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=cKGE3OvFNd5jAIbGE9ocD3KdoxUzDMvYMbDIoK+kebA=; b=QD04yzI9WqGkYU42U7D2UmJcGaT7NRrKI/bRsjeeZa57AjszBv2DtyNC1qu4pu/T5h mR1Wv1/XPDlwligVElTO+TTtRPnNbNPJmJAsQ/rE0BtcZcL79G8Hwc1WhjhlaUgmMO3+ ytFyV0muNqg78OzzS5pjNi3ROYk9IkDpzmW28hfFpTVtSqmvhkhzs3SLjwBu3GKb7Dpw oIkWkq2IESKtMhETRWUbpAmFr+8T9kJhqFEEHHyd0Lim0emKrt1aOjGDB1cV92yvHI86 E4cCoT5FWQL5XH+tKNAbvJEy4Xf5OdnIuI5SJrsZBQ0P7iFcOvCOQDo4v6rHxlmJPyUa iEhA== X-Gm-Message-State: ABy/qLa9XSkq1OENK4yRZgAJG1AD5tgBi3ahXWKhp4spWdvLkVCx7Qp5 bgudw7lqH/XYt7m5gvEPMBO7rL4AAcFfORjISxVrOQ== X-Received: by 2002:a05:600c:11cf:b0:3fc:e7d:ca3e with SMTP id b15-20020a05600c11cf00b003fc0e7dca3emr1385211wmi.2.1688911209936; Sun, 09 Jul 2023 07:00:09 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 26/37] target/arm: Use aesdec_ISB_ISR_AK Date: Sun, 9 Jul 2023 14:59:34 +0100 Message-Id: <20230709135945.250311-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32e.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. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59: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: 700842 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742497wrs; Sun, 9 Jul 2023 07:05:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlG/UfZExG2u6V3zYEbBH0ATpwzCQSkHgFHMQke1IpgF8EzpxbI4GqAe7d+GsK8u/lGj1tp7 X-Received: by 2002:a0c:b399:0:b0:62b:49e1:4946 with SMTP id t25-20020a0cb399000000b0062b49e14946mr8254827qve.21.1688911513358; Sun, 09 Jul 2023 07:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911513; cv=none; d=google.com; s=arc-20160816; b=wfXf0PfRuVVw0lHqVRc9slg1mWAkUeX/ihYzKTzRmAQjHcET0hdO14eMWfHTqw6AH0 XTyOok3NxPW2SMIURD8Dcv8RaCCmjB2iZ5JCoezlMqXbzaQr1LZmHFc7PxNmUUjx6YKm wKNc1/wliCFRVF6JJyAAVyMWlazcRcSpHfBADFJDu21HQM9yTBNYhAfdCuE4aezPhyEC 7hw3Ajwk3hxycY5JTWIAutQdfq4rF3FMtC2eTDrHQqd2lZTy7UeycgM6eGEMVA79SjTY BW2uK7HR/sEMTEJq5hW4rP2sGjKOu0UP5gjTFmTPdE61fnIi1NhGlhoeqlseYhTMI5j3 EHnA== 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=8HOx1ZLKzsBUTcaboEy/mBqeLFtnDXaBWlHTAqwIG7M=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=QiXEXUreJCCxHaEMm91e2O+AZBIsiHL0sz9+soo3Ba4Wunh8C5ylMHm0ODdmfcxo8O uonnno84KvYyP0VHvSm+5tKoCAyCA1mGlc9CX7KYm0sNibO4VfpWGormncIM2mjWnI9u A8QGqK4dqQ0dJgByks5LO7zLlTdeDk/97877JFfXr3XOKJjrSCZf8SOa2oqbMsvtypaq rbExbFNv5G4SRKYkEeXc27Uv6qKKafUbu0HJRrvJwxHBnI78esvT82sg7pJ9Y32SE4T7 6vzYmBwDGkwNC/69UlZBdpCQ9CSOr+wnls7i+fKQSG+IxXsGp2GgkMo2ll4hxn4Xy4i4 fUnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q6pgoeLN; 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 y9-20020a0ce049000000b00635dbf100a6si4743352qvk.126.2023.07.09.07.05.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05: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=q6pgoeLN; 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 1qIUxg-0000Xx-KI; Sun, 09 Jul 2023 10:00:28 -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 1qIUxW-0000T5-EJ for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:18 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxQ-0000dl-Bz for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:18 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fbc77e76abso37949465e9.1 for ; Sun, 09 Jul 2023 07:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911211; x=1691503211; 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=8HOx1ZLKzsBUTcaboEy/mBqeLFtnDXaBWlHTAqwIG7M=; b=q6pgoeLNe2MpDLDUL8FnIdFIT/TMSQlxkBLvAbt6dVm/abqqf5RwCKSpMl+k0vTRCO WkFzzp+Nn0BgtdL7peqfGiIE9ef8DSCVA/x9L53Fnq70kNP3SnrUqtpf/A/GtFMUp1v0 T6ChgfLCRA2MsJ0wWYYXRu5jBgV9x/p0cmpydTmLZCEdLdKhvgzpyo3OUV/QZGQ972fE xrE/ivEMUUFIvk1tpvYK8e4zpX6UsuMciElemUIRZBNwRnhKwRn2ygx4JdR+vXuMa4an xWre+qsb8VynQrEBzkvOgkGg0LCj1THRCNdqiOCePXsL4xB98Jj4+Vubsb1S5LDTPgS5 a1EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911211; x=1691503211; 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=8HOx1ZLKzsBUTcaboEy/mBqeLFtnDXaBWlHTAqwIG7M=; b=ho/J80NVJPQsa7Db5Sl74z6JqgfkCR3DekI0d4caQCFRkkXzJtQjhdwNa17TS4UOf1 ReReSAO658yt4ntF9LXWCpjdTFaGj1lSNFf0kupyG0Ycb1GgZOYI3u5Bjw1i4K72jPYu 0upLG++/o4hyRJWFS9tZIf0r94ttiylPqfpr6PlHmF9E4gfrm0CVk7M56QmJlGxleBTc Fnd+quN6hC9cMm1oIR9uMI3GZjYFtUtRztb5v6cukBtKhjLIMY90/rBBT+8iSTnAhy7P ThavEhSILIv6KIHHJzMNFGebeVyC/p72SV4FZ9q7i7s5hibDTu9gvPS3VQeQE6jj7Tz6 C+uw== X-Gm-Message-State: ABy/qLY5kTuaaTXRJaDQJqQqVHbJahjLF+7Xxq9oWMNXK5/9/q1NOrr0 V3fUPh7RvvKi0ya1ObxjOklJOW1ftUGsMTKKGleYyQ== X-Received: by 2002:a05:600c:29a:b0:3fb:abd0:2b52 with SMTP id 26-20020a05600c029a00b003fbabd02b52mr8285896wmk.13.1688911210816; Sun, 09 Jul 2023 07:00:10 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 27/37] target/arm: Use aesenc_MC Date: Sun, 9 Jul 2023 14:59:35 +0100 Message-Id: <20230709135945.250311-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x333.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700836 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742265wrs; Sun, 9 Jul 2023 07:04:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlFzROrBGuI1rLt6LKAHFeuaBxfZ5dx2Nr+yrn9NJIs0axAlZl0+8WnqS95XP6Rj73CPHVlJ X-Received: by 2002:ac8:4e94:0:b0:400:e685:d18e with SMTP id 20-20020ac84e94000000b00400e685d18emr13824570qtp.18.1688911490026; Sun, 09 Jul 2023 07:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911490; cv=none; d=google.com; s=arc-20160816; b=KMkO5h++HSIEwkAZGlurIR7DD4r5nTo+FfSvN+M+lc6cyGsDAAMIpIeLeGBsvUNg0N TgC8wxQhDJdrq9v2EiW+iXQ08pUUVKHjGGpkIyHo6T2ZH0C540mkLassYnOugvWES/SZ 9RrtZOaABSou/phJj66CctQdOhBbcqzo1LlaeLcMrPJ9oN7cKxEOMNTivH0OtcHWMmfr pSbRilyNzFurowPJOfxmMo5vUDJIzwHXus9nZn1kNFXSL6txY5XuMZ3mGi6ZTpPv8Oh1 q3zPW8dj3T1CAEiBfpyJ8Td8dPDfz1jz4LqSQGyQosrudfKQFJq1sbdeseozPm1geCnz 2uPg== 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=ZNJt+xQSaKcqRS2slBC4RsFLFu+ocScsUgiRpjPIdes=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=Uw7d/J7upAJW7VUEoB+UEACZXjk/4GNXO/BvejUq3b3jGboGORcFRN2ZwMwreko94I jWQt8S7MgTygY1A67+dB6wW0i74PmDPs1LeIpxgofPxv0orB9GjJ5UsAoNKHMw9jI1hZ YPSz/eZy9bM9KvG3OkEoA6KD5QGi8TMAmTV1Ewv0gYYf/C3mgeOUi+ebG3ecn4RKU078 fum90t1NTlpM9RYXZRTOBrGdJzhf7gM2t8z80Rm1bbYUQF87GMb9Po8rUhUGKtWqYgSm erq8CqhE6FMqgfHysK1lixnweo0PmYJGCrENyhmqgycCGbaDjXgnMB+DGx1otYP8tLNd 348A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IsUday6O; 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 c11-20020a05622a058b00b00403aa809bf9si559651qtb.381.2023.07.09.07.04.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:04: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=IsUday6O; 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 1qIUxe-0000Ut-PY; Sun, 09 Jul 2023 10:00:26 -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 1qIUxW-0000T3-DY for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:18 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxQ-0000e0-QZ for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:15 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbc12181b6so40119955e9.2 for ; Sun, 09 Jul 2023 07:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911211; x=1691503211; 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=ZNJt+xQSaKcqRS2slBC4RsFLFu+ocScsUgiRpjPIdes=; b=IsUday6OWCxs7DidWFVGxtSDTOtH3Sf75e5JPoG1b4XLLPWJefXo79qr/+Rjt17Hkz eFqh1+QpHoqqd/q2YuOZ9UNyVefufvaNTCUPe7YZ8UNYw9NDYPKsg1B6qAy8tY1RuPSW HXmdmluz13jyvHy3w9mq3KGKU+bQkrHPIKsujfSK1J6BC5KXoHb4uGyqIjuspDaHyoeR 2/sJqbVJyjnei2V2O7tn9FhNGSxFZKxirUDbWJzYoyswAkiow95KxM3O1c6Fntlpjt+g EsL83HdWzflzk43oKhc6vwJGOeKT6bpeh2Fse2cH9NJ3jC56BTAnX7hjaqWMBj+3OsX2 2A+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911211; x=1691503211; 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=ZNJt+xQSaKcqRS2slBC4RsFLFu+ocScsUgiRpjPIdes=; b=g7huWxshQoxCt52x+0VrX3hfAJBvhQHABWHHTvaAZwBBHof40osFeV7cS/mMpfLP/O FHMgyMGYQBcwBVKsFDbppO3Q0xbSKxD+4IXaEFq82+uK4vLb9tZqbVSzSjCYW+eYOgoT 3mzZX9haIp4SfYgDWlLMIa/2fbwOWk3MSXVbhpkXEQWajoLW9ZT0gcXXX0KG7Q4li622 Vr/9ty/2yqoBkQrbnlaUUCS/HSN7SpQUb4aO+GJ9UOYF3+wFZPLDvSJtWMKVsntvxXCK 5aQsMNYymMfk+fxgtnwkzZsUsfNrcVqRYJJqFS/e5XquTbNSsneaRmyMLXwN6qeCozYc eqqw== X-Gm-Message-State: ABy/qLbOzmRGWg6xHeY3hoby5dfBOPckPrXoqSL6V57VEjp5z60EGmb6 d5hRMi9pnQDC2mM6ao/RQ90tOb8Vu7J52xrCJtoR+A== X-Received: by 2002:a05:600c:2251:b0:3f9:c82e:9d87 with SMTP id a17-20020a05600c225100b003f9c82e9d87mr8786805wmm.13.1688911211576; Sun, 09 Jul 2023 07:00:11 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 28/37] target/arm: Use aesdec_IMC Date: Sun, 9 Jul 2023 14:59:36 +0100 Message-Id: <20230709135945.250311-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x334.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 AESIMC instruction. We have converted everything to crypto/aes-round.h; crypto/aes.h is no longer needed. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59: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: 700846 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4743085wrs; Sun, 9 Jul 2023 07:06:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlFWmCT6vbBVGhNsqD6JpH9Ylyzi1dOJvw68wXDZ1UWV2qBmVWZ1HQRAjEVTWcz8si0creU2 X-Received: by 2002:a05:620a:3905:b0:767:fbe:f4b with SMTP id qr5-20020a05620a390500b007670fbe0f4bmr10836268qkn.72.1688911586638; Sun, 09 Jul 2023 07:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911586; cv=none; d=google.com; s=arc-20160816; b=v4JuY/dtMtGcdnc5/evjXrA0idcuXfln+llWz6GBQzn3AbyzzdWwFL0qeShq122cOQ FyIBoUOWrW70KkfQLNomgWVtI586hYkK8Lq30Ix6zw6w7WHrSZ7WLW3qBeRbngMhpc9G JF9+D6ASuKE6oS+DOMC31IBagA0CT7egsuGP7/XNwGOJQmbY3EgblGigS2MNxXHTRtTx 4P2kiNVKOhRX/+f+Re2fb3D4kfhQXV/IBUpvk1optMXWYOrIpzTqAEAFu5eF/NWjGi7g U/FKbKuXIMLBE41wcvDoo6lYSswmLOOexu9MUT5pHkevH7G9PmjGvInog3YCJglB2djI QjnQ== 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=5cwUPdSqiTi+cpvjs0+320/XSt6FYwReeMeUR4tviQI=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=iCa+IKXXWDxCyxXwEEiB1A1+tyZcsT3U4H09idfjOhyEnQbuYOEJ5aO6QuZazRsQ0C HT+l+hQoc5zHl38RW2c7v+JAKi8RCjlnbV7OGnogZET0f9iW+hOruZrjLDVQOJvg063d 1TryGIk/l8ylh4EqiaEQxwfLtJHNRAx39+B7rWxPqBAr+alIUzQ9SLKhcwNc/iO5ji6Z Z9EdAaDOQpRh4oNmxapFEzDqV91ypO/tlF1BMqadpV+wGYGW4yMCxE/0PwJpTuiOD4eJ XdyImu00r4HEFBTUqXDy+bcpzE/eeT0eKjSWHf92QW6tQDFcL0BF/AjLPDc3NSPmDid+ vgqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LNk6Rza+; 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 bk16-20020a05620a1a1000b00767d0e575dasi367169qkb.229.2023.07.09.07.06.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:06: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=LNk6Rza+; 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 1qIUxj-0000fA-N5; Sun, 09 Jul 2023 10:00: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 1qIUxW-0000T4-Dv for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:18 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxR-0000eG-K8 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:18 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbf1b82dc7so37582515e9.2 for ; Sun, 09 Jul 2023 07:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911212; x=1691503212; 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=5cwUPdSqiTi+cpvjs0+320/XSt6FYwReeMeUR4tviQI=; b=LNk6Rza+MfQaL+5IWRKbAUw+W61RgR/z03p5ElAPllXpfQOuJCqj0Tj07Ir0HwW/2c cyEf7nMJXrM2MlYrgOxg5E+iNt32HpJ6eRpIEuoToU946zsbcn+poHimNe0F4zEp4fe2 xPCPF++fEEAY+nl5AjQDU4mjEWyGv2HwCUa6ZmWSAEaArABAbEm+L4kLbN96utWb80mW WR236VIZ+8gLA8F1dTFO+gKHNSmXXeSzspHPpYuEbOXnb/zVjgkLNh6YEA0wUhic02l4 DiCzUAf7DVm7OL+7TBFPEMgjnuzeYywpFRhys0OnM3akdRhKDJgnsIKjGZpvY54+uIv4 gYAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911212; x=1691503212; 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=5cwUPdSqiTi+cpvjs0+320/XSt6FYwReeMeUR4tviQI=; b=PvPZ/dAVhZ98pbOmHDzavzeZTDdFHN3TAMxjNtbGNQ2EaRtuiV6DK+GB/LyokqhSzq O5gYH/ntVLhG3wfHOl1XiShSThTiS214eCfsPtpfYtlI2qK+jimxJczreD1O2m2q5mK2 I1PTVUiViK/boNhzNOH7WWDApRZrUacVz9ug83wQgmlzy+/YtguMH3KDtgz15/YpyLkU SHuhoN+fvnkQ9ZarfDHuXyXkmXqir77DEPYaG4fDKxxJGr+GSbficws1yMkBbWM8M5Jk ZC0qr2C6GoAl3JsxQ9VWw70f8D6FDtipuZpQsBEo/7uzo4XyRMvc8MrcTtkpBWSQx1d8 W4ng== X-Gm-Message-State: ABy/qLaSElO24xn3Xr+dFu/lQCfFM9Zijaenn7SufJDdn8DWAILE5O3U epu4WlxDS63dJSgtiWelAld1WW1RCdrcK12dpsFtPg== X-Received: by 2002:a1c:7c08:0:b0:3fb:b6f3:e528 with SMTP id x8-20020a1c7c08000000b003fbb6f3e528mr9007714wmc.25.1688911212327; Sun, 09 Jul 2023 07:00:12 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 29/37] target/riscv: Use aesenc_SB_SR_AK Date: Sun, 9 Jul 2023 14:59:37 +0100 Message-Id: <20230709135945.250311-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x329.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 AES64ES instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700838 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742366wrs; Sun, 9 Jul 2023 07:05:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlF/s+hupauJHy2zlxQ3dAh+4t5vBLgfWA9KD863nN3/Hc5lkaJWUCJN8bxIbLdoiwMXJj9e X-Received: by 2002:ac8:7f94:0:b0:3f6:b7a3:8450 with SMTP id z20-20020ac87f94000000b003f6b7a38450mr12669342qtj.64.1688911500411; Sun, 09 Jul 2023 07:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911500; cv=none; d=google.com; s=arc-20160816; b=Twiqxuybdn4UFL8xpJFoR/M2naZMmeaYOqGs50wji7MP8Il40dCPcEPih1GVNJ2Pwc OHfqzf1jBxyWQGpweJeWNAZ2vB0f0PO79EtiVUe8illTeSiuB8NwQo54ynB7qSZpWzmQ rAv0PnRJ6ybKCbi4lsjMVifG/1zqNwF4tgGeICyvkGKD1GXFeO84ZNR/RVDQKuroPi2M J/DZG5DAcxCv7PwgAL1wX/nv3FlkRv/o4IWcn6tsc7RA6KBTn2GFjgr7f4tMvCPS3zFn ubEjYJYPPHALEDM2xnl2UyJ6It4MZPe3ko4s5l/gcn9Fp0E7+3Vf3peoNz5gz3uxCh6L G5iA== 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=SPxXjVkEBfCIbnZstLW82ROIVL7eKNAPasvd0ZIUexI=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=iU2F8pRhoDmN8FEnTsWM0ARmN3nwRNYRaxI3lVGmz7w43CpJEk1o/0jbu7wPLaV6mB IM0cWqgHNPmyDfOspW99OibLNY+BnWl24sGP5Isz1YJ3PZQlAV+5pT+JGJWLfi/lMenB 9GyWf7Msnc3wDr2q7HfuUnIwwSOMYoMoUrf6IVeGT9Ij2awkXl4qBXBAWL0uzs78YsUo /l9kYJWbQb6XrkDUbnfe72PtS839QNGtX1t6Z8aCvQf2poMbzPGL5bjNjtbfWl08QEMq +FD9snWnSiBfjfnQx84XxJ8UdP+/MgWNRoy17mfSL5UmV21Xbm+anEbXwfX8RcNiRvEI EUDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JmkM+Xjl; 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 z8-20020ac87f88000000b00403acaaaeb3si375588qtj.36.2023.07.09.07.05.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05: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=JmkM+Xjl; 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 1qIUxu-0000uV-5y; Sun, 09 Jul 2023 10:00: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 1qIUxY-0000Tc-8c for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxU-0000eN-7s for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:19 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbc63c2e84so40003315e9.3 for ; Sun, 09 Jul 2023 07:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911213; x=1691503213; 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=SPxXjVkEBfCIbnZstLW82ROIVL7eKNAPasvd0ZIUexI=; b=JmkM+XjlAgwR2ckM2fjYcVS5Xm7mQtpDjXqIKJqIG1ZreB5jTzQ00bRYn2kYXBPUws F4QCoag28Rxu73QO1n84ZMqF0ojz1vAAkuIpbi5ZXBQGB82CQzj75Kg5mDnsPuAVFQij xeAug9VHv9zFBbCGKqrJJlJOcs6eqNjt3qHEfeNBkX4pWFHpVvyTP520/yp4zElcYKUL N0TBpwzAmx4E5gFVXvn2rVYruCBkMCrq0Rgh5rSy3Y4/60m/FmnzuatM4IPFRf1tzOC4 XnCvxFp+r9OXvyK4X/rT9nXVX/eXKRIzVtaviRt+r7LbOWopHwqT6mbk5BfKH5aY1K/Z K3fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911213; x=1691503213; 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=SPxXjVkEBfCIbnZstLW82ROIVL7eKNAPasvd0ZIUexI=; b=OCg6kQKaSs/E272InEoEGHkaqKIcMOixpfhNAPqiXD9X5MFBxgsBh9LKYU9sbOt7gQ Y45AmeSc3lkIxjiYlj45xh7tRhX3POpLcT0eSPxb8V7HEtRBecUQvXp5t57OnkIYBSpG b9l88HyB3MBwYCVSkiXiMh8hIv1K+rtiP62sy4ZC2WIpa6cdw6MUKvfAuLBi+aAanF6o dENlXNdyMD5tZfD4vgbAno9dKxCbAwcOqlUBI0X94PjS+cl6tZMgWYdHjTOJX3+yKJZJ uZHbe2ewnfWWEO4WQPhW0LyaF46+YypVY68KEpfX73At+VP7LXmK/orl59SMMwjbvuQK C3fQ== X-Gm-Message-State: ABy/qLa9kCS2yte5U0h1dGdypKazGIA4dNbBDP7kt3BqQm4wD3M/C5gp lJNRGcPm4BAm1Tbv268ujWGZZVnlNtntGjyBbM9jng== X-Received: by 2002:a1c:7916:0:b0:3f8:fac0:ad40 with SMTP id l22-20020a1c7916000000b003f8fac0ad40mr8016684wme.29.1688911213140; Sun, 09 Jul 2023 07:00:13 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 30/37] target/riscv: Use aesdec_ISB_ISR_AK Date: Sun, 9 Jul 2023 14:59:38 +0100 Message-Id: <20230709135945.250311-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32a.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. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59: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: 700845 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742723wrs; Sun, 9 Jul 2023 07:05:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEQU9Atx7z30ArKCi11obV5K37rv4SfcqKtHUK0B2IO2DotAUJtP94+0CEIK2DgrjtXN4+P X-Received: by 2002:a05:620a:2684:b0:767:15d6:a276 with SMTP id c4-20020a05620a268400b0076715d6a276mr10600473qkp.29.1688911542221; Sun, 09 Jul 2023 07:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911542; cv=none; d=google.com; s=arc-20160816; b=M1YbR28TQdlSdtgrg6edXFpzzhSMd3d2heNe6HEQfqIMAQcptiTNsdfcHU8ADk+NPr cr8KYslT4zhjsbc0gaK27foCFLtc636RAaEYiIO7FbXrN+vuj6r5xBFdestHzHxHnOBr EAhZKF2wmPJtCXXUgfiS0zcETtpYvYHr/KNqQ+W9BTI7TuIJ/vb9op74Dxg8VqzTubXF QRzlaC+3bN7AOJyG+3QpJ2ZFKRXKqya8kQTN5shmG/q7mAv1TXRYTDV7RGrTQ+FXRBq3 eXW6wv6B2aRFNgIlzEW4iwJ4oXiKSZ/flqy26QRXSNPZ7sPOpkJpQpeUhdTP1Xg5gYje +65Q== 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=muoNLx2OrRgCzPDttQEHoOl2grqT5w0p62Pb+0kehUU=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=WPlM4R+fav4n/Cd2x2HiNkenn2lDFr8avN6gZBVcGazVVBKi5BOwe9sUmkkWdZFO1W ILAnLD7hJ2jvci50jQ4iLGUiKVI5tn0xlW+SivXoU7ZNwmGtlPr4puFTrFLFTvOvPDB7 c6v+SDA5MScE9Bu73FgGSi35Tda7LL2kCutvAkr8QN7TW/C39IU2PuWdHhAFXYWpG3H8 +7Gw13Q3hXIjOjJLC7sLMY4qkZEQrglzP+whhO7d0O1d37/Vct3oL/aMe3beYKKGmQPM gYaQX1MQT7ywkNgM3EyFPu2jVFkGb9B0fpDv1Zy9yTM3mjz6+O7OHcmh7zO2vJ+8jH4U YyGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LpwQbET2; 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 v22-20020a05620a441600b00767cf98a27asi474979qkp.391.2023.07.09.07.05.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05: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=LpwQbET2; 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 1qIUxu-0000ve-TN; Sun, 09 Jul 2023 10:00: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 1qIUxY-0000Tf-UZ for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxW-0000ef-6B for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:20 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3142970df44so3380040f8f.3 for ; Sun, 09 Jul 2023 07:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911214; x=1691503214; 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=muoNLx2OrRgCzPDttQEHoOl2grqT5w0p62Pb+0kehUU=; b=LpwQbET2QueCCB9bLH6Mpj1qA3yIApEX6mQ61Jd3c4ViJXtkaMxwo53UU8FoKy3y5d ifi7WIWDkRMDUvGBxJ4vCqYr+y35SdkSIi5pLUMXUtbdKOgeSSPN1MNMugYtc9QmHdXZ mCNzA5EhfjIp3w8KvS8FJdsJB/rHcgvnDcf/4E5X1wU36depjUtBFVoo3Lioodgxhngu yUZSbKIpwfCL8oJpCW2mpFFn9CPOTcVxCmtp5o9qM3l7eetrOU4LCWM+8mSICBRiQ94y 8Nb6nx/yZqDoPu23S6dmGw5Z6t+rC7wMNw1xos9VWW9GoTZ5oquUaXw41wXd4CQtfcIJ cYMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911214; x=1691503214; 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=muoNLx2OrRgCzPDttQEHoOl2grqT5w0p62Pb+0kehUU=; b=SHJLeGZCEKVRtBrpQuPZCePSfq4yszHrArAUcUc50O9wMbSaWwuJYvLqTnuZG5fh7r f6Q7wAJgdfxz3ikCO+ogIFbaGu4LvNelDjyA4KtDXRUQGOIEdri0GXP75DBRKJw7PJJL Gy6Trrq6P5T/SKJWLw+JJJQzDD/m80K6FNQHTuxPVhQAXz3NjY1Pcw06ilQDsbekA6G+ wtHK/jqe/gfEExE+CgHN1b4uJNz/426gdBXDC8JjBbHPW27y6RzYxq9Dd2HHJOTVNAXe Z0z31O8GsKDpg48vIOZH/7XblOMUczAK0PSQ/2Qx0BOOwGbdMbWt/W+cFTMS+TwkN2cc PThA== X-Gm-Message-State: ABy/qLYqFYQdNnXAlNTg7QpoWkV6GoIh5CFyDKlR2S+5g/iL+ZE9jWc4 0BqGurLbySmbVVdZp/Y1KM8lZ/mPo+AAZx9fXnRBuQ== X-Received: by 2002:a5d:5911:0:b0:315:8fc0:9155 with SMTP id v17-20020a5d5911000000b003158fc09155mr3235875wrd.44.1688911213927; Sun, 09 Jul 2023 07:00:13 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 31/37] target/riscv: Use aesdec_IMC Date: Sun, 9 Jul 2023 14:59:39 +0100 Message-Id: <20230709135945.250311-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x436.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 AES64IM instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700821 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740668wrs; Sun, 9 Jul 2023 07:01:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlEq0BFDdz0acZakXMOrSw99w1VKkNfgfBYzcCEjflndd5TrvaYOUVOzn5aM1bt5HI5CNbSE X-Received: by 2002:a37:f91e:0:b0:765:6994:3fa1 with SMTP id l30-20020a37f91e000000b0076569943fa1mr8136991qkj.43.1688911310074; Sun, 09 Jul 2023 07:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911310; cv=none; d=google.com; s=arc-20160816; b=mTio1zrBNCr6z2SnkBvfP/YB6VrQsV0V3LvZkXMx5sNHKQd+X1+Gem1L//1WluUy9U t4kY0DTyKz9PaONEbDoWY26DbYPre+PZXDq8/gQGQT3llvsyxIkDyCBXbVz3vuGLY8AA 09vLScjsjzCnk2RadJQirw5hiF64B1OD2PEbz2EoX9zXh9e7buWQqsSiClIU5B3VqRY2 Q2EOHEQVrzIWNiXgODm0ov2diDrCTj+GyMCZkmvSO7olm1h1vVHWlJoVUV7poXb/2UqX /FDU28E7/sA25o3bkPAez4WYaTYFJsmQImIaT8R0v/mofx8kk8v9EkE0CmAY48KMKWXO 191g== 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=ehiRk+/4K4ZdSH5tBEmArhhxk2Xw8P4NzuIBcv7dVgQ=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=TwCvUtQIetnShBc9iF5znGOs3HkSMNwz1xvD5zYGm5TLq6sf0BIPmSDAA9VsP8zFCA bs6Bp5J3P5+BMQVMjr/CfzILp6UCV59yjF1X1DiII/JkTK8Qu3o4udEfWah6OJa+KR4u oZe5xXvL3p8cmHmYAkmQ/S/LN53a1x6uYH3nh0x7V0gW0RCSGsxd+Xm/MHKA4mFpMzZs TKsVV/Wurmq4vXJTe3D0pGXclin2b01qZ8zZfDUXBIHKOgxUOj+zY0h3xAMjTjfVuy4B Yf/bhc9yOB50peObaCq3C4wUDBi+D3XjLCbZwNaPNDbYXubmwmGY+Xsnqjy2PPCLkHFj gu6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=drfjP0nS; 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 bi38-20020a05620a31a600b00767b74227b6si2851327qkb.444.2023.07.09.07.01.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:01: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=drfjP0nS; 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 1qIUxi-0000cZ-H0; Sun, 09 Jul 2023 10:00:30 -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 1qIUxY-0000Td-8r for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxW-0000em-4r for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:19 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbea14706eso36337775e9.2 for ; Sun, 09 Jul 2023 07:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911214; x=1691503214; 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=ehiRk+/4K4ZdSH5tBEmArhhxk2Xw8P4NzuIBcv7dVgQ=; b=drfjP0nSnJVGLCG7MaYpaMfCdaKDboTm3RCxwBSKBWUOtrmIIfyFJqx/D/YngHEiGg 7Ex7P7mFFQS8WYEiiNbjBB37t70GoRB652M/3tCW6xYluqpOi0Sn075w/BughIXNOI4V tbFi5RFIzu/QlbmRdvjW2J47zJsWb8wnug9ob2mQFoHyvsPXT1V/czb6t1ilivajCVB6 PVpf4TPM4TJCASkqV7oJmFGVVl2KYhyGTgktOb5n0IoP+rlB1rmZtoXkaceqVgAYSjBh 6scq/QpCUy+ll3k9Q6gUECYQwqKdDe2rxZcp/lGlyXomqpwu4mhKWAhlgfdtHJDWEw+r Wnyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911214; x=1691503214; 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=ehiRk+/4K4ZdSH5tBEmArhhxk2Xw8P4NzuIBcv7dVgQ=; b=NVbOiWfffUcg8V56z4kRO1pc3CzSYkZlY8oNGzhGJaKdaUeWB06FHFvgrweEs5FVEK ZPC5shRpvF4pw9GfLiwyhmnO7kNev0V/h9k3ruF1adHjEvAw/UegYYBnkXktOEbKbz5H 0fpgzUtZw9V1GI/YjnBQmopgoap1u/Kk4gp7rk8/rj3bp47lPK26WBO/gNS0+i2pBkdc 24UfFYFb76YkwgKlsMYZpY+ze7G6ihXji11SZvs+Dj8H+OyePuN0Iluz+JunPgqsVCNi 5eS4y71RhrNeCiXQiS3emFFeO4PnQ6vRmHVlxa7YM9dSCJ0vEArBnc7Oc0FpS4gKsXy+ Czfw== X-Gm-Message-State: ABy/qLY1dwJpdxtrsuUbo3Lc5JA4gcRFCWP/aehlROEM4eQvA/dhdooq 5q5Bcvvtq0bBd4h3ryZUpnHD0FAoJuBv6g/iCJfOOw== X-Received: by 2002:a7b:ce8e:0:b0:3fb:40ec:9483 with SMTP id q14-20020a7bce8e000000b003fb40ec9483mr8028326wmj.16.1688911214647; Sun, 09 Jul 2023 07:00:14 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 32/37] target/riscv: Use aesenc_SB_SR_MC_AK Date: Sun, 9 Jul 2023 14:59:40 +0100 Message-Id: <20230709135945.250311-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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 AES64ESM instruction. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700840 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4742400wrs; Sun, 9 Jul 2023 07:05:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8AwSRSetH0UXEuZBNiUwaNlkhs+yrnn++znTAx0zGesKeUenNJ4+stgvxGlGCpGsnMpQk X-Received: by 2002:ac8:580f:0:b0:403:3b39:45a0 with SMTP id g15-20020ac8580f000000b004033b3945a0mr13719412qtg.33.1688911503573; Sun, 09 Jul 2023 07:05:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911503; cv=none; d=google.com; s=arc-20160816; b=VCM4YRatjH9qt1B1OmP+dypuFVGIJUxCWFCtVMii/jVF6SpVAlRTyNi31L8NT9Z1KH Lee4Z58zyNHXQmmhvmbqb4Q+GDMtA8b/TvY3DbwIuUn2nX0YyR2n9qjOSDoC9IMaL+Rt VQrrZWeXZW9MKUwHl5xlzhr6Nw8U+sITPcSIL9JT3TnMi+YfFEqsiw20OwPFrAl4k7ny 5Teor9nKmDuCl8+Pi63d1bh4jwIxOEEIYGOGze6XRrx5wUjY3/4WfIxyoTOU2j/p5c56 ilDKLWhvOf+HEtiJklEV/+kPvpWugd3WqvjcoE5G5n8EOd4OApGA1cmvXLwF4fjfwI0x s9sQ== 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=UNvrPJBGJx5dGrfGxip7sDDn/+xiNFreEIZcy5LuLWI=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=hdLmk9QmtPdVfnvAXeNHPF1uD/dHdawgeKMaXsPpOSQzkb5Obnp5nrLJMcKW+p2Y3S MS9pLaijMuATPRu/zjk8o08keIkChbK04aWSqIT0KkDGXRF6iW2LqV27OEAe+4+KS2F/ N+lM4UuOgpZd9SudXChbWiWbUWKYrlDuL6r+RR9U4LA5nrw1iXlMFb35XdVVC21XW9vJ l72iLhReK/TxbasH/vvK0ih8oCR0eeSX30B2s7mpTUz6ioNWLAvXP5s8gFe9fs68kXQF cg0GkUU1CQMg6otL9eJJVDwmJRoRtDO9UcVZCp+FbP7VLFqX/wplxqDTHq45VJYMEPMd ANjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zv48CWl8; 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 f2-20020ac87f02000000b0040358f2660csi4658193qtk.71.2023.07.09.07.05.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:05: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=zv48CWl8; 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 1qIUxe-0000Ur-CU; Sun, 09 Jul 2023 10:00:26 -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 1qIUxZ-0000Th-1w for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxW-0000et-5X for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:20 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3142970df44so3380058f8f.3 for ; Sun, 09 Jul 2023 07:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911215; x=1691503215; 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=UNvrPJBGJx5dGrfGxip7sDDn/+xiNFreEIZcy5LuLWI=; b=zv48CWl8oDi9qBJaFDkRTHWP1ZYVinc4aKnbCxfAgjXd3YQGjqH7EiY988fU07K35/ V00uGoSHuqAn/bI9ykHlgIoEK1dIPWyL1CXp6qIfcMi7hsyo9LuZ8ycwm6XW2X28LU5k IHr+udPai1I0vE9kYENhlu6gSztIMh+QQpicbbjpZW8B7Hl6FTE+kbZaVfVFAAusTpvi dOHpw6t/dArcxcRDQaKOhgWpeKarXBbtH5o4JKE4vVKO4VroOK58OkE01Xa7D+XxOr+Q lVp0iG3u17lw7/mZBQNI6Aka0/c3qjhlA4bpm1zNYzFw1ghGoIGQ1DFBx7+/JECcLOqD dOxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911215; x=1691503215; 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=UNvrPJBGJx5dGrfGxip7sDDn/+xiNFreEIZcy5LuLWI=; b=iOxvrO4LxZ8Y74raFBcWTbU0vJfPGO4UStcM+6sifvZ0aOBxVOA22z/SRI6+8YYpRB UMHOSpEfDOdYrrf8qsqkptxr0zKqg3aN8fbgw4DlJCgMgMYFVLCTxAA2E7DNDOZAlUsB PufleDC1EdSYKZyIbdpK7RRYuofuyb5/h5JKzpxcCL8Lvz8jBuyKe+aR4FlvLe/O/BII TlvXZrjA0WXfDAxg/kMlc/xOFwZA2l1jY8Wl10ZZ3DSSFllnRmSXeYko073/HhYpFInb awetK0VtJZ7p98dTfxlOeB7gQ9SgptIyllVdxcvfi0c7diXZV+reWB8I+pVVmV4dC2eJ N2xg== X-Gm-Message-State: ABy/qLYUFpVQ26Sy1q+GYdcQ/+l5kRdJjSpV/RppUDvZOlCHo+IrJQaZ t7ppPZNpo0KUzIrSkZQqiU6IV2X+Xi745zhm+/zX/g== X-Received: by 2002:adf:da4e:0:b0:314:315a:93b5 with SMTP id r14-20020adfda4e000000b00314315a93b5mr8091387wrl.54.1688911215446; Sun, 09 Jul 2023 07:00:15 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 33/37] target/riscv: Use aesdec_ISB_ISR_IMC_AK Date: Sun, 9 Jul 2023 14:59:41 +0100 Message-Id: <20230709135945.250311-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x429.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. Reviewed-by: Philippe Mathieu-Daudé 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 Sun Jul 9 13:59:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700824 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741164wrs; Sun, 9 Jul 2023 07:02:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlFbEQmL5Kcq+1iE8OQ+oYeEMrJzk5vCQjoM3c0rpZD1fQy1FMHW6XUEdC3G92d+etedtoz2 X-Received: by 2002:ac8:5713:0:b0:400:a6f4:7a1e with SMTP id 19-20020ac85713000000b00400a6f47a1emr14531438qtw.24.1688911367207; Sun, 09 Jul 2023 07:02:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911367; cv=none; d=google.com; s=arc-20160816; b=ECU2CLAyq/pWJ/fJ8fHgfxCWDjl9pTwmj9SLC6XVZS4W5kx+DOds9qVr9jCW4RRGOm zAoR59y8gQNpPYEgvEQ2m9LlujQwQ8lkGVSi1kTltFubBdPiUu2HQmkMfgOEn+1R4W59 2C/JVN7Fr+kBFybKgsKRo+yscFyZcqmyXosFQlMWOoW6XpNXmHQCYwhib/ebkEHRN0VD zeIDHtWYuTzyt0UsRUb+bdV93rZ7DOKG19JcSvl7SVa3ueakep/Ajhs1IT/IBDCkTpKO ISbXlWXes4CkFbvo1vcJGu7JlNmI3ezIylJo+tDakW1dvtPGPU2i1vgx3CV3XrwCJOdP EYYA== 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=LO6Chl8aQYLOaHq+kw102b8WCIYofNouZUqxF+V9shk=; fh=4+sHc5gSB+vLQ14VCh2E8zYmyDBpEZkIg4SetDCy+NM=; b=hLgjXB3l4s7cb9NbnHitfoWrjukmdPtQhrhBtZhjz5OrYO83G/3fD4b9DGUhlum/Uq PrpORpVjW+aBldQPtdQLiKIj//3Zx5n356eLkZp4cPL3jEIQ9QaDoYa5uwwzAFUFhWE/ JG6Bgn1XQkiFYWCOEs7ww8rquqM6EUsTna4QV9x2CwHiAK2CNfwHOb2H4agfGqF7YL0K jrUv3w8XqSHRBNzxdKf81l+AkE4oeueSiE0iBIT6yZDi4uXnAs+hIu7+tSfSzIks1Ohj kujYB87Uuk24HzEVttNsZyXpdAsaI7DxTK8CcRuJHY0BJCI2pM4DQUexZhufYLHNruy3 blUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gl3oLWxK; 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 e13-20020ac85dcd000000b003f50efce557si4672469qtx.233.2023.07.09.07.02.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:02: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=gl3oLWxK; 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 1qIUxi-0000bN-6I; Sun, 09 Jul 2023 10:00:30 -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 1qIUxY-0000Te-Qm for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxW-0000f4-5u for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:20 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fb4146e8fcso27208425e9.0 for ; Sun, 09 Jul 2023 07:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911216; x=1691503216; 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=LO6Chl8aQYLOaHq+kw102b8WCIYofNouZUqxF+V9shk=; b=gl3oLWxKECjToR8Q7LAff5mTQBwoAraMppSlVJOiIAtObDzQwAP9shQ/CnX1w4YBGB OglhGL7H8cTwksAmZI1u5pibQBXDsXNeh29RxP7fy9voLyBEdlFrnHqAKg827YyFxwfs XAK//UTZA9Ord5/QNgvG67FVfp/HeQMp4OaSo+Yk+PVor8OHlXqh2am6CbhCaD1wzade YrINPzsw+wURACRij+lzcZRucsi7Jp3udO/nDpyrdWFhEIYDsISEAd2PcrOMD3jYYCZf 8wWNh2Z0NwvbZvFP3/+5MnomVVaHbGurVaR7b0uDepPtVQ3nz39u6KKZkuabphCmQZ1J wsYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911216; x=1691503216; 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=LO6Chl8aQYLOaHq+kw102b8WCIYofNouZUqxF+V9shk=; b=QaPPR/ZnSNrJ+YXRFu52YkWivJ6v7P8YvNkW7oYLTGh6UIh48vdkTYhuS8xyn8l4by H/IlPJP5tkzafiAmUthnBgenslY4v4vJI/th9/680/CgBd9sBSxbMZF2OgMQ4DBqdOFu UIyolRqhNyPpVmvghCbJ3zXDzf6qlevd+Fio/Trh/SmfGCVItDk0Llk5HMtp7/SBiJfa 1TMmBGeCwAwO0iIbT0jgtAY47BcDKHEeT6vIrzEk3bvqBxuQ8IVYaaTIvOW14MqLamJQ 6idGS9gehSWqsPDvqJ5A0u+wGBkSythcfF2QaPOJJiLsc+kCLYw7cMEm+vyx2fQMYsX7 xBsg== X-Gm-Message-State: ABy/qLaAcoyd8j1lgeQjBcj6g/rKtWYrpjxvfAti+E1IaBYVIpexEL27 67tGXN0l4nm9eTYKmBcSaCEVd5eMjyjkja4EBzgYNw== X-Received: by 2002:a05:600c:d4:b0:3fb:af9a:bf30 with SMTP id u20-20020a05600c00d400b003fbaf9abf30mr9450546wmm.2.1688911216306; Sun, 09 Jul 2023 07:00:16 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 34/37] crypto: Remove AES_shifts, AES_ishifts Date: Sun, 9 Jul 2023 14:59:42 +0100 Message-Id: <20230709135945.250311-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x329.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, replaced by AES_SH_*, AES_ISH_*. Acked-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 c765f11c1e..00e16d3f92 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -114,23 +114,9 @@ const uint8_t AES_isbox[256] = { /* AES ShiftRows, for complete unrolling. */ #define AES_SH(X) (((X) * 5) & 15) -const uint8_t AES_shifts[16] = { - AES_SH(0x0), AES_SH(0x1), AES_SH(0x2), AES_SH(0x3), - AES_SH(0x4), AES_SH(0x5), AES_SH(0x6), AES_SH(0x7), - AES_SH(0x8), AES_SH(0x9), AES_SH(0xA), AES_SH(0xB), - AES_SH(0xC), AES_SH(0xD), AES_SH(0xE), AES_SH(0xF), -}; - /* AES InvShiftRows, for complete unrolling. */ #define AES_ISH(X) (((X) * 13) & 15) -const uint8_t AES_ishifts[16] = { - AES_ISH(0x0), AES_ISH(0x1), AES_ISH(0x2), AES_ISH(0x3), - AES_ISH(0x4), AES_ISH(0x5), AES_ISH(0x6), AES_ISH(0x7), - AES_ISH(0x8), AES_ISH(0x9), AES_ISH(0xA), AES_ISH(0xB), - AES_ISH(0xC), AES_ISH(0xD), AES_ISH(0xE), AES_ISH(0xF), -}; - /* * MixColumns lookup table, for use with rot32. */ From patchwork Sun Jul 9 13:59: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: 700817 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4740100wrs; Sun, 9 Jul 2023 07:00:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlFw8ewYkohDKsTeY1pB0hLHawZGoCUUdJMFpu6E9BzHzaNGTRyU2zBpgtwbZO0LYQbT9/C7 X-Received: by 2002:a05:622a:60d:b0:403:aabf:4efb with SMTP id z13-20020a05622a060d00b00403aabf4efbmr1874681qta.44.1688911245938; Sun, 09 Jul 2023 07:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911245; cv=none; d=google.com; s=arc-20160816; b=sEw1U+9OVExGG7+ToayVsQa6e4KDK+C/izGp+e4k67N12nz+JbRkeBsdszsM2LgBr5 ZjiG11r0S8UQDyo0nKOu3Jhosv7U/uW2DVJMR308GxuDyR4Ju/8njyByS6mdLS2e+tbS qQZ1r7z3UMiiGAhy0mRfP1xLb/hkTnKQmmRolJzlvdbHjKeQT8IjrgylR++8wTm/f2wS SNM8ZN5dMNFby8shHr4AVEJ6XnH1pRzZW2kkwCyEa04eN09WGzP6ppSsuli96rdgWVw1 vunfh+SiURQJp13B1/GMHJDxlrHBCpf1zgCn60lBqVBEnbXPCWzwtb2r8qcgXhtI6dWw fTVQ== 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=KoRRyATrWAHPOTZCqqegjuftHV3UOSCP+hcOlJjHRIM=; fh=4+sHc5gSB+vLQ14VCh2E8zYmyDBpEZkIg4SetDCy+NM=; b=j9GwwPBg+ur16vKNdEr4QV1xX6T7KgufubEgdu/PY16TrQy9YopwZB3uMV3/0G8pbO VZIXINIciABA0PfyH5Mi7qVYw+aAIvcTREm9uMGx3b96i1M4YppHna6TpWDUyt32KRuH qMJYPy6wLGM7w4S0iUH1fThgwoOXjVt2wi1/L3dWz1OFzM2CHYxt0UxVrckgttO70XHH CY4uIxWUcjv5HnBvbRLJx+cuwCirZgf0+PZQB+ZU+wjkevj1HfGaiErTRntE6k0ftDCk eVzkGIFM8Z/TG8T8eWgexp1dMtX1jkWm01yWznNOH0YpPU8G25aPwl24asjkKJERFGaA cWLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kvZpIbfY; 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 19-20020ac85753000000b003f972544a27si4744202qtx.533.2023.07.09.07.00.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:00:45 -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=kvZpIbfY; 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 1qIUxh-0000Zf-Of; Sun, 09 Jul 2023 10:00: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 1qIUxZ-0000Tg-02 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxW-0000fA-Sx for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:20 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31438512cafso3862007f8f.2 for ; Sun, 09 Jul 2023 07:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911217; x=1691503217; 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=KoRRyATrWAHPOTZCqqegjuftHV3UOSCP+hcOlJjHRIM=; b=kvZpIbfYGNIy+I0rYdHKhsssTNTeTEPeI1zevU6MZmSvx43gyg+yzp/k8kWxhr1kQ9 9XMUVORgLe9izVrkXwmjNgDToNqGs+CEv06mEsP+cC/plk27PNCTKBQZ7qAUZJgFayXS yIYutJs5Xa4gkuXm6ZybTn83C0dMpDOEYMGjJ0Lb8ftsvIm6mciLV4Pvdi5qFQfoD2nx DQ3bNw0FhfBVC5PbbTW9GTUReWfslLHNDfF1Z+flcQ0aw+znxySHEkfr+ElbR/Lc9dS3 BkQEgdmJxYh0magkCY5AN1DknLOmTrUcqu0XgxsDJfBYwFtLefU86Yf/oB/mXhQTu9QF bCFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911217; x=1691503217; 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=KoRRyATrWAHPOTZCqqegjuftHV3UOSCP+hcOlJjHRIM=; b=iEbULeJ9v8vI+G1FGNw2+fzugx2hF5LFPdeZubWF2c4v3Fh95OlH10ezeCZjBjyiGC DoJlPErV/X+B2Yy/dL0y8n2Y39GWkEvuY/nuVOe5kRCFsx3IjK5PUptrYKTXi9xdnZHp V/bZ2nQmr5ktp8VLvD2VO1WKJHLTyfsuF7tbK5PIdzTt22DR2xI8G+u6js/oazSDfjZ7 ykIDYgztjJZbzSjgW/eQgP0VtSejQGDFxz7qyg4jPXztByBlWZLl7fFuJ62lpeQWx42I PVDkgDMG2I8C6Xy51to6xE9wbHXPZl8YeJ3HCOoXfGyOYXb7x1o30cQ8j/HfJ+mz5sTR sgEw== X-Gm-Message-State: ABy/qLYzmqeyK800cGDwHSdmi7UrAnNd0j2rSovodzdpATemrBxbab0a hTg9rwkeLswEbfr+MyByTSPb7cACwGxA6DHK9otQUw== X-Received: by 2002:a5d:428b:0:b0:315:94ea:31ad with SMTP id k11-20020a5d428b000000b0031594ea31admr2199514wrq.66.1688911217059; Sun, 09 Jul 2023 07:00:17 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 35/37] crypto: Implement aesdec_IMC with AES_imc_rot Date: Sun, 9 Jul 2023 14:59:43 +0100 Message-Id: <20230709135945.250311-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.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. Acked-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- crypto/aes.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 00e16d3f92..d93883eb18 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1377,39 +1377,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 Sun Jul 9 13:59:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700850 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4743157wrs; Sun, 9 Jul 2023 07:06:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlEO5ZZYW0s6XFpZFGcS5NUp3laS1lTUfB0xp2LdptBXE6JieReqblLYR6pmPTfI2qCfk9N+ X-Received: by 2002:ac8:5942:0:b0:403:788f:5d0e with SMTP id 2-20020ac85942000000b00403788f5d0emr11081861qtz.60.1688911594574; Sun, 09 Jul 2023 07:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911594; cv=none; d=google.com; s=arc-20160816; b=LrFi6/tcAyPadieBvpPE/oDxVGcwAmBdnO9qV7gNxKFCPHzYLEis1XqnOlenjKh42P In1N4dCkxt2vllEg2Jrghm6cLlG3wABkdK1khNaJPHkrE2FsAJ6mxBl/wgMkefa8jwNc W0AWb+rK2By7F3L7aJ+gUslW5t8vwpChBhA+EAw7vV5auLjeFHNu2h6/klfL73NF29Wh b0HJot9O6cfUEkdSZLUmQ11hndksrQKCcgz1e18MyGJkzGRhxiqPgbPnZ2qlc7hfeaXB uqvHXuOk9Z0GSj0PvZEyC+qhkOeNseI6nbFqpSOn55usAFyUZ23CQrqVw0Cn3fXltxa7 vR3w== 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=QDJWgUvS8Zs4L2lTferPtp1fyLNTd5LXy05o4rblG4c=; fh=4+sHc5gSB+vLQ14VCh2E8zYmyDBpEZkIg4SetDCy+NM=; b=kZW+eE56NMXuoajwUzoFTdOGXmsrFgHXoJ94dSXCpYl8pRQhKaHed2BfDwSwBR/EMN lUUjM2V/UdcJz4k6qpSUTzRFZGYfAWRJBepZKypMpXL0HYcnEDdJ8qXLn5vS1i/Db5k/ fiEXCW87LkQ+Z96prcc8isEVmSjcg7K4pbvkhqgEcKevK5ady5j3dILGdK497Pt4pt5U w/WWH5BcphDINOcQBGLBDOgHnK81jC6yasF+Eq3fP6lTj4De0uRCvyNRIwYWK+8PtH+W p01h9usG6m3LcAJsE787O33Ovaq2fyFEK7LbVswWM/KktiR0Yp8TCz7+D736vjQ68gw4 Dm4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UtbXrx6m; 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 m9-20020ac85b09000000b003fddb499f7esi4750208qtw.751.2023.07.09.07.06.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:06: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=UtbXrx6m; 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 1qIUxj-0000dm-0r; Sun, 09 Jul 2023 10:00: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 1qIUxb-0000Tp-7t for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxX-0000fx-92 for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:22 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbc5d5742eso40000845e9.3 for ; Sun, 09 Jul 2023 07:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911218; x=1691503218; 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=QDJWgUvS8Zs4L2lTferPtp1fyLNTd5LXy05o4rblG4c=; b=UtbXrx6mlJE7C5PG7Yb9SjlZDNHkUR/UlMWhmJKT60CM6KsC4INImfvn5IGSF41u5T o1dckCsX9CRed0y8mBADVzo2IZEXXgH4dlqzwcwhSRTTtuarDpk0PlOCsZH+qg8wPf+2 c4YCQxC9KNP46cVuF/Iv+IdvlISkhvdDSsEtmB12qITaooNj/t3lMCZZQ4KfH/famoOi TWufg/MX/AMWcn3Yz7QYe+bu4e6l9/AZxGp8BHnKvU8HdYtYe0HCaqfpF6GlBn3H7Z4D kd5qQJvXs/5ujGipsutrbD5zqt2Jhk2t8zUVw4SpfjlhXUvZ3fpH4r/nLRHuRqytlM98 TQlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911218; x=1691503218; 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=QDJWgUvS8Zs4L2lTferPtp1fyLNTd5LXy05o4rblG4c=; b=TvOUiJyfSFM2/SX+uWjo2DVKxn/EQpLzlPIuDkkC/57lFZG92j5J/zcBrSI12mhuKg Q36/8Q/4RvEtTkLG2bSNt3poENXcoqFYh7BGdesk7RAkay3nnaldvOoW4lUxG7fwdrbl v5iqkgtUKYH4QIR+WvIVJ3zurW6FRDRA+7RQ62m+ODSdgud9/7+2C43c4q+gl3Q9z/mV Fck+OXDGONvl2fcq5s/PsvPs2kOIrV/UwraF4xTDtLKT6W6qXNIQ4g/O4+l62Og8f2Gk SQAUf85IK1M3YmWBYZSWmx4sqYFif65qSe4PQLGsKMFGACDQaxGKBu4lE7Wbx5ok1RdI TdKg== X-Gm-Message-State: ABy/qLZFC0pLiLohr7ZFC07Cx4kTyOK7PgmBPFFpG7rn0esX/VBtbkY2 IGPvkwdnqVAA86wMe6Ef0Kn7fVhGJdL5aF1cLHCViQ== X-Received: by 2002:a7b:c39a:0:b0:3fb:ef86:e2e with SMTP id s26-20020a7bc39a000000b003fbef860e2emr9594442wmj.19.1688911217949; Sun, 09 Jul 2023 07:00:17 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 36/37] crypto: Remove AES_imc Date: Sun, 9 Jul 2023 14:59:44 +0100 Message-Id: <20230709135945.250311-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x334.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. Acked-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 d93883eb18..685efbd583 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -257,270 +257,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 Sun Jul 9 13:59:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700828 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4741722wrs; Sun, 9 Jul 2023 07:03:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSJSdDhWvH+oeW0MrwPtBwMkP4wEes7y68A3dnuYsEZSVpgHelFypubehBYx8A0+StDndB X-Received: by 2002:a05:6358:999d:b0:134:de8b:17ef with SMTP id j29-20020a056358999d00b00134de8b17efmr7220074rwb.18.1688911423785; Sun, 09 Jul 2023 07:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688911423; cv=none; d=google.com; s=arc-20160816; b=zVcaUv111JA/octqrGK9vT6I9qG76/sW/yvIcyhr+/KJ/7YHbVrCn6NvQtAuLWdpWV GZsDjwpY8XBV7aZebWPy5lpY9a7gy8fm0nbjxZUzVfQVTgmwrRdxXvvnte4NIgJYbOT5 zZdClz/51u29NPuaYtKl0qD8eXxO1FIzmrQmq1JqqQpNG0vgAbPdS8v6KJNAaYB1dnS/ 8bZrHQoltA0Hzofk8U8Xx0IdrH/+4sIRIGU0LvbLZ/WmboGWWkUOAZWR1miHWj1ofGxt 7HLTDyeCNGtPBNFjfN6u1OvjJOgryd7Hk9BVuVYwqAxN6HUfg2pw2ouGHjYO062Ju1w0 2zyw== 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=1F2YVr3IWQtmqpjJeR+MoFqCj9awn2sZVMTfzE1Dbtk=; fh=4+sHc5gSB+vLQ14VCh2E8zYmyDBpEZkIg4SetDCy+NM=; b=WnRmDm96bDDcVVPpvxdvJ1O3utg6Xhz/Zv1CuwTkhk/t6W9wtNYlKflIAtJ3ZOK/2n 5Cxb0bcKt+BL+tJsUQrrAM98FsDDbvlYixwF1Vx6jN6Fpb9Vw8RuEQ8qvC7eCLgTtVUJ kh6GaDKtj19m1t+8yCV6XewvzIrGnJ41ax66l0lQ6ytigmrmqnNCfcfygjY+d8e7WaLW Sv7mnU1X9abGj2awFsqyXwsJ93bbi+K5ATt4RgonXhwDi+tzPjMexUObxQQKO/G8lVFn W/DREnX/mNMNULEIy4+1vbuOt/OE1Fx7JlFwvXKNNx2gmRmySIsUgXKR3RSs+LX+6kwr PIEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dU2T5oyz; 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 z1-20020ac87f81000000b003f548ca984asi4788844qtj.604.2023.07.09.07.03.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 07:03:43 -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=dU2T5oyz; 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 1qIUxk-0000g8-Id; Sun, 09 Jul 2023 10:00: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 1qIUxb-0000To-7G for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:23 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIUxY-0000gA-1c for qemu-devel@nongnu.org; Sun, 09 Jul 2023 10:00:22 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-314319c0d3eso3869740f8f.0 for ; Sun, 09 Jul 2023 07:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688911218; x=1691503218; 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=1F2YVr3IWQtmqpjJeR+MoFqCj9awn2sZVMTfzE1Dbtk=; b=dU2T5oyzhOIeLYfE59gHgiR/qMCRsNxJB2TKzHqlMq4/EtZCcJsYa9HxnLAEku4a5s JKNKVh63mHDzLRoZlsyHjFUXxPkPh/jq++sIdl+n/J5+jL6/sdKSD0mOu2b74MoEyW/l AIfq3eHLKUVLNpavjWn45dsP6dygd3dHq2HK0V26AGqEmaO3FCMc8tqL7Ezqmvs0bkuK EPou5BQz2DRHocgqLkirwqZoys6O3vqvFPmmtAyUGSGzeh/Y8nrCAH+GEeacdCM5TAXG RwLSVpo1UzPg2cJvLtI3pu5P+tiBou+NeuYMAilcfYHbnU0AUwGB+JAVXWSIBbedNRAP DQOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688911218; x=1691503218; 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=1F2YVr3IWQtmqpjJeR+MoFqCj9awn2sZVMTfzE1Dbtk=; b=cqH4ckAoLI2dIEahe/yRnpn/BxYYyuQ1WEhccvI/EiFkNYEt6YcC9lWY9rNwTpY4SM e8HlE8aXiQJYg04kji1fOrBC33S6iL7MZz2yWLHV1fQgQuFPY7W6rQ6IbiR35kdNKbh+ vIJCXA6HPWGba1NxDCqU6LKtNnQ4xmY7Hjmyuk/tTdpQABvgBzbiWv6rOnzqPXziP/ea uu91gXrKGVa7RfxcTbvKByFbYNMRPwhTKTuGDdWlDbabPXTR0wDAa9NI0XcQ/gQIiE7k aJ8x4xTNECCA9pyq8gmPzSAivaWVvmksT+fGpHifsox4ib68hcpp2e2QELiGLUC8apmO EhRw== X-Gm-Message-State: ABy/qLbj3teERqtihpJYgsFcocUfshoeTJIa3GptqhcbEVwG6JmK83FZ E5W4mVV7Mku/N+4EA6nOkhwPHdzPsoUntNgY0c+6ww== X-Received: by 2002:a5d:5913:0:b0:314:350a:6912 with SMTP id v19-20020a5d5913000000b00314350a6912mr8365645wrd.36.1688911218749; Sun, 09 Jul 2023 07:00:18 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id v18-20020a5d6792000000b003063a92bbf5sm9239422wru.70.2023.07.09.07.00.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 07:00:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 37/37] crypto: Unexport AES_*_rot, AES_TeN, AES_TdN Date: Sun, 9 Jul 2023 14:59:45 +0100 Message-Id: <20230709135945.250311-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709135945.250311-1-richard.henderson@linaro.org> References: <20230709135945.250311-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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. Acked-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- 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 685efbd583..836d7d5c0b 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -120,7 +120,7 @@ const uint8_t AES_isbox[256] = { /* * 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, @@ -190,7 +190,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, @@ -272,7 +272,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, @@ -338,7 +338,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, @@ -404,7 +405,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, @@ -470,8 +472,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, @@ -537,7 +539,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, @@ -603,7 +606,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, @@ -669,7 +673,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, @@ -735,7 +740,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, @@ -802,7 +808,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, @@ -868,7 +875,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, @@ -934,6 +942,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,