From patchwork Mon Jul 3 10:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 698641 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1665063wrs; Mon, 3 Jul 2023 03:10:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7CbTkxrnn9P7SeMUyhS2FcXZx36sgl8O1hSyz8CHiPi//36NeUVuQ1Xqsv7xHHYv+BjeXP X-Received: by 2002:ac8:584d:0:b0:3f8:6eaa:dcc4 with SMTP id h13-20020ac8584d000000b003f86eaadcc4mr19703839qth.22.1688379020758; Mon, 03 Jul 2023 03:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688379020; cv=none; d=google.com; s=arc-20160816; b=Q2Oexi5Inz+mjWRSkn5B2URjqgwzfC+817ZsISxNZd/DHb5irpgNxvkLn+JghofEMp NIGdNWtoLM8T7fhtDaBkK459Yc3uvSycAd1Obdmtr7mmdwFEDy14p1tQqIhPCcTb9KQL Kea2kERLIMIQzrHLbMwflcXUztu2K3+fJaHe4tmjBHhIZnAa2OgM7HzJ3Y9xHO109hci YYszdmXKvFzOKj37h/XrhMrZSX30diKoQ+8XroXKadAR8bZR9Ljpq8IwTdF1dcITw25S DkqnU+vwrqC4K/uJ0aZfBNhJTkEdnNT0jsjVHt1JmxEq68cgUqFstVNUkC8YTqvFaphh 740Q== 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=QgDoIuhvPgc2IEOs0IRGDFwvtZaiTfC8q6Rpekinx9Q=; b=TRLqHcCp24A+GhRkICMzRWn0wG/hwxIMfNjnc3Hgx6vKMnYu40Cr1BUW4dsQILnMSK YBXdiATsqvR3Hn8WclNjrhCKXmnuF3okz60F99lkKIhYCYZT5M8AVLwTTXfDkHn2JjpY S3p3bngODrGo421JUlQ9RzPGdkLp2ydkQ/ZUEgYNum3+c6yYy6WStOmN/QMP9yYYdS0K FoArF8ui6eGCWyGKFgJZFCrvHys+kxQMewkD2Vb2UaAMAQzwNA64gTEqdlwrVS7CZOQK yj3s9grW3XOi8tAi048Zw+5XOkctJO1TgYwBEBRFBNHrV5D8fSMv9N4kYnlDcj8rZuZ9 qRcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Pwm1FCcY; 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 o13-20020a05622a044d00b004035734bb43si1690804qtx.635.2023.07.03.03.10.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 03:10:20 -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=Pwm1FCcY; 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 1qGGRK-0002fd-7q; Mon, 03 Jul 2023 06:05:50 -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 1qGGRE-0002ae-8D for qemu-devel@nongnu.org; Mon, 03 Jul 2023 06:05:45 -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 1qGGR5-0005hb-MQ for qemu-devel@nongnu.org; Mon, 03 Jul 2023 06:05:40 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3112f5ab0b1so4700342f8f.0 for ; Mon, 03 Jul 2023 03:05:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688378726; x=1690970726; 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=Pwm1FCcYBssMW/ZiMKlkhySlLJ1mlbpGNDpDn0wMiC1glwRLjTVaHH5ifjW0ad/CTO dmjyRLekq5GnQulOD4U0B64r1TEy2U9/MsnRdDF/9K+PMzUILSxT6lpzqf/uNZkxXQw/ zEcLPGcSosKYDMAYX0fR93xfgsnUk+RnaFdteNtVKMM7vUNsjp6nXpG0CKbaULIT/38f VCcUHEuuc02lxjrJtyPKN500p/rncfFXHcRJai93ycWui8xs70S52fOYUcQG+o4PBbRL j7Dtx51SSC1KA7ek+TFm0dY9QMdigg6lTjcZLefKOHHUtQaTRaN9yFAKpyLuguaUiZZF Eliw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688378726; x=1690970726; 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=KPtSrNsEfJVVqLVWbg7U/69He4k7p3NkSX6H2QcVjJsexSusTECTPrY5D4CsroPmJ/ RKIXUs02CzOYbnOQFSTFuUHIIWmmH7ce0PtoNbZ5tCt1mBMXoLAKqTWFe5Q41gRQZLcv +yj7uBF731kK+nOGgzlPBR8mGUZyiExrv1ZwRqonKfM7SpDcpKLSV9Dj9kRrPfSvFSQC 78zkYf5pqlneMI+WG9/MI7zK3vMBxEf+h689Q4nCBvlzUEc8jgq4306EaC7tt4WKx3sB 0QmtqST8ABKjEvIZDZlGYKvTFOACqe7XW5eYS0tGo+gB6s1jd3C4YYVT2G5e5Veqac/k LpoQ== X-Gm-Message-State: ABy/qLYdvdxJ2aDaattjuxvpYSRJjSRJ52lxBiTrTwyFVwvoyczF7zmL 8Wbwt+lf1GB3c8USR2idTnaD4PHYzg/Z1u7cr/icjw== X-Received: by 2002:adf:f7c9:0:b0:311:162a:ce2a with SMTP id a9-20020adff7c9000000b00311162ace2amr7620806wrq.29.1688378726642; Mon, 03 Jul 2023 03:05:26 -0700 (PDT) Received: from stoup.home (91.232.79.188.dynamic.jazztel.es. [188.79.232.91]) by smtp.gmail.com with ESMTPSA id t5-20020a05600001c500b00313f7b077fesm18446562wrx.59.2023.07.03.03.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 03:05:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-riscv@nongnu.org, pbonzini@redhat.com, eduardo@habkost.net, alistair.francis@wdc.com, danielhb413@gmail.com, =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v4 04/37] crypto/aes: Add AES_SH, AES_ISH macros Date: Mon, 3 Jul 2023 12:04:47 +0200 Message-Id: <20230703100520.68224-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230703100520.68224-1-richard.henderson@linaro.org> References: <20230703100520.68224-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=unavailable 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), }; /*