From nobody Tue Jul 28 16:14:03 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1548172000053682.1018328897796; Tue, 22 Jan 2019 07:46:40 -0800 (PST) Received: from [172.30.0.99] (mailu_mailman-core_1.mailu_default [172.30.0.99]) by coreboot.org (Postfix) with ESMTP id 304331120F80; Tue, 22 Jan 2019 15:46:37 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by coreboot.org (Postfix) with ESMTP id 9E0581120F73 for ; Tue, 22 Jan 2019 15:46:33 +0000 (UTC) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x0MFd8wZ113056 for ; Tue, 22 Jan 2019 10:46:32 -0500 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2q65ejt77v-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 22 Jan 2019 10:46:31 -0500 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 Jan 2019 15:46:30 -0000 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 22 Jan 2019 15:46:28 -0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0MFkRo125886754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 22 Jan 2019 15:46:27 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 64998112062; Tue, 22 Jan 2019 15:46:27 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 580D3112061; Tue, 22 Jan 2019 15:46:27 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 22 Jan 2019 15:46:27 +0000 (GMT) From: Stefan Berger To: seabios@seabios.org, kevin@koconnor.net Date: Tue, 22 Jan 2019 10:46:23 -0500 X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190122154624.2507756-1-stefanb@linux.ibm.com> References: <20190122154624.2507756-1-stefanb@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19012215-0068-0000-0000-00000386A16B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010456; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000275; SDB=6.01150191; UDB=6.00599379; IPR=6.00930523; MB=3.00025241; MTD=3.00000008; XFM=3.00000015; UTC=2019-01-22 15:46:29 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19012215-0069-0000-0000-00004739FA8B Message-Id: <20190122154624.2507756-2-stefanb@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-22_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901220122 Message-ID-Hash: ZB2E3QFPFEHEYUC7F3VMWJ4YYYRXUVXR X-Message-ID-Hash: ZB2E3QFPFEHEYUC7F3VMWJ4YYYRXUVXR X-MailFrom: stefanb@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Stefan Berger X-Mailman-Version: 3.2.0 Precedence: list Subject: [SeaBIOS] [PATCH 1/2] tcgbios: Use table to convert hash to buffer size List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: - Authentication-Results: coreboot.org Content-Type: text/plain; charset="utf-8" Use a table to convert the hash to the buffer size the hash needs. Signed-off-by: Stefan Berger --- src/tcgbios.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/tcgbios.c b/src/tcgbios.c index 24846d3..0eabc60 100644 --- a/src/tcgbios.c +++ b/src/tcgbios.c @@ -161,23 +161,38 @@ struct tpm_log_entry { + SHA512_BUFSIZE + SM3_256_BUFSIZE]; } PACKED; =20 +static const struct hash_parameters { + u16 hashalg; + u8 hash_buffersize; +} hash_parameters[] =3D { + { + .hashalg =3D TPM2_ALG_SHA1, + .hash_buffersize =3D SHA1_BUFSIZE, + }, { + .hashalg =3D TPM2_ALG_SHA256, + .hash_buffersize =3D SHA256_BUFSIZE, + }, { + .hashalg =3D TPM2_ALG_SHA384, + .hash_buffersize =3D SHA384_BUFSIZE, + }, { + .hashalg =3D TPM2_ALG_SHA512, + .hash_buffersize =3D SHA512_BUFSIZE, + }, { + .hashalg =3D TPM2_ALG_SM3_256, + .hash_buffersize =3D SM3_256_BUFSIZE, + } +}; + static int tpm20_get_hash_buffersize(u16 hashAlg) { - switch (hashAlg) { - case TPM2_ALG_SHA1: - return SHA1_BUFSIZE; - case TPM2_ALG_SHA256: - return SHA256_BUFSIZE; - case TPM2_ALG_SHA384: - return SHA384_BUFSIZE; - case TPM2_ALG_SHA512: - return SHA512_BUFSIZE; - case TPM2_ALG_SM3_256: - return SM3_256_BUFSIZE; - default: - return -1; + unsigned i; + + for (i =3D 0; i < ARRAY_SIZE(hash_parameters); i++) { + if (hash_parameters[i].hashalg =3D=3D hashAlg) + return hash_parameters[i].hash_buffersize; } + return -1; } =20 // Add an entry at the start of the log describing digest formats --=20 2.17.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org