提交 c8426421 编写于 作者: V Vitaly Chikunov 提交者: Zheng Zengkai

crypto: ecrdsa - Fix incorrect use of vli_cmp

stable inclusion
from stable-v5.10.120
commit 6a1cc25494056e6b8dff243f8b3d9c57259535f6
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6BR

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=6a1cc25494056e6b8dff243f8b3d9c57259535f6

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

commit 7cc7ab73 upstream.

Correctly compare values that shall be greater-or-equal and not just
greater.

Fixes: 0d7a7864 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm")
Cc: <stable@vger.kernel.org>
Signed-off-by: NVitaly Chikunov <vt@altlinux.org>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 c27f1e58
...@@ -113,15 +113,15 @@ static int ecrdsa_verify(struct akcipher_request *req) ...@@ -113,15 +113,15 @@ static int ecrdsa_verify(struct akcipher_request *req)
/* Step 1: verify that 0 < r < q, 0 < s < q */ /* Step 1: verify that 0 < r < q, 0 < s < q */
if (vli_is_zero(r, ndigits) || if (vli_is_zero(r, ndigits) ||
vli_cmp(r, ctx->curve->n, ndigits) == 1 || vli_cmp(r, ctx->curve->n, ndigits) >= 0 ||
vli_is_zero(s, ndigits) || vli_is_zero(s, ndigits) ||
vli_cmp(s, ctx->curve->n, ndigits) == 1) vli_cmp(s, ctx->curve->n, ndigits) >= 0)
return -EKEYREJECTED; return -EKEYREJECTED;
/* Step 2: calculate hash (h) of the message (passed as input) */ /* Step 2: calculate hash (h) of the message (passed as input) */
/* Step 3: calculate e = h \mod q */ /* Step 3: calculate e = h \mod q */
vli_from_le64(e, digest, ndigits); vli_from_le64(e, digest, ndigits);
if (vli_cmp(e, ctx->curve->n, ndigits) == 1) if (vli_cmp(e, ctx->curve->n, ndigits) >= 0)
vli_sub(e, e, ctx->curve->n, ndigits); vli_sub(e, e, ctx->curve->n, ndigits);
if (vli_is_zero(e, ndigits)) if (vli_is_zero(e, ndigits))
e[0] = 1; e[0] = 1;
...@@ -137,7 +137,7 @@ static int ecrdsa_verify(struct akcipher_request *req) ...@@ -137,7 +137,7 @@ static int ecrdsa_verify(struct akcipher_request *req)
/* Step 6: calculate point C = z_1P + z_2Q, and R = x_c \mod q */ /* Step 6: calculate point C = z_1P + z_2Q, and R = x_c \mod q */
ecc_point_mult_shamir(&cc, z1, &ctx->curve->g, z2, &ctx->pub_key, ecc_point_mult_shamir(&cc, z1, &ctx->curve->g, z2, &ctx->pub_key,
ctx->curve); ctx->curve);
if (vli_cmp(cc.x, ctx->curve->n, ndigits) == 1) if (vli_cmp(cc.x, ctx->curve->n, ndigits) >= 0)
vli_sub(cc.x, cc.x, ctx->curve->n, ndigits); vli_sub(cc.x, cc.x, ctx->curve->n, ndigits);
/* Step 7: if R == r signature is valid */ /* Step 7: if R == r signature is valid */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册