Skip to content

Commit

Permalink
crypto: hisilicon/hpre - add check before gx modulo p
Browse files Browse the repository at this point in the history
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: Hui Tang <tanghui20@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Hui Tang authored and Herbert Xu committed Jun 3, 2021
1 parent 1e609f5 commit 9612581
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/crypto/hisilicon/hpre/hpre_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9612581

Please sign in to comment.