From: Herbert Xu <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: [PATCH 6/19] [CRYPTO] gcm: Use crypto_grab_skcipher
Date: Tue, 11 Dec 2007 12:02:57 +0800 [thread overview]
Message-ID: <E1J1wKf-0002jr-00@gondolin.me.apana.org.au> (raw)
In-Reply-To: 20071211040215.GA10360@gondor.apana.org.au
[CRYPTO] gcm: Use crypto_grab_skcipher
This patch converts the gcm algorithm over to crypto_grab_skcipher
which is a prerequisite for IV generation.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/gcm.c | 41 +++++++++++++++++++----------------------
1 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 9c29765..1fdefe5 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -8,9 +8,9 @@
* by the Free Software Foundation.
*/
-#include <crypto/algapi.h>
#include <crypto/ctr.h>
#include <crypto/gf128mul.h>
+#include <crypto/internal/skcipher.h>
#include <crypto/scatterwalk.h>
#include <linux/err.h>
#include <linux/init.h>
@@ -18,10 +18,8 @@
#include <linux/module.h>
#include <linux/slab.h>
-#include "internal.h"
-
struct gcm_instance_ctx {
- struct crypto_spawn ctr;
+ struct crypto_skcipher_spawn ctr;
char cipher_name[CRYPTO_MAX_ALG_NAME];
};
@@ -353,7 +351,7 @@ static int crypto_gcm_init_tfm(struct crypto_tfm *tfm)
unsigned long align;
int err;
- ctr = crypto_spawn_ablkcipher(&ictx->ctr);
+ ctr = crypto_spawn_skcipher(&ictx->ctr);
err = PTR_ERR(ctr);
if (IS_ERR(ctr))
return err;
@@ -400,33 +398,31 @@ static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL);
- ctr = crypto_alg_mod_lookup(ctr_name, CRYPTO_ALG_TYPE_BLKCIPHER,
- CRYPTO_ALG_TYPE_MASK);
+ inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
+ if (!inst)
+ return ERR_PTR(-ENOMEM);
- if (IS_ERR(ctr))
- return ERR_PTR(PTR_ERR(ctr));
+ ctx = crypto_instance_ctx(inst);
+ crypto_set_skcipher_spawn(&ctx->ctr, inst);
+ err = crypto_grab_skcipher(&ctx->ctr, ctr_name, 0,
+ (algt->type ^ CRYPTO_ALG_ASYNC) &
+ algt->mask);
+ if (err)
+ goto err_free_inst;
+
+ ctr = crypto_skcipher_spawn_alg(&ctx->ctr);
/* Not a stream cipher? */
err = -EINVAL;
if (ctr->cra_blocksize != 1)
goto out_put_ctr;
- inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
- err = -ENOMEM;
- if (!inst)
- goto out_put_ctr;
-
err = -ENAMETOOLONG;
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"gcm_base(%s,%s)", ctr->cra_driver_name, cipher_name) >=
CRYPTO_MAX_ALG_NAME)
goto out_put_ctr;
- ctx = crypto_instance_ctx(inst);
- err = crypto_init_spawn(&ctx->ctr, ctr, inst, CRYPTO_ALG_TYPE_MASK);
- if (err)
- goto err_free_inst;
-
memcpy(inst->alg.cra_name, full_name, CRYPTO_MAX_ALG_NAME);
memcpy(ctx->cipher_name, cipher_name, CRYPTO_MAX_ALG_NAME);
@@ -446,11 +442,12 @@ static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
inst->alg.cra_aead.decrypt = crypto_gcm_decrypt;
out:
- crypto_mod_put(ctr);
return inst;
+
+out_put_ctr:
+ crypto_drop_skcipher(&ctx->ctr);
err_free_inst:
kfree(inst);
-out_put_ctr:
inst = ERR_PTR(err);
goto out;
}
@@ -482,7 +479,7 @@ static void crypto_gcm_free(struct crypto_instance *inst)
{
struct gcm_instance_ctx *ctx = crypto_instance_ctx(inst);
- crypto_drop_spawn(&ctx->ctr);
+ crypto_drop_skcipher(&ctx->ctr);
kfree(inst);
}
next prev parent reply other threads:[~2007-12-11 4:03 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-11 4:02 [0/19] Add IV generators and givcrypt Herbert Xu
2007-12-11 4:02 ` [PATCH 1/19] [CRYPTO] blkcipher: Merge ablkcipher and blkcipher into one option/module Herbert Xu
2007-12-11 4:02 ` [PATCH 2/19] [CRYPTO] skcipher: Add givcrypt operations and givcipher type Herbert Xu
2007-12-11 4:02 ` [PATCH 3/19] [CRYPTO] skcipher: Added geniv field Herbert Xu
2007-12-11 4:02 ` [PATCH 4/19] [CRYPTO] cryptd: Use geniv of the underlying algorithm Herbert Xu
2007-12-11 4:02 ` [PATCH 5/19] [CRYPTO] skcipher: Add crypto_grab_skcipher interface Herbert Xu
2007-12-11 4:02 ` Herbert Xu [this message]
2007-12-11 4:02 ` [PATCH 7/19] [CRYPTO] authenc: Use crypto_grab_skcipher Herbert Xu
2007-12-11 4:02 ` [PATCH 8/19] [CRYPTO] skcipher: Remove crypto_spawn_ablkcipher Herbert Xu
2007-12-11 4:03 ` [PATCH 9/19] [CRYPTO] skcipher: Add skcipher_geniv_alloc/skcipher_geniv_free Herbert Xu
2007-12-11 4:05 ` [PATCH 10/19] [CRYPTO] chainiv: Add chain IV generator Herbert Xu
2007-12-11 4:05 ` [PATCH 11/19] [CRYPTO] skcipher: Added skcipher_givcrypt_complete Herbert Xu
2007-12-11 4:05 ` [PATCH 12/19] [CRYPTO] eseqiv: Add Encrypted Sequence Number IV Generator Herbert Xu
2007-12-11 4:05 ` [PATCH 13/19] [CRYPTO] skcipher: Create default givcipher instances Herbert Xu
2007-12-11 4:05 ` [PATCH 14/19] [CRYPTO] seqiv: Add Sequence Number IV Generator Herbert Xu
2007-12-11 4:05 ` [PATCH 15/19] [CRYPTO] skcipher: Add top-level givencrypt/givdecrypt calls Herbert Xu
2007-12-11 4:05 ` [PATCH 16/19] [CRYPTO] aead: Add givcrypt operations Herbert Xu
2007-12-11 4:05 ` [PATCH 17/19] [CRYPTO] authenc: Add givencrypt operation Herbert Xu
2007-12-11 4:05 ` [PATCH 18/19] [CRYPTO] gcm: Add givcrypt operations Herbert Xu
2007-12-11 4:05 ` [PATCH 19/19] [CRYPTO] aead: Add top-level givencrypt/givdecrypt calls Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1J1wKf-0002jr-00@gondolin.me.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).