Use CRYPTO_API() etc. from include/crypto/api.h in preparation for compilation as part of support for FIPS 140 standalone modules. Generated using: ./fipsify.py --config CONFIG_CRYPTO_AEAD2 --source crypto/aead.c --header include/crypto/aead.h include/crypto/internal/aead.h Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx> --- crypto/aead.c | 48 +++++++++++++++++----------------- crypto/fips140-api.c | 25 ++++++++++++++++++ include/crypto/aead.h | 26 +++++++++++++----- include/crypto/internal/aead.h | 28 +++++++++++++------- 4 files changed, 87 insertions(+), 40 deletions(-) diff --git a/crypto/aead.c b/crypto/aead.c index 5d14b775036e..f6cc3a76120e 100644 --- a/crypto/aead.c +++ b/crypto/aead.c @@ -41,7 +41,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key, return ret; } -int crypto_aead_setkey(struct crypto_aead *tfm, +int CRYPTO_API(crypto_aead_setkey)(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { unsigned long alignmask = crypto_aead_alignmask(tfm); @@ -60,9 +60,9 @@ int crypto_aead_setkey(struct crypto_aead *tfm, crypto_aead_clear_flags(tfm, CRYPTO_TFM_NEED_KEY); return 0; } -EXPORT_SYMBOL_GPL(crypto_aead_setkey); +DEFINE_CRYPTO_API(crypto_aead_setkey); -int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize) +int CRYPTO_API(crypto_aead_setauthsize)(struct crypto_aead *tfm, unsigned int authsize) { int err; @@ -79,9 +79,9 @@ int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize) tfm->authsize = authsize; return 0; } -EXPORT_SYMBOL_GPL(crypto_aead_setauthsize); +DEFINE_CRYPTO_API(crypto_aead_setauthsize); -int crypto_aead_encrypt(struct aead_request *req) +int CRYPTO_API(crypto_aead_encrypt)(struct aead_request *req) { struct crypto_aead *aead = crypto_aead_reqtfm(req); @@ -90,9 +90,9 @@ int crypto_aead_encrypt(struct aead_request *req) return crypto_aead_alg(aead)->encrypt(req); } -EXPORT_SYMBOL_GPL(crypto_aead_encrypt); +DEFINE_CRYPTO_API(crypto_aead_encrypt); -int crypto_aead_decrypt(struct aead_request *req) +int CRYPTO_API(crypto_aead_decrypt)(struct aead_request *req) { struct crypto_aead *aead = crypto_aead_reqtfm(req); @@ -104,7 +104,7 @@ int crypto_aead_decrypt(struct aead_request *req) return crypto_aead_alg(aead)->decrypt(req); } -EXPORT_SYMBOL_GPL(crypto_aead_decrypt); +DEFINE_CRYPTO_API(crypto_aead_decrypt); static void crypto_aead_exit_tfm(struct crypto_tfm *tfm) { @@ -189,26 +189,26 @@ static const struct crypto_type crypto_aead_type = { .algsize = offsetof(struct aead_alg, base), }; -int crypto_grab_aead(struct crypto_aead_spawn *spawn, +int CRYPTO_API(crypto_grab_aead)(struct crypto_aead_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask) { spawn->base.frontend = &crypto_aead_type; return crypto_grab_spawn(&spawn->base, inst, name, type, mask); } -EXPORT_SYMBOL_GPL(crypto_grab_aead); +DEFINE_CRYPTO_API(crypto_grab_aead); -struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask) +struct crypto_aead *CRYPTO_API(crypto_alloc_aead)(const char *alg_name, u32 type, u32 mask) { return crypto_alloc_tfm(alg_name, &crypto_aead_type, type, mask); } -EXPORT_SYMBOL_GPL(crypto_alloc_aead); +DEFINE_CRYPTO_API(crypto_alloc_aead); -int crypto_has_aead(const char *alg_name, u32 type, u32 mask) +int CRYPTO_API(crypto_has_aead)(const char *alg_name, u32 type, u32 mask) { return crypto_type_has_alg(alg_name, &crypto_aead_type, type, mask); } -EXPORT_SYMBOL_GPL(crypto_has_aead); +DEFINE_CRYPTO_API(crypto_has_aead); static int aead_prepare_alg(struct aead_alg *alg) { @@ -228,7 +228,7 @@ static int aead_prepare_alg(struct aead_alg *alg) return 0; } -int crypto_register_aead(struct aead_alg *alg) +int CRYPTO_API(crypto_register_aead)(struct aead_alg *alg) { struct crypto_alg *base = &alg->base; int err; @@ -239,15 +239,15 @@ int crypto_register_aead(struct aead_alg *alg) return crypto_register_alg(base); } -EXPORT_SYMBOL_GPL(crypto_register_aead); +DEFINE_CRYPTO_API(crypto_register_aead); -void crypto_unregister_aead(struct aead_alg *alg) +void CRYPTO_API(crypto_unregister_aead)(struct aead_alg *alg) { crypto_unregister_alg(&alg->base); } -EXPORT_SYMBOL_GPL(crypto_unregister_aead); +DEFINE_CRYPTO_API(crypto_unregister_aead); -int crypto_register_aeads(struct aead_alg *algs, int count) +int CRYPTO_API(crypto_register_aeads)(struct aead_alg *algs, int count) { int i, ret; @@ -265,18 +265,18 @@ int crypto_register_aeads(struct aead_alg *algs, int count) return ret; } -EXPORT_SYMBOL_GPL(crypto_register_aeads); +DEFINE_CRYPTO_API(crypto_register_aeads); -void crypto_unregister_aeads(struct aead_alg *algs, int count) +void CRYPTO_API(crypto_unregister_aeads)(struct aead_alg *algs, int count) { int i; for (i = count - 1; i >= 0; --i) crypto_unregister_aead(&algs[i]); } -EXPORT_SYMBOL_GPL(crypto_unregister_aeads); +DEFINE_CRYPTO_API(crypto_unregister_aeads); -int aead_register_instance(struct crypto_template *tmpl, +int CRYPTO_API(aead_register_instance)(struct crypto_template *tmpl, struct aead_instance *inst) { int err; @@ -290,7 +290,7 @@ int aead_register_instance(struct crypto_template *tmpl, return crypto_register_instance(tmpl, aead_crypto_instance(inst)); } -EXPORT_SYMBOL_GPL(aead_register_instance); +DEFINE_CRYPTO_API(aead_register_instance); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Authenticated Encryption with Associated Data (AEAD)"); diff --git a/crypto/fips140-api.c b/crypto/fips140-api.c index 6caef4827a53..896b42fb4330 100644 --- a/crypto/fips140-api.c +++ b/crypto/fips140-api.c @@ -127,3 +127,28 @@ DEFINE_CRYPTO_API_STUB(__crypto_xor); #endif +/* + * crypto/aead.c + */ +#if !IS_BUILTIN(CONFIG_CRYPTO_AEAD2) + +#include <crypto/aead.h> + +DEFINE_CRYPTO_API_STUB(crypto_alloc_aead); +DEFINE_CRYPTO_API_STUB(crypto_has_aead); +DEFINE_CRYPTO_API_STUB(crypto_aead_setkey); +DEFINE_CRYPTO_API_STUB(crypto_aead_setauthsize); +DEFINE_CRYPTO_API_STUB(crypto_aead_encrypt); +DEFINE_CRYPTO_API_STUB(crypto_aead_decrypt); + +#include <crypto/internal/aead.h> + +DEFINE_CRYPTO_API_STUB(crypto_grab_aead); +DEFINE_CRYPTO_API_STUB(crypto_register_aead); +DEFINE_CRYPTO_API_STUB(crypto_unregister_aead); +DEFINE_CRYPTO_API_STUB(crypto_register_aeads); +DEFINE_CRYPTO_API_STUB(crypto_unregister_aeads); +DEFINE_CRYPTO_API_STUB(aead_register_instance); + +#endif + diff --git a/include/crypto/aead.h b/include/crypto/aead.h index 0e8a41638678..714a110a64bf 100644 --- a/include/crypto/aead.h +++ b/include/crypto/aead.h @@ -8,6 +8,7 @@ #ifndef _CRYPTO_AEAD_H #define _CRYPTO_AEAD_H +#include <crypto/api.h> #include <linux/atomic.h> #include <linux/container_of.h> #include <linux/crypto.h> @@ -178,7 +179,9 @@ static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm) * Return: allocated cipher handle in case of success; IS_ERR() is true in case * of an error, PTR_ERR() returns the error code. */ -struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask); +DECLARE_CRYPTO_API(crypto_alloc_aead, struct crypto_aead *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm) { @@ -206,7 +209,9 @@ static inline void crypto_free_aead(struct crypto_aead *tfm) * Return: true when the aead is known to the kernel crypto API; false * otherwise */ -int crypto_has_aead(const char *alg_name, u32 type, u32 mask); +DECLARE_CRYPTO_API(crypto_has_aead, int, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); static inline const char *crypto_aead_driver_name(struct crypto_aead *tfm) { @@ -316,8 +321,9 @@ static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags) * * Return: 0 if the setting of the key was successful; < 0 if an error occurred */ -int crypto_aead_setkey(struct crypto_aead *tfm, - const u8 *key, unsigned int keylen); +DECLARE_CRYPTO_API(crypto_aead_setkey, int, + (struct crypto_aead *tfm, const u8 *key, unsigned int keylen), + (tfm, key, keylen)); /** * crypto_aead_setauthsize() - set authentication data size @@ -329,7 +335,9 @@ int crypto_aead_setkey(struct crypto_aead *tfm, * * Return: 0 if the setting of the key was successful; < 0 if an error occurred */ -int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize); +DECLARE_CRYPTO_API(crypto_aead_setauthsize, int, + (struct crypto_aead *tfm, unsigned int authsize), + (tfm, authsize)); static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) { @@ -355,7 +363,9 @@ static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) * * Return: 0 if the cipher operation was successful; < 0 if an error occurred */ -int crypto_aead_encrypt(struct aead_request *req); +DECLARE_CRYPTO_API(crypto_aead_encrypt, int, + (struct aead_request *req), + (req)); /** * crypto_aead_decrypt() - decrypt ciphertext @@ -379,7 +389,9 @@ int crypto_aead_encrypt(struct aead_request *req); * integrity of the ciphertext or the associated data was violated); * < 0 if an error occurred. */ -int crypto_aead_decrypt(struct aead_request *req); +DECLARE_CRYPTO_API(crypto_aead_decrypt, int, + (struct aead_request *req), + (req)); /** * DOC: Asynchronous AEAD Request Handle diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h index 28a95eb3182d..8abe35a07fd4 100644 --- a/include/crypto/internal/aead.h +++ b/include/crypto/internal/aead.h @@ -8,6 +8,7 @@ #ifndef _CRYPTO_INTERNAL_AEAD_H #define _CRYPTO_INTERNAL_AEAD_H +#include <crypto/api.h> #include <crypto/aead.h> #include <crypto/algapi.h> #include <linux/stddef.h> @@ -96,9 +97,9 @@ static inline struct aead_request *aead_request_cast( return container_of(req, struct aead_request, base); } -int crypto_grab_aead(struct crypto_aead_spawn *spawn, - struct crypto_instance *inst, - const char *name, u32 type, u32 mask); +DECLARE_CRYPTO_API(crypto_grab_aead, int, + (struct crypto_aead_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask), + (spawn, inst, name, type, mask)); static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn) { @@ -157,12 +158,21 @@ static inline unsigned int crypto_aead_chunksize(struct crypto_aead *tfm) return crypto_aead_alg_chunksize(crypto_aead_alg(tfm)); } -int crypto_register_aead(struct aead_alg *alg); -void crypto_unregister_aead(struct aead_alg *alg); -int crypto_register_aeads(struct aead_alg *algs, int count); -void crypto_unregister_aeads(struct aead_alg *algs, int count); -int aead_register_instance(struct crypto_template *tmpl, - struct aead_instance *inst); +DECLARE_CRYPTO_API(crypto_register_aead, int, + (struct aead_alg *alg), + (alg)); +DECLARE_CRYPTO_API(crypto_unregister_aead, void, + (struct aead_alg *alg), + (alg)); +DECLARE_CRYPTO_API(crypto_register_aeads, int, + (struct aead_alg *algs, int count), + (algs, count)); +DECLARE_CRYPTO_API(crypto_unregister_aeads, void, + (struct aead_alg *algs, int count), + (algs, count)); +DECLARE_CRYPTO_API(aead_register_instance, int, + (struct crypto_template *tmpl, struct aead_instance *inst), + (tmpl, inst)); #endif /* _CRYPTO_INTERNAL_AEAD_H */ -- 2.39.3