From patchwork Sun Jul 9 18:28: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: 700856 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4827357wrs; Sun, 9 Jul 2023 11:31:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlFsAQ3txA2FA9RgL50ZO/0nT7fUKg0CRAyhvT3dJ7FoR0rAZqEoT18bQsJgum6xH5hh51c1 X-Received: by 2002:ac8:59c1:0:b0:3f5:19e4:34ce with SMTP id f1-20020ac859c1000000b003f519e434cemr12635113qtf.48.1688927518616; Sun, 09 Jul 2023 11:31:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688927518; cv=none; d=google.com; s=arc-20160816; b=RdL1NOfHFr8DqOLxhOLWmRQxLcYoawMrhFa7vlbKxbLJEyRPC8bRK/nqURrci7A2Ki r+aXvaPhEQbwbDA4KvfuNEfM8oO9S116HdDX2iu5rfxRikPzWRt4NLV/YSkPQYAAJC62 STlCSBJoTRA+dHwmx9BS+mxOdjBAxglrJzVSC5yDWMafA+L4M9j+Bi38RBjfDYrnmjqx rsu+078JkGM/MMUA7k+Y87CnAga+HnB6l0RNfjHAozAeVnWIcgViJZ+UxvVffqTeg1Kq /9AXGejOKL4Eahrs/DHRGmcAxMtxSWuzwCs7mlrMAoh3qo/OONcUa70nc5HqimcP3w+T MT+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=gLgfXZyf9aATX9TfQItUdKukGg6cdQDyWQ8EagJh33A=; fh=lMWaYJWKNNp5se7C5JIc/IAy1MaLsIKSBhk4MhqnayU=; b=DSAczTE3sB5TvHdBblqjnzojij0mnZ7EADkxtzUe3vMZuzAMP9z8Iq86WAqhfVWBNm csHH5N12UsCA041hNAx9ZmE9Kv2T8pAVXYDCrONzxcmBbS+uBq/JMh1mfUmbuVBWFiRR HGDjYorpDsxRyFCnwWptXsSILQS5+vDjLFk9K9bZ3qkEzIYkUuYqEn18hBRqxlTbLzMt mCgDT7lf/ttyIPjp0+RYjnSXwAZ2y4t3ttXUuUb6O+/Mvib3zGgqbU1OLeEQniBX/5/I hURq8EEtt5GXvWgmYt1As5ndwQWN8vXH50Amr7MUvrIE9ftTePOH7wyYIPJztzyPLktk WyKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iAUj9O7+; 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 b8-20020a0ccd08000000b006261566ac3asi4778860qvm.90.2023.07.09.11.31.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 11:31: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=iAUj9O7+; 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 1qIZAU-0008JE-6x; Sun, 09 Jul 2023 14:29: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 1qIZAJ-0008EP-9q for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:29:48 -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 1qIZAG-0000E0-PC for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:29:47 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-307d58b3efbso3573397f8f.0 for ; Sun, 09 Jul 2023 11:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688927382; x=1691519382; 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=iAUj9O7+LFwt3Zf+ETwt8UG82wsavqE/EP9S3iITcm5ub39DVylbXA/wARxo1Le897 BtyzUn3DcgjPfqCwm2dkSj4zTWwdk7V0UJ8WzF1T0Xdmkp/VUKEyORUfBPGJY4B++v2a M2SmjClicyQfkAORq33hNNTGiKZWsTJ9xHowVjC2fZft1W7iJL9aLVvRFYmvfYBFb0pT Xk+BCa9LHmOkjeTCDj4LUaWlm5O4+crXZOVg4qRxIxbL8YbXju/arAL6OJJXvoTVczc1 netakwK5hgyTq3M2u/5BzTC7cueX+4Agvr/92h7P+/rYI7Iy4OZlFOVOFWW0D7DEtVzl Q0/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688927382; x=1691519382; 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=i6TbulDW38I4ZSnFQQm0o3pZFeMHr3IahvjB9niyJU4g9iz3dV/ufoU0pZYTENQA8I V1Tz1NTBRfLAFysHQVB8DC0WWmZf6Dp4OYFHLA+JTOOLeMXBxb8BH75S5XUnzgVeP+n9 qT7QPdKxp8AXkfamdfUWugrh7V+RDmeN+dfoVLDfUiHOmTSFrWL0IpxjgvrlgdkptSR6 ko1CdR6ehkovBs6qsr23xF/F6FsmDLANE3DbGpQlbutMTvt3k7WpefVu173jEP9O5siN R1kElUpLkFGxlB3ft4gnLnPVBjEeT0BhnfEJNhAnVm9zXXlb27sOPnEliBYDBjetPqEZ 04Dw== X-Gm-Message-State: ABy/qLboUC69hUbyfJfb6A4aFX26cSXkl5Hepu65jPhjnlTXMjmVcFAx rBrH4+mggOVRl2vffFpD6DnuYHpm+5U6xkwCpVqavg== X-Received: by 2002:a5d:5303:0:b0:313:deda:c444 with SMTP id e3-20020a5d5303000000b00313dedac444mr7925547wrv.24.1688927382497; Sun, 09 Jul 2023 11:29:42 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id q15-20020a7bce8f000000b003fbe791a0e8sm8317108wmj.0.2023.07.09.11.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 11:29:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [PULL 04/37] crypto/aes: Add AES_SH, AES_ISH macros Date: Sun, 9 Jul 2023 19:28:19 +0100 Message-Id: <20230709182934.309468-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709182934.309468-1-richard.henderson@linaro.org> References: <20230709182934.309468-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 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), }; /*