Commit 205bd52c authored by Hui Tang's avatar Hui Tang Committed by Zheng Zengkai
Browse files

crypto: hisilicon/hpre - add check before gx modulo p

mainline inclusion
from mainline-master
commit 9612581f
category: feature
bugzilla: 173981
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9612581fc10919ef70aae1fa4dcf6e20d85a14a7



----------------------------------------------------------------------

The result of gx modulo p is zero if gx is equal to p, so return
error immediately if gx is equal to p.

Signed-off-by: default avatarHui Tang <tanghui20@huawei.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarMingqiang Ling <lingmingqiang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 812b3407
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -1841,8 +1841,12 @@ static int hpre_curve25519_src_init(struct hpre_asym_request *hpre_req,
	 * When src_data equals (2^255 - 19) ~  (2^255 - 1), it is out of p,
	 * we get its modulus to p, and then use it.
	 */
	if (memcmp(ptr, p, ctx->key_sz) >= 0)
	if (memcmp(ptr, p, ctx->key_sz) == 0) {
		dev_err(dev, "gx is p!\n");
		return -EINVAL;
	} else if (memcmp(ptr, p, ctx->key_sz) > 0) {
		hpre_curve25519_src_modulo_p(ptr);
	}

	hpre_req->src = ptr;
	msg->in = cpu_to_le64(dma);