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;