[PATCH RFC 073/104] crypto: fips140: convert crypto/skcipher.c to using crypto API wrappers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/skcipher.c --header include/crypto/skcipher.h include/crypto/internal/skcipher.h

Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx>
---
 crypto/fips140-api.c               | 31 +++++++++++++
 crypto/skcipher.c                  | 72 +++++++++++++++---------------
 include/crypto/internal/skcipher.h | 51 ++++++++++++---------
 include/crypto/skcipher.h          | 35 ++++++++++-----
 4 files changed, 122 insertions(+), 67 deletions(-)

diff --git a/crypto/fips140-api.c b/crypto/fips140-api.c
index 112212b32d6d..115a0fc99e31 100644
--- a/crypto/fips140-api.c
+++ b/crypto/fips140-api.c
@@ -578,3 +578,34 @@ DEFINE_CRYPTO_API_STUB(simd_unregister_aeads);
 
 #endif
 
+/*
+ * crypto/skcipher.c
+ */
+#if !IS_BUILTIN(CONFIG_CRYPTO_SKCIPHER2)
+
+#include <crypto/skcipher.h>
+
+DEFINE_CRYPTO_API_STUB(crypto_alloc_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_alloc_sync_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_has_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_skcipher_setkey);
+DEFINE_CRYPTO_API_STUB(crypto_skcipher_encrypt);
+DEFINE_CRYPTO_API_STUB(crypto_skcipher_decrypt);
+DEFINE_CRYPTO_API_STUB(crypto_skcipher_export);
+DEFINE_CRYPTO_API_STUB(crypto_skcipher_import);
+
+#include <crypto/internal/skcipher.h>
+
+DEFINE_CRYPTO_API_STUB(crypto_grab_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_register_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_unregister_skcipher);
+DEFINE_CRYPTO_API_STUB(crypto_register_skciphers);
+DEFINE_CRYPTO_API_STUB(crypto_unregister_skciphers);
+DEFINE_CRYPTO_API_STUB(skcipher_register_instance);
+DEFINE_CRYPTO_API_STUB(skcipher_walk_virt);
+DEFINE_CRYPTO_API_STUB(skcipher_walk_aead_encrypt);
+DEFINE_CRYPTO_API_STUB(skcipher_walk_aead_decrypt);
+DEFINE_CRYPTO_API_STUB(skcipher_alloc_instance_simple);
+
+#endif
+
diff --git a/crypto/skcipher.c b/crypto/skcipher.c
index de5fc91bba26..0bc53ac3fd0f 100644
--- a/crypto/skcipher.c
+++ b/crypto/skcipher.c
@@ -35,7 +35,7 @@ static inline struct skcipher_alg *__crypto_skcipher_alg(
 	return container_of(alg, struct skcipher_alg, base);
 }
 
