From patchwork Fri Jun 9 02:23:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 690883 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp599046wru; Thu, 8 Jun 2023 19:31:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QFFCyWjFhvZtbd7gWbFnjSmxBiJJUnZD/H9IiNTFLa7zEE7wS5eJq/NI86HH8hagB2bHG X-Received: by 2002:a05:6214:1c0c:b0:628:335a:173d with SMTP id u12-20020a0562141c0c00b00628335a173dmr339139qvc.43.1686277898867; Thu, 08 Jun 2023 19:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686277898; cv=none; d=google.com; s=arc-20160816; b=DKhT/zjPU62LcH4mj5yCWLCm6Op7QwRW55GLyZV0eLIbT7dYEJ2phgRWSp1KCR9Xxi 7RNwngkSggaHvJx4/cF2WA3FAa4dgeCCeHB12jXak5pg6vZt+iJ4fYWQMGiHZkTQpzOh QvkSX2g66RcMeahfq32pVpMwz37BjwWDYOAh3LAqBRYew8g7ff4TAXR+5e6EzXOttBPo uzj24OzwCxAgjfaEQrDb793Y1OsdSzUtcdIciyajliPq7UL6H09rycXgumo/XTb1qhj8 uBASAyQ14C5UUA8i3VMrTcPjwsa0PTrT2evAaXOmOYKJPyxpwr7QAx0YtmA7x3DJtzBX UHzw== 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=gaCBgV+3yGAR2caIA8mNUKr5d+J0BSK2P+519bphi4Yk9V9n0usS9s7ZF7RmG5/CRA +6hYWOXeIQhJnfpOuTzsuLcUq4P36e2MfFsRidafd2UKYq5mW+Cnn30OSGEi2wFg6Se8 7W/JA6+2LT90jMK0e5GLnogQVg6JbhFI3CXcH/+1CnuXt2MX/sSFptKdaTT1Cj9UFN45 0S4bM0T3zKj5Z8m5jWk/LPxZXselu6fuoXs8nJj+d55j8Y1Hlw8NKNSyye56PQw2rrXF 6HHq7HG1dbvl2qRMbV0iHDsGCutPJpHROquiHY+W/VJUuabPxDr9h8VCgqDjR6gP62PP P1Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gWQM2343; 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 jq14-20020ad45fce000000b0062399777b51si1639821qvb.275.2023.06.08.19.31.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Jun 2023 19:31:38 -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=gWQM2343; 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 1q7Rnl-0002jp-Oa; Thu, 08 Jun 2023 22:24:33 -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 1q7Rnc-0002cT-3Q for qemu-devel@nongnu.org; Thu, 08 Jun 2023 22:24:24 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0: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 1q7RnQ-0005ab-Sj for qemu-devel@nongnu.org; Thu, 08 Jun 2023 22:24:23 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-652328c18d5so985153b3a.1 for ; Thu, 08 Jun 2023 19:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686277451; x=1688869451; 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=gWQM2343o958ZSfZZxG+oH4fY82Wtp1H2JgJQuCgf47FVRI0t1ynCPpfHLBufnXzrE Vw+G0pcYq96FsJB+FGfRLbB6OvhZR8eGdhO2smz2qMexeFGsSCcYGK3xekUvZA8f6dYT twGBBhBX2iSHgS1GwMANElrZwGPiN8YLMsU7Y5vjEOgLndcVM5ZNkEodvYEc09ybZgGc RJhXGhfpfNmrQZDR0OJYge0RgQz5u4U/O3wWZh/no9VcN84L9+Rh96yp6FMFXBmIF/IB mk8kZ8K7qxHOXP6C78mGNDFI6pCMGrEAqUUMixnG4BKgImA+ESl6oykeBROUmom7bvEW JnWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686277451; x=1688869451; 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=hnpe5KV+N9IrkMGyj1sX501QxDOcGX8ZeNPh3KqLVBxJd8NAYRjlCiQJJ2qiOYZWDD NhqUrL9NpFWFWYcA+wUR5IzR68oLdygvu4WRrATRA3/b9M37nNsQq5ZJqUhqqTbC8tnp G0+fq1Zz3mpvXCj4YkDAayaF8RjGliGLk7IfzE56fKezLeyB7GVpm6O1AKqlOrNqWmWD 8UmIPJIO3uM5NqdzT9KBDLC4WXKrC2Q62JryQ5nu866UDQe7Lyp5Mlv3Yvb0l8dujvtj SPYYBq6xCfKqJNhTniNE2MnmIP2x080iPQZOXr+Uz9DvQDgoU63aDEU81CnB9rJ+dXPV 54Lg== X-Gm-Message-State: AC+VfDzluZSCddHa5FUfkuydXimhdNsD1LHR7EP3okJwvQ/ostwf+yJQ 60GtpYbzFLafOGNUpMc+kpqdgOJ2sKdm1d5+uNA= X-Received: by 2002:a05:6a00:1494:b0:662:a9c3:7b4e with SMTP id v20-20020a056a00149400b00662a9c37b4emr5586357pfu.24.1686277451604; Thu, 08 Jun 2023 19:24:11 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:b071:df63:5761:f449]) by smtp.gmail.com with ESMTPSA id x25-20020a62fb19000000b0063afb08afeesm1686458pfm.67.2023.06.08.19.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 19:24:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: ardb@kernel.org, berrange@redhat.com, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, pbonzini@redhat.com Subject: [PATCH v2 09/38] target/arm: Use aesenc_SB_SR_AK Date: Thu, 8 Jun 2023 19:23:32 -0700 Message-Id: <20230609022401.684157-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230609022401.684157-1-richard.henderson@linaro.org> References: <20230609022401.684157-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-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=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 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)); }