From patchwork Fri Jan 18 05:58:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 10769451 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 716A514E5 for ; Fri, 18 Jan 2019 05:58:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E29B2E368 for ; Fri, 18 Jan 2019 05:58:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28D9E2E379; Fri, 18 Jan 2019 05:58:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 775D52E368 for ; Fri, 18 Jan 2019 05:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727158AbfARF65 (ORCPT ); Fri, 18 Jan 2019 00:58:57 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2256 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727100AbfARF65 (ORCPT ); Fri, 18 Jan 2019 00:58:57 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BC6407D50AC1ED243926; Fri, 18 Jan 2019 13:58:54 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Fri, 18 Jan 2019 13:58:49 +0800 From: Xiongfeng Wang To: , , CC: , , , , , Subject: [PATCH V3 1/5] crypto: api - add a helper to (un)register a array of templates Date: Fri, 18 Jan 2019 13:58:11 +0800 Message-ID: <1547791095-48339-2-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> References: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiongfeng Wang This patch add a helper to (un)register a array of templates. The following patches will use this helper to simplify the code. Signed-off-by: Xiongfeng Wang Reviewed-by: Eric Biggers --- crypto/algapi.c | 27 +++++++++++++++++++++++++++ include/crypto/algapi.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/crypto/algapi.c b/crypto/algapi.c index 713baab..4c9c86b 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -494,6 +494,24 @@ int crypto_register_template(struct crypto_template *tmpl) } EXPORT_SYMBOL_GPL(crypto_register_template); +int crypto_register_templates(struct crypto_template *tmpls, int count) +{ + int i, err; + + for (i = 0; i < count; i++) { + err = crypto_register_template(&tmpls[i]); + if (err) + goto out; + } + return 0; + +out: + for (--i; i >= 0; --i) + crypto_unregister_template(&tmpls[i]); + return err; +} +EXPORT_SYMBOL_GPL(crypto_register_templates); + void crypto_unregister_template(struct crypto_template *tmpl) { struct crypto_instance *inst; @@ -523,6 +541,15 @@ void crypto_unregister_template(struct crypto_template *tmpl) } EXPORT_SYMBOL_GPL(crypto_unregister_template); +void crypto_unregister_templates(struct crypto_template *tmpls, int count) +{ + int i; + + for (i = count - 1; i >= 0; --i) + crypto_unregister_template(&tmpls[i]); +} +EXPORT_SYMBOL_GPL(crypto_unregister_templates); + static struct crypto_template *__crypto_lookup_template(const char *name) { struct crypto_template *q, *tmpl = NULL; diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 093869f..4be38cd 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -143,7 +143,9 @@ struct ablkcipher_walk { void crypto_mod_put(struct crypto_alg *alg); int crypto_register_template(struct crypto_template *tmpl); +int crypto_register_templates(struct crypto_template *tmpls, int count); void crypto_unregister_template(struct crypto_template *tmpl); +void crypto_unregister_templates(struct crypto_template *tmpls, int count); struct crypto_template *crypto_lookup_template(const char *name); int crypto_register_instance(struct crypto_template *tmpl, From patchwork Fri Jan 18 05:58:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 10769457 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0903B1390 for ; Fri, 18 Jan 2019 05:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA2252E6D9 for ; Fri, 18 Jan 2019 05:59:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB7212E72D; Fri, 18 Jan 2019 05:59:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA28F2E6D9 for ; Fri, 18 Jan 2019 05:59:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726919AbfARF7M (ORCPT ); Fri, 18 Jan 2019 00:59:12 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2197 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727142AbfARF7C (ORCPT ); Fri, 18 Jan 2019 00:59:02 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E250B42F33078F77ADB7; Fri, 18 Jan 2019 13:58:59 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Fri, 18 Jan 2019 13:58:49 +0800 From: Xiongfeng Wang To: , , CC: , , , , , Subject: [PATCH V3 2/5] crypto: ccm - use template array registering API to simplify the code Date: Fri, 18 Jan 2019 13:58:12 +0800 Message-ID: <1547791095-48339-3-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> References: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiongfeng Wang Use crypto template array registering API to simplify the code. Signed-off-by: Xiongfeng Wang Reviewed-by: Eric Biggers --- crypto/ccm.c | 78 ++++++++++++++++++------------------------------------------ 1 file changed, 23 insertions(+), 55 deletions(-) diff --git a/crypto/ccm.c b/crypto/ccm.c index b242fd0..50df8f0 100644 --- a/crypto/ccm.c +++ b/crypto/ccm.c @@ -589,12 +589,6 @@ static int crypto_ccm_create(struct crypto_template *tmpl, struct rtattr **tb) mac_name); } -static struct crypto_template crypto_ccm_tmpl = { - .name = "ccm", - .create = crypto_ccm_create, - .module = THIS_MODULE, -}; - static int crypto_ccm_base_create(struct crypto_template *tmpl, struct rtattr **tb) { @@ -618,12 +612,6 @@ static int crypto_ccm_base_create(struct crypto_template *tmpl, cipher_name); } -static struct crypto_template crypto_ccm_base_tmpl = { - .name = "ccm_base", - .create = crypto_ccm_base_create, - .module = THIS_MODULE, -}; - static int crypto_rfc4309_setkey(struct crypto_aead *parent, const u8 *key, unsigned int keylen) { @@ -854,12 +842,6 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl, goto out; } -static struct crypto_template crypto_rfc4309_tmpl = { - .name = "rfc4309", - .create = crypto_rfc4309_create, - .module = THIS_MODULE, -}; - static int crypto_cbcmac_digest_setkey(struct crypto_shash *parent, const u8 *inkey, unsigned int keylen) { @@ -999,51 +981,37 @@ static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb) return err; } -static struct crypto_template crypto_cbcmac_tmpl = { - .name = "cbcmac", - .create = cbcmac_create, - .free = shash_free_instance, - .module = THIS_MODULE, +static struct crypto_template crypto_ccm_tmpls[] = { + { + .name = "cbcmac", + .create = cbcmac_create, + .free = shash_free_instance, + .module = THIS_MODULE, + }, { + .name = "ccm_base", + .create = crypto_ccm_base_create, + .module = THIS_MODULE, + }, { + .name = "ccm", + .create = crypto_ccm_create, + .module = THIS_MODULE, + }, { + .name = "rfc4309", + .create = crypto_rfc4309_create, + .module = THIS_MODULE, + }, }; static int __init crypto_ccm_module_init(void) { - int err; - - err = crypto_register_template(&crypto_cbcmac_tmpl); - if (err) - goto out; - - err = crypto_register_template(&crypto_ccm_base_tmpl); - if (err) - goto out_undo_cbcmac; - - err = crypto_register_template(&crypto_ccm_tmpl); - if (err) - goto out_undo_base; - - err = crypto_register_template(&crypto_rfc4309_tmpl); - if (err) - goto out_undo_ccm; - -out: - return err; - -out_undo_ccm: - crypto_unregister_template(&crypto_ccm_tmpl); -out_undo_base: - crypto_unregister_template(&crypto_ccm_base_tmpl); -out_undo_cbcmac: - crypto_register_template(&crypto_cbcmac_tmpl); - goto out; + return crypto_register_templates(crypto_ccm_tmpls, + ARRAY_SIZE(crypto_ccm_tmpls)); } static void __exit crypto_ccm_module_exit(void) { - crypto_unregister_template(&crypto_rfc4309_tmpl); - crypto_unregister_template(&crypto_ccm_tmpl); - crypto_unregister_template(&crypto_ccm_base_tmpl); - crypto_unregister_template(&crypto_cbcmac_tmpl); + crypto_unregister_templates(crypto_ccm_tmpls, + ARRAY_SIZE(crypto_ccm_tmpls)); } module_init(crypto_ccm_module_init); From patchwork Fri Jan 18 05:58:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 10769453 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F3541390 for ; Fri, 18 Jan 2019 05:59:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392002E368 for ; Fri, 18 Jan 2019 05:59:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B68D2E379; Fri, 18 Jan 2019 05:59:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3FE92E368 for ; Fri, 18 Jan 2019 05:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727248AbfARF7C (ORCPT ); Fri, 18 Jan 2019 00:59:02 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2194 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727234AbfARF7C (ORCPT ); Fri, 18 Jan 2019 00:59:02 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D0FA6571B3B51639CD2C; Fri, 18 Jan 2019 13:58:59 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Fri, 18 Jan 2019 13:58:50 +0800 From: Xiongfeng Wang To: , , CC: , , , , , Subject: [PATCH V3 3/5] crypto: gcm - use template array registering API to simplify the code Date: Fri, 18 Jan 2019 13:58:13 +0800 Message-ID: <1547791095-48339-4-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> References: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiongfeng Wang Use crypto template array registering API to simplify the code. Signed-off-by: Xiongfeng Wang Reviewed-by: Eric Biggers --- crypto/gcm.c | 73 +++++++++++++++++++----------------------------------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/crypto/gcm.c b/crypto/gcm.c index e438492..31eb694 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -727,12 +727,6 @@ static int crypto_gcm_create(struct crypto_template *tmpl, struct rtattr **tb) ctr_name, "ghash"); } -static struct crypto_template crypto_gcm_tmpl = { - .name = "gcm", - .create = crypto_gcm_create, - .module = THIS_MODULE, -}; - static int crypto_gcm_base_create(struct crypto_template *tmpl, struct rtattr **tb) { @@ -756,12 +750,6 @@ static int crypto_gcm_base_create(struct crypto_template *tmpl, ctr_name, ghash_name); } -static struct crypto_template crypto_gcm_base_tmpl = { - .name = "gcm_base", - .create = crypto_gcm_base_create, - .module = THIS_MODULE, -}; - static int crypto_rfc4106_setkey(struct crypto_aead *parent, const u8 *key, unsigned int keylen) { @@ -989,12 +977,6 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl, goto out; } -static struct crypto_template crypto_rfc4106_tmpl = { - .name = "rfc4106", - .create = crypto_rfc4106_create, - .module = THIS_MODULE, -}; - static int crypto_rfc4543_setkey(struct crypto_aead *parent, const u8 *key, unsigned int keylen) { @@ -1231,10 +1213,24 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl, goto out; } -static struct crypto_template crypto_rfc4543_tmpl = { - .name = "rfc4543", - .create = crypto_rfc4543_create, - .module = THIS_MODULE, +static struct crypto_template crypto_gcm_tmpls[] = { + { + .name = "gcm_base", + .create = crypto_gcm_base_create, + .module = THIS_MODULE, + }, { + .name = "gcm", + .create = crypto_gcm_create, + .module = THIS_MODULE, + }, { + .name = "rfc4106", + .create = crypto_rfc4106_create, + .module = THIS_MODULE, + }, { + .name = "rfc4543", + .create = crypto_rfc4543_create, + .module = THIS_MODULE, + }, }; static int __init crypto_gcm_module_init(void) @@ -1247,42 +1243,19 @@ static int __init crypto_gcm_module_init(void) sg_init_one(&gcm_zeroes->sg, gcm_zeroes->buf, sizeof(gcm_zeroes->buf)); - err = crypto_register_template(&crypto_gcm_base_tmpl); - if (err) - goto out; - - err = crypto_register_template(&crypto_gcm_tmpl); + err = crypto_register_templates(crypto_gcm_tmpls, + ARRAY_SIZE(crypto_gcm_tmpls)); if (err) - goto out_undo_base; + kfree(gcm_zeroes); - err = crypto_register_template(&crypto_rfc4106_tmpl); - if (err) - goto out_undo_gcm; - - err = crypto_register_template(&crypto_rfc4543_tmpl); - if (err) - goto out_undo_rfc4106; - - return 0; - -out_undo_rfc4106: - crypto_unregister_template(&crypto_rfc4106_tmpl); -out_undo_gcm: - crypto_unregister_template(&crypto_gcm_tmpl); -out_undo_base: - crypto_unregister_template(&crypto_gcm_base_tmpl); -out: - kfree(gcm_zeroes); return err; } static void __exit crypto_gcm_module_exit(void) { kfree(gcm_zeroes); - crypto_unregister_template(&crypto_rfc4543_tmpl); - crypto_unregister_template(&crypto_rfc4106_tmpl); - crypto_unregister_template(&crypto_gcm_tmpl); - crypto_unregister_template(&crypto_gcm_base_tmpl); + crypto_unregister_templates(crypto_gcm_tmpls, + ARRAY_SIZE(crypto_gcm_tmpls)); } module_init(crypto_gcm_module_init); From patchwork Fri Jan 18 05:58:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 10769455 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0602C14E5 for ; Fri, 18 Jan 2019 05:59:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCB7F2E368 for ; Fri, 18 Jan 2019 05:59:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0B432E379; Fri, 18 Jan 2019 05:59:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 765592E368 for ; Fri, 18 Jan 2019 05:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727241AbfARF7C (ORCPT ); Fri, 18 Jan 2019 00:59:02 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2195 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727237AbfARF7C (ORCPT ); Fri, 18 Jan 2019 00:59:02 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id D71C7E507BD3EF291321; Fri, 18 Jan 2019 13:58:59 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Fri, 18 Jan 2019 13:58:51 +0800 From: Xiongfeng Wang To: , , CC: , , , , , Subject: [PATCH V3 4/5] crypto: ctr - use template array registering API to simplify the code Date: Fri, 18 Jan 2019 13:58:14 +0800 Message-ID: <1547791095-48339-5-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> References: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiongfeng Wang Use crypto template array registering API to simplify the code. Signed-off-by: Xiongfeng Wang Reviewed-by: Eric Biggers --- crypto/ctr.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/crypto/ctr.c b/crypto/ctr.c index 4c743a9..ec8f8b6 100644 --- a/crypto/ctr.c +++ b/crypto/ctr.c @@ -171,12 +171,6 @@ static int crypto_ctr_create(struct crypto_template *tmpl, struct rtattr **tb) return err; } -static struct crypto_template crypto_ctr_tmpl = { - .name = "ctr", - .create = crypto_ctr_create, - .module = THIS_MODULE, -}; - static int crypto_rfc3686_setkey(struct crypto_skcipher *parent, const u8 *key, unsigned int keylen) { @@ -366,36 +360,28 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, goto out; } -static struct crypto_template crypto_rfc3686_tmpl = { - .name = "rfc3686", - .create = crypto_rfc3686_create, - .module = THIS_MODULE, +static struct crypto_template crypto_ctr_tmpls[] = { + { + .name = "ctr", + .create = crypto_ctr_create, + .module = THIS_MODULE, + }, { + .name = "rfc3686", + .create = crypto_rfc3686_create, + .module = THIS_MODULE, + }, }; static int __init crypto_ctr_module_init(void) { - int err; - - err = crypto_register_template(&crypto_ctr_tmpl); - if (err) - goto out; - - err = crypto_register_template(&crypto_rfc3686_tmpl); - if (err) - goto out_drop_ctr; - -out: - return err; - -out_drop_ctr: - crypto_unregister_template(&crypto_ctr_tmpl); - goto out; + return crypto_register_templates(crypto_ctr_tmpls, + ARRAY_SIZE(crypto_ctr_tmpls)); } static void __exit crypto_ctr_module_exit(void) { - crypto_unregister_template(&crypto_rfc3686_tmpl); - crypto_unregister_template(&crypto_ctr_tmpl); + crypto_unregister_templates(crypto_ctr_tmpls, + ARRAY_SIZE(crypto_ctr_tmpls)); } module_init(crypto_ctr_module_init); From patchwork Fri Jan 18 05:58:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 10769459 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 023001390 for ; Fri, 18 Jan 2019 05:59:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E34AB2E727 for ; Fri, 18 Jan 2019 05:59:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7E112E72E; Fri, 18 Jan 2019 05:59:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86ECA2E727 for ; Fri, 18 Jan 2019 05:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727142AbfARF7S (ORCPT ); Fri, 18 Jan 2019 00:59:18 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2196 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727084AbfARF7C (ORCPT ); Fri, 18 Jan 2019 00:59:02 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DC9FB45E15388DB10ECF; Fri, 18 Jan 2019 13:58:59 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Fri, 18 Jan 2019 13:58:51 +0800 From: Xiongfeng Wang To: , , CC: , , , , , Subject: [PATCH V3 5/5] crypto: chacha20poly1305 - use template array registering API to simplify the code Date: Fri, 18 Jan 2019 13:58:15 +0800 Message-ID: <1547791095-48339-6-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> References: <1547791095-48339-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiongfeng Wang Use crypto template array registering API to simplify the code. Signed-off-by: Xiongfeng Wang Reviewed-by: Eric Biggers --- crypto/chacha20poly1305.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/crypto/chacha20poly1305.c b/crypto/chacha20poly1305.c index fef1144..ed2e12e 100644 --- a/crypto/chacha20poly1305.c +++ b/crypto/chacha20poly1305.c @@ -701,37 +701,28 @@ static int rfc7539esp_create(struct crypto_template *tmpl, struct rtattr **tb) return chachapoly_create(tmpl, tb, "rfc7539esp", 8); } -static struct crypto_template rfc7539_tmpl = { - .name = "rfc7539", - .create = rfc7539_create, - .module = THIS_MODULE, -}; - -static struct crypto_template rfc7539esp_tmpl = { - .name = "rfc7539esp", - .create = rfc7539esp_create, - .module = THIS_MODULE, +static struct crypto_template rfc7539_tmpls[] = { + { + .name = "rfc7539", + .create = rfc7539_create, + .module = THIS_MODULE, + }, { + .name = "rfc7539esp", + .create = rfc7539esp_create, + .module = THIS_MODULE, + }, }; static int __init chacha20poly1305_module_init(void) { - int err; - - err = crypto_register_template(&rfc7539_tmpl); - if (err) - return err; - - err = crypto_register_template(&rfc7539esp_tmpl); - if (err) - crypto_unregister_template(&rfc7539_tmpl); - - return err; + return crypto_register_templates(rfc7539_tmpls, + ARRAY_SIZE(rfc7539_tmpls)); } static void __exit chacha20poly1305_module_exit(void) { - crypto_unregister_template(&rfc7539esp_tmpl); - crypto_unregister_template(&rfc7539_tmpl); + crypto_unregister_templates(rfc7539_tmpls, + ARRAY_SIZE(rfc7539_tmpls)); } module_init(chacha20poly1305_module_init);