Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp86800rbb; Fri, 23 Feb 2024 12:42:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUo/2ycXQEtzPGqn2bnjBXDbQLwsB4u7DjpSx6hr7b7xuGBuCm5Hpd9kQ40HTF73yfx31Yyom9nF//luTucP8AuY403iTa+3To26ieFpg== X-Google-Smtp-Source: AGHT+IE48gGXmRdZvicMOp0ZoYMUqmPI17zVA6NXscz6hTIpgfbEjzPr6G2fgjB9qjRGb8Qji7Cc X-Received: by 2002:a05:620a:4015:b0:787:9044:c07d with SMTP id h21-20020a05620a401500b007879044c07dmr1533213qko.15.1708720959721; Fri, 23 Feb 2024 12:42:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708720959; cv=pass; d=google.com; s=arc-20160816; b=S1G+ha+6sVbhXOm4RmpC13wS5rgOgMaNTDpiIsksq/4zeBi+jx9yaqsBl1jU3Gk5IH Av1zZYYw4rjWh0+De7EtFhlcPlE33VdNGCwU5jTXle9dnM+OX7x9TPwcdOffWjMgHFRa IlRNkun67f28c1IGYFzKtVxSruxd2gSFHN2Cu+cAHnV4lqZr/mXa972KimhfHgsmVkFU DB6oagBoTgO95CAdEocQhgYSpzCIBS6D9eIQjorLF2V8eze/PeFJrc+Ccxm7Yfl2Ie6u 4zTRtSVZufPXBA5xSrcepQG24P9zw6HaIjBzBoP8HElt3enRUGJEJVJZZ/uWnmZWzk40 iiEQ== 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=G3IjMdpj4emUT3ZzC3klHJNBKOdCDwj0U+QnyvVlbSlcjeMqpuMnANOszEjCzuxxa6 2kCK4GXmDZQEwG0uDd7URvKiOJVL2sxIHyHDLHZew2RDkKsW0FkQC+T9sTb4lPcHQ+7i JwRPOT8yvqopoczXEJa9P5EapSMC9qSfHxHaInRt9yU6z5QfwvwnywxsBPzwrHB2ZNex jJ5xM3LBtr7P0td0W/gQ1oOf+tpmgS7A4nhxwyL7FtU2JlNq8YjFJaDktbRwoxbR8MU+ 2kfwmCJiZKkAAiziAtPv0rbLCFJDHm8mlYgegL1fSWJtoeZ+CHSSGq4Y54EMeyAoIPw4 y8Lw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lLeqXE5L; 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-79118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s15-20020a05622a018f00b0042e6a06d159si1243583qtw.715.2024.02.23.12.42.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 12:42:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79118-linux.lists.archive=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=lLeqXE5L; 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-79118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79118-linux.lists.archive=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 5C4FF1C22932 for ; Fri, 23 Feb 2024 20:42:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B20961493A6; Fri, 23 Feb 2024 20:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="lLeqXE5L" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 78F5114532B; Fri, 23 Feb 2024 20:42:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708720934; cv=none; b=ncG6jPopy7uXFrpof2RzImyv3//s4f80s+edJBF5gPxFX0C+dES6Nudo5U18P9SoSuiu4oaqO03fh93PyG6fFFAGdlxio4OTH3pIzfeU+++6HChDZQY5sAHQDPhJK0iSPKzTCc2yFk8ruvcVZEm/+hvUWQ3TY5p4r37AKXqBqZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708720934; c=relaxed/simple; bh=lUuzPnZtqYdFvF6hiy1auTq+Az0+wC1o9vh1IKFDu8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c/yhb/pyGhxaG0/JgkGjeGT++HJeG3zazdCXYu3P5OKzs96yvbC7I00TQa+vvihAmr3mBoXuo+YHulJyFD5kOtacy+SkfZ3B6PoKl/K5vTeV0uBtMci/IQqOpIi7oeh7zKheecTkdbM871h4I70pItFb6KPINY7Orb5Cy+VsDTk= 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=lLeqXE5L; arc=none smtp.client-ip=148.163.156.1 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 (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41NK27NB007232; Fri, 23 Feb 2024 20:42:08 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=lLeqXE5LWjbiqIMEkg1GZbBv2F+XCdoCDCCG18DBDIQU3JeFrGpwK4/BjsnZKmi9VAU0 RxcXAgvLCp8HPIHxFRpCeMEDm+yFZKvsTNctGmsovMOfqykww8tWsRWyjOSIojPvRCWO KaGIq0JK98/mclmbAolC1oth8SM7f31FUPjxlf8ma/3/ENccFhThM6REhOfYi5KQ5nRB ljLceqEy/rW3QNWGCJhh08P7ZEPMCBk0hjP3+3Wtd8YkxUNsOLTv+rk5DNI2iFN4/+Sf VkZ5uVl8HHtviuQcSh3VnUBmr7dpaKSROAeesMvu7Xybtsm2CJg2NGj8N8o6qu8UZFWv ww== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wf21t0uqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 20:42:07 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41NKTIKi003611; Fri, 23 Feb 2024 20:42:06 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wb74u8bc0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 20:42:06 +0000 Received: from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com [10.39.53.229]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41NKg4Jj6685332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Feb 2024 20:42:06 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CC5358059; Fri, 23 Feb 2024 20:42:04 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BC3F58061; Fri, 23 Feb 2024 20:42:03 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 23 Feb 2024 20:42:03 +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 v3 02/10] crypto: ecdsa - Adjust tests on length of key parameters Date: Fri, 23 Feb 2024 15:41:41 -0500 Message-ID: <20240223204149.4055630-3-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240223204149.4055630-1-stefanb@linux.ibm.com> References: <20240223204149.4055630-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 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vALespw88SB8BWtXSoUps--_cmqV19ZQ X-Proofpoint-ORIG-GUID: vALespw88SB8BWtXSoUps--_cmqV19ZQ 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-23_06,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402230152 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; -- 2.43.0