[PATCH] Crypto module : rearrange the default functions of akcipher

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

 



According to your last email, we rearrange the default functions,
move the code that sets the default functions from
crypto_register_akcipher into akcipher_prepare_alg,
add the set_pub_key function check at the same time.

Signed-off-by: yangmengfei1394 <yangmengfei1394@xxxxxxxxxxxxxx>
---
 crypto/akcipher.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/crypto/akcipher.c b/crypto/akcipher.c
index 7960ceb528c3..45502446b231 100644
--- a/crypto/akcipher.c
+++ b/crypto/akcipher.c
@@ -126,19 +126,6 @@ struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type,
 }
 EXPORT_SYMBOL_GPL(crypto_alloc_akcipher);
 
-static void akcipher_prepare_alg(struct akcipher_alg *alg)
-{
-	struct crypto_istat_akcipher *istat = akcipher_get_stat(alg);
-	struct crypto_alg *base = &alg->base;
-
-	base->cra_type = &crypto_akcipher_type;
-	base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
-	base->cra_flags |= CRYPTO_ALG_TYPE_AKCIPHER;
-
-	if (IS_ENABLED(CONFIG_CRYPTO_STATS))
-		memset(istat, 0, sizeof(*istat));
-}
-
 static int akcipher_default_op(struct akcipher_request *req)
 {
 	return -ENOSYS;
@@ -150,8 +137,9 @@ static int akcipher_default_set_key(struct crypto_akcipher *tfm,
 	return -ENOSYS;
 }
 
-int crypto_register_akcipher(struct akcipher_alg *alg)
+static void akcipher_prepare_alg(struct akcipher_alg *alg)
 {
+	struct crypto_istat_akcipher *istat = akcipher_get_stat(alg);
 	struct crypto_alg *base = &alg->base;
 
 	if (!alg->sign)
@@ -164,6 +152,20 @@ int crypto_register_akcipher(struct akcipher_alg *alg)
 		alg->decrypt = akcipher_default_op;
 	if (!alg->set_priv_key)
 		alg->set_priv_key = akcipher_default_set_key;
+	if (!alg->set_pub_key)
+		alg->set_pub_key = akcipher_default_set_key;
+
+	base->cra_type = &crypto_akcipher_type;
+	base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
+	base->cra_flags |= CRYPTO_ALG_TYPE_AKCIPHER;
+
+	if (IS_ENABLED(CONFIG_CRYPTO_STATS))
+		memset(istat, 0, sizeof(*istat));
+}
+
+int crypto_register_akcipher(struct akcipher_alg *alg)
+{
+	struct crypto_alg *base = &alg->base;
 
 	akcipher_prepare_alg(alg);
 	return crypto_register_alg(base);
-- 
2.35.1.windows.2




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