From patchwork Tue Jun 20 11:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 694474 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp246216wrm; Tue, 20 Jun 2023 04:14:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76D2puXSWtP6ZOR3q6RSyXQNDvopEnEstIcys7AUj27/Al3mGulP3L2Yy0LCF7KnEBYGhP X-Received: by 2002:ac8:7d07:0:b0:3fd:e953:74df with SMTP id g7-20020ac87d07000000b003fde95374dfmr3556818qtb.25.1687259665613; Tue, 20 Jun 2023 04:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687259665; cv=none; d=google.com; s=arc-20160816; b=NGA21FNd7EspSewtbhs8YDCjiZFx1ipRznQzCCPTfHmm+llPcsM2uPDzRk04DVSHhe wLBz3VJb+z6R/76fOGLqS0rr776mC/ncjHEH39PTR6/kQrD4iqrOBfJftPbThD6O4pkl UteyJ/UJ2LuZ8XCNHpvueyCS2klkCl+yP0Qx7YQZfjFcRF7bPNg5ayk8enMuHNE00gkh nXW3nzAOfSWvWTDOpKwGM1VCjrDtBA50n68N/1ISAKuvqvzK2JrgF/8CnLfIoVWV+OZ5 UDDQAbB3CUsb8sabHzjHM1YHnutKEUlFPhoBzTP6pxV6LuROBR/LUlI88gw3UFBj387S KKww== 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=mjZWs2Y+Z9mHPnjXNP6VJFYBwuCl2SNNXRyLlkiAXFM=; b=imxeJItrAHlZr5APuL4ObZafUJcv483+WApS6pOwNJxz13oQVMPjowszoQon+So41N 9e+QuURkddCAbcAIELU+vCj2hxPidD4yecFjibH4V4c01iA7trWjJPjr7kLl4R+icS/f 9GgNJxDdkPmkrCMYQqx2TXbsQBx6CM/sW0gS23m7fjSK13CfqqNUo+U8lAh/n7x8E6EY eHluLImIEgn1d5+N3L/vpMI79eSqE1zd+CtnO0ISb83YPNkn2dzh7AeYkKapD0U/yTNE u3Tb8A+oWW99qWYgmCCMaTNnx0edSOu0jrTFpnqYQ/K4xM723uySeXxrocQy61XhAVsL Z5CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WtTpfhmL; 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 w3-20020a05622a190300b003f365244139si658154qtc.70.2023.06.20.04.14.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Jun 2023 04:14:25 -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=WtTpfhmL; 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 1qBZDg-00063c-DK; Tue, 20 Jun 2023 07:08:20 -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 1qBZDe-0005zl-CI for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:18 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qBZDa-0004ET-FR for qemu-devel@nongnu.org; Tue, 20 Jun 2023 07:08:18 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9829a5ae978so717136966b.2 for ; Tue, 20 Jun 2023 04:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687259293; x=1689851293; 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=mjZWs2Y+Z9mHPnjXNP6VJFYBwuCl2SNNXRyLlkiAXFM=; b=WtTpfhmL836K+SDKJZcnTDhDgLuRfsn2tUQaR+Ia6h+vYJ19/2sEg9HfMbl5DfxEAz mrQVHhwidUHoKlaKS+pS6yo/9BaxNdhFSgBUL4SCagAkRidQx+/CnFN4KhvH5/EnHVkr uOG7naBuHjCO0jQ9tN/R0Wak8YXWZ3M61uy3f1aFJ6pTZmBS3xpFHjgMbOw3eT6fOUbR 5J13df0NCNGtD+U3jyWeHFCBYqomFY5/RclGg+4zfeRMhfTMgUYOLEh1LKnlYpzoUdi4 2z2dLKhMIRltl3jikMstAWJo2OFkUDB82bco3eapx5xIH1nERF631xZ/qhSsQHziTenb GRVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687259293; x=1689851293; 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=mjZWs2Y+Z9mHPnjXNP6VJFYBwuCl2SNNXRyLlkiAXFM=; b=AwJrkOgSgw3Zfbe7G5Lv0i86DPPVmdTsmU2h+Xi8C6slm7rCm6B7QXTKATMLVf3/XR vSHLXKJTxkxDDb8X1Uq9ImvYHCzkYdTW0qcysZXP8wh0uRHd/1kMlfRDwnlr5hqmEPFH wBhDUdo6d09/0WDyB+PBt5N2EmYt7Ms87RN+HfbTdguJfsylNc82J1gsmM9g2v1Myu17 yvWsD0KnmLwqYyzFcb9oJig+2ciC4uoB47w8LkNMjSbQWdGK9i7WS8fmrFGKT8UvgtoB syBYHHRQrK3jjcK/r8Q62Tz2xM+tJRfrDw7DaHbPO2Q+VvIvQA5U/ow0BcxoCAOQO0aK vLKg== X-Gm-Message-State: AC+VfDywjyvqopH7Q3K+xVpm94ILe1+UcgMyNDQ2d7RBHGoWLl9iF1qr r9cLLCHsGrjXiVBZFvJmVecIah0A78KUi8b+XVenj2Ro X-Received: by 2002:a17:907:6ea7:b0:988:9836:3fdb with SMTP id sh39-20020a1709076ea700b0098898363fdbmr6149505ejc.11.1687259293201; Tue, 20 Jun 2023 04:08:13 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 04:08:12 -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 Subject: [PATCH v3 08/37] target/arm: Use aesenc_SB_SR_AK Date: Tue, 20 Jun 2023 13:07:29 +0200 Message-Id: <20230620110758.787479-9-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::62e; envelope-from=richard.henderson@linaro.org; helo=mail-ej1-x62e.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 This implements the AESE instruction. Signed-off-by: Richard Henderson --- target/arm/tcg/crypto_helper.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index 75882d9ea3..00f3b21507 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -15,6 +15,7 @@ #include "exec/helper-proto.h" #include "tcg/tcg-gvec-desc.h" #include "crypto/aes.h" +#include "crypto/aes-round.h" #include "crypto/sm4.h" #include "vec_internal.h" @@ -45,6 +46,8 @@ static void clear_tail_16(void *vd, uint32_t desc) clear_tail(vd, opr_sz, max_sz); } +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) { @@ -70,7 +73,26 @@ void HELPER(crypto_aese)(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_sbox, AES_shifts); + 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. + * The Arm AddRoundKey comes first, while the API AddRoundKey + * comes last: perform the xor here, and provide zero to API. + */ + if (HOST_BIG_ENDIAN) { + t.d[0] = st->d[1] ^ rk->d[1]; + t.d[1] = st->d[0] ^ rk->d[0]; + aesenc_SB_SR_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; + aesenc_SB_SR_AK(ad, &t, &aes_zero, false); + } } clear_tail(vd, opr_sz, simd_maxsz(desc)); }