Skip to content

Commit 6a1cc25

Browse files
vt-altgregkh
authored andcommitted
crypto: ecrdsa - Fix incorrect use of vli_cmp
commit 7cc7ab7 upstream. Correctly compare values that shall be greater-or-equal and not just greater. Fixes: 0d7a786 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm") Cc: <stable@vger.kernel.org> Signed-off-by: Vitaly Chikunov <vt@altlinux.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c013f7d commit 6a1cc25

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crypto/ecrdsa.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ static int ecrdsa_verify(struct akcipher_request *req)
113113

114114
/* Step 1: verify that 0 < r < q, 0 < s < q */
115115
if (vli_is_zero(r, ndigits) ||
116-
vli_cmp(r, ctx->curve->n, ndigits) == 1 ||
116+
vli_cmp(r, ctx->curve->n, ndigits) >= 0 ||
117117
vli_is_zero(s, ndigits) ||
118-
vli_cmp(s, ctx->curve->n, ndigits) == 1)
118+
vli_cmp(s, ctx->curve->n, ndigits) >= 0)
119119
return -EKEYREJECTED;
120120

121121
/* Step 2: calculate hash (h) of the message (passed as input) */
122122
/* Step 3: calculate e = h \mod q */
123123
vli_from_le64(e, digest, ndigits);
124-
if (vli_cmp(e, ctx->curve->n, ndigits) == 1)
124+
if (vli_cmp(e, ctx->curve->n, ndigits) >= 0)
125125
vli_sub(e, e, ctx->curve->n, ndigits);
126126
if (vli_is_zero(e, ndigits))
127127
e[0] = 1;
@@ -137,7 +137,7 @@ static int ecrdsa_verify(struct akcipher_request *req)
137137
/* Step 6: calculate point C = z_1P + z_2Q, and R = x_c \mod q */
138138
ecc_point_mult_shamir(&cc, z1, &ctx->curve->g, z2, &ctx->pub_key,
139139
ctx->curve);
140-
if (vli_cmp(cc.x, ctx->curve->n, ndigits) == 1)
140+
if (vli_cmp(cc.x, ctx->curve->n, ndigits) >= 0)
141141
vli_sub(cc.x, cc.x, ctx->curve->n, ndigits);
142142

143143
/* Step 7: if R == r signature is valid */

0 commit comments

Comments
 (0)