From nobody Sat Nov 23 15:30:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723433359352147.84922263096576; Sun, 11 Aug 2024 20:29:19 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 30AF11509; Sun, 11 Aug 2024 23:29:18 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D50CF1533; Sun, 11 Aug 2024 23:29:01 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D255D14DC; Sun, 11 Aug 2024 23:28:57 -0400 (EDT) Received: from smtp.cecloud.com (unknown [1.203.97.240]) by lists.libvirt.org (Postfix) with ESMTP id D05D5AD6 for ; Sun, 11 Aug 2024 23:28:56 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by smtp.cecloud.com (Postfix) with ESMTP id E3F04900112 for ; Mon, 12 Aug 2024 11:28:54 +0800 (CST) Received: from localhost.localdomain (unknown [111.48.58.10]) by smtp.cecloud.com (postfix) whith ESMTP id P1340312T281473323495792S1723433333601431_; Mon, 12 Aug 2024 11:28:54 +0800 (CST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 X-IP-DOMAINF: 1 X-RL-SENDER: luzhipeng@cestc.cn X-SENDER: luzhipeng@cestc.cn X-LOGIN-NAME: luzhipeng@cestc.cn X-FST-TO: devel@lists.libvirt.org X-RCPT-COUNT: 2 X-LOCAL-RCPT-COUNT: 1 X-MUTI-DOMAIN-COUNT: 0 X-SENDER-IP: 111.48.58.10 X-ATTACHMENT-NUM: 0 X-UNIQUE-TAG: X-System-Flag: 0 From: luzhipeng To: devel@lists.libvirt.org Subject: [PATCH] crypto: add support for sm4 without key length suffix Date: Mon, 12 Aug 2024 11:28:31 +0800 Message-Id: <20240812032831.273-1-luzhipeng@cestc.cn> X-Mailer: git-send-email 2.34.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 2PUY5C7K6OVQO3SCMYPDWRI5ZBEYGVWR X-Message-ID-Hash: 2PUY5C7K6OVQO3SCMYPDWRI5ZBEYGVWR X-MailFrom: luzhipeng@cestc.cn X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: luzhipeng X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZM-MESSAGEID: 1723433360862116600 Content-Type: text/plain; charset="utf-8" qemu add sm4 in release 9, but the name of sm4 doesn't have the key length suffix, So set size to 0, construct cipher name without key length as suffix. Signed-off-by: luzhipeng --- docs/formatstorageencryption.rst | 8 +++++--- src/qemu/qemu_block.c | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/formatstorageencryption.rst b/docs/formatstorageencryptio= n.rst index 066d285090..6cb8cf024c 100644 --- a/docs/formatstorageencryption.rst +++ b/docs/formatstorageencryption.rst @@ -75,11 +75,13 @@ initialization vector generation. =20 ``name`` The name of the cipher algorithm used for data encryption, such as '= aes', - 'des', 'cast5', 'serpent', 'twofish', etc. Support of the specific + 'des', 'cast5', 'serpent', 'twofish', 'sm4', etc. Support of the spe= cific algorithm is storage driver implementation dependent. ``size`` - The size of the cipher in bits, such as '256', '192', '128', etc. Su= pport - of the specific size for a specific cipher is hypervisor dependent. + The size of the cipher in bits, such as '256', '192', '128', '0', et= c. + '0' indicates that the encryption algorithm name doesn't have key le= ngth + suffix. Support of the specific size for a specific cipher is hyperv= isor + dependent. ``mode`` An optional cipher algorithm mode such as 'cbc', 'xts', 'ecb', etc. Support of the specific cipher mode is hypervisor dependent. diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d6cdf521c4..f63f3a36e0 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -2137,9 +2137,13 @@ qemuBlockStorageSourceCreateGetEncryptionLUKS(virSto= rageSource *src, =20 if (src->encryption) { if (src->encryption->encinfo.cipher_name) { - cipheralg =3D g_strdup_printf("%s-%u", - src->encryption->encinfo.cipher_na= me, - src->encryption->encinfo.cipher_si= ze); + if (src->encryption->encinfo.cipher_size) { + cipheralg =3D g_strdup_printf("%s-%u", + src->encryption->encinfo.ciphe= r_name, + src->encryption->encinfo.ciphe= r_size); + } else { + cipheralg =3D g_strdup_printf("%s", src->encryption->encin= fo.cipher_name); + } } =20 if (virJSONValueObjectAdd(&props, --=20 2.31.1