Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp867479pxb; Fri, 22 Apr 2022 13:01:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYgWYmYPSBlHka/w4uAN89dPUM5U0mI0gph37kroapg2pcGAVejFnG0MwaKbJTM7aYbQ+K X-Received: by 2002:a17:90a:9901:b0:1cb:aa19:5eee with SMTP id b1-20020a17090a990100b001cbaa195eeemr7328015pjp.158.1650657719255; Fri, 22 Apr 2022 13:01:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650657719; cv=none; d=google.com; s=arc-20160816; b=kWwtebbMX44fCzC79J/zIL/olTpDIPylnCHiT40kqvNbJtOxOqSrVSt33Bhq5w948o gk8Im7DunfFe/NpFsza0mkJAdbFDeZRZaX6OkYnX56pPp+M0Lybw1Nl4eamvdiyN47gP Xaf4ka9bbcviwH2gz5wWZO5jAN9kHUw3d1A2QmzlPXreB5TYvMvQWxghHWyF4K81EvEV xmOBwPIHlRLeYhqdMAenfxiOQb75Zzkgo/XZ/BdRo3wcwaS3xzN2kTpFPAoUwU7h9LNV aI3rSaRhbSULUWeEgXTs15oMeNBUNYbbLpvxVmutCOrpYlvT0iodUg+OdVZ5+rIJjRa0 3LeQ== 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:cc:to:from:dkim-signature; bh=yH3e3O+rZ2tn1EqO8Imom1AG6duRE+lhELtbT/HFyQQ=; b=cMgZV9NPc6H7JI0/8UykI3ha/tcIjJm9maw6rww7piwWyZtmeRRU33rYPlnFyMsbVk Dq4zG/8Kpf6ZNODcyGzrqrE5nUtV8KWjX81q5scK0rIqdgnmsIvU89Fivrg7ASezUS6D be8/TDEzkAtV6+hqkiXRfisnKpMrntm6VWti/nm9h5brFA11I7B28MwVDjtK8MB2LKhS udKtUqvQIC6Hj+tn0KX3t54LDIVMPVZqTdqgWeqWL52gRGOOIvH4k7/HLGuVP/9Q1/9O I/TsevNFvr1br9wM6G9yX0JsQsMxnE4DqvmY55p0zWWFiYw65dPnpToBDnNC+SEOra/r Gi/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HoRT8AfG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c66-20020a633545000000b0039d6935cd5dsi136087pga.602.2022.04.22.13.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:01:59 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HoRT8AfG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E64ED8903; Fri, 22 Apr 2022 12:00:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391649AbiDUTAl (ORCPT + 99 others); Thu, 21 Apr 2022 15:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351440AbiDUTAk (ORCPT ); Thu, 21 Apr 2022 15:00:40 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3651D2194; Thu, 21 Apr 2022 11:57:48 -0700 (PDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23LINT1q004811; Thu, 21 Apr 2022 18:57:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=yH3e3O+rZ2tn1EqO8Imom1AG6duRE+lhELtbT/HFyQQ=; b=HoRT8AfGNws3DCRe8JbbeZdb47cRPtTdbowwNQ89lQ811a8pm4EeZHQIHWJAjuXDEJk8 AgxSoDB9yBO7rd0o0QJiG7MaxkoAzLQ/gfKgGzTOTiNU+0Nmbd4yuP13gYUxT+9DeMRo lxau7Ymh1XOIt6jRKtd9IlASWqDi9/4diZ5YW0fdoA59w0KV/INByjP1LpBSg0Ju49Hp YHyGF/Z8+l55c4Y0E0tyuVto0s2gdDCnwZeNZQA5bMAIqVYzpfybbStmPxmpzzKr6uQS rbgbnig5qsXDLs9pbhc1F49VyMZ27a37Zbn1R2qUHc+1kp0JICPkRfUL4sMIhzV1RJF3 Zw== Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0b-001b2d01.pphosted.com with ESMTP id 3fjer8xke8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 18:57:43 +0000 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23LIr0kx027257; Thu, 21 Apr 2022 18:57:42 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma04wdc.us.ibm.com with ESMTP id 3ffneantn8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 18:57:42 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23LIvggD61342052 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Apr 2022 18:57:42 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D78E124053; Thu, 21 Apr 2022 18:57:42 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15F89124052; Thu, 21 Apr 2022 18:57:42 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 21 Apr 2022 18:57:42 +0000 (GMT) From: Stefan Berger To: herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stefan Berger , stable@vger.kernel.org Subject: [PATCH] ecdsa: Fix incorrect usage of vli_cmp Date: Thu, 21 Apr 2022 14:57:40 -0400 Message-Id: <20220421185740.799271-1-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7VZxFIY05jd0-f9UHPCO1iLIfXjU5szl X-Proofpoint-ORIG-GUID: 7VZxFIY05jd0-f9UHPCO1iLIfXjU5szl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-21_04,2022-04-21_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 impostorscore=0 mlxscore=0 priorityscore=1501 phishscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 adultscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204210098 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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-kernel@vger.kernel.org Fix incorrect usage of vli_cmp when calculating the value of res.x. For signature verification to succeed, res.x must be the same as the r component of the signature which is in the range of [1..n-1] with 'n' being the order of the curve. Therefore, when res.x equals n calculate res.x = res.x - n as well. Signature verification could have previously unnecessarily failed in extremely rare cases. Fixes: 4e6602916bc6 ("crypto: ecdsa - Add support for ECDSA signature verification") Cc: Signed-off-by: Stefan Berger --- crypto/ecdsa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c index b3a8a6b572ba..674ab9275366 100644 --- a/crypto/ecdsa.c +++ b/crypto/ecdsa.c @@ -120,8 +120,8 @@ static int _ecdsa_verify(struct ecc_ctx *ctx, const u64 *hash, const u64 *r, con /* res = u1*G + u2 * pub_key */ ecc_point_mult_shamir(&res, u1, &curve->g, u2, &ctx->pub_key, curve); - /* res.x = res.x mod n (if res.x > order) */ - if (unlikely(vli_cmp(res.x, curve->n, ndigits) == 1)) + /* res.x = res.x mod n (if res.x >= order) */ + if (unlikely(vli_cmp(res.x, curve->n, ndigits) >= 0)) /* faster alternative for NIST p384, p256 & p192 */ vli_sub(res.x, res.x, curve->n, ndigits); -- 2.34.1