[PATCH 065/106] crypto: convert exported crypto symbol into pluggable interface for CONFIG_CRYPTO_TWOFISH and CONFIG_CRYPTO_TWOFISH_COMMON crypto
Jay Wang
wanjay at amazon.com
Wed Feb 11 18:46:41 PST 2026
Apply Crypto API wrappers to the exported crypto symbol in
CONFIG_CRYPTO_TWOFISH- and CONFIG_CRYPTO_TWOFISH_COMMON-related crypto
to convert them into pluggable interface.
Signed-off-by: Jay Wang <wanjay at amazon.com>
---
crypto/Makefile | 4 ++--
crypto/fips140/fips140-api.c | 11 +++++++++++
crypto/twofish_generic.c | 4 ++--
include/crypto/twofish.h | 11 ++++++++---
4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/crypto/Makefile b/crypto/Makefile
index 326b37002e3d..e93edc49840a 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -130,8 +130,8 @@ crypto-objs-$(CONFIG_CRYPTO_DES) += des_generic.o
crypto-objs-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
crypto-objs-$(CONFIG_CRYPTO_BLOWFISH) += blowfish_generic.o
crypto-objs-$(CONFIG_CRYPTO_BLOWFISH_COMMON) += blowfish_common.o
-obj-$(CONFIG_CRYPTO_TWOFISH) += twofish_generic.o
-obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
+crypto-objs-$(CONFIG_CRYPTO_TWOFISH) += twofish_generic.o
+crypto-objs-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o
CFLAGS_serpent_generic.o := $(call cc-option,-fsched-pressure) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149
crypto-objs-$(CONFIG_CRYPTO_AES) += aes.o
diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c
index 5b0ae8476ce7..9ad530743d1f 100644
--- a/crypto/fips140/fips140-api.c
+++ b/crypto/fips140/fips140-api.c
@@ -672,3 +672,14 @@ DEFINE_CRYPTO_API_STUB(sm4_expandkey);
DEFINE_CRYPTO_API_STUB(sm4_crypt_block);
#endif
+/*
+ * crypto/twofish_common.c
+ */
+#if IS_BUILTIN(CONFIG_CRYPTO_TWOFISH_COMMON)
+
+#include <crypto/twofish.h>
+
+DEFINE_CRYPTO_API_STUB(__twofish_setkey);
+DEFINE_CRYPTO_API_STUB(twofish_setkey);
+
+#endif
diff --git a/crypto/twofish_generic.c b/crypto/twofish_generic.c
index 368018cfa9bf..0d9cefa3350b 100644
--- a/crypto/twofish_generic.c
+++ b/crypto/twofish_generic.c
@@ -187,8 +187,8 @@ static void __exit twofish_mod_fini(void)
crypto_unregister_alg(&alg);
}
-module_init(twofish_mod_init);
-module_exit(twofish_mod_fini);
+crypto_module_init(twofish_mod_init);
+crypto_module_exit(twofish_mod_fini);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION ("Twofish Cipher Algorithm");
diff --git a/include/crypto/twofish.h b/include/crypto/twofish.h
index f6b307a58554..4695480f5d44 100644
--- a/include/crypto/twofish.h
+++ b/include/crypto/twofish.h
@@ -2,6 +2,7 @@
#ifndef _CRYPTO_TWOFISH_H
#define _CRYPTO_TWOFISH_H
+#include <crypto/api.h>
#include <linux/types.h>
#define TF_MIN_KEY_SIZE 16
@@ -18,8 +19,12 @@ struct twofish_ctx {
u32 s[4][256], w[8], k[32];
};
-int __twofish_setkey(struct twofish_ctx *ctx, const u8 *key,
- unsigned int key_len);
-int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len);
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_TWOFISH_COMMON, __twofish_setkey, int,
+ (struct twofish_ctx *ctx, const u8 *key, unsigned int key_len),
+ (ctx, key, key_len));
+
+DECLARE_CRYPTO_API(CONFIG_CRYPTO_TWOFISH_COMMON, twofish_setkey, int,
+ (struct crypto_tfm *tfm, const u8 *key, unsigned int key_len),
+ (tfm, key, key_len));
#endif
--
2.47.3
More information about the linux-arm-kernel
mailing list