Apply Crypto API wrappers to the exported crypto symbol in CONFIG_CRYPTO_DH-related crypto to convert them into pluggable interface.
This patch is partially based on work by Vegard Nossum, with modifications. Unlike the original, we do not include DEFINE_CRYPTO_API since only one copy of the crypto symbols is kept, either in the crypto module or in the main kernel, and we ensure such wrapper do not have impact on crypto already chosen built as module. Co-developed-by: Vegard Nossum <[email protected]> Signed-off-by: Jay Wang <[email protected]> --- crypto/Makefile | 2 +- crypto/dh.c | 4 ++-- crypto/fips140/fips140-api.c | 13 +++++++------ include/crypto/dh.h | 14 +++++++++++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index 42b45a8941b4..7b1188d5d953 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -40,7 +40,7 @@ crypto-objs-$(CONFIG_CRYPTO_HKDF) += hkdf.o dh_generic-y := dh.o dh_generic-y += dh_helper.o -obj-$(CONFIG_CRYPTO_DH) += dh_generic.o +crypto-objs-$(CONFIG_CRYPTO_DH) += dh_generic.o $(obj)/rsapubkey.asn1.o: $(obj)/rsapubkey.asn1.c $(obj)/rsapubkey.asn1.h $(obj)/rsaprivkey.asn1.o: $(obj)/rsaprivkey.asn1.c $(obj)/rsaprivkey.asn1.h diff --git a/crypto/dh.c b/crypto/dh.c index 8250eeeebd0f..5eacd5a4a92a 100644 --- a/crypto/dh.c +++ b/crypto/dh.c @@ -920,8 +920,8 @@ static void __exit dh_exit(void) crypto_unregister_kpp(&dh); } -module_init(dh_init); -module_exit(dh_exit); +crypto_module_init(dh_init); +crypto_module_exit(dh_exit); MODULE_ALIAS_CRYPTO("dh"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("DH generic algorithm"); diff --git a/crypto/fips140/fips140-api.c b/crypto/fips140/fips140-api.c index 8db92603bd59..0b1794340b77 100644 --- a/crypto/fips140/fips140-api.c +++ b/crypto/fips140/fips140-api.c @@ -578,13 +578,14 @@ DEFINE_CRYPTO_API_STUB(hkdf_expand); #endif /* - * crypto/hkdf.c + * crypto/dh_helper.c */ -#if IS_BUILTIN(CONFIG_CRYPTO_HKDF) +#if IS_BUILTIN(CONFIG_CRYPTO_DH) -#include <crypto/hkdf.h> +#include <crypto/dh.h> -DEFINE_CRYPTO_API_STUB(hkdf_extract); -DEFINE_CRYPTO_API_STUB(hkdf_expand); +DEFINE_CRYPTO_API_STUB(crypto_dh_key_len); +DEFINE_CRYPTO_API_STUB(crypto_dh_encode_key); +DEFINE_CRYPTO_API_STUB(crypto_dh_decode_key); -#endif \ No newline at end of file +#endif diff --git a/include/crypto/dh.h b/include/crypto/dh.h index 7b863e911cb4..08d74c548535 100644 --- a/include/crypto/dh.h +++ b/include/crypto/dh.h @@ -8,6 +8,8 @@ #ifndef _CRYPTO_DH_ #define _CRYPTO_DH_ +#include <crypto/api.h> + /** * DOC: DH Helper Functions * @@ -48,7 +50,9 @@ struct dh { * * Return: size of the key in bytes */ -unsigned int crypto_dh_key_len(const struct dh *params); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_DH, crypto_dh_key_len, unsigned int, + (const struct dh *params), + (params)); /** * crypto_dh_encode_key() - encode the private key @@ -63,7 +67,9 @@ unsigned int crypto_dh_key_len(const struct dh *params); * * Return: -EINVAL if buffer has insufficient size, 0 on success */ -int crypto_dh_encode_key(char *buf, unsigned int len, const struct dh *params); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_DH, crypto_dh_encode_key, int, + (char *buf, unsigned int len, const struct dh *params), + (buf, len, params)); /** * crypto_dh_decode_key() - decode a private key @@ -77,7 +83,9 @@ int crypto_dh_encode_key(char *buf, unsigned int len, const struct dh *params); * * Return: -EINVAL if buffer has insufficient size, 0 on success */ -int crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params); +DECLARE_CRYPTO_API(CONFIG_CRYPTO_DH, crypto_dh_decode_key, int, + (const char *buf, unsigned int len, struct dh *params), + (buf, len, params)); /** * __crypto_dh_decode_key() - decode a private key without parameter checks -- 2.47.3
