From patchwork Thu Feb 15 23:14:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 201818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp179183dyb; Thu, 15 Feb 2024 15:15:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUjIai7WZbYaYkGaz0bCQ1oEXlIzlfKmAA+weKlUbEQvczFF1j+3WdCp43GBypGx6wfQlw7Y/ztxzeSPwOOQ7Oo6j6yZQ== X-Google-Smtp-Source: AGHT+IF8s+b7IJbRfU9aNGoeRE7SKF9K/UJrpYYtORV91hWWIvzyjW1HH8rvbBfOl+B8TJGYSQ5q X-Received: by 2002:a05:620a:4611:b0:781:5e3a:a85f with SMTP id br17-20020a05620a461100b007815e3aa85fmr5217146qkb.17.1708038949187; Thu, 15 Feb 2024 15:15:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708038949; cv=pass; d=google.com; s=arc-20160816; b=qS30OLRc5ClY7ft5KRWL3NHKPVsUgjJbMLuuj6Be7XX++lMA7lwpEtSth8iAZBzgDq X5q8iWSZwdMlRcGI/9fVlIixpLJZ+uVQ1yHx8fAd6z7ZwfHR/LO3AX5rbWlc36MLDl6o Mk/29lgmPxg9IU6NXnc6HDn8zt48aEEz8XtN3tGqWCzWDefsiEOAG9fb2lyXiVZYTDTn EBD5/faN/uC+GYWj7m9Apfwelf6Lb3q6dwtq+XHIwJ+CHAvatTdv1H1vSo3hG0ZtrQjd AlKssHTQ0CWKVHpW2Tn29SPK3945eAHXGSnbdXEDL/gj0lpXgH25x8YSySUcNwvK88qC R2Kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UfCoxw1GwPsVnPVgicCJh55bEckUIM/iCOGiq6BVP00=; fh=nKmjVxPwCa773nyq5JxrCa37ZALdOpLJMBES7dZaGuw=; b=j8EzJPgKkJ5ykBxi+bYrvspj37HObvEjfTRwnt9ja/k7s2Lj1OjHdnjTU91d/P0uBF c6ZW/FXPuY+OjTQuDVtlP9ReJynqoAUMW6NWTghSxDPvLjgUNmew41AdTHkRSDS/rQ0A W61ThnURLAPipZJrP7i1DAOWs0hatLOac70DNh1YOSAFj9WcS/JwJedDUIGMtgcwQSWC AMBQVEuQ0DS1T6R8Axz6IsBbb4M0siOaw6bkIpNbvudL7rqYPyygeOZsc/H4F58rTBbG +kyFrPNEhyV+m97HRcwvaVVp+liah98bJQTyWEn/Cw1JufvLKT+h7jkUmF3/kpnPm9OK dsWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="FQmD/QGF"; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-67801-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67801-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z16-20020a05620a261000b007873b0181fdsi1813318qko.69.2024.02.15.15.15.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 15:15:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67801-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="FQmD/QGF"; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-67801-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67801-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8C5801C22B61 for ; Thu, 15 Feb 2024 23:15:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13B141468F2; Thu, 15 Feb 2024 23:14:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="FQmD/QGF" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 461F71419B5; Thu, 15 Feb 2024 23:14:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708038873; cv=none; b=hDK3ONLt0cS3VBXYL0/jkw2srIFDc3qJNpd0bmAn5Hbrv6OFdP0g7rtkhPVGTbG2rU5zzvOx0URbHUvUStFgppRe6fDDnTRDc26cflM8CeR5GGMMPVFiDNsUdQwqXZsrSFbvKGW0Re+pb3GA2Yz8gLjQmxZ1ZDYNFO01Ca55EsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708038873; c=relaxed/simple; bh=lUuzPnZtqYdFvF6hiy1auTq+Az0+wC1o9vh1IKFDu8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VGW+BYlyyhakrorXitK5HHqQqFGbRZRYqsCSVI56HR/Px8kButTFnZzJIFNn9CIPC/4oxINt+AIkgg4qQWXV+R3KJTfcbmfHKXFmizjk5JRhISajCEMy4lbvSFu5fHTfKSqCM2VoHzsQYzWaghB0YYI/4LLlNdH6ocrIUshszJ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=FQmD/QGF; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41FMQYo6030816; Thu, 15 Feb 2024 23:14:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=UfCoxw1GwPsVnPVgicCJh55bEckUIM/iCOGiq6BVP00=; b=FQmD/QGFsBdmIQGtulFC9X4pN4IqutKevyiC/RF1Y7wQho4LPU6TR8OGsAPMLb1AGSqd yYOiqy6WCrlLWzrgLl4TYNWlKVeAj5sWzzVf6pK5FBYtUWadUAEsiAhMgoHy9fj3vAs+ Qzym7XVmNV5EmtF7hXSxNfJ+M5f0gXNNBpaJpsNGEXfYW0JzGlC9kSmL9LYCNAIrPMn+ AEG8W7Vrte08VNe2XY7i640fLckREOOie+t0cgfUL3Qca6BkzabzV+jGqDhRDw9eMnLv Ts3HZP7oa+ZHXfOD+JVa3Hlv1HG+uvfmKl8sW8cVpKi7mNUT3bv5OFi3UjsaW9197Jd4 ag== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w9q8n7j36-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 23:14:25 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41FN7pxC016307; Thu, 15 Feb 2024 23:14:24 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6mymytet-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 23:14:24 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41FNEMdl6619688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Feb 2024 23:14:24 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F17F658050; Thu, 15 Feb 2024 23:14:21 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D56358056; Thu, 15 Feb 2024 23:14:21 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 15 Feb 2024 23:14:21 +0000 (GMT) From: Stefan Berger To: keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net Cc: linux-kernel@vger.kernel.org, saulo.alessandre@tse.jus.br, Stefan Berger Subject: [PATCH v2 02/14] crypto: ecdsa - Adjust tests on length of key parameters Date: Thu, 15 Feb 2024 18:14:01 -0500 Message-ID: <20240215231414.3857320-3-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240215231414.3857320-1-stefanb@linux.ibm.com> References: <20240215231414.3857320-1-stefanb@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3_KZMTl1k5YMPE4lG2TSjpxfLQoDrU_M X-Proofpoint-ORIG-GUID: 3_KZMTl1k5YMPE4lG2TSjpxfLQoDrU_M X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-15_22,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=999 impostorscore=0 adultscore=0 suspectscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402150181 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791008648974899360 X-GMAIL-MSGID: 1791008648974899360 In preparation for support of NIST P521, adjust the basic tests on the length of the provided key parameters to only ensure that the length of the x plus y coordinates parameter array is not an odd number and that each coordinate fits into an array of 'ndigits' digits. Mathematical tests on the key's parameters are then done in ecc_is_pubkey_valid_full rejecting invalid keys. The change is necessary since NIST P521 keys do not have keys with coordinates that each fully require 'full' digits (= u64), unlike NIST P192/256/384 that all require multiple 'full' digits. 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 ba8fb76fd165..64e1e69d53ba 100644 --- a/crypto/ecdsa.c +++ b/crypto/ecdsa.c @@ -230,7 +230,7 @@ static int ecdsa_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsig if (ret < 0) return ret; - if (keylen < 1 || (((keylen - 1) >> 1) % sizeof(u64)) != 0) + if (keylen < 1 || ((keylen - 1) & 1) != 0) return -EINVAL; /* we only accept uncompressed format indicated by '4' */ if (d[0] != 4) @@ -239,7 +239,7 @@ static int ecdsa_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsig keylen--; digitlen = keylen >> 1; - ndigits = digitlen / sizeof(u64); + ndigits = DIV_ROUND_UP(digitlen, sizeof(u64)); if (ndigits != ctx->curve->g.ndigits) return -EINVAL;