From patchwork Fri May 22 08:30:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 6461971 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2724E9F318 for ; Fri, 22 May 2015 08:31:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 15E9320376 for ; Fri, 22 May 2015 08:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E703320392 for ; Fri, 22 May 2015 08:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751355AbbEVIa4 (ORCPT ); Fri, 22 May 2015 04:30:56 -0400 Received: from helcar.hengli.com.au ([209.40.204.226]:49637 "EHLO helcar.hengli.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751228AbbEVIax (ORCPT ); Fri, 22 May 2015 04:30:53 -0400 Received: from gondolin.me.apana.org.au ([192.168.0.6]) by norbury.hengli.com.au with esmtp (Exim 4.80 #3 (Debian)) id 1YviLy-0001Bx-FD; Fri, 22 May 2015 18:30:50 +1000 Received: from herbert by gondolin.me.apana.org.au with local (Exim 4.80) (envelope-from ) id 1YviLy-0000x5-2I; Fri, 22 May 2015 16:30:50 +0800 Subject: [v2 PATCH 2/13] crypto: seqiv - Use aead_register_instance References: <20150522082708.GA3507@gondor.apana.org.au> To: Linux Crypto Mailing List , netdev@vger.kernel.org, "David S. Miller" , Johannes Berg , Marcel Holtmann , Steffen Klassert , Stephan Mueller Message-Id: From: Herbert Xu Date: Fri, 22 May 2015 16:30:50 +0800 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP New style AEAD instances must use aead_register_instance. This worked by chance because aead_geniv_alloc is still setting things the old way. This patch converts the template over to the create model where we are responsible for instance registration so that we can call the correct function. Signed-off-by: Herbert Xu --- crypto/seqiv.c | 135 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 56 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/crypto/seqiv.c b/crypto/seqiv.c index a9bfbda..2680e94 100644 --- a/crypto/seqiv.c +++ b/crypto/seqiv.c @@ -38,6 +38,8 @@ struct seqiv_aead_ctx { u8 salt[] __attribute__ ((aligned(__alignof__(u32)))); }; +static void seqiv_free(struct crypto_instance *inst); + static int seqiv_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { @@ -583,23 +585,20 @@ static void seqiv_aead_exit(struct crypto_tfm *tfm) crypto_put_default_null_skcipher(); } -static struct crypto_template seqiv_tmpl; -static struct crypto_template seqniv_tmpl; - -static struct crypto_instance *seqiv_ablkcipher_alloc(struct rtattr **tb) +static int seqiv_ablkcipher_create(struct crypto_template *tmpl, + struct rtattr **tb) { struct crypto_instance *inst; + int err; - inst = skcipher_geniv_alloc(&seqiv_tmpl, tb, 0, 0); + inst = skcipher_geniv_alloc(tmpl, tb, 0, 0); if (IS_ERR(inst)) - goto out; + return PTR_ERR(inst); - if (inst->alg.cra_ablkcipher.ivsize < sizeof(u64)) { - skcipher_geniv_free(inst); - inst = ERR_PTR(-EINVAL); - goto out; - } + err = -EINVAL; + if (inst->alg.cra_ablkcipher.ivsize < sizeof(u64)) + goto free_inst; inst->alg.cra_ablkcipher.givencrypt = seqiv_givencrypt_first; @@ -609,18 +608,28 @@ static struct crypto_instance *seqiv_ablkcipher_alloc(struct rtattr **tb) inst->alg.cra_ctxsize += inst->alg.cra_ablkcipher.ivsize; inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx); + inst->alg.cra_alignmask |= __alignof__(u32) - 1; + + err = crypto_register_instance(tmpl, inst); + if (err) + goto free_inst; + out: - return inst; + return err; + +free_inst: + skcipher_geniv_free(inst); + goto out; } -static struct crypto_instance *seqiv_old_aead_alloc(struct aead_instance *aead) +static int seqiv_old_aead_create(struct crypto_template *tmpl, + struct aead_instance *aead) { struct crypto_instance *inst = aead_crypto_instance(aead); + int err = -EINVAL; - if (inst->alg.cra_aead.ivsize < sizeof(u64)) { - aead_geniv_free(aead); - return ERR_PTR(-EINVAL); - } + if (inst->alg.cra_aead.ivsize < sizeof(u64)) + goto free_inst; inst->alg.cra_aead.givencrypt = seqiv_aead_givencrypt_first; @@ -630,28 +639,38 @@ static struct crypto_instance *seqiv_old_aead_alloc(struct aead_instance *aead) inst->alg.cra_ctxsize = inst->alg.cra_aead.ivsize; inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx); - return inst; + err = crypto_register_instance(tmpl, inst); + if (err) + goto free_inst; + +out: + return err; + +free_inst: + aead_geniv_free(aead); + goto out; } -static struct crypto_instance *seqiv_aead_alloc(struct rtattr **tb) +static int seqiv_aead_create(struct crypto_template *tmpl, struct rtattr **tb) { struct aead_instance *inst; struct crypto_aead_spawn *spawn; struct aead_alg *alg; + int err; - inst = aead_geniv_alloc(&seqiv_tmpl, tb, 0, 0); + inst = aead_geniv_alloc(tmpl, tb, 0, 0); if (IS_ERR(inst)) - goto out; + return PTR_ERR(inst); + + inst->alg.base.cra_alignmask |= __alignof__(u32) - 1; if (inst->alg.base.cra_aead.encrypt) - return seqiv_old_aead_alloc(inst); + return seqiv_old_aead_create(tmpl, inst); - if (inst->alg.ivsize < sizeof(u64)) { - aead_geniv_free(inst); - inst = ERR_PTR(-EINVAL); - goto out; - } + err = -EINVAL; + if (inst->alg.ivsize < sizeof(u64)) + goto free_inst; spawn = aead_instance_ctx(inst); alg = crypto_spawn_aead_alg(spawn); @@ -675,43 +694,43 @@ static struct crypto_instance *seqiv_aead_alloc(struct rtattr **tb) inst->alg.base.cra_exit = seqiv_aead_compat_exit; } + err = aead_register_instance(tmpl, inst); + if (err) + goto free_inst; + out: - return aead_crypto_instance(inst); + return err; + +free_inst: + aead_geniv_free(inst); + goto out; } -static struct crypto_instance *seqiv_alloc(struct rtattr **tb) +static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb) { struct crypto_attr_type *algt; - struct crypto_instance *inst; int err; algt = crypto_get_attr_type(tb); if (IS_ERR(algt)) - return ERR_CAST(algt); + return PTR_ERR(algt); err = crypto_get_default_rng(); if (err) - return ERR_PTR(err); + return err; if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK) - inst = seqiv_ablkcipher_alloc(tb); + err = seqiv_ablkcipher_create(tmpl, tb); else - inst = seqiv_aead_alloc(tb); - - if (IS_ERR(inst)) - goto put_rng; - - inst->alg.cra_alignmask |= __alignof__(u32) - 1; + err = seqiv_aead_create(tmpl, tb); -out: - return inst; + if (err) + crypto_put_default_rng(); -put_rng: - crypto_put_default_rng(); - goto out; + return err; } -static struct crypto_instance *seqniv_alloc(struct rtattr **tb) +static int seqniv_create(struct crypto_template *tmpl, struct rtattr **tb) { struct aead_instance *inst; struct crypto_aead_spawn *spawn; @@ -720,18 +739,16 @@ static struct crypto_instance *seqniv_alloc(struct rtattr **tb) err = crypto_get_default_rng(); if (err) - return ERR_PTR(err); - - inst = aead_geniv_alloc(&seqniv_tmpl, tb, 0, 0); + return err; + inst = aead_geniv_alloc(tmpl, tb, 0, 0); + err = PTR_ERR(inst); if (IS_ERR(inst)) goto put_rng; - if (inst->alg.ivsize < sizeof(u64)) { - aead_geniv_free(inst); - inst = ERR_PTR(-EINVAL); - goto put_rng; - } + err = -EINVAL; + if (inst->alg.ivsize < sizeof(u64)) + goto free_inst; spawn = aead_instance_ctx(inst); alg = crypto_spawn_aead_alg(spawn); @@ -748,9 +765,15 @@ static struct crypto_instance *seqniv_alloc(struct rtattr **tb) inst->alg.base.cra_ctxsize = sizeof(struct seqiv_aead_ctx); inst->alg.base.cra_ctxsize += inst->alg.base.cra_aead.ivsize; + err = aead_register_instance(tmpl, inst); + if (err) + goto free_inst; + out: - return aead_crypto_instance(inst); + return err; +free_inst: + aead_geniv_free(inst); put_rng: crypto_put_default_rng(); goto out; @@ -767,14 +790,14 @@ static void seqiv_free(struct crypto_instance *inst) static struct crypto_template seqiv_tmpl = { .name = "seqiv", - .alloc = seqiv_alloc, + .create = seqiv_create, .free = seqiv_free, .module = THIS_MODULE, }; static struct crypto_template seqniv_tmpl = { .name = "seqniv", - .alloc = seqniv_alloc, + .create = seqniv_create, .free = seqiv_free, .module = THIS_MODULE, };