mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-21 06:01:23 +00:00
[CRYPTO] authenc: Use crypto_grab_skcipher
This patch converts the authenc algorithm over to crypto_grab_skcipher which is a prerequisite for IV generation. This patch also changes authenc to set its ASYNC status depending on the ASYNC status of the underlying skcipher. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
b9c55aa475
commit
9ffde35a8e
1 changed files with 38 additions and 27 deletions
|
@ -10,7 +10,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <crypto/algapi.h>
|
#include <crypto/internal/skcipher.h>
|
||||||
#include <crypto/authenc.h>
|
#include <crypto/authenc.h>
|
||||||
#include <crypto/scatterwalk.h>
|
#include <crypto/scatterwalk.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
struct authenc_instance_ctx {
|
struct authenc_instance_ctx {
|
||||||
struct crypto_spawn auth;
|
struct crypto_spawn auth;
|
||||||
struct crypto_spawn enc;
|
struct crypto_skcipher_spawn enc;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct crypto_authenc_ctx {
|
struct crypto_authenc_ctx {
|
||||||
|
@ -237,7 +237,7 @@ static int crypto_authenc_init_tfm(struct crypto_tfm *tfm)
|
||||||
if (IS_ERR(auth))
|
if (IS_ERR(auth))
|
||||||
return PTR_ERR(auth);
|
return PTR_ERR(auth);
|
||||||
|
|
||||||
enc = crypto_spawn_ablkcipher(&ictx->enc);
|
enc = crypto_spawn_skcipher(&ictx->enc);
|
||||||
err = PTR_ERR(enc);
|
err = PTR_ERR(enc);
|
||||||
if (IS_ERR(enc))
|
if (IS_ERR(enc))
|
||||||
goto err_free_hash;
|
goto err_free_hash;
|
||||||
|
@ -270,42 +270,36 @@ static void crypto_authenc_exit_tfm(struct crypto_tfm *tfm)
|
||||||
|
|
||||||
static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
|
static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
|
||||||
{
|
{
|
||||||
|
struct crypto_attr_type *algt;
|
||||||
struct crypto_instance *inst;
|
struct crypto_instance *inst;
|
||||||
struct crypto_alg *auth;
|
struct crypto_alg *auth;
|
||||||
struct crypto_alg *enc;
|
struct crypto_alg *enc;
|
||||||
struct authenc_instance_ctx *ctx;
|
struct authenc_instance_ctx *ctx;
|
||||||
|
const char *enc_name;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD);
|
algt = crypto_get_attr_type(tb);
|
||||||
if (err)
|
err = PTR_ERR(algt);
|
||||||
|
if (IS_ERR(algt))
|
||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
|
|
||||||
|
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
|
auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
|
||||||
CRYPTO_ALG_TYPE_HASH_MASK);
|
CRYPTO_ALG_TYPE_HASH_MASK);
|
||||||
if (IS_ERR(auth))
|
if (IS_ERR(auth))
|
||||||
return ERR_PTR(PTR_ERR(auth));
|
return ERR_PTR(PTR_ERR(auth));
|
||||||
|
|
||||||
enc = crypto_attr_alg(tb[2], CRYPTO_ALG_TYPE_BLKCIPHER,
|
enc_name = crypto_attr_alg_name(tb[2]);
|
||||||
CRYPTO_ALG_TYPE_BLKCIPHER_MASK);
|
err = PTR_ERR(enc_name);
|
||||||
inst = ERR_PTR(PTR_ERR(enc));
|
if (IS_ERR(enc_name))
|
||||||
if (IS_ERR(enc))
|
|
||||||
goto out_put_auth;
|
goto out_put_auth;
|
||||||
|
|
||||||
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
|
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
if (!inst)
|
if (!inst)
|
||||||
goto out_put_enc;
|
goto out_put_auth;
|
||||||
|
|
||||||
err = -ENAMETOOLONG;
|
|
||||||
if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
|
|
||||||
"authenc(%s,%s)", auth->cra_name, enc->cra_name) >=
|
|
||||||
CRYPTO_MAX_ALG_NAME)
|
|
||||||
goto err_free_inst;
|
|
||||||
|
|
||||||
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
|
|
||||||
"authenc(%s,%s)", auth->cra_driver_name,
|
|
||||||
enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
|
|
||||||
goto err_free_inst;
|
|
||||||
|
|
||||||
ctx = crypto_instance_ctx(inst);
|
ctx = crypto_instance_ctx(inst);
|
||||||
|
|
||||||
|
@ -313,11 +307,28 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
|
||||||
if (err)
|
if (err)
|
||||||
goto err_free_inst;
|
goto err_free_inst;
|
||||||
|
|
||||||
err = crypto_init_spawn(&ctx->enc, enc, inst, CRYPTO_ALG_TYPE_MASK);
|
crypto_set_skcipher_spawn(&ctx->enc, inst);
|
||||||
|
err = crypto_grab_skcipher(&ctx->enc, enc_name, 0,
|
||||||
|
crypto_requires_sync(algt->type,
|
||||||
|
algt->mask));
|
||||||
if (err)
|
if (err)
|
||||||
goto err_drop_auth;
|
goto err_drop_auth;
|
||||||
|
|
||||||
inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC;
|
enc = crypto_skcipher_spawn_alg(&ctx->enc);
|
||||||
|
|
||||||
|
err = -ENAMETOOLONG;
|
||||||
|
if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
|
||||||
|
"authenc(%s,%s)", auth->cra_name, enc->cra_name) >=
|
||||||
|
CRYPTO_MAX_ALG_NAME)
|
||||||
|
goto err_drop_enc;
|
||||||
|
|
||||||
|
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
|
||||||
|
"authenc(%s,%s)", auth->cra_driver_name,
|
||||||
|
enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
|
||||||
|
goto err_drop_enc;
|
||||||
|
|
||||||
|
inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
|
||||||
|
inst->alg.cra_flags |= enc->cra_flags & CRYPTO_ALG_ASYNC;
|
||||||
inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority;
|
inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority;
|
||||||
inst->alg.cra_blocksize = enc->cra_blocksize;
|
inst->alg.cra_blocksize = enc->cra_blocksize;
|
||||||
inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask;
|
inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask;
|
||||||
|
@ -338,16 +349,16 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
|
||||||
inst->alg.cra_aead.decrypt = crypto_authenc_decrypt;
|
inst->alg.cra_aead.decrypt = crypto_authenc_decrypt;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
crypto_mod_put(enc);
|
|
||||||
out_put_auth:
|
|
||||||
crypto_mod_put(auth);
|
crypto_mod_put(auth);
|
||||||
return inst;
|
return inst;
|
||||||
|
|
||||||
|
err_drop_enc:
|
||||||
|
crypto_drop_skcipher(&ctx->enc);
|
||||||
err_drop_auth:
|
err_drop_auth:
|
||||||
crypto_drop_spawn(&ctx->auth);
|
crypto_drop_spawn(&ctx->auth);
|
||||||
err_free_inst:
|
err_free_inst:
|
||||||
kfree(inst);
|
kfree(inst);
|
||||||
out_put_enc:
|
out_put_auth:
|
||||||
inst = ERR_PTR(err);
|
inst = ERR_PTR(err);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +367,7 @@ static void crypto_authenc_free(struct crypto_instance *inst)
|
||||||
{
|
{
|
||||||
struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst);
|
struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst);
|
||||||
|
|
||||||
crypto_drop_spawn(&ctx->enc);
|
crypto_drop_skcipher(&ctx->enc);
|
||||||
crypto_drop_spawn(&ctx->auth);
|
crypto_drop_spawn(&ctx->auth);
|
||||||
kfree(inst);
|
kfree(inst);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue