From patchwork Mon Jul 3 10:05:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 698638 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp1664854wrs; Mon, 3 Jul 2023 03:09:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFPyFXzWEp2vaApXJK3F4XrPW/hz6J7xB9CFbM2IMUyqROWIAj9qgtIj8LihbkrrQa+bUIW X-Received: by 2002:a05:6214:258b:b0:636:39ed:4def with SMTP id fq11-20020a056214258b00b0063639ed4defmr13252700qvb.12.1688378984958; Mon, 03 Jul 2023 03:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688378984; cv=none; d=google.com; s=arc-20160816; b=hEHXMhGTyz3xGiLEHn4dBinCD808jzUUbkjZ0IREwWDUei3/hdgkT3BE4MQDghB7lc S6oYDU1X/KtXb+7Har9OEfmcL3JJ+JmPIrZAcjKujqG44cOevt5v6UfrcfVYpjHc1oyZ DVWVSqs7mpLwoPpecV9bc/IcoaxOW5EJmc0bxMkMPXxtS157E9pZcOHIU/VobSqk5PqI MTFVRwUKmhzdMc7CTjW7/LJX33o+7MdrzP9NzDFM166GDxu0Hi3I0PwSw2bufMk/4Afl 50I1W35I4VsPx+u1nxxi3H4VwrLokgjwDGLa2fMU8qahfD8MphlPdX7VimpwpdBbTzEY d4vA== 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=UEsv77WByzgBc2oRedydI0QuEnu20ntgk1P70X2mStE=; fh=DiqGMcF5+wJ0/Fe6a4a0YfMDHaiC5n3qovds/BNTPmI=; b=RZMSEUJSXExJZcWG7+yCQuMbXmt9MSxAtjO/Y9kkK+JNQanoNxLOTKgfUP4g/wogZA gM6VVCU2Rqb3jLMM41u1IWfZq2Zc8fAsEiozNPTrTx5ATJ18UgjFBLGuY8o149x2y2d5 6Wk2OGU39wwBlwSatUYw7awEA+uQBFLGz+LwFRFO7EPwzFOvRYi1EdR1YPFfoTCALPsP 1ODWnklEN5XmGV+dIiVKGSs/UupmlbpxIkgEWX8R1LuAIcDc6qMX4nMdCrguxVsmLunn H7KMKb/YVWsYCD4XDFO43cHcU8Re0uL73oHjdaJbt6UmuJWT5uriCOrwHiqsd8PV5MrF tPbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uHiYfhKw; 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 q13-20020a05621419ed00b00634020f4717si11169253qvc.556.2023.07.03.03.09.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jul 2023 03:09:44 -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=uHiYfhKw; 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 1qGGRi-00039m-JM; Mon, 03 Jul 2023 06:06:14 -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 1qGGRc-00033M-U8 for qemu-devel@nongnu.org; Mon, 03 Jul 2023 06:06:08 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qGGRL-0005vf-Cj for qemu-devel@nongnu.org; Mon, 03 Jul 2023 06:06:08 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3112f5ab0b1so4700798f8f.0 for ; Mon, 03 Jul 2023 03:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688378750; x=1690970750; 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=UEsv77WByzgBc2oRedydI0QuEnu20ntgk1P70X2mStE=; b=uHiYfhKwnw1I57OcVIqitUWlypy7M1mJKy2Gi3bSQEDUl1aZsd5hUSfUazumXVLdgt GxOM3oU+yuEaOnay7X26f8fIa1Gckle9bn8FbdU8p1uwSb3bnKxO/rWVpQl29J15bXwy Wvs3pJ0ecXo9C8Qhci1ECN98iFuoBfALN+SmpN2Y7hAUj/lQm6mixz46+ohjWA43KrlO GELj/WyLv+IQ22rvqs6UhO1pcHZTCg6G9SuWSBeVD1rmdysI+eZkfbqlc8Uf0tM8nY6h JwMeYC4y8FuXC/wO6rG/ajeyioI703PZIRQ7pXN5G53zaD6ffNWd75TZoCzqZKA3TiPL FjuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688378750; x=1690970750; 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=UEsv77WByzgBc2oRedydI0QuEnu20ntgk1P70X2mStE=; b=bkYxBYyv1lUtc6Zad9S7buTIhbDaRIHK/65rh8SRAgLCxsHT4lYTo+7EOvw6ObFtcN ek16nukioTQkZlbG3PShZoSvrztEulCCQNi4MWCIUdoHSMFYcN8r1lpQrQBeaLnxCDN/ uakivEeHYfMM3ysK7lhI/M5QUBX/bwm5yTk6qdWTwG3IW9RQ/LnehcdYwyIhykjWvzRs fH8wAjbya8Bn8fgUolyuypFBqGKZdli93NoRikcu+gJBmNmpy8Tynob8QujsKJoU9ZcZ HNzLjp8Ydv+p3WTzPGvfIXA56tyioG9TFLxUZY/zs6LuFTCYVoEC8wbgEbHPY7QDX3aj bJSQ== X-Gm-Message-State: ABy/qLYNxf9lRlVnSIoQdGmPcefGSHcCH782psguH8gRc3j6bQS/onBI hHqDNgnBGNnHDmmLxL221paxjKmGFPY31B89+diTPA== X-Received: by 2002:a5d:4a09:0:b0:30e:3f54:f8c9 with SMTP id m9-20020a5d4a09000000b0030e3f54f8c9mr7207560wrq.10.1688378749888; Mon, 03 Jul 2023 03:05:49 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 03:05:49 -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 Subject: [PATCH v4 26/37] target/arm: Use aesdec_ISB_ISR_AK Date: Mon, 3 Jul 2023 12:05:09 +0200 Message-Id: <20230703100520.68224-27-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::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.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 implements the AESD instruction. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- target/arm/tcg/crypto_helper.c | 37 +++++++++++++++------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index 00f3b21507..d2cb74e7fc 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -48,26 +48,6 @@ static void clear_tail_16(void *vd, uint32_t desc) static const AESState aes_zero = { }; -static void do_crypto_aese(uint64_t *rd, uint64_t *rn, uint64_t *rm, - const uint8_t *sbox, const uint8_t *shift) -{ - union CRYPTO_STATE rk = { .l = { rm[0], rm[1] } }; - union CRYPTO_STATE st = { .l = { rn[0], rn[1] } }; - int i; - - /* xor state vector with round key */ - rk.l[0] ^= st.l[0]; - rk.l[1] ^= st.l[1]; - - /* combine ShiftRows operation and sbox substitution */ - for (i = 0; i < 16; i++) { - CR_ST_BYTE(st, i) = sbox[CR_ST_BYTE(rk, shift[i])]; - } - - rd[0] = st.l[0]; - rd[1] = st.l[1]; -} - void HELPER(crypto_aese)(void *vd, void *vn, void *vm, uint32_t desc) { intptr_t i, opr_sz = simd_oprsz(desc); @@ -102,7 +82,22 @@ void HELPER(crypto_aesd)(void *vd, void *vn, void *vm, uint32_t desc) intptr_t i, opr_sz = simd_oprsz(desc); for (i = 0; i < opr_sz; i += 16) { - do_crypto_aese(vd + i, vn + i, vm + i, AES_isbox, AES_ishifts); + AESState *ad = (AESState *)(vd + i); + AESState *st = (AESState *)(vn + i); + AESState *rk = (AESState *)(vm + i); + AESState t; + + /* Our uint64_t are in the wrong order for big-endian. */ + if (HOST_BIG_ENDIAN) { + t.d[0] = st->d[1] ^ rk->d[1]; + t.d[1] = st->d[0] ^ rk->d[0]; + aesdec_ISB_ISR_AK(&t, &t, &aes_zero, false); + ad->d[0] = t.d[1]; + ad->d[1] = t.d[0]; + } else { + t.v = st->v ^ rk->v; + aesdec_ISB_ISR_AK(ad, &t, &aes_zero, false); + } } clear_tail(vd, opr_sz, simd_maxsz(desc)); }