Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp225222imm; Wed, 18 Jul 2018 00:44:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpejYo4teo0Gh9nfpgTZhpzK2JmtymHZvAgK1cqA0Ijpab3/LGl2gz2GIXpiNlF+ESTjxs6R X-Received: by 2002:a17:902:8308:: with SMTP id bd8-v6mr4902461plb.329.1531899862300; Wed, 18 Jul 2018 00:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531899862; cv=none; d=google.com; s=arc-20160816; b=tMBwPUwfZLIO1rDLsavbJLYkgbWnY5MdblS+ngHaBOpfgadsx18glHeAPuJyiUPFDw 58tyP4EKy0FzoHZGaxj/KorYzbktF6irwbWv5iJqgFl7vHceQvtGVDacGxvuStrddcDs iIZdl2TWnqcxfxdh+hUaXyOMjXSrI9A9UN7WLWXyTfaNu5IdvJ0XUN1ErEPOtlIGtVRQ xfaRNnyoANd1zcg0lbHEROxiHjT9z/NbISUkFipHaND5eK3yQp6woMJyGMSa3xSLX8Ys dziwTXRD0nUQCbB8PR1A+dFYZgaCLe+dHNxHJaAjBgg3FOD7lEjIs0taesq/YOhnje5a PK7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=pU7ZABFDDdjB7yw+T5z8pzv3IpRwOHLkZbUnHmxk3+g=; b=t9iDNGQ4cI5xUfAuN31qPz8JDJ5VZI4io8lP40vr+G4+1XfcceCaR9V3bWV4j+16my ZeqQa9QPlrIYz+gkdU+Ts85Od+//OyDIULU2t3o//5+nO3CyICDKygx+dbc8T2/VfvEQ c+UMkqsRNAFCRdHB1oOKZMvMV2r1UH8g33d6p67czzSwju6tVh5NMFHTzhP0bAHwAcKY xmZCP969Yi6K/GJU2Hag57DKmg95O8RqCyN9RK4CKd3kGbF1EzWsx3gNUamrsOuDbgQW 3O0nm5yeTLXraEIpU+w72MiBvYfHXNEpKNWKM1ztFh0Auk4TfxtX7M+vRBLgBGjehrs5 2Pyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8-v6si2931211pgl.101.2018.07.18.00.44.07; Wed, 18 Jul 2018 00:44:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729972AbeGRITQ (ORCPT + 99 others); Wed, 18 Jul 2018 04:19:16 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9642 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728948AbeGRITP (ORCPT ); Wed, 18 Jul 2018 04:19:15 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 55111A1C17F3D; Wed, 18 Jul 2018 15:42:28 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.382.0; Wed, 18 Jul 2018 15:42:22 +0800 From: Xiongfeng Wang To: , , CC: , , , , , Subject: [PATCH 2/5] crypto: ccm - use template array registering API to simplify the code Date: Wed, 18 Jul 2018 15:30:52 +0800 Message-ID: <1531899055-29362-3-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1531899055-29362-1-git-send-email-wangxiongfeng2@huawei.com> References: <1531899055-29362-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use crypto template array registering API to simplify the code. Signed-off-by: Xiongfeng Wang --- crypto/ccm.c | 82 ++++++++++++++++++++---------------------------------------- 1 file changed, 27 insertions(+), 55 deletions(-) diff --git a/crypto/ccm.c b/crypto/ccm.c index 0a08334..1742d41 100644 --- a/crypto/ccm.c +++ b/crypto/ccm.c @@ -586,12 +586,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) { @@ -615,12 +609,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) { @@ -851,12 +839,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) { @@ -996,51 +978,41 @@ 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, +#define CCM_TEMPLATE_NUM 4 + +static struct crypto_template crypto_ccm_tmpl[CCM_TEMPLATE_NUM] = { + { + .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_template_array(crypto_ccm_tmpl, + CCM_TEMPLATE_NUM); } 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_template_array(crypto_ccm_tmpl, CCM_TEMPLATE_NUM); } module_init(crypto_ccm_module_init); -- 1.7.12.4