Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp948614lqb; Wed, 29 May 2024 16:08:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVaA6bst3L4VZ7eGNnvYLOfSNeyQGsorqqc05bVubv02I1RgBnGfFuOHtEMpQDtwTOrxRwgedAEbK/V/5xmEDmLjAFPo+2KEZbJdGszUw== X-Google-Smtp-Source: AGHT+IF2I80Gf8X7+rbfNzRni/Zm/zDCDmu+LxbNF+JkNVxzNWaBZfR5H2FhEnc+U0TuB9/FHD/3 X-Received: by 2002:a05:6a21:338e:b0:1af:cbe1:8a50 with SMTP id adf61e73a8af0-1b264520f57mr532184637.10.1717024135190; Wed, 29 May 2024 16:08:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717024135; cv=pass; d=google.com; s=arc-20160816; b=xRsU7fh3l+QYqfIRZO29lI0kzWZ7njMtZ65g0/xy93j6M6m8hStpGLZapAH+o8CUQ8 fUlI5UORXkXcjo40VQNvLy2mZ0SCOL8cI/ehoN39LrUBTfI/c6l+0BFv/HdT7hZgWKIB xc7JrF5l9O7dY0OYmTNrHJOZWo8AD+zEd0PkTcmL33OhDRdTIjsj7VA1xikhQ5WDil0v IPlnn36utBBcL5XjHN5ICk1qUoiUnjKMqLVvehsOTEWJ3A7NhvGWfFn5ERW6REMjWQBz ms7c5x79OMOFnjLQft03zbivfTezNoKzKydY4PstC7++6RGdw3BH3ps1yQs3PKm2+vzF Pv6g== 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=tfpTIOiHxnILFvod7wxA6yfuRrE3T97/xxPgvdUVf78=; fh=qWaHGaLnoZMbZLsxbD3hLSG+MPwUg0lga6uvbq6TyXU=; b=vE9EpkDTxdrS+22GJq/6p5xFT3q8sd45S65ywlGASE98dzHrWtwWgbsF7lFbrtgcE2 BGr3uAOlUPdXjTjDb08IBx6O0BK9cmk04MDK7GYnO+QnsnRg+Z45iWXnzIwYIzena3qK K+6nWX0gaMnERyuQlOwLmdH53NeCTW+2giNc/fWSFncQHLqzPCIyqlyN/5vnlHmzwhxl oum0zYknUieEuBmnSRMTAEG//NxKvEb8q9ihM/h6pLJHEOMWv991c7NN10xmWHtDjnag +afMyuddKJYbuYOEBqzRi6FogqmmyV21pzUdcKBvYM2jFIiJvKidj+ZPLIxO5GFooRjt oiUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Fzoj78OU; 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-4511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4511-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822ae56c27si10920101a12.804.2024.05.29.16.08.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 16:08:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Fzoj78OU; 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-4511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4511-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8C899284956 for ; Wed, 29 May 2024 23:08:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8E0B1CB33B; Wed, 29 May 2024 23:08:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Fzoj78OU" 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 2D575178360; Wed, 29 May 2024 23:08:43 +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=1717024126; cv=none; b=LV2oaLcPqm9P24U05seULfO/RDqDtytkQuKh/N3Awy1xCn4yGXmTljrBIJ2gAYVOKAiSHDzyWMrFI/xEjz8PSql200YgLLOPnOhCB/v3kIJR8KnvB7u6uxoz+xQtMoxttC9cljhgTiI21SC0mHuz8RV4OKaogwnFKgQgOItGZ9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717024126; c=relaxed/simple; bh=9hflfRrZb424cwnqf/iro650WO5bVJxeXnW7wHQXjYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eRw24G+2L7h50SvdpQ7sgBBcy6hB2+5elufI3zDdzhUVazTj0p7GBI3/5oEW4l9SdkSfj7mHlssqo1A5zYaLRPyeGn0dnmnwA12JVjanfZULTgr5/I2Qg6WguhDqAIaibUc8VXdJKY5wcp6h0JJAdWYyzVRAZ3XRYZarngtg2Kw= 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=Fzoj78OU; 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 (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44TMbxPF022947; Wed, 29 May 2024 23:08:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc : content-transfer-encoding : date : from : in-reply-to : message-id : mime-version : references : subject : to; s=pp1; bh=tfpTIOiHxnILFvod7wxA6yfuRrE3T97/xxPgvdUVf78=; b=Fzoj78OUKHHCFEyeln+BzC2zzqAYVAOVwnm136g+5Ly3IyNAckUI+nnfyPf/Yw9wpFAJ +bHjqitYE+0VRSwuv4ZtCU3uf7bsH7AaFuiImb59763z9liNDzwqRa+BBy9YCR+lK5Jj trfv2g2h9o/3Idtru+Ba0Y+LPaS+rlwj1IrnIUrnZrDNFOuFjJKxBrjic07T+OQ3fAtV xTlNah3DMv4kVPpJov3EzGTUplCeb6cV7tN07IZczro5QiNr5ZlKdwbwT/e5ecu1jTqu LQIlOA5gZF19pQG9aD6tOIjlvqkXoCNilyEJ4+ZSq/zbiMG9Ju74IaRx67LS0Biic7bZ 1g== 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 3yedakg1pd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 May 2024 23:08:37 +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 44TLiGx8026662; Wed, 29 May 2024 23:08:36 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ydpd2pkn0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 29 May 2024 23:08:36 +0000 Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44TN8XVF18481820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 29 May 2024 23:08:35 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 95E3958056; Wed, 29 May 2024 23:08:33 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D951D58054; Wed, 29 May 2024 23:08:32 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 29 May 2024 23:08:32 +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, lukas@wunner.de, jarkko@kernel.org, Stefan Berger Subject: [PATCH 2/2] crypto: ecdsa - Use ecc_digits_from_bytes to convert signature Date: Wed, 29 May 2024 19:08:27 -0400 Message-ID: <20240529230827.379111-3-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529230827.379111-1-stefanb@linux.ibm.com> References: <20240529230827.379111-1-stefanb@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: z0xQju7NkbK5RIUZcofU-LpnTH1PkTj3 X-Proofpoint-GUID: z0xQju7NkbK5RIUZcofU-LpnTH1PkTj3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-29_16,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 bulkscore=0 mlxlogscore=999 impostorscore=0 spamscore=0 mlxscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405290166 Since ecc_digits_from_bytes will provide zeros when an insufficient number of bytes are passed in the input byte array, use it to convert the r and s components of the signature to digits directly from the input byte array. This avoids going through an intermediate byte array that has the first few bytes filled with zeros. Signed-off-by: Stefan Berger --- crypto/ecdsa.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c index fa029f36110b..941cdc2b889b 100644 --- a/crypto/ecdsa.c +++ b/crypto/ecdsa.c @@ -38,7 +38,6 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag, size_t bufsize = ndigits * sizeof(u64); ssize_t diff = vlen - bufsize; const char *d = value; - u8 rs[ECC_MAX_BYTES]; if (!value || !vlen) return -EINVAL; @@ -46,7 +45,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag, /* diff = 0: 'value' has exacly the right size * diff > 0: 'value' has too many bytes; one leading zero is allowed that * makes the value a positive integer; error on more - * diff < 0: 'value' is missing leading zeros, which we add + * diff < 0: 'value' is missing leading zeros */ if (diff > 0) { /* skip over leading zeros that make 'value' a positive int */ @@ -61,14 +60,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag, if (-diff >= bufsize) return -EINVAL; - if (diff) { - /* leading zeros not given in 'value' */ - memset(rs, 0, -diff); - } - - memcpy(&rs[-diff], d, vlen); - - ecc_swap_digits((u64 *)rs, dest, ndigits); + ecc_digits_from_bytes(d, vlen, dest, ndigits); return 0; } -- 2.43.0