From nobody Thu Nov 28 10:36:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694153292; cv=none; d=zohomail.com; s=zohoarc; b=NmndXhuEekH3bryZovNTxo2IoPgCqJutBgCHkzWO+RzDzduN/66oCS2N+8kUtTgPuML1xKQu9kAGnukpfUmcZtFsy2bWhmxVyHVLN9tzf3eZubD7tfFsbEQWBKgtUKYiQ1sfUS7p8Li3Wp/hM/piB/V0yMUdEkIERKyF+NHYAOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694153292; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KTZoQQBHRX8Eh4+DjB2iRGNyN+rFo0jz7PJ5kMgxxIY=; b=UlXtjdon4G86Dj0BxvhXP9HRycNkNHbmYYgCBjF69dCltreEVzzH9OjzMeCcbN5GN/t27XbWyfsWUGsvqitZeeb2MvyqYq8iPS/J53FLh2srMc+/DN0xMk+mheSVHMOx+CSic8RkBRk4Ip7D6sx/wpkyRQX4xGTM+hK0unbekNE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694153292638935.9234475006853; Thu, 7 Sep 2023 23:08:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeUdX-0001h4-I3; Fri, 08 Sep 2023 02:06:35 -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 1qeUdH-00014D-Gt for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:06:25 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeUdD-0005r5-UE for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:06:19 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1c09673b006so13016985ad.1 for ; Thu, 07 Sep 2023 23:06:15 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id q1-20020a170902dac100b001c3267ae31bsm715231plx.301.2023.09.07.23.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 23:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694153174; x=1694757974; darn=nongnu.org; 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=KTZoQQBHRX8Eh4+DjB2iRGNyN+rFo0jz7PJ5kMgxxIY=; b=qFi9mMQqmNsId7IXThapFxJzlVFQ05UGmWabgbLH7b9A6qB6cK2NfW3HS+sukoNwBU daO9eEo3Y5XCnKR1aaW2t3ZyUAq5CSdfr4comItyvyHvlGKyfekrkTTx7eKDEg9w1GvZ xLiCxg7z2nwp9xcjrh6wxyHtBElvQSGTfWdq2M+fvcMsha3vOlXI/DUT1EEzxP25Rc4x I8D7Bn+jGAq0hpYDJqqj/vvUt2cEkQRKs1KuJbX59NalW20DgFniMtr/0d0W64lkUVT4 Wd84l9bDjvG4envGvmioxkN0Hy+Lm+hv3dJEgVHwy4j3CFsJ9vBNqPZSWlokpGMYk/5a Sz1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694153174; x=1694757974; 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=KTZoQQBHRX8Eh4+DjB2iRGNyN+rFo0jz7PJ5kMgxxIY=; b=em3ylP8dL1FMhmjEFLi29KY1gAKmEgxubNXg6Ysni5dzONaBBT315LZ7I+bJGtducf XBt5gfpWlgUynyf/RA7Ek4NhtI5vwJt/Vnqc3cYRqZ7U51XSeQhT/sMVZr/kbJhN2eU0 G1T6/K1e0rXHuPd+cRHaVqcMqWGube2dlvOPMkQkqtnbPfaa2bcxtxoyeunHK3Vtmhss /pt3itnaIGCcmYgkdxhHy3/DuvSH0+EJ0y0YNpFab3zzyq+x5tmrXmocpInbe+1YAEQK ntm8teL0aGHkVu3m6IZjJ/sBhSuRs4i0AaC5W+whlK+Kxf2YXnf7sSQawaPGbZTfIL2O 2fJg== X-Gm-Message-State: AOJu0YwB/FT0Nr3I5x4ukqlvGAK08qLRq5yZX6OZMA5BC6wWpupWQiMq 8PnVNVUYIGwlIo26AdyuZG9kYySNqXEYb0C+ X-Google-Smtp-Source: AGHT+IFKK9ALwSmCSR5SKHKzs+U1OskQW2iX3aSfqSix7em4UEY11vci0TwU/71wBJOWpzQXTYKAfA== X-Received: by 2002:a17:902:da92:b0:1bb:d280:5e0b with SMTP id j18-20020a170902da9200b001bbd2805e0bmr2138565plx.18.1694153173653; Thu, 07 Sep 2023 23:06:13 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Max Chou , Frank Chang , Richard Henderson , Alistair Francis Subject: [PULL 20/65] crypto: Create sm4_subword Date: Fri, 8 Sep 2023 16:03:46 +1000 Message-ID: <20230908060431.1903919-21-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230908060431.1903919-1-alistair.francis@wdc.com> References: <20230908060431.1903919-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=alistair23@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694153294757100003 Content-Type: text/plain; charset="utf-8" From: Max Chou Allows sharing of sm4_subword between different targets. Signed-off-by: Max Chou Reviewed-by: Frank Chang Reviewed-by: Richard Henderson Signed-off-by: Max Chou Message-ID: <20230711165917.2629866-14-max.chou@sifive.com> Signed-off-by: Alistair Francis --- include/crypto/sm4.h | 8 ++++++++ target/arm/tcg/crypto_helper.c | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/crypto/sm4.h b/include/crypto/sm4.h index 9bd3ebc62e..de8245d8a7 100644 --- a/include/crypto/sm4.h +++ b/include/crypto/sm4.h @@ -3,4 +3,12 @@ =20 extern const uint8_t sm4_sbox[256]; =20 +static inline uint32_t sm4_subword(uint32_t word) +{ + return sm4_sbox[word & 0xff] | + sm4_sbox[(word >> 8) & 0xff] << 8 | + sm4_sbox[(word >> 16) & 0xff] << 16 | + sm4_sbox[(word >> 24) & 0xff] << 24; +} + #endif diff --git a/target/arm/tcg/crypto_helper.c b/target/arm/tcg/crypto_helper.c index fdd70abbfd..7cadd61e12 100644 --- a/target/arm/tcg/crypto_helper.c +++ b/target/arm/tcg/crypto_helper.c @@ -614,10 +614,7 @@ static void do_crypto_sm4e(uint64_t *rd, uint64_t *rn,= uint64_t *rm) CR_ST_WORD(d, (i + 3) % 4) ^ CR_ST_WORD(n, i); =20 - t =3D sm4_sbox[t & 0xff] | - sm4_sbox[(t >> 8) & 0xff] << 8 | - sm4_sbox[(t >> 16) & 0xff] << 16 | - sm4_sbox[(t >> 24) & 0xff] << 24; + t =3D sm4_subword(t); =20 CR_ST_WORD(d, i) ^=3D t ^ rol32(t, 2) ^ rol32(t, 10) ^ rol32(t, 18= ) ^ rol32(t, 24); @@ -651,10 +648,7 @@ static void do_crypto_sm4ekey(uint64_t *rd, uint64_t *= rn, uint64_t *rm) CR_ST_WORD(d, (i + 3) % 4) ^ CR_ST_WORD(m, i); =20 - t =3D sm4_sbox[t & 0xff] | - sm4_sbox[(t >> 8) & 0xff] << 8 | - sm4_sbox[(t >> 16) & 0xff] << 16 | - sm4_sbox[(t >> 24) & 0xff] << 24; + t =3D sm4_subword(t); =20 CR_ST_WORD(d, i) ^=3D t ^ rol32(t, 13) ^ rol32(t, 23); } --=20 2.41.0