Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp291410lqb; Tue, 28 May 2024 16:09:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWksq+WD5kzLJxCnEF59Ki+MmQG7JEEVWLWCBCkt5yvutTlMCIiRqitIxSghgT6NY07tLkcpKDzjp9TIBkrEAJs3VZhK7Ub0ha0GZGzLQ== X-Google-Smtp-Source: AGHT+IHcjMiD/Ge4sPtJGqYAP0dj0NooGe9PeyHavK74gwX+INyfGGC+4ozcJjEqsR/PCP3BVVfq X-Received: by 2002:a17:906:c017:b0:a59:9b52:cfc5 with SMTP id a640c23a62f3a-a62649bd8f5mr867698966b.37.1716937798044; Tue, 28 May 2024 16:09:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716937798; cv=pass; d=google.com; s=arc-20160816; b=nDG5NOE978oexyi/tQFietVr4UId8giFx+DZM/rD3C7ponxavHZXbxBsmU5Z+iE8Pp +ca2Jgd8PO2NhfDT/9Za8o2nbFaJWe72HTqmEPRuYdtZh7ZLjnzJTi1dWGw8ber6ffng A11LRC52DEtbV8RsCoh97T2NmxR5AwJjdKhjGLYHgGF1TkJL8HCMYqU2iN5IhwtMQTda h3adG98qvKkym612JGYaGnDwx/TNi5AqQQE6F/apAh/Gg6625znwHRZS03E850nggboE BJ3EtSgktlPJM4/U47f2N8LWfC9Lf1mnq/OazMV5kN6gDPhXwKFMTuVWTG6rr5Ed7b3h g6VA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=WvNWSp6lx/IvEk6EHb9JEbX1F2HTWtBj47gyU+SCJ/o=; fh=legKMKRAS+KU1oH/lJ07R5kzwhb7Gr/5tO7xrXlyHPA=; b=wkoi1N1j81b6V3hGYwWzN+dFjDeT6jyjtWBScN5X66Hq0e5DIgKzb6p6AB3LAQpp6r dUSRODmt5TWw56wJVPX3+5U0Nke6VDwgiSkshG6osTwMIAlidPfDWrozEXpvG7bOyv/K W9GJ+LGECsFvBQ0+0xxUh5T06xYxmtAEuG0YqGaMWoBO9HDZk/JBxVJlK1rTZgLClpGx u5b2sAeNPQyTEZgHHnnF9O9MnPbhMtm82Uysn6Ekcc2r6gSTA/C1vxzs/3j5uqLrDrbT Re9wqX9dcjrjjr6tF3WuDTfKVgvvloy4VtnSNhoo3oEnmaXkJVUERTABqbstlPEj/Yw0 t5gQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kJY0Lznq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6419b8ab2esi21325666b.263.2024.05.28.16.09.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 16:09:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4483-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=@kernel.org header.s=k20201202 header.b=kJY0Lznq; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 C32951F22A86 for ; Tue, 28 May 2024 23:09:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AA2313E8B0; Tue, 28 May 2024 23:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kJY0Lznq" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1C03F17C6A; Tue, 28 May 2024 23:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716937792; cv=none; b=rcva1/GO/JZV2ey3cqEl0ea1EHS3whag0W98zW4LyiBo0hgEoaq+gjEgpNiol6TikefoHyBrO2H6qZK70IwsmGXeV/Y6f1uPAShJTy81chUix68qLsu6ChxzGZTEcpkTb65HNy3M75uOpZOyDlj9AMwnbC4QiNcmuYtmLbq1njU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716937792; c=relaxed/simple; bh=onyWA+d2BlSWT+ML9qSE85yyFiLFQ+oqmdDWiKsYT04=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=aDCMCnbfMemUrqCVYnc6wbb2ge53guWT7+XRdYxSbhiNY2hIsGRx02Uy55Nj+imB5x3PAenCY6g7tkJ7/ZJMStKFAFyTZZr/OQ8G7taI5icak63Kp2ZmHeg59ryS9bV626dARI6ytyKwdExis9bVuGCK7acM22Y7AhK30LJqy7o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kJY0Lznq; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4B77C3277B; Tue, 28 May 2024 23:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716937791; bh=onyWA+d2BlSWT+ML9qSE85yyFiLFQ+oqmdDWiKsYT04=; h=Date:To:Cc:Subject:From:References:In-Reply-To:From; b=kJY0LznqSZD8TdDuLyfHr40B7u5c/8/Gbldd3grLHo6tIDaj/svY5WYltsMtMYfWY l15pysUR0LlQi6+V7uCPLwM9m8GE6Y7skGcSo/Bm077AJ/OQxKWNeXK9poG0dmPCHu atubP0Ecm9kXzyZiTEk9ubRV10iYJcLdgxvUKZH0a54tq9gtEfnWJftDe55e1SK7Pw dwlXPnKBxzjFIb+Y/Bx3wjNgYiD0IxXawzwxT1Er8BkUxUcjC5nPrjEzWcgbe1NdM2 hx8dbysWf5mtn/WehHouBRe7Mjuc7QY6u31SOVPgAr5+EUBWuQ7gYjw0kEijPQ9EsL dbZZpqAAcfYbg== Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 29 May 2024 02:09:45 +0300 Message-Id: To: "Jarkko Sakkinen" , "Herbert Xu" Cc: , , , "James Prestwood" , "David Woodhouse" , "Eric Biggers" , "James Bottomley" , , "Stefan Berger" , "Lennart Poettering" , "David S. Miller" , "open list" , "David Howells" , "Peter Huewe" , "Jason Gunthorpe" , "James Bottomley" , "Ard Biesheuvel" , "Mario Limonciello" Subject: Re: [PATCH v7 5/5] keys: asymmetric: Add tpm2_key_ecdsa From: "Jarkko Sakkinen" X-Mailer: aerc 0.17.0 References: <20240528210823.28798-1-jarkko@kernel.org> <20240528210823.28798-6-jarkko@kernel.org> In-Reply-To: On Wed May 29, 2024 at 12:42 AM EEST, Jarkko Sakkinen wrote: > On Wed May 29, 2024 at 12:08 AM EEST, Jarkko Sakkinen wrote: > > + /* Encode the ASN.1 signature: */ > > +#define TPM2_KEY_ECDSA_SIG_SIZE (2 + 2 * (2 + SHA256_DIGEST_SIZE) + r= _0 + s_0) > > + pr_info("sig_size=3D%d\n", TPM2_KEY_ECDSA_SIG_SIZE); > > + ptr[0] =3D 0x30; /* SEQUENCE */ > > + ptr[1] =3D TPM2_KEY_ECDSA_SIG_SIZE - 2; > > +#define TPM2_KEY_ECDSA_SIG_R_TAG 2 > > +#define TPM2_KEY_ECDSA_SIG_R_SIZE 3 > > +#define TPM2_KEY_ECDSA_SIG_R_BODY 4 > > + ptr[TPM2_KEY_ECDSA_SIG_R_TAG] =3D 0x02; /* INTEGER */ > > + ptr[TPM2_KEY_ECDSA_SIG_R_SIZE] =3D SHA256_DIGEST_SIZE + r_0; > > + ptr[TPM2_KEY_ECDSA_SIG_R_BODY] =3D 0x00; /* maybe dummy write */ > > + memcpy(&ptr[TPM2_KEY_ECDSA_SIG_R_BODY + r_0], r, SHA256_DIGEST_SIZE); > > +#define TPM2_KEY_ECDSA_SIG_S_TAG (4 + r_0 + SHA256_DIGEST_SIZE) > > +#define TPM2_KEY_ECDSA_SIG_S_SIZE (5 + r_0 + SHA256_DIGEST_SIZE) > > +#define TPM2_KEY_ECDSA_SIG_S_BODY (6 + r_0 + SHA256_DIGEST_SIZE) > > + ptr[TPM2_KEY_ECDSA_SIG_S_TAG] =3D 0x02; /* INTEGER */ > > + ptr[TPM2_KEY_ECDSA_SIG_S_SIZE] =3D SHA256_DIGEST_SIZE + s_0; > > + ptr[TPM2_KEY_ECDSA_SIG_S_BODY] =3D 0x00; /* maybe dummy write */ > > + memcpy(&ptr[TPM2_KEY_ECDSA_SIG_S_BODY + s_0], s, SHA256_DIGEST_SIZE); > > + ret =3D TPM2_KEY_ECDSA_SIG_SIZE; > > Stefan, so this how I realized the signature encoding, thanks to > your earlier remarks [1]! I found out based on that a few glitches > and ended up with this better structured ECDSA signature encoder, > so thank you for doing that. 1. SHA384 would fit without any significant changes. 2. SHA512 will require a single additional byte, i.e. prefix byte 0x81 for the sequence (not for coeffients). 3. SM3 similarly is also trivial to add. Both will be also easy to add later on. I would not enlarge this patch set from what it is now. So I think this is pretty well along the lines of: https://datatracker.ietf.org/doc/draft-woodhouse-cert-best-practice/ BR, Jarkko