Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp754130pxb; Fri, 22 Apr 2022 10:25:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS//G811AitIrjRrvP+F5X2vRvR/ZHV8L4dNBmF/isCK96MfR+uUvWSKubYU5KKtkOaG6V X-Received: by 2002:a62:ed0e:0:b0:4fa:11ed:2ad1 with SMTP id u14-20020a62ed0e000000b004fa11ed2ad1mr6192029pfh.34.1650648356057; Fri, 22 Apr 2022 10:25:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650648356; cv=none; d=google.com; s=arc-20160816; b=rWQysc+6UWar/4uMnvd+H/6wk/AsQwL+3kT0FB4yGhVWhTySvS/FWb7IrNoMUncmis KFS39sM/1m62GUEb5Tv4gM6GZ9M5J5D28dWUvPDrQNprmvz7p33eLlV/abTqOM9ptAuL FeNKySH0InRm+V45YWJHTFgM6ioGLf3GKAl3U2KAqKQJJ1KflKrK6s+CtenQI5K7nxPy nPm69YTgsqUGouy4AYXeYk01MLyIMvmkaQpYN36FPHdmKVjBwychGXOm2KyELU6Y4/B5 DFWtCO0sGhpK2CrB3tXmJyG7yeN/N/IPaUY1PxJI+eXyTolqKH1n1Ga+vpc/PdWFhx3i 0pMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from; bh=FZJaFd36A22Jyvm/BF4gISIpG94cATA424dmpwmTGBI=; b=wf+TrHF5D+9Y/UJeRYSomtyC/x5ZpT9hsR1jHBl+jOrdSPbBHhcd/9/wl7dBA3h7Cf x9FEfLekeD04ug/tnaauuROf1l/guJk+ciX6/JHDbUG/bjKzjBxJbc4ARDrB4DPGfaKw 7tBQDGr4fTzF8SvWyKK7fDR85BmW573dxShpyVjNflZw5nBrCIZh7KqkUuZFPFUAIzMd I7OnxE0UCL139vFH5NNhvn31ZCrUQ4AIz+T7ULBiq/RmYc4VAJya5kQ9VZc1sDwmDMf/ mnsURK0HtZvoT8JF3ifLcCtJWPfCEbIxNVk6Z+OsJVCeO9FYI/KQNGYMdGAkTTP8ONfV XLJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b12-20020a63eb4c000000b003aa45e24352si8905284pgk.322.2022.04.22.10.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 10:25:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1206A79398; Fri, 22 Apr 2022 10:19:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355257AbiDURgz (ORCPT + 99 others); Thu, 21 Apr 2022 13:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390806AbiDURgy (ORCPT ); Thu, 21 Apr 2022 13:36:54 -0400 X-Greylist: delayed 521 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 21 Apr 2022 10:34:03 PDT Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C3E474A3CE for ; Thu, 21 Apr 2022 10:34:03 -0700 (PDT) Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id 87EA972C8DC; Thu, 21 Apr 2022 20:25:21 +0300 (MSK) Received: from beacon.altlinux.org (unknown [193.43.10.250]) by imap.altlinux.org (Postfix) with ESMTPSA id 39C424A46F0; Thu, 21 Apr 2022 20:25:21 +0300 (MSK) From: Vitaly Chikunov To: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org Subject: [PATCH] crypto: ecrdsa - Fix incorrect use of vli_cmp Date: Thu, 21 Apr 2022 20:25:10 +0300 Message-Id: <20220421172511.14371-1-vt@altlinux.org> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Correctly compare values that shall be greater-or-equal and not just greater. Fixes: 0d7a78643f69 ("crypto: ecrdsa - add EC-RDSA (GOST 34.10) algorithm") Cc: Signed-off-by: Vitaly Chikunov --- crypto/ecrdsa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto/ecrdsa.c b/crypto/ecrdsa.c index b32ffcaad9adf..f3c6b5e15e75b 100644 --- a/crypto/ecrdsa.c +++ b/crypto/ecrdsa.c @@ -113,15 +113,15 @@ static int ecrdsa_verify(struct akcipher_request *req) /* Step 1: verify that 0 < r < q, 0 < s < q */ 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_cmp(s, ctx->curve->n, ndigits) == 1) + vli_cmp(s, ctx->curve->n, ndigits) >= 0) return -EKEYREJECTED; /* Step 2: calculate hash (h) of the message (passed as input) */ /* Step 3: calculate e = h \mod q */ 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); if (vli_is_zero(e, ndigits)) e[0] = 1; @@ -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 */ ecc_point_mult_shamir(&cc, z1, &ctx->curve->g, z2, &ctx->pub_key, 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); /* Step 7: if R == r signature is valid */ -- 2.11.0