Commit b0ab0797 authored by Weili Qian's avatar Weili Qian Committed by Herbert Xu

crypto: hisilicon/hpre - ensure private key less than n

The private key of the curve key size generated by stdrng, which maybe
not less than n. Therefore, the private key with the curve key size
minus 1 is generated to ensure that the private key is less than n.
Signed-off-by: default avatarWeili Qian <qianweili@huawei.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent b3882fa2
...@@ -1392,9 +1392,9 @@ static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, ...@@ -1392,9 +1392,9 @@ static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
unsigned int len) unsigned int len)
{ {
struct hpre_ctx *ctx = kpp_tfm_ctx(tfm); struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
unsigned int sz, sz_shift, curve_sz;
struct device *dev = ctx->dev; struct device *dev = ctx->dev;
char key[HPRE_ECC_MAX_KSZ]; char key[HPRE_ECC_MAX_KSZ];
unsigned int sz, sz_shift;
struct ecdh params; struct ecdh params;
int ret; int ret;
...@@ -1406,7 +1406,13 @@ static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, ...@@ -1406,7 +1406,13 @@ static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
/* Use stdrng to generate private key */ /* Use stdrng to generate private key */
if (!params.key || !params.key_size) { if (!params.key || !params.key_size) {
params.key = key; params.key = key;
params.key_size = hpre_ecdh_get_curvesz(ctx->curve_id); curve_sz = hpre_ecdh_get_curvesz(ctx->curve_id);
if (!curve_sz) {
dev_err(dev, "Invalid curve size!\n");
return -EINVAL;
}
params.key_size = curve_sz - 1;
ret = ecdh_gen_privkey(ctx, &params); ret = ecdh_gen_privkey(ctx, &params);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment