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_SKCIPHER2 --source crypto/lskcipher.c --header include/crypto/skcipher.h include/crypto/internal/skcipher.h Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx> --- crypto/fips140-api.c | 24 ++++++++++++++++ crypto/lskcipher.c | 44 +++++++++++++++--------------- include/crypto/internal/skcipher.h | 34 +++++++++++++++-------- include/crypto/skcipher.h | 21 ++++++++------ 4 files changed, 82 insertions(+), 41 deletions(-) diff --git a/crypto/fips140-api.c b/crypto/fips140-api.c index 9c9f9d57f99d..70b896ef42ff 100644 --- a/crypto/fips140-api.c +++ b/crypto/fips140-api.c @@ -442,3 +442,27 @@ DEFINE_CRYPTO_API_STUB(crypto_grab_kpp); #endif +/* + * crypto/lskcipher.c + */ +#if !IS_BUILTIN(CONFIG_CRYPTO_SKCIPHER2) + +#include <crypto/skcipher.h> + +DEFINE_CRYPTO_API_STUB(crypto_alloc_lskcipher); +DEFINE_CRYPTO_API_STUB(crypto_lskcipher_setkey); +DEFINE_CRYPTO_API_STUB(crypto_lskcipher_encrypt); +DEFINE_CRYPTO_API_STUB(crypto_lskcipher_decrypt); + +#include <crypto/internal/skcipher.h> + +DEFINE_CRYPTO_API_STUB(crypto_grab_lskcipher); +DEFINE_CRYPTO_API_STUB(crypto_register_lskcipher); +DEFINE_CRYPTO_API_STUB(crypto_unregister_lskcipher); +DEFINE_CRYPTO_API_STUB(crypto_register_lskciphers); +DEFINE_CRYPTO_API_STUB(crypto_unregister_lskciphers); +DEFINE_CRYPTO_API_STUB(lskcipher_register_instance); +DEFINE_CRYPTO_API_STUB(lskcipher_alloc_instance_simple); + +#endif + diff --git a/crypto/lskcipher.c b/crypto/lskcipher.c index c2e2c38b5aa8..147a897ae5ea 100644 --- a/crypto/lskcipher.c +++ b/crypto/lskcipher.c @@ -50,7 +50,7 @@ static int lskcipher_setkey_unaligned(struct crypto_lskcipher *tfm, return ret; } -int crypto_lskcipher_setkey(struct crypto_lskcipher *tfm, const u8 *key, +int CRYPTO_API(crypto_lskcipher_setkey)(struct crypto_lskcipher *tfm, const u8 *key, unsigned int keylen) { unsigned long alignmask = crypto_lskcipher_alignmask(tfm); @@ -64,7 +64,7 @@ int crypto_lskcipher_setkey(struct crypto_lskcipher *tfm, const u8 *key, else return cipher->setkey(tfm, key, keylen); } -EXPORT_SYMBOL_GPL(crypto_lskcipher_setkey); +DEFINE_CRYPTO_API(crypto_lskcipher_setkey); static int crypto_lskcipher_crypt_unaligned( struct crypto_lskcipher *tfm, const u8 *src, u8 *dst, unsigned len, @@ -137,23 +137,23 @@ static int crypto_lskcipher_crypt(struct crypto_lskcipher *tfm, const u8 *src, return crypt(tfm, src, dst, len, iv, CRYPTO_LSKCIPHER_FLAG_FINAL); } -int crypto_lskcipher_encrypt(struct crypto_lskcipher *tfm, const u8 *src, +int CRYPTO_API(crypto_lskcipher_encrypt)(struct crypto_lskcipher *tfm, const u8 *src, u8 *dst, unsigned len, u8 *iv) { struct lskcipher_alg *alg = crypto_lskcipher_alg(tfm); return crypto_lskcipher_crypt(tfm, src, dst, len, iv, alg->encrypt); } -EXPORT_SYMBOL_GPL(crypto_lskcipher_encrypt); +DEFINE_CRYPTO_API(crypto_lskcipher_encrypt); -int crypto_lskcipher_decrypt(struct crypto_lskcipher *tfm, const u8 *src, +int CRYPTO_API(crypto_lskcipher_decrypt)(struct crypto_lskcipher *tfm, const u8 *src, u8 *dst, unsigned len, u8 *iv) { struct lskcipher_alg *alg = crypto_lskcipher_alg(tfm); return crypto_lskcipher_crypt(tfm, src, dst, len, iv, alg->decrypt); } -EXPORT_SYMBOL_GPL(crypto_lskcipher_decrypt); +DEFINE_CRYPTO_API(crypto_lskcipher_decrypt); static int crypto_lskcipher_crypt_sg(struct skcipher_request *req, int (*crypt)(struct crypto_lskcipher *tfm, @@ -325,21 +325,21 @@ int crypto_init_lskcipher_ops_sg(struct crypto_tfm *tfm) return 0; } -int crypto_grab_lskcipher(struct crypto_lskcipher_spawn *spawn, +int CRYPTO_API(crypto_grab_lskcipher)(struct crypto_lskcipher_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask) { spawn->base.frontend = &crypto_lskcipher_type; return crypto_grab_spawn(&spawn->base, inst, name, type, mask); } -EXPORT_SYMBOL_GPL(crypto_grab_lskcipher); +DEFINE_CRYPTO_API(crypto_grab_lskcipher); -struct crypto_lskcipher *crypto_alloc_lskcipher(const char *alg_name, +struct crypto_lskcipher *CRYPTO_API(crypto_alloc_lskcipher)(const char *alg_name, u32 type, u32 mask) { return crypto_alloc_tfm(alg_name, &crypto_lskcipher_type, type, mask); } -EXPORT_SYMBOL_GPL(crypto_alloc_lskcipher); +DEFINE_CRYPTO_API(crypto_alloc_lskcipher); static int lskcipher_prepare_alg(struct lskcipher_alg *alg) { @@ -359,7 +359,7 @@ static int lskcipher_prepare_alg(struct lskcipher_alg *alg) return 0; } -int crypto_register_lskcipher(struct lskcipher_alg *alg) +int CRYPTO_API(crypto_register_lskcipher)(struct lskcipher_alg *alg) { struct crypto_alg *base = &alg->co.base; int err; @@ -370,15 +370,15 @@ int crypto_register_lskcipher(struct lskcipher_alg *alg) return crypto_register_alg(base); } -EXPORT_SYMBOL_GPL(crypto_register_lskcipher); +DEFINE_CRYPTO_API(crypto_register_lskcipher); -void crypto_unregister_lskcipher(struct lskcipher_alg *alg) +void CRYPTO_API(crypto_unregister_lskcipher)(struct lskcipher_alg *alg) { crypto_unregister_alg(&alg->co.base); } -EXPORT_SYMBOL_GPL(crypto_unregister_lskcipher); +DEFINE_CRYPTO_API(crypto_unregister_lskcipher); -int crypto_register_lskciphers(struct lskcipher_alg *algs, int count) +int CRYPTO_API(crypto_register_lskciphers)(struct lskcipher_alg *algs, int count) { int i, ret; @@ -396,18 +396,18 @@ int crypto_register_lskciphers(struct lskcipher_alg *algs, int count) return ret; } -EXPORT_SYMBOL_GPL(crypto_register_lskciphers); +DEFINE_CRYPTO_API(crypto_register_lskciphers); -void crypto_unregister_lskciphers(struct lskcipher_alg *algs, int count) +void CRYPTO_API(crypto_unregister_lskciphers)(struct lskcipher_alg *algs, int count) { int i; for (i = count - 1; i >= 0; --i) crypto_unregister_lskcipher(&algs[i]); } -EXPORT_SYMBOL_GPL(crypto_unregister_lskciphers); +DEFINE_CRYPTO_API(crypto_unregister_lskciphers); -int lskcipher_register_instance(struct crypto_template *tmpl, +int CRYPTO_API(lskcipher_register_instance)(struct crypto_template *tmpl, struct lskcipher_instance *inst) { int err; @@ -421,7 +421,7 @@ int lskcipher_register_instance(struct crypto_template *tmpl, return crypto_register_instance(tmpl, lskcipher_crypto_instance(inst)); } -EXPORT_SYMBOL_GPL(lskcipher_register_instance); +DEFINE_CRYPTO_API(lskcipher_register_instance); static int lskcipher_setkey_simple(struct crypto_lskcipher *tfm, const u8 *key, unsigned int keylen) @@ -480,7 +480,7 @@ static void lskcipher_free_instance_simple(struct lskcipher_instance *inst) * Return: a pointer to the new instance, or an ERR_PTR(). The caller still * needs to register the instance. */ -struct lskcipher_instance *lskcipher_alloc_instance_simple( +struct lskcipher_instance *CRYPTO_API(lskcipher_alloc_instance_simple)( struct crypto_template *tmpl, struct rtattr **tb) { u32 mask; @@ -590,4 +590,4 @@ struct lskcipher_instance *lskcipher_alloc_instance_simple( lskcipher_free_instance_simple(inst); return ERR_PTR(err); } -EXPORT_SYMBOL_GPL(lskcipher_alloc_instance_simple); +DEFINE_CRYPTO_API(lskcipher_alloc_instance_simple); diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h index d5aa535263f6..69de98e9819a 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h @@ -8,6 +8,7 @@ #ifndef _CRYPTO_INTERNAL_SKCIPHER_H #define _CRYPTO_INTERNAL_SKCIPHER_H +#include <crypto/api.h> #include <crypto/algapi.h> #include <crypto/internal/cipher.h> #include <crypto/scatterwalk.h> @@ -100,9 +101,9 @@ int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask); -int crypto_grab_lskcipher(struct crypto_lskcipher_spawn *spawn, - struct crypto_instance *inst, - const char *name, u32 type, u32 mask); +DECLARE_CRYPTO_API(crypto_grab_lskcipher, int, + (struct crypto_lskcipher_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask), + (spawn, inst, name, type, mask)); static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn) { @@ -164,12 +165,21 @@ void crypto_unregister_skciphers(struct skcipher_alg *algs, int count); int skcipher_register_instance(struct crypto_template *tmpl, struct skcipher_instance *inst); -int crypto_register_lskcipher(struct lskcipher_alg *alg); -void crypto_unregister_lskcipher(struct lskcipher_alg *alg); -int crypto_register_lskciphers(struct lskcipher_alg *algs, int count); -void crypto_unregister_lskciphers(struct lskcipher_alg *algs, int count); -int lskcipher_register_instance(struct crypto_template *tmpl, - struct lskcipher_instance *inst); +DECLARE_CRYPTO_API(crypto_register_lskcipher, int, + (struct lskcipher_alg *alg), + (alg)); +DECLARE_CRYPTO_API(crypto_unregister_lskcipher, void, + (struct lskcipher_alg *alg), + (alg)); +DECLARE_CRYPTO_API(crypto_register_lskciphers, int, + (struct lskcipher_alg *algs, int count), + (algs, count)); +DECLARE_CRYPTO_API(crypto_unregister_lskciphers, void, + (struct lskcipher_alg *algs, int count), + (algs, count)); +DECLARE_CRYPTO_API(lskcipher_register_instance, int, + (struct crypto_template *tmpl, struct lskcipher_instance *inst), + (tmpl, inst)); int skcipher_walk_virt(struct skcipher_walk *__restrict walk, struct skcipher_request *__restrict req, @@ -247,8 +257,10 @@ static inline struct crypto_lskcipher *lskcipher_cipher_simple( return *ctx; } -struct lskcipher_instance *lskcipher_alloc_instance_simple( - struct crypto_template *tmpl, struct rtattr **tb); +DECLARE_CRYPTO_API(lskcipher_alloc_instance_simple, struct lskcipher_instance *, + ( + struct crypto_template *tmpl, struct rtattr **tb), + (tmpl, tb)); static inline struct lskcipher_alg *lskcipher_ialg_simple( struct lskcipher_instance *inst) diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h index 9e5853464345..8ce770bb1f48 100644 --- a/include/crypto/skcipher.h +++ b/include/crypto/skcipher.h @@ -8,6 +8,7 @@ #ifndef _CRYPTO_SKCIPHER_H #define _CRYPTO_SKCIPHER_H +#include <crypto/api.h> #include <linux/atomic.h> #include <linux/container_of.h> #include <linux/crypto.h> @@ -297,8 +298,9 @@ struct crypto_sync_skcipher *crypto_alloc_sync_skcipher(const char *alg_name, * 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_lskcipher *crypto_alloc_lskcipher(const char *alg_name, - u32 type, u32 mask); +DECLARE_CRYPTO_API(crypto_alloc_lskcipher, struct crypto_lskcipher *, + (const char *alg_name, u32 type, u32 mask), + (alg_name, type, mask)); static inline struct crypto_tfm *crypto_skcipher_tfm( struct crypto_skcipher *tfm) @@ -636,8 +638,9 @@ static inline int crypto_sync_skcipher_setkey(struct crypto_sync_skcipher *tfm, * * Return: 0 if the setting of the key was successful; < 0 if an error occurred */ -int crypto_lskcipher_setkey(struct crypto_lskcipher *tfm, - const u8 *key, unsigned int keylen); +DECLARE_CRYPTO_API(crypto_lskcipher_setkey, int, + (struct crypto_lskcipher *tfm, const u8 *key, unsigned int keylen), + (tfm, key, keylen)); static inline unsigned int crypto_skcipher_min_keysize( struct crypto_skcipher *tfm) @@ -761,8 +764,9 @@ int crypto_skcipher_import(struct skcipher_request *req, const void *in); * then this many bytes have been left unprocessed; * < 0 if an error occurred */ -int crypto_lskcipher_encrypt(struct crypto_lskcipher *tfm, const u8 *src, - u8 *dst, unsigned len, u8 *siv); +DECLARE_CRYPTO_API(crypto_lskcipher_encrypt, int, + (struct crypto_lskcipher *tfm, const u8 *src, u8 *dst, unsigned len, u8 *siv), + (tfm, src, dst, len, siv)); /** * crypto_lskcipher_decrypt() - decrypt ciphertext @@ -781,8 +785,9 @@ int crypto_lskcipher_encrypt(struct crypto_lskcipher *tfm, const u8 *src, * then this many bytes have been left unprocessed; * < 0 if an error occurred */ -int crypto_lskcipher_decrypt(struct crypto_lskcipher *tfm, const u8 *src, - u8 *dst, unsigned len, u8 *siv); +DECLARE_CRYPTO_API(crypto_lskcipher_decrypt, int, + (struct crypto_lskcipher *tfm, const u8 *src, u8 *dst, unsigned len, u8 *siv), + (tfm, src, dst, len, siv)); /** * DOC: Symmetric Key Cipher Request Handle -- 2.39.3