Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp77696lqc; Thu, 29 Feb 2024 10:45:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX6cthmjBR/+ZP2VRfRZ+wNrLLOBdTYJIjz/3/XSeMCDcznt0RUlwuPPk0RbxpmjSeFUo99TLKABH4Tu91iaRVOqykTTMo7o8W5xDXuEg== X-Google-Smtp-Source: AGHT+IFFLGklRVlRqZPj2u7CB/IT62I/zlGnNfFj50FcXyzWPOt14MXQOHY1Aa9dowX6HUJU8G64 X-Received: by 2002:a05:6402:26c5:b0:565:5de9:719b with SMTP id x5-20020a05640226c500b005655de9719bmr2590948edd.25.1709232352640; Thu, 29 Feb 2024 10:45:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709232352; cv=pass; d=google.com; s=arc-20160816; b=wqs0YI51sFHBjJjMEebtpqIPLfB/Wcl7NpD9X9Di5MI1ckHF//0ooBTJ6UkZIV3I3w AcZdJSAr0o3TOzBY/HJgSLI8RIP/tfjyuUYDioCHcJs+2CWFKhZKn3bNfoSIwjFnF8JX 59J8vc+XqlcBSLe9mGTfxrtdb2D2BaWNEbSJV1FPui4Dl60Vvr4lopR2tjKMlr+pgRcV 0UpgmHI3woACCsdv0dZBV5TPncVD6IA57i0QOyTPsJg5oro9e/D2Xyh8DmvEzINOhX0P 2UEbpnYSoTb7y399ndprjFUo5Erl1o5dkNOUjkG48K0QAx4QztjVeVPg94CwZ4t3+QCh /fEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=D9o3Kfl5WFxHfdGBbvRR+ALXYgzdRvMHt5vVY/Spbj4=; fh=oaC6g1rvngpUy3NBPUH3HwPaOzR9292cM7qLBeN9XRU=; b=eUnhOq5m8/YTLvAwfyBfxdCiW2jdCEltf8nZHtHbtztO2NCf0yy/UIgGq+BBNP5PFj XmtzgiwZPNc5MyLZIbRmiDmaaUyui+aWpa/M0yCulrhiLBBXcBsLt3JKbppqFi7Xdyj1 1arZS5KkfQQPXavrkdbtn9Fj/dvHhgNKuRByBziMLtl+Bi6PWSn++6uccorRa1KXvfes 3EAKEeak8Wm+0owoDbFfqd6z9SD+5IR7F9ZVLqnEuUrU5z0+cwpu1GGjv50a73F1ZKZS /xJdfpLSJlnKwHXIHhssThYj88NR+E622yAo6ASN4DOe2TMiTPHT39DBMKZfX9fOnnz0 awzg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=C2JZT0gS; 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-crypto+bounces-2403-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2403-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g8-20020a056402090800b005669c0be0a1si798205edz.163.2024.02.29.10.45.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 10:45:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2403-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=C2JZT0gS; 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-crypto+bounces-2403-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2403-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4DE241F24158 for ; Thu, 29 Feb 2024 18:45:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCA8A7D08C; Thu, 29 Feb 2024 18:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="C2JZT0gS" X-Original-To: linux-crypto@vger.kernel.org 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 A5C5C224D7; Thu, 29 Feb 2024 18:45:47 +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=1709232349; cv=none; b=WW1QWrxA/e5qEMe2mGhohVbvC5JQJ+iAbCMEbr1vl9kw9a6BaxMcnY1yKSk36QSgcRufYeMvl+Oxo6R/2kqvI6h0A+pZO5W6Pd8Gn2rx2xsiWBVmFAP9ZSapB1mPxPag6Eh4flvgZo1XBvzMG4AlknP+9JvPn960Wj0ED99sWA8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709232349; c=relaxed/simple; bh=srDQGGkHiAhws+fa4eSK+i2bnu9b0FjHTKnPBFQOPkw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=M46tn0lcFOzY2p1lsJaKWlbO5zfAuRUma9AnSl5CLr2Dat+TzNjVitdLAOJXAdYG1FvOPXInBOyadc/nUWMPXapkENsYC2ws0IhnhFCaa877yi890ugD7Lg4W8p8Mllwcc+EdSzFQX3mOKoEcM+ErX50PknSpxpynPGPPuWrNYA= 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=C2JZT0gS; 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 (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41TIVINc010426; Thu, 29 Feb 2024 18:45:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=D9o3Kfl5WFxHfdGBbvRR+ALXYgzdRvMHt5vVY/Spbj4=; b=C2JZT0gSbsio1mNQ1WEmGl4LT6yQrDsRofTmerA81PCKo/LEHPh4dwF35iVgVWFvoKMQ X+nhOiZ/h/5qdsytkA8BEkOF/v1AkehrwaDfo9+VCxlIzzmX9e+E+6VzJJEm64tfjUWO XnzGGMIgz4HMgTaJcSkhlC7hdyxwB6gg9E1McMGGsjI6oaD0oetvacOARJPDEo7w+t8R t29P5Ak2h4RQIkICI932Epm1/iK2HmyWJymLWJebmRMGrKSNqzwyIgb3Vv1XlIENDhRD lDVtSPU3RUeXbsgWK0Bi8E1KfkTVInHFJS9HezXAlVypNbqp50MGGHLtriISMSXCXNwN ZQ== 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 3wjxug926q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Feb 2024 18:45:41 +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 41THOwAv008178; Thu, 29 Feb 2024 18:45:40 GMT Received: from smtprelay05.dal12v.mail.ibm.com ([172.16.1.7]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3wfv9mqbpx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Feb 2024 18:45:40 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay05.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41TIjbkC39387560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Feb 2024 18:45:39 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2CF2258076; Thu, 29 Feb 2024 18:45:37 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E8CB58074; Thu, 29 Feb 2024 18:45:36 +0000 (GMT) Received: from [9.47.158.152] (unknown [9.47.158.152]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 29 Feb 2024 18:45:36 +0000 (GMT) Message-ID: Date: Thu, 29 Feb 2024 13:45:35 -0500 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 00/10] Add support for NIST P521 to ecdsa Content-Language: en-US To: Lukas Wunner Cc: keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net, linux-kernel@vger.kernel.org, saulo.alessandre@tse.jus.br References: <20240223204149.4055630-1-stefanb@linux.ibm.com> <20240229093419.GA32424@wunner.de> From: Stefan Berger In-Reply-To: <20240229093419.GA32424@wunner.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4VdUngd0qbAv4ZhZpXJPYWucAscKEPsh X-Proofpoint-ORIG-GUID: 4VdUngd0qbAv4ZhZpXJPYWucAscKEPsh 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-29_04,2024-02-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxscore=0 phishscore=0 spamscore=0 suspectscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402290144 On 2/29/24 04:34, Lukas Wunner wrote: > On Fri, Feb 23, 2024 at 03:41:39PM -0500, Stefan Berger wrote: >> This series adds support for the NIST P521 curve to the ecdsa module. >> >> An issue with the current code in ecdsa is that it assumes that input >> arrays providing key coordinates for example, are arrays of digits >> (a 'digit' is a 'u64'). This works well for all currently supported >> curves, such as NIST P192/256/384, but does not work for NIST P521 where >> coordinates are 8 digits + 2 bytes long. So some of the changes deal with >> converting byte arrays to digits and adjusting tests on input byte >> array lengths to tolerate arrays not providing multiples of 8 bytes. > > Don't you also need to amend software_key_query()? In the "issig" case, > it calculates len = crypto_sig_maxsize(sig), which is 72 bytes for P521, > then further below calculates "info->max_sig_size = 2 * (len + 3) + 2;" > > I believe the ASN.1 encoded integers are just 66 bytes instead of 72, > so info->max_sig_size is 6 bytes too large. Am I missing something? Right! Good catch. While the 'keyctl pkey_verify' interface was already working the space was too generous with 72 bytes. So I adjusted ecdsa_max_size now to base the size calculations on nbits rather than ndigits and we now get 66 bytes. For so-far supported curves the max_sig_size is: 2 bytes for sequence (0x30) + following length as single byte Each coordinate may have a 0 prepended to make a possibly negative number positive: => 2 + 2 * (2 + 1 + len) In case of NIST P521 the max signature length is calculated as follows: 3 bytes for sequence (0x30) + following length as 2 bytes The coordinates won't have a preprended 0 byte since only 1 bit is used in the highest bit, so only 2 bytes for => 3 + 2 * (2 + len) We would have to adjust the math there as well. The max. signature size for NIST P521 is 139 rather than 140 with the first formula. Stefan > > Thanks, > > Lukas