From patchwork Tue Jun 20 11:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694483 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp247036wrm; Tue, 20 Jun 2023 04:16:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kq+HH1OAotmHLq1WWpkhK//Dszrkn2icpzJctC35ICBSq8ZtmJcQsznkjTaQXfs37Z9ke X-Received: by 2002:a05:622a:1392:b0:3fd:ea62:bc3b with SMTP id o18-20020a05622a139200b003fdea62bc3bmr10412102qtk.33.1687259778146; Tue, 20 Jun 2023 04:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259778; cv=none; d=google.com; s=arc-20160816; b=zoaRaUNtrIcBHz7qvBXknToTZiBgtOae+VaLbYXhMm9gxx1Fucm3fCAeK3frVLJQvK DMNlbgOpRR6jWYvMUEhL7b1pnlvKCnI/EDemmOrDWD2Ogj/xO8yJD/01kt57XL0waJjo mc8RqT2NyrqdydFQ/4JgyAqYELdV0SMsfY/fkBJWHyS///iOwLEHSgjBGfkUV7EfSR17 UvWRqncH/2g3qh5LmqBA9DV/FrHO0JFghSQA/cCyUCdXqsDGSkcPl7VcuXpnYxHFvH4a fZHlW1WuUX4blJvcMPF6BJ7VQ7vTFVumaBg0kieE6bcepRfcy/8NW7yJUTAQ0YwxMgmB j3Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SPTofI9JsvJrrcptDf/DV5w5SQH9XzTd4Au47XuO2js=; b=EJnBrQVL2PjM5+hbXD2Z9845bgo1ZRa6OWNNACWt/AH6xtnMbgclFuyJscI1fQuJFD ceVBzkHJ/ZRcE/psg74sSUeyzJUpM/G1Lcqk3Wu36BtQnsprUBPv/Lv8D06u89gBS7iQ SylsgRK2n/joBmNhscWCyXFjdiJF632FocMR9GrrlpmZGYWSzcW2ebCVyyL93VdwQm9l /LXV5iaMYZtNxeqEu5hSoPB8mGF4JyYmsJMy+rrxYcVZUyflDAY7yWyLhkd5M4c+jz98 t8AnZskdGdfcmngLU7TfpKueK07m4Wl7GIwiiAGROL0AUkoMKJzH+flI/GJo4tZOUD2+ yQGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gPIFjYXT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z13-20020a05622a028d00b003f41b7430c1si680663qtw.608.2023.06.20.04.16.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gPIFjYXT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qBZEQ-00078a-Vx; Tue, 20 Jun 2023 07:09:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qBZE6-0006ft-Ff for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:46 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZE4-0004XL-5R for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:46 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-9887ebe16d0so334651466b.2 for ; Tue, 20 Jun 2023 04:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259323; x=1689851323; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SPTofI9JsvJrrcptDf/DV5w5SQH9XzTd4Au47XuO2js=; b=gPIFjYXTMHbhLGRAx822xADv/NBe6+4/86riiKtDe9ZVPuEMKaykUORVhCgZC2Bmgd aoEtrzDGVdF0AHSvY7kmg136hh6RlVLhXluWyyYKdwpS1VazATY9bbDdOtqBKnMMfDbg 6Bgugp9qIEHR885O2kYH0FOSvRx34h093Qjb7uN58K58LGIolwEs8J7Ljd4w66gGnVS0 qOeX5xSTkkfWQwGTpFX+egH++nAyFOBylBOb+2xwca9IFwJPiR+Nqw2oYHMpiBHnklNg cvPjVahcWu+0P2kwQcueCaNDt0DxZWEwfHAtB7hSaDgBjw3T7MR7wHhjzwcVm1xP9SRZ CyUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259323; x=1689851323; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SPTofI9JsvJrrcptDf/DV5w5SQH9XzTd4Au47XuO2js=; b=U9a3Ei8Wz3rh0QGV7tAGxTBMMGjGzc7PQdvRZFXyfdYYGWknZf+Pi/pJyX9Nuh1Q0l 7jDjkKCdsuuL8SYvvDPx7CInRJ4FjvKKkMUJWVy9dyd2tle0EcxHurvA2BIiIqDPJEm2 ++b5emO+pKwgQL1CqGlxUEkxm1YtfykzFZkrWau8YC1rzKM823mRuKimOaQeoGWTFcaH C6jFV7LMy67rzJFVgWZiRs2IBBt+Zj3rkB+uXxlYfeUEwjrThnL9YCEyJbF3ik1GXNJk DXkf/+sR6VvXHJ/WgRIATdMJumYAcwbtZ2SXSLlV8TSxWIKKbyKGX6cIC31yP3f+03T3 NMMg== X-Gm-Message-State: AC+VfDy1s5dse0ZHhvegnaUnB2lVt9qzTXbkerydqThF2WuDREz2R4Fu o7BdFhLUydrJ4I5DYjHa7qknauCKVWSEghKZIDcjbW1m X-Received: by 2002:a17:907:2d28:b0:982:6bba:79c5 with SMTP id gs40-20020a1709072d2800b009826bba79c5mr11745289ejc.72.1687259322836; Tue, 20 Jun 2023 04:08:42 -0700 (PDT) Received: from stoup.lan ([176.176.183.29]) by smtp.gmail.com with ESMTPSA id x17-20020a170906711100b009884f015a44sm1170687ejj.49.2023.06.20.04.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 32/37] crypto: Implement aesdec_IMC with AES_imc_rot Date: Tue, 20 Jun 2023 13:07:53 +0200 Message-Id: <20230620110758.787479-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230620110758.787479-1-richard.henderson@linaro.org> References: <20230620110758.787479-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This method uses one uint32_t * 256 table instead of 4, which means its data cache overhead is less. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Acked-by: Daniel P. Berrangé --- crypto/aes.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 9795ae8614..307c27947c 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1411,39 +1411,39 @@ aesdec_IMC_swap(AESState *r, const AESState *st, bool swap) bool be = HOST_BIG_ENDIAN ^ swap; uint32_t t; - /* Note that AES_imc is encoded for big-endian. */ - t = (AES_imc[st->b[swap_b ^ 0x0]][0] ^ - AES_imc[st->b[swap_b ^ 0x1]][1] ^ - AES_imc[st->b[swap_b ^ 0x2]][2] ^ - AES_imc[st->b[swap_b ^ 0x3]][3]); - if (!be) { + /* Note that AES_imc_rot is encoded for little-endian. */ + t = ( AES_imc_rot[st->b[swap_b ^ 0x0]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x1]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x2]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x3]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 0] = t; - t = (AES_imc[st->b[swap_b ^ 0x4]][0] ^ - AES_imc[st->b[swap_b ^ 0x5]][1] ^ - AES_imc[st->b[swap_b ^ 0x6]][2] ^ - AES_imc[st->b[swap_b ^ 0x7]][3]); - if (!be) { + t = ( AES_imc_rot[st->b[swap_b ^ 0x4]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x5]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x6]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x7]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 1] = t; - t = (AES_imc[st->b[swap_b ^ 0x8]][0] ^ - AES_imc[st->b[swap_b ^ 0x9]][1] ^ - AES_imc[st->b[swap_b ^ 0xA]][2] ^ - AES_imc[st->b[swap_b ^ 0xB]][3]); - if (!be) { + t = ( AES_imc_rot[st->b[swap_b ^ 0x8]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0x9]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xA]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xB]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 2] = t; - t = (AES_imc[st->b[swap_b ^ 0xC]][0] ^ - AES_imc[st->b[swap_b ^ 0xD]][1] ^ - AES_imc[st->b[swap_b ^ 0xE]][2] ^ - AES_imc[st->b[swap_b ^ 0xF]][3]); - if (!be) { + t = ( AES_imc_rot[st->b[swap_b ^ 0xC]] ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xD]], 8) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xE]], 16) ^ + rol32(AES_imc_rot[st->b[swap_b ^ 0xF]], 24)); + if (be) { t = bswap32(t); } r->w[swap_w ^ 3] = t;