From patchwork Thu Aug 31 06:45:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Carvalho X-Patchwork-Id: 808055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xjXxY22QDz9s7F for ; Thu, 31 Aug 2017 16:47:45 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xjXxY0VzQzDqYx for ; Thu, 31 Aug 2017 16:47:45 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.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 lists.ozlabs.org (Postfix) with ESMTPS id 3xjXw20NWvzDqT0 for ; Thu, 31 Aug 2017 16:46:25 +1000 (AEST) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7V6hnOX049266 for ; Thu, 31 Aug 2017 02:46:24 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cpa7cn39d-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 31 Aug 2017 02:46:23 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 31 Aug 2017 00:46:23 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 31 Aug 2017 00:46:21 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7V6kK1t65601782 for ; Wed, 30 Aug 2017 23:46:20 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C8AA778037 for ; Thu, 31 Aug 2017 00:46:20 -0600 (MDT) Received: from legolas.ibm.com (unknown [9.85.193.48]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 2CB4E7804D for ; Thu, 31 Aug 2017 00:46:19 -0600 (MDT) From: Claudio Carvalho To: skiboot@lists.ozlabs.org Date: Thu, 31 Aug 2017 03:45:54 -0300 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504161961-12190-1-git-send-email-cclaudio@linux.vnet.ibm.com> References: <1504161961-12190-1-git-send-email-cclaudio@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17083106-0004-0000-0000-000012D9FCD7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007640; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000226; SDB=6.00910085; UDB=6.00456503; IPR=6.00690365; BA=6.00005562; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016938; XFM=3.00000015; UTC=2017-08-31 06:46:21 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17083106-0005-0000-0000-000080EDB900 Message-Id: <1504161961-12190-7-git-send-email-cclaudio@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-31_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708310102 Subject: [Skiboot] [PATCH 06/13] libstb: rename drivers/sw_driver.* to cvc/c1vc_mbedtls.* X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This gives a better name to the drivers/sw_driver.* files and also moves them to a better place. The function names are also renamed accordingly. sw_driver emulates the container version 1 verification code so that we can run tests using mambo. In summary, the function to verify containers is not emulated, but the sha512 function is emulated using the sha512 code provided by the mbedtls project. Signed-off-by: Claudio Carvalho --- libstb/cvc/Makefile.inc | 2 +- libstb/cvc/c1vc_mbedtls.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ libstb/cvc/c1vc_mbedtls.h | 24 ++++++++++++++ libstb/drivers/Makefile.inc | 2 +- libstb/drivers/sw_driver.c | 76 --------------------------------------------- libstb/drivers/sw_driver.h | 24 -------------- libstb/rom.c | 4 +-- 7 files changed, 104 insertions(+), 104 deletions(-) create mode 100644 libstb/cvc/c1vc_mbedtls.c create mode 100644 libstb/cvc/c1vc_mbedtls.h delete mode 100644 libstb/drivers/sw_driver.c delete mode 100644 libstb/drivers/sw_driver.h diff --git a/libstb/cvc/Makefile.inc b/libstb/cvc/Makefile.inc index 8ce86d5..ab3419e 100644 --- a/libstb/cvc/Makefile.inc +++ b/libstb/cvc/Makefile.inc @@ -4,7 +4,7 @@ CVC_DIR = libstb/cvc SUBDIRS += $(CVC_DIR) -CVC_SRCS = c1vc.c +CVC_SRCS = c1vc.c c1vc_mbedtls.c CVC_OBJS = $(CVC_SRCS:%.c=%.o) CVC = $(CVC_DIR)/built-in.o diff --git a/libstb/cvc/c1vc_mbedtls.c b/libstb/cvc/c1vc_mbedtls.c new file mode 100644 index 0000000..8a7c404 --- /dev/null +++ b/libstb/cvc/c1vc_mbedtls.c @@ -0,0 +1,76 @@ +/* Copyright 2013-2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "../rom.h" +#include "sha512.h" +#include "c1vc_mbedtls.h" + +static sha2_hash_t *hw_key_hash = NULL; + +static int c1vc_mbedtls_verify(void *container __unused) +{ + return -100; +} + +static void c1vc_mbedtls_sha512(const uint8_t *data, size_t len, uint8_t *digest) +{ + mbedtls_sha512_context ctx; + mbedtls_sha512_init(&ctx); + memset(digest, 0, sizeof(sha2_hash_t)); + mbedtls_sha512_starts(&ctx, 0); // SHA512 = 0 + mbedtls_sha512_update(&ctx, data, len); + mbedtls_sha512_finish(&ctx, digest); + mbedtls_sha512_free(&ctx); +} + +static void c1vc_mbedtls_cleanup(void) +{ + return; +} + +static struct container_verification_code c1vc = { + .name = "software", + .verify = c1vc_mbedtls_verify, + .sha512 = c1vc_mbedtls_sha512, + .cleanup = c1vc_mbedtls_cleanup +}; + +void c1vc_mbedtls_probe(const struct dt_node *node) +{ + const char* hash_algo; + + if (!dt_node_is_compatible(node, "ibm,secureboot-v1-softrom")) { + return; + } + + hash_algo = dt_prop_get(node, "hash-algo"); + if (strcmp(hash_algo, "sha512")) { + /** + * @fwts-label ROMHashAlgorithmInvalid + * @fwts-advice Hostboot creates the ibm,secureboot node and + * the hash-algo property. Check that the ibm,secureboot node + * layout has not changed. + */ + prlog(PR_ERR, "ROM: hash-algo=%s not expected\n", hash_algo); + return; + } + hw_key_hash = (sha2_hash_t*) dt_prop_get(node, "hw-key-hash"); + + rom_set_driver(&c1vc); +} diff --git a/libstb/cvc/c1vc_mbedtls.h b/libstb/cvc/c1vc_mbedtls.h new file mode 100644 index 0000000..9027138 --- /dev/null +++ b/libstb/cvc/c1vc_mbedtls.h @@ -0,0 +1,24 @@ +/* Copyright 2013-2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __C1VC_MBEDTLS_H +#define __C1VC_MBEDTLS_H + +#include + +extern void c1vc_mbedtls_probe(const struct dt_node *node); + +#endif /* __C1VC_MBEDTLS_H */ diff --git a/libstb/drivers/Makefile.inc b/libstb/drivers/Makefile.inc index 6425208..4ea867f 100644 --- a/libstb/drivers/Makefile.inc +++ b/libstb/drivers/Makefile.inc @@ -4,7 +4,7 @@ DRIVERS_DIR = libstb/drivers SUBDIRS += $(DRIVERS_DIR) -DRIVERS_SRCS = tpm_i2c_interface.c tpm_i2c_nuvoton.c sw_driver.c sha512.c +DRIVERS_SRCS = tpm_i2c_interface.c tpm_i2c_nuvoton.c sha512.c DRIVERS_OBJS = $(DRIVERS_SRCS:%.c=%.o) DRIVERS = $(DRIVERS_DIR)/built-in.o diff --git a/libstb/drivers/sw_driver.c b/libstb/drivers/sw_driver.c deleted file mode 100644 index 55224a2..0000000 --- a/libstb/drivers/sw_driver.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright 2013-2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "../rom.h" -#include "sha512.h" -#include "sw_driver.h" - -static sha2_hash_t *hw_key_hash = NULL; - -static int stb_software_verify(void *container __unused) -{ - return -100; -} - -static void stb_software_sha512(const uint8_t *data, size_t len, uint8_t *digest) -{ - mbedtls_sha512_context ctx; - mbedtls_sha512_init(&ctx); - memset(digest, 0, sizeof(sha2_hash_t)); - mbedtls_sha512_starts(&ctx, 0); // SHA512 = 0 - mbedtls_sha512_update(&ctx, data, len); - mbedtls_sha512_finish(&ctx, digest); - mbedtls_sha512_free(&ctx); -} - -static void stb_software_cleanup(void) -{ - return; -} - -static struct container_verification_code c1vc = { - .name = "software", - .verify = stb_software_verify, - .sha512 = stb_software_sha512, - .cleanup = stb_software_cleanup -}; - -void stb_software_probe(const struct dt_node *node) -{ - const char* hash_algo; - - if (!dt_node_is_compatible(node, "ibm,secureboot-v1-softrom")) { - return; - } - - hash_algo = dt_prop_get(node, "hash-algo"); - if (strcmp(hash_algo, "sha512")) { - /** - * @fwts-label ROMHashAlgorithmInvalid - * @fwts-advice Hostboot creates the ibm,secureboot node and - * the hash-algo property. Check that the ibm,secureboot node - * layout has not changed. - */ - prlog(PR_ERR, "ROM: hash-algo=%s not expected\n", hash_algo); - return; - } - hw_key_hash = (sha2_hash_t*) dt_prop_get(node, "hw-key-hash"); - - rom_set_driver(&c1vc); -} diff --git a/libstb/drivers/sw_driver.h b/libstb/drivers/sw_driver.h deleted file mode 100644 index 73adabf..0000000 --- a/libstb/drivers/sw_driver.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2013-2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __SW_DRIVER_H -#define __SW_DRIVER_H - -#include - -extern void stb_software_probe(const struct dt_node *node); - -#endif /* __ROMCODE_H */ diff --git a/libstb/rom.c b/libstb/rom.c index 9054420..04ab364 100644 --- a/libstb/rom.c +++ b/libstb/rom.c @@ -17,7 +17,7 @@ #include #include "rom.h" #include "cvc/c1vc.h" -#include "drivers/sw_driver.h" +#include "cvc/c1vc_mbedtls.h" static struct container_verification_code *c1vc = NULL; @@ -30,7 +30,7 @@ struct container_verification_code* rom_init(const struct dt_node *node __unused c1vc_probe(node); if (!c1vc) - stb_software_probe(node); + c1vc_mbedtls_probe(node); if (!c1vc) prlog(PR_NOTICE, "ROM: no rom driver found\n");