summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2023-05-19 16:28:35 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2023-05-24 18:12:33 +0800
commitf5a7da4cc8b8285293fdc629267321f6d485cb43 (patch)
treedfbb090a47d7ad5c902825e1c100580a11a96fa4
parent1ffd603f162d49c07143db4d4b5ea8575d5b1020 (diff)
downloadlinux-crypto-f5a7da4cc8b8285293fdc629267321f6d485cb43.tar.gz
linux-crypto-f5a7da4cc8b8285293fdc629267321f6d485cb43.zip
crypto: cipher - Add crypto_clone_cipher
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>
Diffstat (limited to '')
-rw-r--r--crypto/cipher.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/crypto/cipher.c b/crypto/cipher.c
index b47141ed..d39ef5f7 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -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);