From patchwork Thu Oct 27 06:55:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianjia Zhang X-Patchwork-Id: 11611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp71910wru; Wed, 26 Oct 2022 23:58:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7gQsRbg+8UiSgKldbR9t6R31aA3rR6hQMzuUlOyJnShPof684D1vBAFCdEI3G4R6NvRjcN X-Received: by 2002:a17:902:724c:b0:177:5080:cbeb with SMTP id c12-20020a170902724c00b001775080cbebmr47882621pll.67.1666853902151; Wed, 26 Oct 2022 23:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666853902; cv=none; d=google.com; s=arc-20160816; b=rWprxnnTewL41dEl3HmIUWX/dME7HEdZ0921f2jpIH1XORN8XsP4Zcnb2+Zios1Y16 NDKXWF8rg+6xFc7j5Kkiha41/b/BkozxFbJ8FKumgZOWqp11HVk9y94OBbI3Y0u2h10w 3eyzdmd1FxCe2XYEJni4WDU41SCMlWSBKNEJ/GodSOaOANiMr7z6He0SVArHGp1LtBHs 9URF7x44faZ3Nq7ndoA+e6PA3rig6K4cbKSWFjs5EaLRiY4nTw07ERsoKcFOIV2KEfi3 TnBbSPAXceZj2ErTnTYm/gQnbPo8bBNjum//VWV58wzcZjZQA3T7tbpe1ixwVBio5x4i hNyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rHSyVlQyQiHtYMUPA93G/tFaq5SvsTuWnEA+5nIcnuQ=; b=pjC/z32cD4xO/eIC+COBFgxy75Vah0GqgUizPvL5KlBYOZP1nqvBOvAO3FWu/11C8G dv5xAiOiOm14uqRQ6/gicbVe5DtNIcqoKQLc6VRKHbFr1fkGmRCYln2lNw+qtBQZsq3R EjThUP6UsMVZsHcmvH1jx7ooCOYaGyBc9B1iENBhieYrjm85yPw3lhJB1FOc6HXEXdCG REOaeVq2Mi9++FuDbEfovw7t5g1NQhaxBVwWMoxHFugU0sIaMUvPE/AD6eIlWtR9r9AP p4XqWH6J9YxUPDwVmb6qlSdj5tnYH3aYlAzu55qzVpAPA8m9MCYQBM9T0PFjkWcwkdUR uomw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v135-20020a63618d000000b0043ba2df0855si581601pgb.726.2022.10.26.23.58.08; Wed, 26 Oct 2022 23:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234748AbiJ0G4r (ORCPT + 99 others); Thu, 27 Oct 2022 02:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234698AbiJ0Gzy (ORCPT ); Thu, 27 Oct 2022 02:55:54 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF51939BBC; Wed, 26 Oct 2022 23:55:32 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R301e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0VTAHLqG_1666853722; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0VTAHLqG_1666853722) by smtp.aliyun-inc.com; Thu, 27 Oct 2022 14:55:23 +0800 From: Tianjia Zhang To: Herbert Xu , "David S. Miller" , Jussi Kivilinna , Ard Biesheuvel , Mark Brown , Catalin Marinas , Will Deacon , Maxime Coquelin , Alexandre Torgue , Eric Biggers , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Cc: Tianjia Zhang Subject: [PATCH v3 08/13] crypto: arm64/sm4 - export reusable CE acceleration functions Date: Thu, 27 Oct 2022 14:55:00 +0800 Message-Id: <20221027065505.15306-9-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20221027065505.15306-1-tianjia.zhang@linux.alibaba.com> References: <20221027065505.15306-1-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747822997250716841?= X-GMAIL-MSGID: =?utf-8?q?1747822997250716841?= In the accelerated implementation of the SM4 algorithm using the Crypto Extension instructions, there are some functions that can be reused in the upcoming accelerated implementation of the GCM/CCM mode, and the CBC/CFB encryption is reused in the optimized implementation of SVESM4. Signed-off-by: Tianjia Zhang --- arch/arm64/crypto/sm4-ce-glue.c | 5 +++++ arch/arm64/crypto/sm4-ce.h | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 arch/arm64/crypto/sm4-ce.h diff --git a/arch/arm64/crypto/sm4-ce-glue.c b/arch/arm64/crypto/sm4-ce-glue.c index ff2d8442d473..63abcadc684b 100644 --- a/arch/arm64/crypto/sm4-ce-glue.c +++ b/arch/arm64/crypto/sm4-ce-glue.c @@ -36,6 +36,11 @@ asmlinkage void sm4_ce_cfb_dec(const u32 *rkey, u8 *dst, const u8 *src, asmlinkage void sm4_ce_ctr_enc(const u32 *rkey, u8 *dst, const u8 *src, u8 *iv, unsigned int nblks); +EXPORT_SYMBOL(sm4_ce_expand_key); +EXPORT_SYMBOL(sm4_ce_crypt_block); +EXPORT_SYMBOL(sm4_ce_cbc_enc); +EXPORT_SYMBOL(sm4_ce_cfb_enc); + static int sm4_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int key_len) { diff --git a/arch/arm64/crypto/sm4-ce.h b/arch/arm64/crypto/sm4-ce.h new file mode 100644 index 000000000000..109c21b37590 --- /dev/null +++ b/arch/arm64/crypto/sm4-ce.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * SM4 common functions for Crypto Extensions + * Copyright (C) 2022 Tianjia Zhang + */ + +void sm4_ce_expand_key(const u8 *key, u32 *rkey_enc, u32 *rkey_dec, + const u32 *fk, const u32 *ck); + +void sm4_ce_crypt_block(const u32 *rkey, u8 *dst, const u8 *src); + +void sm4_ce_cbc_enc(const u32 *rkey_enc, u8 *dst, const u8 *src, + u8 *iv, unsigned int nblocks); + +void sm4_ce_cfb_enc(const u32 *rkey_enc, u8 *dst, const u8 *src, + u8 *iv, unsigned int nblocks);