From nobody Wed Jan 15 16:07:24 2025 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 1548875185996255.00504989562444; Wed, 30 Jan 2019 11:06:25 -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 42BF71120EDA; Wed, 30 Jan 2019 19:06:22 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by coreboot.org (Postfix) with ESMTP id EF7A71120ECD for ; Wed, 30 Jan 2019 19:06:18 +0000 (UTC) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x0UJ108u013663 for ; Wed, 30 Jan 2019 14:06:17 -0500 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0b-001b2d01.pphosted.com with ESMTP id 2qbfm4pqg3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 30 Jan 2019 14:06:17 -0500 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 30 Jan 2019 19:06:16 -0000 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 30 Jan 2019 19:06:15 -0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0UJ6EiL17367120 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 30 Jan 2019 19:06:14 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 34612AC062; Wed, 30 Jan 2019 19:06:14 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 31997AC059; Wed, 30 Jan 2019 19:06:14 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 30 Jan 2019 19:06:14 +0000 (GMT) From: Stefan Berger To: seabios@seabios.org, kevin@koconnor.net Date: Wed, 30 Jan 2019 14:06:06 -0500 X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190130190607.3360267-1-stefanb@linux.ibm.com> References: <20190130190607.3360267-1-stefanb@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19013019-0060-0000-0000-000003031213 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010505; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000277; SDB=6.01154040; UDB=6.00601715; IPR=6.00934417; MB=3.00025357; MTD=3.00000008; XFM=3.00000015; UTC=2019-01-30 19:06:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19013019-0061-0000-0000-0000481E26B1 Message-Id: <20190130190607.3360267-2-stefanb@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-30_14:,, 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=1015 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-1901300143 Message-ID-Hash: EPLYIVXIGJCQ7E5PJ2W4OOU6TZTW67NK X-Message-ID-Hash: EPLYIVXIGJCQ7E5PJ2W4OOU6TZTW67NK 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 v3 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 it 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