[PATCH RFC 045/104] crypto: fips140: convert crypto/dh_helper.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_DH --source crypto/dh_helper.c --header include/crypto/dh.h

Signed-off-by: Vegard Nossum <vegard.nossum@xxxxxxxxxx>
---
 crypto/dh_helper.c   | 12 ++++++------
 crypto/fips140-api.c | 13 +++++++++++++
 include/crypto/dh.h  | 12 +++++++++---
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/crypto/dh_helper.c b/crypto/dh_helper.c
index 2d499879328b..d3001289d152 100644
--- a/crypto/dh_helper.c
+++ b/crypto/dh_helper.c
@@ -31,13 +31,13 @@ static inline unsigned int dh_data_size(const struct dh *p)
 	return p->key_size + p->p_size + p->g_size;
 }
 
-unsigned int crypto_dh_key_len(const struct dh *p)
+unsigned int CRYPTO_API(crypto_dh_key_len)(const struct dh *p)
 {
 	return DH_KPP_SECRET_MIN_SIZE + dh_data_size(p);
 }
-EXPORT_SYMBOL_GPL(crypto_dh_key_len);
+DEFINE_CRYPTO_API(crypto_dh_key_len);
 
-int crypto_dh_encode_key(char *buf, unsigned int len, const struct dh *params)
+int CRYPTO_API(crypto_dh_encode_key)(char *buf, unsigned int len, const struct dh *params)
 {
 	u8 *ptr = buf;
 	u8 * const end = ptr + len;
@@ -61,7 +61,7 @@ int crypto_dh_encode_key(char *buf, unsigned int len, const struct dh *params)
 		return -EINVAL;
 	return 0;
 }
-EXPORT_SYMBOL_GPL(crypto_dh_encode_key);
+DEFINE_CRYPTO_API(crypto_dh_encode_key);
 
 int __crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params)
 {
@@ -91,7 +91,7 @@ int __crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params)
 	return 0;
 }
 
-int crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params)
+int CRYPTO_API(crypto_dh_decode_key)(const char *buf, unsigned int len, struct dh *params)
 {
 	int err;
 
@@ -117,4 +117,4 @@ int crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(crypto_dh_decode_key);
+DEFINE_CRYPTO_API(crypto_dh_decode_key);
diff --git a/crypto/fips140-api.c b/crypto/fips140-api.c
index 816a55809f4a..600c759cbc5e 100644
--- a/crypto/fips140-api.c
+++ b/crypto/fips140-api.c
@@ -350,3 +350,16 @@ DEFINE_CRYPTO_API_STUB(cryptd_free_aead);
 
 #endif
 
+/*
+ * crypto/dh_helper.c
+ */
+#if !IS_BUILTIN(CONFIG_CRYPTO_DH)
+
+#include <crypto/dh.h>
+
+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
+
diff --git a/include/crypto/dh.h b/include/crypto/dh.h
index b5891c21cfe0..f876d46b16d6 100644
--- a/include/crypto/dh.h
+++ b/include/crypto/dh.h
@@ -50,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(crypto_dh_key_len, unsigned int,
+	(const struct dh *params),
+	(params));
 
 /**
  * crypto_dh_encode_key() - encode the private key
@@ -65,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(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
@@ -79,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(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.39.3





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