From patchwork Fri Jul 9 15:38:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1503244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ZetZbJTm; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLy543jzyz9sRN for ; Sat, 10 Jul 2021 01:39:20 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GLy536849z307g for ; Sat, 10 Jul 2021 01:39:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ZetZbJTm; dkim-atps=neutral X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ZetZbJTm; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GLy4y3C1Xz2yft for ; Sat, 10 Jul 2021 01:39:13 +1000 (AEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 169FYCFn063636; Fri, 9 Jul 2021 11:39:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=XUBLkGPAERVi4txPDZkxlOyjtfyGTZeX3jlC+i7iEFU=; b=ZetZbJTmAPOINmIDve1Mahx/gzkd4exUcHO33as/qgYRKaIbbKYJcM+NsUOqbSn73zHs itl0wmrJca4BJk0zgRODx9wysvy0EMbID1BO5IureTCiEGamF31Y7l0AA+fOPQDLZKwG v65lv/x86CUgiFZ6zq6gqbSDEfmNixJUJ1WV6Lo+40HWoNWJqnbsizAp8j2qWY9uV9c+ yoEqyqmGwNGvvMG1dAsgiNm3/F9loTkbFW8BWE6fYxoCJxzZI3VTnnTk6w4JDl5NGO9U N+G0DJXZkLLEjgaakFKsxLWWCUoLJAw/6+TYZhpiEkysbeg0ienpP90ddKI9tMZHA1HM Ow== Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0b-001b2d01.pphosted.com with ESMTP id 39pmd4r4fm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 11:39:11 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 169FRB2J014543; Fri, 9 Jul 2021 15:39:10 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma05wdc.us.ibm.com with ESMTP id 39jfhe3u6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 15:39:10 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 169Fd9pW24642046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 15:39:09 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 14A7778066; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CF0BB78069; Fri, 9 Jul 2021 15:39:08 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.152]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 15:39:08 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org Date: Fri, 9 Jul 2021 11:38:59 -0400 Message-Id: <20210709153903.691945-2-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> References: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vd1PgLpl6GgrYEtuviKavX7_YScdU3Yx X-Proofpoint-ORIG-GUID: vd1PgLpl6GgrYEtuviKavX7_YScdU3Yx X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_09:2021-07-09, 2021-07-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 spamscore=0 priorityscore=1501 bulkscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090078 Subject: [SLOF] [PATCH v4 1/5] tcgbios: Change format of S_CRTM_VERSION string to ucs-2 X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Stefan Berger Change the format of the S_CRTM_VERSION string to ucs-2 since this is what seems to be commonly used by other firmwares following insight from a TCG work group member. Signed-off-by: Alexey Kardashevskiy Tested-by: Stefan Berger Signed-off-by: Stefan Berger --- Makefile.gen | 2 +- lib/libtpm/Makefile | 1 + lib/libtpm/tcgbios.c | 23 ++++++++++++----------- make.rules | 3 ++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Makefile.gen b/Makefile.gen index f18c57a..6f78829 100644 --- a/Makefile.gen +++ b/Makefile.gen @@ -164,7 +164,7 @@ distclean_gen: clean_top common-libs: @echo " ====== Building common libraries ======" - $(MAKE) -C $(LIBCMNDIR) $(COMMON_LIBS) + $(MAKE) -C $(LIBCMNDIR) $(COMMON_LIBS) RELEASE=-DRELEASE=\"\\\"$(RELEASE)\\\"\" board-libs: $(MAKE) -C lib $(MAKEARG) diff --git a/lib/libtpm/Makefile b/lib/libtpm/Makefile index 9d32dfc..895dbfd 100644 --- a/lib/libtpm/Makefile +++ b/lib/libtpm/Makefile @@ -15,6 +15,7 @@ TOPCMNDIR ?= ../.. CPPFLAGS = -I../libc/include $(CPUARCHDEF) -I$(INCLBRDDIR) \ -I$(INCLCMNDIR) -I$(INCLCMNDIR)/$(CPUARCH) -I$(SLOFCMNDIR) CPPFLAGS += -I../libhvcall +CPPFLAGS += $(RELEASE) LDFLAGS = -nostdlib diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index dcf0cc6..24ac83c 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -1108,24 +1108,25 @@ uint32_t tpm_measure_gpt(void) uint32_t tpm_measure_scrtm(void) { - uint32_t rc; - char *version_start = strstr((char *)&print_version, "FW Version"); - char *version_end; - uint32_t version_length; + uint32_t rc, i; char *slof_text_start = (char *)&_slof_text; uint32_t slof_text_length = (long)&_slof_text_end - (long)&_slof_text; const char *scrtm = "S-CRTM Contents"; - - version_end = strchr(version_start, '\r'); - version_length = version_end - version_start; +#define _TT(a, x) a##x +#define _T(a, x) _TT(a, x) + unsigned short ucs2_version[] = _T(L, RELEASE); dprintf("Measure S-CRTM Version: addr = %p, length = %d\n", - version_start, version_length); + ucs2_version, ucs2_length); + + for (i = 0; i < ARRAY_SIZE(ucs2_version); ++i) + ucs2_version[i] = cpu_to_le16(ucs2_version[i]); rc = tpm_add_measurement_to_log(0, EV_S_CRTM_VERSION, - version_start, version_length, - (uint8_t *)version_start, - version_length); + (char *)ucs2_version, + sizeof(ucs2_version), + (uint8_t *)ucs2_version, + sizeof(ucs2_version)); if (rc) return rc; diff --git a/make.rules b/make.rules index 885eea3..d37c365 100644 --- a/make.rules +++ b/make.rules @@ -79,6 +79,7 @@ CPP ?= $(CROSS)cpp WARNFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -Wformat-security -Wextra -Wno-unused-parameter CFLAGS ?= -g -O2 -fno-builtin -ffreestanding -nostdinc -msoft-float \ -fno-strict-aliasing -mno-altivec -mabi=no-altivec \ - -fno-stack-protector -fno-asynchronous-unwind-tables $(WARNFLAGS) + -fno-stack-protector -fno-asynchronous-unwind-tables $(WARNFLAGS) \ + -fshort-wchar export CC AS LD CLEAN OBJCOPY OBJDUMP STRIP AR RANLIB CFLAGS From patchwork Fri Jul 9 15:39:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1503248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Dl+D7cEP; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLy586PCMz9sWX for ; Sat, 10 Jul 2021 01:39:24 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GLy585Kypz30D7 for ; Sat, 10 Jul 2021 01:39:24 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Dl+D7cEP; dkim-atps=neutral X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Dl+D7cEP; dkim-atps=neutral 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 lists.ozlabs.org (Postfix) with ESMTPS id 4GLy520p2Bz2yyb for ; Sat, 10 Jul 2021 01:39:17 +1000 (AEST) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 169FWtQY181752; Fri, 9 Jul 2021 11:39:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=js65e+GEsgN7ZOxck6LHE5YA/LpyDrdFPBocOR8mFac=; b=Dl+D7cEPzgWXMah1Q3OheOtoNsAoRHYlZYt4+MnssT7T7BPMAn6E4QakRSIdzEDnnEEw VNmwOxzTL3f2U3IODGF8CQPIWzKiw9E6I7SB1jmw4cJJgTpQbKYpJ19kYojZOj3i2ZUl WHINkrXUh2twRimc4UaKqlKr+Zx9pU1yGkaNntZlvpyks615DWFQnFY71ZkmrryJKqBy qcYIWhMRP2iS4dhIHSrBnMC6PtBchRcHLOov831r5xDQ6YaXm60Fo4kasFhsfztqBp0w 0L6wnc3cVU4EO1a36Qc5LTV5PSzYrt8cZ42Z130k7WwiR+YZpkpyoc8xWxp34oUq9sEs QQ== Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 39phqkw1jy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 11:39:12 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 169FRmTh007007; Fri, 9 Jul 2021 15:39:11 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma03wdc.us.ibm.com with ESMTP id 39jfhe3ry3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 15:39:10 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 169Fd9vx38207778 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 15:39:09 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BDDE7805E; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 390497805C; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.152]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org Date: Fri, 9 Jul 2021 11:39:00 -0400 Message-Id: <20210709153903.691945-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> References: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: rqQkC8t8ALvjvn-IxqXOb87aZoyrnBVF X-Proofpoint-GUID: rqQkC8t8ALvjvn-IxqXOb87aZoyrnBVF X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_09:2021-07-09, 2021-07-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090078 Subject: [SLOF] [PATCH v4 2/5] tcgbios: Use assembly for 32 bit rotr in sha256 X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Stefan Berger Use assembly for the 32 bit rotr in the sha256 implementation similar to the assembly used in the sha1 and sha512 implementations. Signed-off-by: Stefan Berger --- lib/libtpm/sha256.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/libtpm/sha256.c b/lib/libtpm/sha256.c index c6b8767..1a0aa9a 100644 --- a/lib/libtpm/sha256.c +++ b/lib/libtpm/sha256.c @@ -22,10 +22,16 @@ typedef struct _sha256_ctx { uint32_t h[8]; } sha256_ctx; -static inline uint32_t rotr(uint32_t x, uint8_t n) -{ - return (x >> n) | (x << (32 - n)); -} +#define rotr(VAL, N) \ +({ \ + uint32_t res; \ + __asm__ ( \ + "rotrwi %0, %1, %2\n\t" \ + : "=r" (res) \ + : "r" (VAL), "i" (N) \ + ); \ + res; \ +}) static inline uint32_t Ch(uint32_t x, uint32_t y, uint32_t z) { From patchwork Fri Jul 9 15:39:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1503246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=pGGBM9QK; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLy56513kz9sWd for ; Sat, 10 Jul 2021 01:39:22 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GLy56244hz3bXy for ; Sat, 10 Jul 2021 01:39:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=pGGBM9QK; dkim-atps=neutral X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=pGGBM9QK; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GLy4y4V8Wz2yyb for ; Sat, 10 Jul 2021 01:39:13 +1000 (AEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 169FYC64063666; Fri, 9 Jul 2021 11:39:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=i8mfm3S0zzs2Kh0Sdrq16baEJzf66/THA7Ps6tGzwlc=; b=pGGBM9QKACn9A+eg1nm5Rkbrii2KnkgsGt6AH8v5F+uBBy20sPvqkDu5rqi609xDDYEn fHAo6IYvIDbrk3VxM+vlxYDsnjcL9igWt1LVZaY7M1TCi9/clsWzjY1Awm5+u9qgJtv+ QAXS/cnU5y2v2YfwMd/NXyWISnF06hn98dAwv3ypOykrP0TyhNOgph6SBx6Zw5wEn+Dw ltZm0nVqIi9kjdVCP/j+N/j0HFxzd92f/WxbrO82adNVjKXCeedVAZcB+YdRSY6N2SBz FSUsA86hVoq3DTY4+3eviCi+TUl4dG+G1wW4R2zDGOecmysWM6RRSI9VdAWtmJd/jsU9 lw== Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 39pmd4r4fw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 11:39:11 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 169FRFCR009064; Fri, 9 Jul 2021 15:39:11 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01wdc.us.ibm.com with ESMTP id 39jfhdkvep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 15:39:11 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 169Fd9WX38207784 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 15:39:10 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5EE978060; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C88C7805C; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.152]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org Date: Fri, 9 Jul 2021 11:39:01 -0400 Message-Id: <20210709153903.691945-4-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> References: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: rb8UsWCCKLBFwxsAj5Vu0OZL-_T03Dma X-Proofpoint-ORIG-GUID: rb8UsWCCKLBFwxsAj5Vu0OZL-_T03Dma X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_09:2021-07-09, 2021-07-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 spamscore=0 priorityscore=1501 bulkscore=0 adultscore=0 suspectscore=0 mlxlogscore=947 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090078 Subject: [SLOF] [PATCH v4 3/5] tcgbios: Use The proper sha function for each PCR bank X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Stefan Berger Instead of just using sha256 for all PCR banks (and truncating the value or zero-padding it) use the proper hash function for each one of the banks. For unimplemented hashes, fill the buffer with 0xff. Signed-off-by: Stefan Berger --- lib/libtpm/tcgbios.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index 24ac83c..e43745e 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -127,28 +127,32 @@ static const struct hash_parameters { uint8_t hashalg_flag; uint8_t hash_buffersize; const char *name; + void (*hashfunc)(const uint8_t *data, uint32_t length, uint8_t *hash); } hash_parameters[] = { { .hashalg = TPM2_ALG_SHA1, .hashalg_flag = TPM2_ALG_SHA1_FLAG, .hash_buffersize = SHA1_BUFSIZE, .name = "SHA1", + .hashfunc = sha1, }, { .hashalg = TPM2_ALG_SHA256, .hashalg_flag = TPM2_ALG_SHA256_FLAG, .hash_buffersize = SHA256_BUFSIZE, .name = "SHA256", + .hashfunc = sha256, }, { .hashalg = TPM2_ALG_SHA384, .hashalg_flag = TPM2_ALG_SHA384_FLAG, .hash_buffersize = SHA384_BUFSIZE, .name = "SHA384", - + .hashfunc = sha384, }, { .hashalg = TPM2_ALG_SHA512, .hashalg_flag = TPM2_ALG_SHA512_FLAG, .hash_buffersize = SHA512_BUFSIZE, .name = "SHA512", + .hashfunc = sha512, }, { .hashalg = TPM2_ALG_SM3_256, .hashalg_flag = TPM2_ALG_SM3_256_FLAG, @@ -233,6 +237,25 @@ static const char * tpm20_hashalg_flag_to_name(uint8_t hashalg_flag) return NULL; } +static void tpm2_hash_data(uint16_t hashAlg, + const uint8_t *data, uint32_t data_len, + uint8_t *hash) +{ + unsigned i; + + for (i = 0; i < ARRAY_SIZE(hash_parameters); i++) { + if (hash_parameters[i].hashalg == hashAlg) { + if (hash_parameters[i].hashfunc) { + hash_parameters[i].hashfunc(data, data_len, + hash); + } else { + memset(hash, 0xff, + hash_parameters[i].hash_buffersize); + } + } + } +} + /* * Build the TPM2 TPML_DIGEST_VALUES data structure from the given hash. * Follow the PCR bank configuration of the TPM and write the same hash @@ -242,13 +265,15 @@ static const char * tpm20_hashalg_flag_to_name(uint8_t hashalg_flag) * hash when writing it in the area of the sha1 hash. * * le: the log entry to build the digest in - * sha1: the sha1 hash value to use + * hashdata: the data to hash + * hashdata_len: the length of the hashdata * bigEndian: whether to build in big endian format for the TPM or log * little endian for the log (TPM 2.0) * * Returns the digest size; -1 on fatal error */ -static int tpm20_build_digest(struct tpm_log_entry *le, const uint8_t *sha256, +static int tpm20_build_digest(struct tpm_log_entry *le, + const uint8_t *hashdata, uint32_t hashdata_len, bool bigEndian) { struct tpms_pcr_selection *sel; @@ -297,9 +322,8 @@ static int tpm20_build_digest(struct tpm_log_entry *le, const uint8_t *sha256, else v->hashAlg = cpu_to_le16(be16_to_cpu(sel->hashAlg)); - memset(v->hash, 0, hsize); - memcpy(v->hash, sha256, - hsize < SHA256_BUFSIZE ? hsize : SHA256_BUFSIZE); + tpm2_hash_data(be16_to_cpu(sel->hashAlg), hashdata, hashdata_len, + v->hash); dest += sizeof(*v) + hsize; sel = nsel; @@ -865,7 +889,6 @@ static uint32_t tpm_add_measurement_to_log(uint32_t pcrindex, const uint8_t *hashdata, uint32_t hashdatalen) { - uint8_t hash[SHA256_BUFSIZE]; struct tpm_log_entry le = { .hdr.pcrindex = cpu_to_log32(pcrindex), .hdr.eventtype = cpu_to_log32(eventtype), @@ -873,8 +896,7 @@ static uint32_t tpm_add_measurement_to_log(uint32_t pcrindex, int digest_len; int ret; - sha256(hashdata, hashdatalen, hash); - digest_len = tpm20_build_digest(&le, hash, true); + digest_len = tpm20_build_digest(&le, hashdata, hashdatalen, true); if (digest_len < 0) return TCGBIOS_GENERAL_ERROR; ret = tpm20_extend(&le, digest_len); @@ -882,7 +904,7 @@ static uint32_t tpm_add_measurement_to_log(uint32_t pcrindex, tpm_set_failure(); return TCGBIOS_COMMAND_ERROR; } - tpm20_build_digest(&le, hash, false); + tpm20_build_digest(&le, hashdata, hashdatalen, false); return tpm_log_event_long(&le.hdr, digest_len, info, infolen); } From patchwork Fri Jul 9 15:39:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1503247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Wti5Qm7v; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLy574l22z9sWX for ; Sat, 10 Jul 2021 01:39:23 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GLy573gzrz30B2 for ; Sat, 10 Jul 2021 01:39:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Wti5Qm7v; dkim-atps=neutral X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Wti5Qm7v; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GLy4z4yvCz2yyb for ; Sat, 10 Jul 2021 01:39:15 +1000 (AEST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 169FXACF075697; Fri, 9 Jul 2021 11:39:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=dteMknbQ8+E1iOuVZKLdbVn6aTRtTX4j2sV5FNFGr2Q=; b=Wti5Qm7vbCp4RgRFQv+rkQuCLA5G+fiXjkz1yA5f1SH6YN/3x5e15m6pDzqQXdTCtQpQ fVtZyjqnYM/ciJZvyAXk7U0L57dWXwFqCjOghOtRyi8jErfFrQFyszFmvqZAdtl/tJyd t3zQjda8IcN+dW9yNRITcj75GlVVff5JussfC9oB4jdc5WCElQ8M/oqUvNoHKL1z2YEu q5epNnjVRTTsksIW1J4jN+xVbjiYmn4gMQuG0qyPuGbcb7aR436NEQ+/bdi9kkcbYcbF KB5ECVYWmwuvXoy7EPXQ3JJ21ZfT8SOjE8AXpNVpyzufALQo5Mhve3BB7HPuPQkUGRum cw== Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 39p1ycq3dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 11:39:12 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 169FSAXV000583; Fri, 9 Jul 2021 15:39:12 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma04dal.us.ibm.com with ESMTP id 39jfhfhn5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 15:39:12 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 169FdAUM41681394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 15:39:10 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C96978070; Fri, 9 Jul 2021 15:39:10 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 02D237805E; Fri, 9 Jul 2021 15:39:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.152]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 15:39:09 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org Date: Fri, 9 Jul 2021 11:39:02 -0400 Message-Id: <20210709153903.691945-5-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> References: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: nyJGfD9gBSsasPJ_jFL6HXdtytNNhlgM X-Proofpoint-ORIG-GUID: nyJGfD9gBSsasPJ_jFL6HXdtytNNhlgM X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_09:2021-07-09, 2021-07-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 malwarescore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090078 Subject: [SLOF] [PATCH v4 4/5] tcgbios: Add test cases and test script to run them X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Stefan Berger Add test cases for sha1, sha256, sha384, and sha512 and a test script to run the test cases. The tests are passing on little and big endian machines (Fedora 28). Signed-off-by: Stefan Berger --- lib/libtpm/sha.c | 27 ++++++++++++++++++++ lib/libtpm/sha256.c | 26 +++++++++++++++++++ lib/libtpm/sha512.c | 36 ++++++++++++++++++++++++++ lib/libtpm/sha_test.h | 59 +++++++++++++++++++++++++++++++++++++++++++ lib/libtpm/test.sh | 31 +++++++++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 lib/libtpm/sha_test.h create mode 100755 lib/libtpm/test.sh diff --git a/lib/libtpm/sha.c b/lib/libtpm/sha.c index 43de658..902a4ba 100644 --- a/lib/libtpm/sha.c +++ b/lib/libtpm/sha.c @@ -203,3 +203,30 @@ void sha1(const uint8_t *data, uint32_t length, uint8_t *hash) sha1_do(&ctx, data, length); memcpy(hash, &ctx.h[0], 20); } + +#ifdef MAIN + +#include "sha_test.h" + +int main(void) +{ + TESTVECTORS(data); + uint8_t hash[20]; + char input[64]; + int err = 0; + size_t i; + + for (i = 0; i < ARRAY_SIZE(data); i++) + err |= test_hash(sha1, hash, sizeof(hash), + data[i], strlen(data[i]), + SHA1); + + memset(input, 'a', sizeof(input)); + /* cover critical input size around 56 bytes */ + for (i = 50; i < sizeof(input); i++) + err |= test_hash(sha1, hash, sizeof(hash), + input, i, SHA1); + + return err; +} +#endif diff --git a/lib/libtpm/sha256.c b/lib/libtpm/sha256.c index 1a0aa9a..79bcb83 100644 --- a/lib/libtpm/sha256.c +++ b/lib/libtpm/sha256.c @@ -218,3 +218,29 @@ void sha256(const uint8_t *data, uint32_t length, uint8_t *hash) sha256_do(&ctx, data, length); memcpy(hash, ctx.h, sizeof(ctx.h)); } + +#ifdef MAIN + +#include "sha_test.h" + +int main(void) +{ + TESTVECTORS(data); + uint8_t hash[32]; + char input[64]; + int err = 0; + size_t i; + + for (i = 0; i < ARRAY_SIZE(data); i++) + err |= test_hash(sha256, hash, sizeof(hash), + data[i], strlen(data[i]), + SHA256); + + memset(input, 'a', sizeof(input)); + /* cover critical input size around 56 bytes */ + for (i = 50; i < sizeof(input); i++) + err |= test_hash(sha256, hash, sizeof(hash), input, i, SHA256); + + return err; +} +#endif diff --git a/lib/libtpm/sha512.c b/lib/libtpm/sha512.c index f9267ef..86831ab 100644 --- a/lib/libtpm/sha512.c +++ b/lib/libtpm/sha512.c @@ -247,3 +247,39 @@ void sha512(const uint8_t *data, uint32_t length, uint8_t *hash) sha512_do(&ctx, data, length); memcpy(hash, ctx.h, sizeof(ctx.h)); } + + +#ifdef MAIN + +#include "sha_test.h" + +int main(void) +{ + TESTVECTORS(data); + uint8_t hash512[64]; + uint8_t hash384[48]; + char input[128]; + int err = 0; + size_t i; + + for (i = 0; i < ARRAY_SIZE(data); i++) { + err |= test_hash(sha384, hash384, sizeof(hash384), + data[i], strlen(data[i]), + SHA384); + err |= test_hash(sha512, hash512, sizeof(hash512), + data[i], strlen(data[i]), + SHA512); + } + + memset(input, 'a', sizeof(input)); + /* cover critical input size around 112 bytes */ + for (i = 110; i < sizeof(input); i++) { + err |= test_hash(sha384, hash384, sizeof(hash384), + input, i, SHA384); + err |= test_hash(sha512, hash512, sizeof(hash512), + input, i, SHA512); + } + + return err; +} +#endif diff --git a/lib/libtpm/sha_test.h b/lib/libtpm/sha_test.h new file mode 100644 index 0000000..af82fac --- /dev/null +++ b/lib/libtpm/sha_test.h @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2021 IBM Corporation + * All rights reserved. + * This program and the accompanying materials + * are made available under the terms of the BSD License + * which accompanies this distribution, and is available at + * http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * IBM Corporation - initial implementation + *****************************************************************************/ + +#ifndef SHA_TEST_H +#define SHA_TEST_H + +#include + +#include "helpers.h" + +/* to avoid compilation issues do not include openssl/sha.h */ +unsigned char *SHA1(const unsigned char *, size_t, unsigned char *); +unsigned char *SHA256(const unsigned char *, size_t, unsigned char *); +unsigned char *SHA384(const unsigned char *, size_t, unsigned char *); +unsigned char *SHA512(const unsigned char *, size_t, unsigned char *); + +typedef void (*hashfunc)(const uint8_t *data, uint32_t length, uint8_t *hash); +typedef unsigned char *(*osslhashfunc)(const unsigned char *, size_t, + unsigned char *); + +#define TESTVECTORS(NAME) \ +char *NAME[] = { \ + "", \ + "abc", \ + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", \ + "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" \ +}; + +static inline int +test_hash(hashfunc hf, uint8_t *hash, size_t hashlen, + const char *data, uint32_t length, + osslhashfunc osslhf) +{ + unsigned char expected[hashlen]; + int ret = 0; + + osslhf((const unsigned char *)data, length, expected); + + hf((uint8_t *)data, length, hash); + if (!memcmp(hash, expected, hashlen)) { + printf("PASS: input length: %u\n", length); + } else { + printf("FAIL data: %s\n", data); + ret = 1; + } + + return ret; +} + +#endif /* SHA_TEST_H */ diff --git a/lib/libtpm/test.sh b/lib/libtpm/test.sh new file mode 100755 index 0000000..4b0567a --- /dev/null +++ b/lib/libtpm/test.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +cd $(dirname "$0") + +CC=${HOSTCC:-gcc} +CFLAGS="-Wall -Wextra -Werror -I../../include -I../../slof -I../../lib/libc/include -DMAIN" +LDFLAGS="-lcrypto" + +function fail() { + rm -f ${EXEC} + echo "Test failed" + exit 1 +} + +function run_test() { + local msg="$1" + local src="$2" + + EXEC="./${src%%.c}-test" + + echo ${msg} + ${CC} ${CFLAGS} ${src} -o ${EXEC} ${LDFLAGS} || exit 1 + ${EXEC} || fail + rm -f ${EXEC} +} + +run_test "SHA-1 test:" sha.c +run_test "SHA-256 test:" sha256.c +run_test "SHA-384 & SHA-512 test:" sha512.c + +echo "All tests passed" +exit 0 From patchwork Fri Jul 9 15:39:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1503249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ta5HjcUV; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLy5B0Y0lz9sWX for ; Sat, 10 Jul 2021 01:39:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GLy596YMxz30C0 for ; Sat, 10 Jul 2021 01:39:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ta5HjcUV; dkim-atps=neutral X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ta5HjcUV; dkim-atps=neutral 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 lists.ozlabs.org (Postfix) with ESMTPS id 4GLy520vgsz3005 for ; Sat, 10 Jul 2021 01:39:17 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 169FXn4u117084; Fri, 9 Jul 2021 11:39:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Fkvri3X8Q238U5kSodQeffVS4KgE/1cj8jr1AMkLb3g=; b=ta5HjcUVFw+5udqCiDIX8YvJenqDkQY2TaoNaVF7ACNqApZTtxfzwf3oUrAnKhbfzsXK fdFUWWwp2Z3K4avot/nUm07VQqltn5H4mOcIBxml2MZhfRTOIYKwtOOwzev/e33eBSoM yR+GAUJ/N6z31gRNldy+hzln09cq60vaCLhAdbpB7ZB0IEcSmLevXFpIiaXqguj8bFu6 GwsavQb6A61QVhBPJAlPaIB/T6PR28GJ49hO5EcwX91YNLDh2DaNvAvu95GdW3UUwwuL Lmmd48k2q4j8A24R99fitcLYqVDf8p13EN/zt5HEwuDtd4HFhjyHvgJ0hvsHFSOPidZ6 ZA== Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 39pcs6m17t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 11:39:13 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 169FS9FR000349; Fri, 9 Jul 2021 15:39:12 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma04dal.us.ibm.com with ESMTP id 39jfhfhn64-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 15:39:12 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 169FdAdF45482442 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 15:39:10 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A9C8A7806A; Fri, 9 Jul 2021 15:39:10 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D06F7805E; Fri, 9 Jul 2021 15:39:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.152]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 15:39:10 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org Date: Fri, 9 Jul 2021 11:39:03 -0400 Message-Id: <20210709153903.691945-6-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> References: <20210709153903.691945-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: utVXO4QezKxlhs7O4d95rBov2f6AnQEc X-Proofpoint-GUID: utVXO4QezKxlhs7O4d95rBov2f6AnQEc X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_09:2021-07-09, 2021-07-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=980 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090078 Subject: [SLOF] [PATCH v4 5/5] Travis: Add script for running tests on Travis X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Stefan Berger Signed-off-by: Stefan Berger --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..df4998b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +dist: bionic +language: c + +addons: + apt: + packages: + - libssl-dev + +script: + - ./lib/libtpm/test.sh + +matrix: + inlcude: + - os: linux + arch: ppc64le