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: 155888 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2870220jaa; Thu, 17 Jan 2019 21:58:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN69VW3TtZRd54uxN60XAgMdmsC6wqoOBNnyewYq+MwJU8ufXhbRnnxStHe6sttZd2NJkvAj X-Received: by 2002:a63:f141:: with SMTP id o1mr16616175pgk.134.1547791138700; Thu, 17 Jan 2019 21:58:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547791138; cv=none; d=google.com; s=arc-20160816; b=HZe26lzxm8w3CX+Mp/LgPJVyQMKIUdxpGDovE9sPeTPnR9EUzBLUpJR+ljxcfn85Cj zIA+7iUZb2a0EyWjPOrCcsu187sg6tfB5JxNikEA01v0nQjhp/M+IIej4zOi2wts16er wTGRKCGwwIVbQHTQ1jTp3DmVRnYBcVR/WTF0jlxQa5E3A6dghyFPnezaSFTsVM/s/F+5 jxZJBaDSbbNzDjuKOpy5TjO0P82y//1P6GCTPWrUD5Ywf4vzp81cm44u8s+JvKshJU4M Oe8Cehu57Wr5tHHU+1bchLJ9nMGx9TOPBftd7LKPZgwiqke0Kq3Pimzke02zalsXPVYe 1RPQ== 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; bh=qgbETkJveeRquwRYZS6EcFdYNlCvVItdivYyetqbvrw=; b=a8qGVWS49DRQtEO2HUWvC3YO9WZ9dJlXdSdrmE7i9lLpSr0u/Hm8/giwkKtyv10eDI ya6cKlExUGgQ+4GXkNrYT/bTmKysaegpvt5EkaCiporG19iJVDsrF9Cy1PyhVHqoVy+9 lZCa0QldL9pQGT0kcq7ci1dDNABJtVyEhYi0ME8sP1aUX58MdxDM88fkHIUNQN6fW+ku TajAvPBTTleo798TLsrScW+ounKpIreflpwW8SGRNUPVi8/Q2K7tIlMfETH6+AyQGSXb RDhVmQdSUvvVxZFH1KpG5eyAIN7TJSVXbirq5HUej96Dea9IeMYoeyFtc/9XT+hR76CC gs3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 e11si3751825pgf.450.2019.01.17.21.58.58; Thu, 17 Jan 2019 21:58:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727158AbfARF65 (ORCPT + 3 others); 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 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(+) -- 1.7.12.4 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: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: 155889 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2870266jaa; Thu, 17 Jan 2019 21:59:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN6gh85KwbBER7zwcdAiwjEVG4xC1sqXUywSvzawIohv8hFTGJ6n6Tt/uSawdtuwC7Wymj0k X-Received: by 2002:a63:2b82:: with SMTP id r124mr1435394pgr.300.1547791143751; Thu, 17 Jan 2019 21:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547791143; cv=none; d=google.com; s=arc-20160816; b=oqGAjRYLNHxp71fPHgtwS1U4xmEwZ0iE77cyPb0/vS7dNQbpFqjnH4X1e2lnlJhrOM JI5ADw5vdprPNWEtDDYTx8qYDczenGI5LI+jAaSorMpzF+/saPhkdhDPX+ZVoatoAr4c qeiTP+TVoerG/z9hbz9aH5Fr6qDqiN6/89GnyEWPy9aolSfBKkBG5AVa59g6ArlHd4s1 qcjfc4TGnbJbHXabNmydKrDDfQQ4KozjGHpn8GLKWurJaJtoDnVRlNqIbOky0IldNqNJ Pq9xasgmVUgiGQjGu61vaMm0ODTb0ftUWYWn61XQhO+Y5dfx2Go9pxJTbv3aTpvceSmj 02cg== 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; bh=1ck7mDTpUdLAeuUBiXeHdVIQjDMISmufPVZ2Qw4LsWs=; b=vtOCT+H8uJH9UcaSVk7b17GdKwonsXq9lHSxBPeiWjnSlZmXoYfU3u2OYgHMkOw8cb KBGF1kxgnXoO66r7nHXqav+RKpP9YjeVbLQGRw/PjL/1eLnDc0b38WkYXhvsJnG0+pI5 hHUrS524r0KQ3weYQFIqbvvoD0I4ugex/d+H2Y10bdhIMFm8Rt0+fzUbAIXE7pLdxrSH SDcBa+OshUYTgOGleOXJcynI/256vKqZ7wx7RRzugU2pSMljZr06AOKB2k6kCmgy/E+E LIf57YTJJOcL+/l5PB6ngA6eki4FHls2AJFWmTOb5MJCSt/MmxDRsqnOAp/uZ8zxangE cpyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-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 x6si580817plv.321.2019.01.17.21.59.03; Thu, 17 Jan 2019 21:59:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727248AbfARF7C (ORCPT + 3 others); 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 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(-) -- 1.7.12.4 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);