From patchwork Sun Jul 9 18:29:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700927 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4830534wrs; Sun, 9 Jul 2023 11:44:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlEPLOWUuaZB0XxBf+LybuDcZTx2k5yAu0OhWFCmfFSgdcKtDptbqwYkKGciwsud8nvu6fGA X-Received: by 2002:a0c:dd8c:0:b0:62b:33fb:d04c with SMTP id v12-20020a0cdd8c000000b0062b33fbd04cmr9501693qvk.31.1688928270839; Sun, 09 Jul 2023 11:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688928270; cv=none; d=google.com; s=arc-20160816; b=BfKAO9etlxRsZjEXdJGRKzE2AVEt8Q/JrZNrCDZ8mR9L562D17yLkgZ7jRaCsCBjSX GcpzcduP6lODUV9ipkVZVjsyKXHXPX5yL8Gtgi7RnWeKXD6gY+5jhzj8353bOysvoL/z wSjnPmDjdhnwybVKkz2MR201aYOCaPEreZB9jXtilF4fcBO/HAF9IqdOJjjC15jN//At lEaTldFMmzL1yIetz6/KY4Gqz2Q129zR7VzclMYG1dvucGqSyjFdow3KU2rTVJMkrUSj pT6CgfwjKAaSuja7hFoZlJfJXW8RHKUkjWndhGhmihuUolt8lRoTEN/eCE+9kBsW75hU Dp3A== 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=lMWaYJWKNNp5se7C5JIc/IAy1MaLsIKSBhk4MhqnayU=; b=Kz6DY4aDL1lLHLPS7g+3ed4o83C8yAo8TYan100Uu3Co/ledxODfnN42buZVHifkDd ge4vNJ1l9Q/xxNZS1kXj8BB9bl2Du6D6eIXb6bEF4wt18Am9cBkELpH1mo7zjw8O64j3 d1JFv69HJAejdtzdje0r5wb8V1q/r9waSEml8ukX0bFKBq19a1OaLfDcw72azF4RC4Io W14KbtN7G723Yc04D2lnDnb2QuoEB9EK9pfUrqVnNpuB7fmzsl3TAC3P0UPDbu1NjJvn CGLd4IFMEd2FBNrD8T1a0d2IHrTrncb1yDfhtO3vQRRYqFVi8j0v/RjgxHN1wS4yfo4X xsfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jYEt8ghh; 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 b17-20020a0c9b11000000b00625bb5fc662si4809869qve.232.2023.07.09.11.44.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 11:44: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=jYEt8ghh; 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 1qIZEM-0005pX-As; Sun, 09 Jul 2023 14:33: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 1qIZE2-0003gl-8d for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:38 -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 1qIZE0-0004I1-Ip for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:37 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbf1b82d9cso39263965e9.2 for ; Sun, 09 Jul 2023 11:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688927615; x=1691519615; 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=jYEt8ghh2tTy4YfzkHOmJk71IGprWwIzM/TcJt4Wdps2hJpwjzQomwm0ecLfWq5Z1I k7W+XJPPXBwigCehQ4K5wRiNR6/lnR8khleqGuHqgxnFeN4nQF94HEmH88YZ8wOmz394 Lbd8cuuC7P1DAp7NEyNkSQApQ6H3W727Wwa7DEw3NH5secY6saadfk4FprUlznOwX2kI 6OVDQAhUVLBgKa/xNys1gVvAxiZjS/UOEXg6mFwShky3Q3rQ4AjNZc0/6w7fYUPUFp4L 74JuTQdv2mxOeu09HjOrCSScIKaNa1v/SWaKq3ciZ9dGjrB1wIW4EjyBI/7SjL8bUgyE aUbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688927615; x=1691519615; 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=SDcavctPlo9A8ibskGv1fXm1a2qPdcLK1I70+IyjdFUjEAQeaALg1Du3B8Al89qyXM SiXSMHtfrnsa5rwg7O6g4dBguIwBFsXEdVf4Tgspu5pqsy8tzfUTGcxUC4JfGrcj0J/n 0TKktX7DHEq+88cuvnbAQv67rrePNRqVnn5yL0i2fL1s1n3u6UxfIX6KtIhBrv3iiHNF AYJxAKep2pWBhO6cct5QCVwjv7rP6Hty4SHrFzzM+jAUJ8dbgVEp51Vw7YD1dVOYoNpo ZRV4gHVipX+LLVOazpTocwKqi9NWMdg3Y+rT33xIVVHNUIuv9oPRZDhF8AkiSuFV4TfD 89kg== X-Gm-Message-State: ABy/qLaGgR4//CSxUOSBtEurv5iyGjl6xpQI8O0B1QCZczwrmUrBxMN7 S0/E3Jn8244elT4V84+tCjsqDNyZXDH6qN+a+Cu8nA== X-Received: by 2002:a1c:7514:0:b0:3fc:173:b670 with SMTP id o20-20020a1c7514000000b003fc0173b670mr5082965wmc.41.1688927615347; Sun, 09 Jul 2023 11:33:35 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id e17-20020a5d4e91000000b0031433760a92sm9635256wru.115.2023.07.09.11.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 11:33:35 -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 35/37] crypto: Implement aesdec_IMC with AES_imc_rot Date: Sun, 9 Jul 2023 19:29:21 +0100 Message-Id: <20230709182934.309468-70-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::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 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;