* [PATCH] Crypto: Fix one bug when use kernel ecdsa algorithm
@ 2023-05-10 7:51 yangmengfei1394
2023-05-19 8:33 ` Herbert Xu
2023-05-22 3:30 ` [PATCH] Crypto module : rearrange the default functions of akcipher yangmengfei1394
0 siblings, 2 replies; 4+ messages in thread
From: yangmengfei1394 @ 2023-05-10 7:51 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-crypto, linux-kernel, ymf
From: ymf <yangmengfei1394@phytium.com.cn>
We are trying to use kernel ecdsa algorithm to sign something.
When we call the crypto_akcipher_set_priv_key function, the
system collapses because it comes to NULL pointer.We find out
kerenl ecdsa algorithm has not offered the set_priv_key function.
So we think it might be necessary to check whether set_priv_key is
available when crypto_akcipher_set_priv_key is called.
Signed-off-by: ymf <yangmengfei1394@phytium.com.cn>
---
include/crypto/akcipher.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h
index f35fd653e4e5..a68f0e23bf89 100644
--- a/include/crypto/akcipher.h
+++ b/include/crypto/akcipher.h
@@ -459,7 +459,9 @@ static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm,
unsigned int keylen)
{
struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
-
- return alg->set_priv_key(tfm, key, keylen);
+ if (likely(alg->set_priv_key != NULL))
+ return alg->set_priv_key(tfm, key, keylen);
+ else
+ return -EPERM;
}
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Crypto: Fix one bug when use kernel ecdsa algorithm
2023-05-10 7:51 [PATCH] Crypto: Fix one bug when use kernel ecdsa algorithm yangmengfei1394
@ 2023-05-19 8:33 ` Herbert Xu
2023-05-22 3:30 ` [PATCH] Crypto module : rearrange the default functions of akcipher yangmengfei1394
1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2023-05-19 8:33 UTC (permalink / raw)
To: yangmengfei1394; +Cc: davem, linux-crypto, linux-kernel, yangmengfei1394
yangmengfei1394@phytium.com.cn wrote:
>
> diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h
> index f35fd653e4e5..a68f0e23bf89 100644
> --- a/include/crypto/akcipher.h
> +++ b/include/crypto/akcipher.h
> @@ -459,7 +459,9 @@ static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm,
> unsigned int keylen)
> {
> struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
> -
> - return alg->set_priv_key(tfm, key, keylen);
> + if (likely(alg->set_priv_key != NULL))
> + return alg->set_priv_key(tfm, key, keylen);
> + else
> + return -EPERM;
> }
> #endif
Instead of doing this, we should move the code that sets the
default functions from crypto_register_akcipher into
akcipher_prepare_alg.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Crypto module : rearrange the default functions of akcipher
2023-05-10 7:51 [PATCH] Crypto: Fix one bug when use kernel ecdsa algorithm yangmengfei1394
2023-05-19 8:33 ` Herbert Xu
@ 2023-05-22 3:30 ` yangmengfei1394
2023-06-02 10:19 ` Herbert Xu
1 sibling, 1 reply; 4+ messages in thread
From: yangmengfei1394 @ 2023-05-22 3:30 UTC (permalink / raw)
To: herbert, davem; +Cc: linux-crypto, linux-kernel, yangmengfei1394
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@phytium.com.cn>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Crypto module : rearrange the default functions of akcipher
2023-05-22 3:30 ` [PATCH] Crypto module : rearrange the default functions of akcipher yangmengfei1394
@ 2023-06-02 10:19 ` Herbert Xu
0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2023-06-02 10:19 UTC (permalink / raw)
To: yangmengfei1394; +Cc: davem, linux-crypto, linux-kernel
On Mon, May 22, 2023 at 11:30:27AM +0800, yangmengfei1394 wrote:
> 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.
Why are you adding set_pub_key? Every implementation should
provide this function.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-02 10:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-10 7:51 [PATCH] Crypto: Fix one bug when use kernel ecdsa algorithm yangmengfei1394
2023-05-19 8:33 ` Herbert Xu
2023-05-22 3:30 ` [PATCH] Crypto module : rearrange the default functions of akcipher yangmengfei1394
2023-06-02 10:19 ` Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.