[PATCH RFC 040/104] crypto: fips140: convert crypto/cipher.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 --source crypto/cipher.c --header include/crypto/internal/cipher.h

Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx>
---
 crypto/cipher.c                  | 16 ++++++++--------
 crypto/fips140-api.c             | 14 ++++++++++++++
 include/crypto/internal/cipher.h | 20 +++++++++++++-------
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/crypto/cipher.c b/crypto/cipher.c
index 1fe62bf79656..7aeb577ac388 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -39,7 +39,7 @@ static int setkey_unaligned(struct crypto_cipher *tfm, const u8 *key,
 
 }
 
-int crypto_cipher_setkey(struct crypto_cipher *tfm,
+int CRYPTO_API(crypto_cipher_setkey)(struct crypto_cipher *tfm,
 			 const u8 *key, unsigned int keylen)
 {
 	struct cipher_alg *cia = crypto_cipher_alg(tfm);
@@ -53,7 +53,7 @@ int crypto_cipher_setkey(struct crypto_cipher *tfm,
 
 	return cia->cia_setkey(crypto_cipher_tfm(tfm), key, keylen);
 }
-EXPORT_SYMBOL_NS_GPL(crypto_cipher_setkey, "CRYPTO_INTERNAL");
+DEFINE_CRYPTO_API(crypto_cipher_setkey);
 
 static inline void cipher_crypt_one(struct crypto_cipher *tfm,
 				    u8 *dst, const u8 *src, bool enc)
@@ -76,21 +76,21 @@ static inline void cipher_crypt_one(struct crypto_cipher *tfm,
 	}
 }
 
-void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
+void CRYPTO_API(crypto_cipher_encrypt_one)(struct crypto_cipher *tfm,
 			       u8 *dst, const u8 *src)
 {
 	cipher_crypt_one(tfm, dst, src, true);
 }
-EXPORT_SYMBOL_NS_GPL(crypto_cipher_encrypt_one, "CRYPTO_INTERNAL");
+DEFINE_CRYPTO_API(crypto_cipher_encrypt_one);
 
-void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
+void CRYPTO_API(crypto_cipher_decrypt_one)(struct crypto_cipher *tfm,
 			       u8 *dst, const u8 *src)
 {
 	cipher_crypt_one(tfm, dst, src, false);
 }
-EXPORT_SYMBOL_NS_GPL(crypto_cipher_decrypt_one, "CRYPTO_INTERNAL");
+DEFINE_CRYPTO_API(crypto_cipher_decrypt_one);
 
-struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
+struct crypto_cipher *CRYPTO_API(crypto_clone_cipher)(struct crypto_cipher *cipher)
 {
 	struct crypto_tfm *tfm = crypto_cipher_tfm(cipher);
 	struct crypto_alg *alg = tfm->__crt_alg;
@@ -116,4 +116,4 @@ struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher)
 
 	return ncipher;
 }
-EXPORT_SYMBOL_GPL(crypto_clone_cipher);
+DEFINE_CRYPTO_API(crypto_clone_cipher);
diff --git a/crypto/fips140-api.c b/crypto/fips140-api.c
index df1dfcd5cf22..c05fc645a5b6 100644
--- a/crypto/fips140-api.c
+++ b/crypto/fips140-api.c
@@ -313,3 +313,17 @@ DEFINE_CRYPTO_API_STUB(crypto_authenc_extractkeys);
 
 #endif
 
+/*
+ * crypto/cipher.c
+ */
+#if !IS_BUILTIN(CONFIG_CRYPTO)
+
+#include <crypto/internal/cipher.h>
+
+DEFINE_CRYPTO_API_STUB(crypto_cipher_setkey);
+DEFINE_CRYPTO_API_STUB(crypto_cipher_encrypt_one);
+DEFINE_CRYPTO_API_STUB(crypto_cipher_decrypt_one);
+DEFINE_CRYPTO_API_STUB(crypto_clone_cipher);
+
+#endif
+
diff --git a/include/crypto/internal/cipher.h b/include/crypto/internal/cipher.h
index 5030f6d2df31..13c48b20879c 100644
--- a/include/crypto/internal/cipher.h
+++ b/include/crypto/internal/cipher.h
@@ -11,6 +11,7 @@
 #ifndef _CRYPTO_INTERNAL_CIPHER_H
 #define _CRYPTO_INTERNAL_CIPHER_H
 
+#include <crypto/api.h>
 #include <crypto/algapi.h>
 
 struct crypto_cipher {
@@ -149,8 +150,9 @@ static inline void crypto_cipher_clear_flags(struct crypto_cipher *tfm,
  *
  * Return: 0 if the setting of the key was successful; < 0 if an error occurred
  */
-int crypto_cipher_setkey(struct crypto_cipher *tfm,
-			 const u8 *key, unsigned int keylen);
+DECLARE_CRYPTO_API(crypto_cipher_setkey, int,
+	(struct crypto_cipher *tfm, const u8 *key, unsigned int keylen),
+	(tfm, key, keylen));
 
 /**
  * crypto_cipher_encrypt_one() - encrypt one block of plaintext
@@ -161,8 +163,9 @@ int crypto_cipher_setkey(struct crypto_cipher *tfm,
  * Invoke the encryption operation of one block. The caller must ensure that
  * the plaintext and ciphertext buffers are at least one block in size.
  */
-void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
-			       u8 *dst, const u8 *src);
+DECLARE_CRYPTO_API(crypto_cipher_encrypt_one, void,
+	(struct crypto_cipher *tfm, u8 *dst, const u8 *src),
+	(tfm, dst, src));
 
 /**
  * crypto_cipher_decrypt_one() - decrypt one block of ciphertext
@@ -173,10 +176,13 @@ void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,
  * Invoke the decryption operation of one block. The caller must ensure that
  * the plaintext and ciphertext buffers are at least one block in size.
  */
-void crypto_cipher_decrypt_one(struct crypto_cipher *tfm,
-			       u8 *dst, const u8 *src);
+DECLARE_CRYPTO_API(crypto_cipher_decrypt_one, void,
+	(struct crypto_cipher *tfm, u8 *dst, const u8 *src),
+	(tfm, dst, src));
 
-struct crypto_cipher *crypto_clone_cipher(struct crypto_cipher *cipher);
+DECLARE_CRYPTO_API(crypto_clone_cipher, struct crypto_cipher *,
+	(struct crypto_cipher *cipher),
+	(cipher));
 
 struct crypto_cipher_spawn {
 	struct crypto_spawn base;
-- 
2.39.3





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux