Skip to content

Commit

Permalink
crypto: cipher - Add crypto_clone_cipher
Browse files Browse the repository at this point in the history
Allow simple ciphers to be cloned, if they don't have a cra_init
function.  This basically rules out those ciphers that require a
fallback.

In future simple ciphers will be eliminated, and replaced with a
linear skcipher interface.  When that happens this restriction will
disappear.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Herbert Xu committed May 24, 2023
1 parent cf2eddc commit 51d8d6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crypto/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,26 @@ 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);

ntfm = __crypto_alloc_tfm(alg, CRYPTO_ALG_TYPE_CIPHER,
CRYPTO_ALG_TYPE_MASK);
if (IS_ERR(ntfm))
return ERR_CAST(ntfm);

ntfm->crt_flags = tfm->crt_flags;

ncipher = __crypto_cipher_cast(ntfm);

return ncipher;
}
EXPORT_SYMBOL_GPL(crypto_clone_cipher);
2 changes: 2 additions & 0 deletions include/crypto/internal/cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
u8 *dst, const u8 *src);

struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher);

struct crypto_cipher_spawn {
struct crypto_spawn base;
};
Expand Down

0 comments on commit 51d8d6d

Please sign in to comment.