-int skcipher_walk_virt(struct skcipher_walk *__restrict walk,
+int CRYPTO_API(skcipher_walk_virt)(struct skcipher_walk *__restrict walk,
 		       struct skcipher_request *__restrict req, bool atomic)
 {
 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
@@ -69,7 +69,7 @@ int skcipher_walk_virt(struct skcipher_walk *__restrict walk,
 
 	return skcipher_walk_first(walk, atomic);
 }
-EXPORT_SYMBOL_GPL(skcipher_walk_virt);
+DEFINE_CRYPTO_API(skcipher_walk_virt);
 
 static int skcipher_walk_aead_common(struct skcipher_walk *__restrict walk,
 				     struct aead_request *__restrict req,
@@ -97,7 +97,7 @@ static int skcipher_walk_aead_common(struct skcipher_walk *__restrict walk,
 	return skcipher_walk_first(walk, atomic);
 }
 
-int skcipher_walk_aead_encrypt(struct skcipher_walk *__restrict walk,
+int CRYPTO_API(skcipher_walk_aead_encrypt)(struct skcipher_walk *__restrict walk,
 			       struct aead_request *__restrict req,
 			       bool atomic)
 {
@@ -105,9 +105,9 @@ int skcipher_walk_aead_encrypt(struct skcipher_walk *__restrict walk,
 
 	return skcipher_walk_aead_common(walk, req, atomic);
 }
-EXPORT_SYMBOL_GPL(skcipher_walk_aead_encrypt);
+DEFINE_CRYPTO_API(skcipher_walk_aead_encrypt);
 
-int skcipher_walk_aead_decrypt(struct skcipher_walk *__restrict walk,
+int CRYPTO_API(skcipher_walk_aead_decrypt)(struct skcipher_walk *__restrict walk,
 			       struct aead_request *__restrict req,
 			       bool atomic)
 {
@@ -117,7 +117,7 @@ int skcipher_walk_aead_decrypt(struct skcipher_walk *__restrict walk,
 
 	return skcipher_walk_aead_common(walk, req, atomic);
 }
-EXPORT_SYMBOL_GPL(skcipher_walk_aead_decrypt);
+DEFINE_CRYPTO_API(skcipher_walk_aead_decrypt);
 
 static void skcipher_set_needkey(struct crypto_skcipher *tfm)
 {
@@ -146,7 +146,7 @@ static int skcipher_setkey_unaligned(struct crypto_skcipher *tfm,
 	return ret;
 }
 
-int crypto_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
+int CRYPTO_API(crypto_skcipher_setkey)(struct crypto_skcipher *tfm, const u8 *key,
 			   unsigned int keylen)
 {
 	struct skcipher_alg *cipher = crypto_skcipher_alg(tfm);
@@ -181,9 +181,9 @@ int crypto_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
 	crypto_skcipher_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
 	return 0;
 }
-EXPORT_SYMBOL_GPL(crypto_skcipher_setkey);
+DEFINE_CRYPTO_API(crypto_skcipher_setkey);
 
-int crypto_skcipher_encrypt(struct skcipher_request *req)
+int CRYPTO_API(crypto_skcipher_encrypt)(struct skcipher_request *req)
 {
 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 	struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
@@ -194,9 +194,9 @@ int crypto_skcipher_encrypt(struct skcipher_request *req)
 		return crypto_lskcipher_encrypt_sg(req);
 	return alg->encrypt(req);
 }
-EXPORT_SYMBOL_GPL(crypto_skcipher_encrypt);
+DEFINE_CRYPTO_API(crypto_skcipher_encrypt);
 
-int crypto_skcipher_decrypt(struct skcipher_request *req)
+int CRYPTO_API(crypto_skcipher_decrypt)(struct skcipher_request *req)
 {
 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 	struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
@@ -207,7 +207,7 @@ int crypto_skcipher_decrypt(struct skcipher_request *req)
 		return crypto_lskcipher_decrypt_sg(req);
 	return alg->decrypt(req);
 }
-EXPORT_SYMBOL_GPL(crypto_skcipher_decrypt);
+DEFINE_CRYPTO_API(crypto_skcipher_decrypt);
 
 static int crypto_lskcipher_export(struct skcipher_request *req, void *out)
 {
@@ -245,7 +245,7 @@ static int skcipher_noimport(struct skcipher_request *req, const void *in)
 	return 0;
 }
 
-int crypto_skcipher_export(struct skcipher_request *req, void *out)
+int CRYPTO_API(crypto_skcipher_export)(struct skcipher_request *req, void *out)
 {
 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 	struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
@@ -254,9 +254,9 @@ int crypto_skcipher_export(struct skcipher_request *req, void *out)
 		return crypto_lskcipher_export(req, out);
 	return alg->export(req, out);
 }
-EXPORT_SYMBOL_GPL(crypto_skcipher_export);
+DEFINE_CRYPTO_API(crypto_skcipher_export);
 
-int crypto_skcipher_import(struct skcipher_request *req, const void *in)
+int CRYPTO_API(crypto_skcipher_import)(struct skcipher_request *req, const void *in)
 {
 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 	struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
@@ -265,7 +265,7 @@ int crypto_skcipher_import(struct skcipher_request *req, const void *in)
 		return crypto_lskcipher_import(req, in);
 	return alg->import(req, in);
 }
-EXPORT_SYMBOL_GPL(crypto_skcipher_import);
+DEFINE_CRYPTO_API(crypto_skcipher_import);
 
 static void crypto_skcipher_exit_tfm(struct crypto_tfm *tfm)
 {
@@ -374,23 +374,23 @@ static const struct crypto_type crypto_skcipher_type = {
 	.algsize = offsetof(struct skcipher_alg, base),
 };
 
-int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn,
+int CRYPTO_API(crypto_grab_skcipher)(struct crypto_skcipher_spawn *spawn,
 			 struct crypto_instance *inst,
 			 const char *name, u32 type, u32 mask)
 {
 	spawn->base.frontend = &crypto_skcipher_type;
 	return crypto_grab_spawn(&spawn->base, inst, name, type, mask);
 }
-EXPORT_SYMBOL_GPL(crypto_grab_skcipher);
+DEFINE_CRYPTO_API(crypto_grab_skcipher);
 
-struct crypto_skcipher *crypto_alloc_skcipher(const char *alg_name,
+struct crypto_skcipher *CRYPTO_API(crypto_alloc_skcipher)(const char *alg_name,
 					      u32 type, u32 mask)
 {
 	return crypto_alloc_tfm(alg_name, &crypto_skcipher_type, type, mask);
 }
-EXPORT_SYMBOL_GPL(crypto_alloc_skcipher);
+DEFINE_CRYPTO_API(crypto_alloc_skcipher);
 
-struct crypto_sync_skcipher *crypto_alloc_sync_skcipher(
+struct crypto_sync_skcipher *CRYPTO_API(crypto_alloc_sync_skcipher)(
 				const char *alg_name, u32 type, u32 mask)
 {
 	struct crypto_skcipher *tfm;
@@ -413,13 +413,13 @@ struct crypto_sync_skcipher *crypto_alloc_sync_skcipher(
 
 	return (struct crypto_sync_skcipher *)tfm;
 }
-EXPORT_SYMBOL_GPL(crypto_alloc_sync_skcipher);
+DEFINE_CRYPTO_API(crypto_alloc_sync_skcipher);
 
-int crypto_has_skcipher(const char *alg_name, u32 type, u32 mask)
+int CRYPTO_API(crypto_has_skcipher)(const char *alg_name, u32 type, u32 mask)
 {
 	return crypto_type_has_alg(alg_name, &crypto_skcipher_type, type, mask);
 }
-EXPORT_SYMBOL_GPL(crypto_has_skcipher);
+DEFINE_CRYPTO_API(crypto_has_skcipher);
 
 int skcipher_prepare_alg_common(struct skcipher_alg_common *alg)
 {
@@ -465,7 +465,7 @@ static int skcipher_prepare_alg(struct skcipher_alg *alg)
 	return 0;
 }
 
-int crypto_register_skcipher(struct skcipher_alg *alg)
+int CRYPTO_API(crypto_register_skcipher)(struct skcipher_alg *alg)
 {
 	struct crypto_alg *base = &alg->base;
 	int err;
@@ -476,15 +476,15 @@ int crypto_register_skcipher(struct skcipher_alg *alg)
 
 	return crypto_register_alg(base);
 }
-EXPORT_SYMBOL_GPL(crypto_register_skcipher);
+DEFINE_CRYPTO_API(crypto_register_skcipher);
 
-void crypto_unregister_skcipher(struct skcipher_alg *alg)
+void CRYPTO_API(crypto_unregister_skcipher)(struct skcipher_alg *alg)
 {
 	crypto_unregister_alg(&alg->base);
 }
-EXPORT_SYMBOL_GPL(crypto_unregister_skcipher);
+DEFINE_CRYPTO_API(crypto_unregister_skcipher);
 
-int crypto_register_skciphers(struct skcipher_alg *algs, int count)
+int CRYPTO_API(crypto_register_skciphers)(struct skcipher_alg *algs, int count)
 {
 	int i, ret;
 
@@ -502,18 +502,18 @@ int crypto_register_skciphers(struct skcipher_alg *algs, int count)
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(crypto_register_skciphers);
+DEFINE_CRYPTO_API(crypto_register_skciphers);
 
-void crypto_unregister_skciphers(struct skcipher_alg *algs, int count)
+void CRYPTO_API(crypto_unregister_skciphers)(struct skcipher_alg *algs, int count)
 {
 	int i;
 
 	for (i = count - 1; i >= 0; --i)
 		crypto_unregister_skcipher(&algs[i]);
 }
-EXPORT_SYMBOL_GPL(crypto_unregister_skciphers);
+DEFINE_CRYPTO_API(crypto_unregister_skciphers);
 
-int skcipher_register_instance(struct crypto_template *tmpl,
+int CRYPTO_API(skcipher_register_instance)(struct crypto_template *tmpl,
 			   struct skcipher_instance *inst)
 {
 	int err;
@@ -527,7 +527,7 @@ int skcipher_register_instance(struct crypto_template *tmpl,
 
 	return crypto_register_instance(tmpl, skcipher_crypto_instance(inst));
 }
-EXPORT_SYMBOL_GPL(skcipher_register_instance);
+DEFINE_CRYPTO_API(skcipher_register_instance);
 
 static int skcipher_setkey_simple(struct crypto_skcipher *tfm, const u8 *key,
 				  unsigned int keylen)
@@ -584,7 +584,7 @@ static void skcipher_free_instance_simple(struct skcipher_instance *inst)
  * Return: a pointer to the new instance, or an ERR_PTR().  The caller still
  *	   needs to register the instance.
  */
-struct skcipher_instance *skcipher_alloc_instance_simple(
+struct skcipher_instance *CRYPTO_API(skcipher_alloc_instance_simple)(
 	struct crypto_template *tmpl, struct rtattr **tb)
 {
 	u32 mask;
@@ -635,7 +635,7 @@ struct skcipher_instance *skcipher_alloc_instance_simple(
 	skcipher_free_instance_simple(inst);
 	return ERR_PTR(err);
 }
-EXPORT_SYMBOL_GPL(skcipher_alloc_instance_simple);
+DEFINE_CRYPTO_API(skcipher_alloc_instance_simple);
 
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Symmetric key cipher type");
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h
index 69de98e9819a..d55b9b9d42a1 100644
--- a/include/crypto/internal/skcipher.h
+++ b/include/crypto/internal/skcipher.h
@@ -97,9 +97,9 @@ static inline void skcipher_request_complete(struct skcipher_request *req, int e
 	crypto_request_complete(&req->base, err);
 }
 
-int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn,
-			 struct crypto_instance *inst,
-			 const char *name, u32 type, u32 mask);
+DECLARE_CRYPTO_API(crypto_grab_skcipher, int,
+	(struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask),
+	(spawn, inst, name, type, mask));
 
 DECLARE_CRYPTO_API(crypto_grab_lskcipher, int,
 	(struct crypto_lskcipher_spawn *spawn, struct crypto_instance *inst, const char *name, u32 type, u32 mask),
@@ -158,12 +158,21 @@ static inline void crypto_skcipher_set_reqsize_dma(
 	skcipher->reqsize = reqsize;
 }
 
-int crypto_register_skcipher(struct skcipher_alg *alg);
-void crypto_unregister_skcipher(struct skcipher_alg *alg);
-int crypto_register_skciphers(struct skcipher_alg *algs, int count);
-void crypto_unregister_skciphers(struct skcipher_alg *algs, int count);
-int skcipher_register_instance(struct crypto_template *tmpl,
-			       struct skcipher_instance *inst);
+DECLARE_CRYPTO_API(crypto_register_skcipher, int,
+	(struct skcipher_alg *alg),
+	(alg));
+DECLARE_CRYPTO_API(crypto_unregister_skcipher, void,
+	(struct skcipher_alg *alg),
+	(alg));
+DECLARE_CRYPTO_API(crypto_register_skciphers, int,
+	(struct skcipher_alg *algs, int count),
+	(algs, count));
+DECLARE_CRYPTO_API(crypto_unregister_skciphers, void,
+	(struct skcipher_alg *algs, int count),
+	(algs, count));
+DECLARE_CRYPTO_API(skcipher_register_instance, int,
+	(struct crypto_template *tmpl, struct skcipher_instance *inst),
+	(tmpl, inst));
 
 DECLARE_CRYPTO_API(crypto_register_lskcipher, int,
 	(struct lskcipher_alg *alg),
@@ -181,15 +190,15 @@ 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,
-		       bool atomic);
-int skcipher_walk_aead_encrypt(struct skcipher_walk *__restrict walk,
-			       struct aead_request *__restrict req,
-			       bool atomic);
-int skcipher_walk_aead_decrypt(struct skcipher_walk *__restrict walk,
-			       struct aead_request *__restrict req,
-			       bool atomic);
+DECLARE_CRYPTO_API(skcipher_walk_virt, int,
+	(struct skcipher_walk *__restrict walk, struct skcipher_request *__restrict req, bool atomic),
+	(walk, req, atomic));
+DECLARE_CRYPTO_API(skcipher_walk_aead_encrypt, int,
+	(struct skcipher_walk *__restrict walk, struct aead_request *__restrict req, bool atomic),
+	(walk, req, atomic));
+DECLARE_CRYPTO_API(skcipher_walk_aead_decrypt, int,
+	(struct skcipher_walk *__restrict walk, struct aead_request *__restrict req, bool atomic),
+	(walk, req, atomic));
 
 static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm)
 {
@@ -238,8 +247,10 @@ skcipher_cipher_simple(struct crypto_skcipher *tfm)
 	return ctx->cipher;
 }
 
-struct skcipher_instance *skcipher_alloc_instance_simple(
-	struct crypto_template *tmpl, struct rtattr **tb);
+DECLARE_CRYPTO_API(skcipher_alloc_instance_simple, struct skcipher_instance *,
+	(
+	struct crypto_template *tmpl, struct rtattr **tb),
+	(tmpl, tb));
 
 static inline struct crypto_alg *skcipher_ialg_simple(
 	struct skcipher_instance *inst)
diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
index 8ce770bb1f48..ad2e945de9fa 100644
--- a/include/crypto/skcipher.h
+++ b/include/crypto/skcipher.h
@@ -277,11 +277,13 @@ static inline struct crypto_skcipher *__crypto_skcipher_cast(
  * 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_skcipher *crypto_alloc_skcipher(const char *alg_name,
-					      u32 type, u32 mask);
+DECLARE_CRYPTO_API(crypto_alloc_skcipher, struct crypto_skcipher *,
+	(const char *alg_name, u32 type, u32 mask),
+	(alg_name, type, mask));
 
-struct crypto_sync_skcipher *crypto_alloc_sync_skcipher(const char *alg_name,
-					      u32 type, u32 mask);
+DECLARE_CRYPTO_API(crypto_alloc_sync_skcipher, struct crypto_sync_skcipher *,
+	(const char *alg_name, u32 type, u32 mask),
+	(alg_name, type, mask));
 
 
 /**
@@ -357,7 +359,9 @@ static inline void crypto_free_lskcipher(struct crypto_lskcipher *tfm)
  * Return: true when the skcipher is known to the kernel crypto API; false
  *	   otherwise
  */
-int crypto_has_skcipher(const char *alg_name, u32 type, u32 mask);
+DECLARE_CRYPTO_API(crypto_has_skcipher, int,
+	(const char *alg_name, u32 type, u32 mask),
+	(alg_name, type, mask));
 
 static inline const char *crypto_skcipher_driver_name(
 	struct crypto_skcipher *tfm)
@@ -613,8 +617,9 @@ static inline void crypto_lskcipher_clear_flags(struct crypto_lskcipher *tfm,
  *
  * Return: 0 if the setting of the key was successful; < 0 if an error occurred
  */
-int crypto_skcipher_setkey(struct crypto_skcipher *tfm,
-			   const u8 *key, unsigned int keylen);
+DECLARE_CRYPTO_API(crypto_skcipher_setkey, int,
+	(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen),
+	(tfm, key, keylen));
 
 static inline int crypto_sync_skcipher_setkey(struct crypto_sync_skcipher *tfm,
 					 const u8 *key, unsigned int keylen)
@@ -700,7 +705,9 @@ static inline struct crypto_sync_skcipher *crypto_sync_skcipher_reqtfm(
  *
  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  */
-int crypto_skcipher_encrypt(struct skcipher_request *req);
+DECLARE_CRYPTO_API(crypto_skcipher_encrypt, int,
+	(struct skcipher_request *req),
+	(req));
 
 /**
  * crypto_skcipher_decrypt() - decrypt ciphertext
@@ -713,7 +720,9 @@ int crypto_skcipher_encrypt(struct skcipher_request *req);
  *
  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  */
-int crypto_skcipher_decrypt(struct skcipher_request *req);
+DECLARE_CRYPTO_API(crypto_skcipher_decrypt, int,
+	(struct skcipher_request *req),
+	(req));
 
 /**
  * crypto_skcipher_export() - export partial state
@@ -731,7 +740,9 @@ int crypto_skcipher_decrypt(struct skcipher_request *req);
  *
  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  */
-int crypto_skcipher_export(struct skcipher_request *req, void *out);
+DECLARE_CRYPTO_API(crypto_skcipher_export, int,
+	(struct skcipher_request *req, void *out),
+	(req, out));
 
 /**
  * crypto_skcipher_import() - import partial state
@@ -746,7 +757,9 @@ int crypto_skcipher_export(struct skcipher_request *req, void *out);
  *
  * Return: 0 if the cipher operation was successful; < 0 if an error occurred
  */
-int crypto_skcipher_import(struct skcipher_request *req, const void *in);
+DECLARE_CRYPTO_API(crypto_skcipher_import, int,
+	(struct skcipher_request *req, const void *in),
+	(req, in));
 
 /**
  * crypto_lskcipher_encrypt() - encrypt plaintext
-- 
2.39.3





[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux