aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
authorMark Brown <broonie@kernel.org>2026-05-29 22:22:18 +0100
committerMark Brown <broonie@kernel.org>2026-05-29 22:22:24 +0100
commit091bddd6f3606ee19980772e41e0d5c8cb34dce7 (patch)
treef6f9c17ea6c1aa02dc2ca7549ef44311221ab779 /crypto
parentd020f44bb364ba5456cdb834ebe68773ce9ff02b (diff)
parent8415598365503ced2e3d019491b0a2756c85c494 (diff)
downloadlinux-next-history-091bddd6f3606ee19980772e41e0d5c8cb34dce7.tar.gz
Merge branch 'main' of https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
Diffstat (limited to 'crypto')
-rw-r--r--crypto/ahash.c70
-rw-r--r--crypto/api.c76
-rw-r--r--crypto/cipher.c28
-rw-r--r--crypto/cmac.c16
-rw-r--r--crypto/cryptd.c16
-rw-r--r--crypto/hmac.c31
-rw-r--r--crypto/internal.h10
-rw-r--r--crypto/shash.c37
8 files changed, 10 insertions, 274 deletions
diff --git a/crypto/ahash.c b/crypto/ahash.c
index 7a730324c50e2..85dcd120de3ee 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -862,76 +862,6 @@ bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg)
}
EXPORT_SYMBOL_GPL(crypto_hash_alg_has_setkey);
-struct crypto_ahash *crypto_clone_ahash(struct crypto_ahash *hash)
-{
- struct hash_alg_common *halg = crypto_hash_alg_common(hash);
- struct crypto_tfm *tfm = crypto_ahash_tfm(hash);
- struct crypto_ahash *fb = NULL;
- struct crypto_ahash *nhash;
- struct ahash_alg *alg;
- int err;
-
- if (!crypto_hash_alg_has_setkey(halg)) {
- tfm = crypto_tfm_get(tfm);
- if (IS_ERR(tfm))
- return ERR_CAST(tfm);
-
- return hash;
- }
-
- nhash = crypto_clone_tfm(&crypto_ahash_type, tfm);
-
- if (IS_ERR(nhash))
- return nhash;
-
- nhash->reqsize = hash->reqsize;
- nhash->statesize = hash->statesize;
-
- if (likely(hash->using_shash)) {
- struct crypto_shash **nctx = crypto_ahash_ctx(nhash);
- struct crypto_shash *shash;
-
- shash = crypto_clone_shash(ahash_to_shash(hash));
- if (IS_ERR(shash)) {
- err = PTR_ERR(shash);
- goto out_free_nhash;
- }
- crypto_ahash_tfm(nhash)->exit = crypto_exit_ahash_using_shash;
- nhash->using_shash = true;
- *nctx = shash;
- return nhash;
- }
-
- if (crypto_ahash_need_fallback(hash)) {
- fb = crypto_clone_ahash(crypto_ahash_fb(hash));
- err = PTR_ERR(fb);
- if (IS_ERR(fb))
- goto out_free_nhash;
-
- crypto_ahash_tfm(nhash)->fb = crypto_ahash_tfm(fb);
- }
-
- err = -ENOSYS;
- alg = crypto_ahash_alg(hash);
- if (!alg->clone_tfm)
- goto out_free_fb;
-
- err = alg->clone_tfm(nhash, hash);
- if (err)
- goto out_free_fb;
-
- crypto_ahash_tfm(nhash)->exit = crypto_ahash_exit_tfm;
-
- return nhash;
-
-out_free_fb:
- crypto_free_ahash(fb);
-out_free_nhash:
- crypto_free_ahash(nhash);
- return ERR_PTR(err);
-}
-EXPORT_SYMBOL_GPL(crypto_clone_ahash);
-
static int ahash_default_export_core(struct ahash_request *req, void *out)
{
return -ENOSYS;
diff --git a/crypto/api.c b/crypto/api.c
index 74e17d5049c99..4349c2caa23aa 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -405,20 +405,19 @@ void crypto_shoot_alg(struct crypto_alg *alg)
}
EXPORT_SYMBOL_GPL(crypto_shoot_alg);
-struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type,
- u32 mask, gfp_t gfp)
+struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
+ u32 mask)
{
struct crypto_tfm *tfm;
unsigned int tfm_size;
int err = -ENOMEM;
tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask);
- tfm = kzalloc(tfm_size, gfp);
+ tfm = kzalloc(tfm_size, GFP_KERNEL);
if (tfm == NULL)
goto out_err;
tfm->__crt_alg = alg;
- refcount_set(&tfm->refcnt, 1);
if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm)))
goto cra_init_failed;
@@ -435,13 +434,6 @@ out_err:
out:
return tfm;
}
-EXPORT_SYMBOL_GPL(__crypto_alloc_tfmgfp);
-
-struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
- u32 mask)
-{
- return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL);
-}
EXPORT_SYMBOL_GPL(__crypto_alloc_tfm);
/*
@@ -500,43 +492,23 @@ err:
}
EXPORT_SYMBOL_GPL(crypto_alloc_base);
-static void *crypto_alloc_tfmmem(struct crypto_alg *alg,
- const struct crypto_type *frontend, int node,
- gfp_t gfp)
-{
- struct crypto_tfm *tfm;
- unsigned int tfmsize;
- unsigned int total;
- char *mem;
-
- tfmsize = frontend->tfmsize;
- total = tfmsize + sizeof(*tfm) + frontend->extsize(alg);
-
- mem = kzalloc_node(total, gfp, node);
- if (mem == NULL)
- return ERR_PTR(-ENOMEM);
-
- tfm = (struct crypto_tfm *)(mem + tfmsize);
- tfm->__crt_alg = alg;
- tfm->node = node;
- refcount_set(&tfm->refcnt, 1);
-
- return mem;
-}
-
void *crypto_create_tfm_node(struct crypto_alg *alg,
const struct crypto_type *frontend,
int node)
{
struct crypto_tfm *tfm;
+ size_t size;
char *mem;
int err;
- mem = crypto_alloc_tfmmem(alg, frontend, node, GFP_KERNEL);
- if (IS_ERR(mem))
- goto out;
+ size = frontend->tfmsize + sizeof(*tfm) + frontend->extsize(alg);
+ mem = kzalloc_node(size, GFP_KERNEL, node);
+ if (!mem)
+ return ERR_PTR(-ENOMEM);
tfm = (struct crypto_tfm *)(mem + frontend->tfmsize);
+ tfm->__crt_alg = alg;
+ tfm->node = node;
tfm->fb = tfm;
err = frontend->init_tfm(tfm);
@@ -560,32 +532,6 @@ out:
}
EXPORT_SYMBOL_GPL(crypto_create_tfm_node);
-void *crypto_clone_tfm(const struct crypto_type *frontend,
- struct crypto_tfm *otfm)
-{
- struct crypto_alg *alg = otfm->__crt_alg;
- struct crypto_tfm *tfm;
- char *mem;
-
- mem = ERR_PTR(-ESTALE);
- if (unlikely(!crypto_mod_get(alg)))
- goto out;
-
- mem = crypto_alloc_tfmmem(alg, frontend, otfm->node, GFP_ATOMIC);
- if (IS_ERR(mem)) {
- crypto_mod_put(alg);
- goto out;
- }
-
- tfm = (struct crypto_tfm *)(mem + frontend->tfmsize);
- tfm->crt_flags = otfm->crt_flags;
- tfm->fb = tfm;
-
-out:
- return mem;
-}
-EXPORT_SYMBOL_GPL(crypto_clone_tfm);
-
struct crypto_alg *crypto_find_alg(const char *alg_name,
const struct crypto_type *frontend,
u32 type, u32 mask)
@@ -675,8 +621,6 @@ void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm)
if (IS_ERR_OR_NULL(mem))
return;
- if (!refcount_dec_and_test(&tfm->refcnt))
- return;
alg = tfm->__crt_alg;
if (!tfm->exit && alg->cra_exit)
diff --git a/crypto/cipher.c b/crypto/cipher.c
index 1fe62bf79656b..c9dab656a622e 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -89,31 +89,3 @@ void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
cipher_crypt_one(tfm, dst, src, false);
}
EXPORT_SYMBOL_NS_GPL(crypto_cipher_decrypt_one, "CRYPTO_INTERNAL");
-
-struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
-{
- struct crypto_tfm *tfm = crypto_cipher_tfm(cipher);
- struct crypto_alg *alg = tfm->__crt_alg;
- struct crypto_cipher *ncipher;
- struct crypto_tfm *ntfm;
-
- if (alg->cra_init)
- return ERR_PTR(-ENOSYS);
-
- if (unlikely(!crypto_mod_get(alg)))
- return ERR_PTR(-ESTALE);
-
- ntfm = __crypto_alloc_tfmgfp(alg, CRYPTO_ALG_TYPE_CIPHER,
- CRYPTO_ALG_TYPE_MASK, GFP_ATOMIC);
- if (IS_ERR(ntfm)) {
- crypto_mod_put(alg);
- return ERR_CAST(ntfm);
- }
-
- ntfm->crt_flags = tfm->crt_flags;
-
- ncipher = __crypto_cipher_cast(ntfm);
-
- return ncipher;
-}
-EXPORT_SYMBOL_GPL(crypto_clone_cipher);
diff --git a/crypto/cmac.c b/crypto/cmac.c
index 1b03964abe007..83e58937f0136 100644
--- a/crypto/cmac.c
+++ b/crypto/cmac.c
@@ -151,21 +151,6 @@ static int cmac_init_tfm(struct crypto_shash *tfm)
return 0;
}
-static int cmac_clone_tfm(struct crypto_shash *tfm, struct crypto_shash *otfm)
-{
- struct cmac_tfm_ctx *octx = crypto_shash_ctx(otfm);
- struct cmac_tfm_ctx *ctx = crypto_shash_ctx(tfm);
- struct crypto_cipher *cipher;
-
- cipher = crypto_clone_cipher(octx->child);
- if (IS_ERR(cipher))
- return PTR_ERR(cipher);
-
- ctx->child = cipher;
-
- return 0;
-}
-
static void cmac_exit_tfm(struct crypto_shash *tfm)
{
struct cmac_tfm_ctx *ctx = crypto_shash_ctx(tfm);
@@ -222,7 +207,6 @@ static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->alg.finup = crypto_cmac_digest_finup;
inst->alg.setkey = crypto_cmac_digest_setkey;
inst->alg.init_tfm = cmac_init_tfm;
- inst->alg.clone_tfm = cmac_clone_tfm;
inst->alg.exit_tfm = cmac_exit_tfm;
inst->free = shash_free_singlespawn_instance;
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index aba9fe0f23b4a..d8dbf07ab4269 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -452,21 +452,6 @@ static int cryptd_hash_init_tfm(struct crypto_ahash *tfm)
return 0;
}
-static int cryptd_hash_clone_tfm(struct crypto_ahash *ntfm,
- struct crypto_ahash *tfm)
-{
- struct cryptd_hash_ctx *nctx = crypto_ahash_ctx(ntfm);
- struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(tfm);
- struct crypto_shash *hash;
-
- hash = crypto_clone_shash(ctx->child);
- if (IS_ERR(hash))
- return PTR_ERR(hash);
-
- nctx->child = hash;
- return 0;
-}
-
static void cryptd_hash_exit_tfm(struct crypto_ahash *tfm)
{
struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(tfm);
@@ -700,7 +685,6 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
inst->alg.halg.base.cra_ctxsize = sizeof(struct cryptd_hash_ctx);
inst->alg.init_tfm = cryptd_hash_init_tfm;
- inst->alg.clone_tfm = cryptd_hash_clone_tfm;
inst->alg.exit_tfm = cryptd_hash_exit_tfm;
inst->alg.init = cryptd_hash_init_enqueue;
diff --git a/crypto/hmac.c b/crypto/hmac.c
index 148af460ae974..807e08b252c55 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -158,20 +158,6 @@ static int hmac_init_tfm(struct crypto_shash *parent)
return 0;
}
-static int hmac_clone_tfm(struct crypto_shash *dst, struct crypto_shash *src)
-{
- struct hmac_ctx *sctx = crypto_shash_ctx(src);
- struct hmac_ctx *dctx = crypto_shash_ctx(dst);
- struct crypto_shash *hash;
-
- hash = crypto_clone_shash(sctx->hash);
- if (IS_ERR(hash))
- return PTR_ERR(hash);
-
- dctx->hash = hash;
- return 0;
-}
-
static void hmac_exit_tfm(struct crypto_shash *parent)
{
struct hmac_ctx *tctx = crypto_shash_ctx(parent);
@@ -235,7 +221,6 @@ static int __hmac_create_shash(struct crypto_template *tmpl,
inst->alg.import_core = hmac_import_core;
inst->alg.setkey = hmac_setkey;
inst->alg.init_tfm = hmac_init_tfm;
- inst->alg.clone_tfm = hmac_clone_tfm;
inst->alg.exit_tfm = hmac_exit_tfm;
inst->free = shash_free_singlespawn_instance;
@@ -423,21 +408,6 @@ static int hmac_init_ahash_tfm(struct crypto_ahash *parent)
return 0;
}
-static int hmac_clone_ahash_tfm(struct crypto_ahash *dst,
- struct crypto_ahash *src)
-{
- struct ahash_hmac_ctx *sctx = crypto_ahash_ctx(src);
- struct ahash_hmac_ctx *dctx = crypto_ahash_ctx(dst);
- struct crypto_ahash *hash;
-
- hash = crypto_clone_ahash(sctx->hash);
- if (IS_ERR(hash))
- return PTR_ERR(hash);
-
- dctx->hash = hash;
- return 0;
-}
-
static void hmac_exit_ahash_tfm(struct crypto_ahash *parent)
{
struct ahash_hmac_ctx *tctx = crypto_ahash_ctx(parent);
@@ -503,7 +473,6 @@ static int hmac_create_ahash(struct crypto_template *tmpl, struct rtattr **tb,
inst->alg.import_core = hmac_import_core_ahash;
inst->alg.setkey = hmac_setkey_ahash;
inst->alg.init_tfm = hmac_init_ahash_tfm;
- inst->alg.clone_tfm = hmac_clone_ahash_tfm;
inst->alg.exit_tfm = hmac_exit_ahash_tfm;
inst->free = ahash_free_singlespawn_instance;
diff --git a/crypto/internal.h b/crypto/internal.h
index 8fbe0226d48e2..b0a10986f61e7 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -10,7 +10,6 @@
#include <crypto/algapi.h>
#include <linux/completion.h>
-#include <linux/err.h>
#include <linux/jump_label.h>
#include <linux/list.h>
#include <linux/module.h>
@@ -120,14 +119,10 @@ void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
struct crypto_alg *nalg);
void crypto_remove_final(struct list_head *list);
void crypto_shoot_alg(struct crypto_alg *alg);
-struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type,
- u32 mask, gfp_t gfp);
struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
u32 mask);
void *crypto_create_tfm_node(struct crypto_alg *alg,
const struct crypto_type *frontend, int node);
-void *crypto_clone_tfm(const struct crypto_type *frontend,
- struct crypto_tfm *otfm);
static inline void *crypto_create_tfm(struct crypto_alg *alg,
const struct crypto_type *frontend)
@@ -211,10 +206,5 @@ static inline int crypto_is_test_larval(struct crypto_larval *larval)
return larval->alg.cra_driver_name[0];
}
-static inline struct crypto_tfm *crypto_tfm_get(struct crypto_tfm *tfm)
-{
- return refcount_inc_not_zero(&tfm->refcnt) ? tfm : ERR_PTR(-EOVERFLOW);
-}
-
#endif /* _CRYPTO_INTERNAL_H */
diff --git a/crypto/shash.c b/crypto/shash.c
index 2f07d0bd1f61b..351cba3c11070 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -395,43 +395,6 @@ int crypto_has_shash(const char *alg_name, u32 type, u32 mask)
}
EXPORT_SYMBOL_GPL(crypto_has_shash);
-struct crypto_shash *crypto_clone_shash(struct crypto_shash *hash)
-{
- struct crypto_tfm *tfm = crypto_shash_tfm(hash);
- struct shash_alg *alg = crypto_shash_alg(hash);
- struct crypto_shash *nhash;
- int err;
-
- if (!crypto_shash_alg_has_setkey(alg)) {
- tfm = crypto_tfm_get(tfm);
- if (IS_ERR(tfm))
- return ERR_CAST(tfm);
-
- return hash;
- }
-
- if (!alg->clone_tfm && (alg->init_tfm || alg->base.cra_init))
- return ERR_PTR(-ENOSYS);
-
- nhash = crypto_clone_tfm(&crypto_shash_type, tfm);
- if (IS_ERR(nhash))
- return nhash;
-
- if (alg->clone_tfm) {
- err = alg->clone_tfm(nhash, hash);
- if (err) {
- crypto_free_shash(nhash);
- return ERR_PTR(err);
- }
- }
-
- if (alg->exit_tfm)
- crypto_shash_tfm(nhash)->exit = crypto_shash_exit_tfm;
-
- return nhash;
-}
-EXPORT_SYMBOL_GPL(crypto_clone_shash);
-
int hash_prepare_alg(struct hash_alg_common *alg)
{
struct crypto_alg *base = &alg->base;