From patchwork Fri Jun 9 02:23:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 690880 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp598897wru; Thu, 8 Jun 2023 19:31:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66o8rQU1LM43TDSre00mUyld2KMm0zksU7UoCVTieNCVaYAU9X0W2a0yeduT49IoZ7Ruo2 X-Received: by 2002:a05:622a:86:b0:3f6:aac5:a1dd with SMTP id o6-20020a05622a008600b003f6aac5a1ddmr273579qtw.9.1686277860671; Thu, 08 Jun 2023 19:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686277860; cv=none; d=google.com; s=arc-20160816; b=NFac5HfTwdqUnL2qGP/Fxh/FGVUWII0BCiP7Yot8CysRfnpMDqWNCWMO5zYyqWXzWP 5vDpBtJeP83XPCTN0S84wbvQ9ljunta/dFA0ohmOxwsOat19rm9KP14Na3IKTIaDwSU2 E4knq6oVywXFrUWY2TtH7WsAdxw3jtCh4uOtSy5HBbrNzCL0az3bCsETduXjMVUW2XTP lv1pY3fBombfixvGHSF1tUjHPAKZM/Zot16A110omsImqxyylfpk9tTPoCZghGyJNH3X ST7DeuK2fpvxZmnJgUlQeCEBcAzD/eeZCaicfbl49YBlA3ArwGhm8223Mrj/hhVFEzSw wo2g== 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=OLFFYuouFCwCamulVOLZsWjyEyGPIaWGGn4/nOjW+MQ=; b=BYLJY1PPR3+z0QKic7eFQpKYumkpQVwC8Ab9VNzwR4INAWtoYXZdfNPIOJDECe137C 8DhYEEt6zpLAMtgqbrAmFZViR/foKVEMU4U7CdIXbp+R8cd99V55GHVs7xJyWhMHzxPw YfHnA/GTHLmHedVZzxp8cifGBNAqk1tqz3F8TPMroptszQ3qeQTcSrogUw49VkRXd/gl veMyVr8KzOhdKwSzqLADR0eSw8j/WPNjbtkmkn2yaFB46NSIg3JRR9TbNhWDUBFWEPd6 mwmhTcL80kI8LrM6DapLPSfl06mpVxN75cZaRrrb8+KVLw/cjSojng7iHXKbUgv/8MYW M88Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PxzwrRJr; 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 z17-20020a05622a029100b003f52f9e96bdsi1541410qtw.139.2023.06.08.19.31.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Jun 2023 19:31:00 -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=PxzwrRJr; 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 1q7Rnp-0002o9-Dk; Thu, 08 Jun 2023 22:24:37 -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 1q7Rnj-0002gw-5o for qemu-devel@nongnu.org; Thu, 08 Jun 2023 22:24:31 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q7RnT-0005c0-Lw for qemu-devel@nongnu.org; Thu, 08 Jun 2023 22:24:30 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-651f2f38634so1298780b3a.0 for ; Thu, 08 Jun 2023 19:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686277454; x=1688869454; 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=OLFFYuouFCwCamulVOLZsWjyEyGPIaWGGn4/nOjW+MQ=; b=PxzwrRJr8LCPlDpM3n83k2c2C+GIpsT+zRjbo7kNvDyEw/52rzqo/mlvJrwtyFXlkG 7MZLCprZM4fjDefcRb+ZSEXJPS1Tz7+qk3UhrbpD7P/m7tozMpzF+ilUZbKCXtJNoczu oU8F7Fmnn6lgJpLU1CLgMn7da6BN5CXPlyoDu0M4fs/Ltm+PoKE7NeoSUcyI7ZWWq+t4 FY6hoc9mqUaCQhdcczpEJt27MCslUoeXvhgKMNjql9fTMdnzCnNzDijwz2Uf9ebs3ECa OOGCubbLpElJVQc0OhBvqn4KxdkQGXHNsEU/jbJU+impQ1xQhcICUNCoJamFuXhsbCmk t8Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686277454; x=1688869454; 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=OLFFYuouFCwCamulVOLZsWjyEyGPIaWGGn4/nOjW+MQ=; b=XX5Ysy21m3ABaq7/E6RM9kGDLfM61OGOjO11xUDN+ziMKe0ejRxabbpRDQOJsC41LE G0/CTgRAMVsb/E721LK+UJVaTd9Yr1mBW68AAZ1FZiqAU0Bx5IR0jjLgE+767xvcgwUY /XoClv1m0G8qKZuBXsrZkrnIhD/kPwSX6RBKrKz2Ao7uZHuXBvuUFGFAht/gMra0wQN1 Uq1hVdm/U+qgCLLw/I52c0tmsf52VzEu2aU+MGGngqobpb3TsUxhTcPAV/NBNaNdDM/n JNb9kBAWwBgIS5CbaNI0D1MKmOK4YsrXDo0+vHJC1MR9Rc1PfAuRU1Mkck8qKjTomI7Q gqFQ== X-Gm-Message-State: AC+VfDz+Lig3HZVZZgul5oCNDmDdprEs1A4zdgLO0S3nR/MuKjG31FZn 8/WPBeTuRAokStbWvhxubExKu27fQsmm4O1g0sk= X-Received: by 2002:a05:6a00:194d:b0:656:e7a2:5322 with SMTP id s13-20020a056a00194d00b00656e7a25322mr12901890pfk.26.1686277454456; Thu, 08 Jun 2023 19:24:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 19:24:14 -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 12/38] crypto: Add aesdec_ISB_ISR_AK Date: Thu, 8 Jun 2023 19:23:35 -0700 Message-Id: <20230609022401.684157-13-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::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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 Add a primitive for InvSubBytes + InvShiftRows + AddRoundKey. Signed-off-by: Richard Henderson --- host/include/generic/host/aes-round.h | 4 +++ include/crypto/aes-round.h | 21 +++++++++++++ crypto/aes.c | 43 +++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/host/include/generic/host/aes-round.h b/host/include/generic/host/aes-round.h index 19c8505e2b..e8f6bb0b99 100644 --- a/host/include/generic/host/aes-round.h +++ b/host/include/generic/host/aes-round.h @@ -13,4 +13,8 @@ void aesenc_SB_SR_AK_accel(AESState *, const AESState *, const AESState *, bool) QEMU_ERROR("unsupported accel"); +void aesdec_ISB_ISR_AK_accel(AESState *, const AESState *, + const AESState *, bool) + QEMU_ERROR("unsupported accel"); + #endif diff --git a/include/crypto/aes-round.h b/include/crypto/aes-round.h index 15ea1f42bc..56376cc83b 100644 --- a/include/crypto/aes-round.h +++ b/include/crypto/aes-round.h @@ -41,4 +41,25 @@ static inline void aesenc_SB_SR_AK(AESState *r, const AESState *st, } } +/* + * Perform InvSubBytes + InvShiftRows. + */ + +void aesdec_ISB_ISR_AK_gen(AESState *ret, const AESState *st, + const AESState *rk); +void aesdec_ISB_ISR_AK_genrev(AESState *ret, const AESState *st, + const AESState *rk); + +static inline void aesdec_ISB_ISR_AK(AESState *r, const AESState *st, + const AESState *rk, bool be) +{ + if (HAVE_AES_ACCEL) { + aesdec_ISB_ISR_AK_accel(r, st, rk, be); + } else if (HOST_BIG_ENDIAN == be) { + aesdec_ISB_ISR_AK_gen(r, st, rk); + } else { + aesdec_ISB_ISR_AK_genrev(r, st, rk); + } +} + #endif /* CRYPTO_AES_ROUND_H */ diff --git a/crypto/aes.c b/crypto/aes.c index 896f6f44f1..767930223c 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1293,6 +1293,49 @@ void aesenc_SB_SR_AK_genrev(AESState *r, const AESState *s, const AESState *k) aesenc_SB_SR_AK_swap(r, s, k, true); } +/* Perform InvSubBytes + InvShiftRows. */ +static inline void +aesdec_ISB_ISR_AK_swap(AESState *ret, const AESState *st, + const AESState *rk, bool swap) +{ + const int swap_b = swap ? 15 : 0; + AESState t; + + t.b[swap_b ^ 0x0] = AES_isbox[st->b[swap_b ^ AES_ISH_0]]; + t.b[swap_b ^ 0x1] = AES_isbox[st->b[swap_b ^ AES_ISH_1]]; + t.b[swap_b ^ 0x2] = AES_isbox[st->b[swap_b ^ AES_ISH_2]]; + t.b[swap_b ^ 0x3] = AES_isbox[st->b[swap_b ^ AES_ISH_3]]; + t.b[swap_b ^ 0x4] = AES_isbox[st->b[swap_b ^ AES_ISH_4]]; + t.b[swap_b ^ 0x5] = AES_isbox[st->b[swap_b ^ AES_ISH_5]]; + t.b[swap_b ^ 0x6] = AES_isbox[st->b[swap_b ^ AES_ISH_6]]; + t.b[swap_b ^ 0x7] = AES_isbox[st->b[swap_b ^ AES_ISH_7]]; + t.b[swap_b ^ 0x8] = AES_isbox[st->b[swap_b ^ AES_ISH_8]]; + t.b[swap_b ^ 0x9] = AES_isbox[st->b[swap_b ^ AES_ISH_9]]; + t.b[swap_b ^ 0xa] = AES_isbox[st->b[swap_b ^ AES_ISH_A]]; + t.b[swap_b ^ 0xb] = AES_isbox[st->b[swap_b ^ AES_ISH_B]]; + t.b[swap_b ^ 0xc] = AES_isbox[st->b[swap_b ^ AES_ISH_C]]; + t.b[swap_b ^ 0xd] = AES_isbox[st->b[swap_b ^ AES_ISH_D]]; + t.b[swap_b ^ 0xe] = AES_isbox[st->b[swap_b ^ AES_ISH_E]]; + t.b[swap_b ^ 0xf] = AES_isbox[st->b[swap_b ^ AES_ISH_F]]; + + /* + * Perform the AddRoundKey with generic vectors. + * This may be expanded to either host integer or host vector code. + * The key and output endianness match, so no bswap required. + */ + ret->v = t.v ^ rk->v; +} + +void aesdec_ISB_ISR_AK_gen(AESState *r, const AESState *s, const AESState *k) +{ + aesdec_ISB_ISR_AK_swap(r, s, k, false); +} + +void aesdec_ISB_ISR_AK_genrev(AESState *r, const AESState *s, const AESState *k) +{ + aesdec_ISB_ISR_AK_swap(r, s, k, true); +} + /** * Expand the cipher key into the encryption key schedule. */