X-Received: by 2002:a17:902:7041:b0:14f:c724:42c7 with SMTP id h1-20020a170902704100b0014fc72442c7mr519687plt.11.1645635984549; Wed, 23 Feb 2022 09:06:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645635984; cv=none; d=google.com; s=arc-20160816; b=bFuBHOUjhFvu/D8W+mJdjHIybT1x86RgDevK9WyoGHxYkE0R1hJBsZyutVl9QchNgD rwJJN8osSEjywVs1vBOT4tsNGfrgaSoLUWsDYvXkJEq1ByxSCT/BQJsjjAxnOwCamZ6P eSGBzmOo/ZyPSQqbBPGmZlc61JgHoL78an0bxFgAGTjjyrjSIWoGaizP0/Y75HDwcDR3 D3Nfr0IYkad/jK/UFP/XRMOxG+2kspnmf5VCUJw7uwz7LEgiNTuIwf+aNQMWhFsIocER OTZJRdYCDxLx/J7UYQ8NRLHLgvtLjXmH9T+UXQIrHfznSXY29VTMze5DJcPx99gETWIM CENg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=yQRw2U1RIGjPUALylSOtfnkoUtNVeiiu15dc2jGdgYo=; b=idmS4U/dRFwVT+OT91z4vUK9RRwrOM6cNz0fyJzdZ3IM7PYeKI6/9nweT1jrF0/R8U 5SAP0NTLIR3VYbzQYbH9bKJTQhi7LM46mUaKq6nMuW/FDSXC/NqfoISf+WAaUm7WFBmp B+e9p56tJBQ+pIFzVaWBI6MZHLIgyyqyhzUThKAhKljDxiJRSs0F8IsdV4JHHQ5Vl3Gc lBTeMRvWV96wAGQD2mYuj6K/UZGuXt+f91ENEji8f4aRjQBd5R7H4YfbcC8yWs1aNxHy ZMLMpFo4lC1om9pt3VjNOnyass/iOzPv9c+eaG8ziQvrw4u+AdXtRcnhm+zunhMP/aIS dA5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v185si132822pgd.836.2022.02.23.09.06.05; Wed, 23 Feb 2022 09:06:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242747AbiBWQVk (ORCPT + 99 others); Wed, 23 Feb 2022 11:21:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242728AbiBWQVj (ORCPT ); Wed, 23 Feb 2022 11:21:39 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2BA9C5DA5 for ; Wed, 23 Feb 2022 08:21:10 -0800 (PST) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[127.0.0.1]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1nMuNV-00087t-O4; Wed, 23 Feb 2022 17:20:33 +0100 Message-ID: Date: Wed, 23 Feb 2022 17:20:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v5 4/5] crypto: caam - add in-kernel interface for blob generator Content-Language: en-US To: Jarkko Sakkinen Cc: =?UTF-8?Q?Horia_Geant=c4=83?= , Aymen Sghaier , Herbert Xu , "David S. Miller" , kernel@pengutronix.de, David Gstir , Pankaj Gupta , Tim Harvey , Matthias Schiffer , James Bottomley , Mimi Zohar , David Howells , James Morris , Eric Biggers , "Serge E. Hallyn" , Jan Luebbe , Richard Weinberger , Franck LENORMAND , Sumit Garg , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org References: <20220222195819.2313913-1-a.fatoum@pengutronix.de> <20220222195819.2313913-5-a.fatoum@pengutronix.de> From: Ahmad Fatoum In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: a.fatoum@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23.02.22 16:41, Jarkko Sakkinen wrote: > On Tue, Feb 22, 2022 at 08:58:18PM +0100, Ahmad Fatoum wrote: >> The NXP Cryptographic Acceleration and Assurance Module (CAAM) >> can be used to protect user-defined data across system reboot: >> >> - When the system is fused and boots into secure state, the master >> key is a unique never-disclosed device-specific key >> - random key is encrypted by key derived from master key >> - data is encrypted using the random key >> - encrypted data and its encrypted random key are stored alongside >> - This blob can now be safely stored in non-volatile memory >> >> On next power-on: >> - blob is loaded into CAAM >> - CAAM writes decrypted data either into memory or key register >> >> Add functions to realize encrypting and decrypting into memory alongside >> the CAAM driver. >> >> They will be used in a later commit as a source for the trusted key >> seal/unseal mechanism. >> >> Reviewed-by: David Gstir >> Reviewed-by: Pankaj Gupta >> Tested-By: Tim Harvey >> Tested-by: Matthias Schiffer >> Signed-off-by: Steffen Trumtrar >> Signed-off-by: Ahmad Fatoum >> --- >> To: "Horia Geantă" >> To: Aymen Sghaier >> To: Herbert Xu >> To: "David S. Miller" >> Cc: James Bottomley >> Cc: Jarkko Sakkinen >> Cc: Mimi Zohar >> Cc: David Howells >> Cc: James Morris >> Cc: Eric Biggers >> Cc: "Serge E. Hallyn" >> Cc: Jan Luebbe >> Cc: David Gstir >> Cc: Richard Weinberger >> Cc: Franck LENORMAND >> Cc: Sumit Garg >> Cc: Tim Harvey >> Cc: Matthias Schiffer >> Cc: Pankaj Gupta >> Cc: linux-integrity@vger.kernel.org >> Cc: keyrings@vger.kernel.org >> Cc: linux-crypto@vger.kernel.org >> Cc: linux-kernel@vger.kernel.org >> Cc: linux-security-module@vger.kernel.org >> --- >> drivers/crypto/caam/Kconfig | 3 + >> drivers/crypto/caam/Makefile | 1 + >> drivers/crypto/caam/blob_gen.c | 230 +++++++++++++++++++++++++++++++++ >> include/soc/fsl/caam-blob.h | 56 ++++++++ >> 4 files changed, 290 insertions(+) >> create mode 100644 drivers/crypto/caam/blob_gen.c >> create mode 100644 include/soc/fsl/caam-blob.h >> >> diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig >> index 84ea7cba5ee5..ea9f8b1ae981 100644 >> --- a/drivers/crypto/caam/Kconfig >> +++ b/drivers/crypto/caam/Kconfig >> @@ -151,6 +151,9 @@ config CRYPTO_DEV_FSL_CAAM_RNG_API >> Selecting this will register the SEC4 hardware rng to >> the hw_random API for supplying the kernel entropy pool. >> >> +config CRYPTO_DEV_FSL_CAAM_BLOB_GEN >> + bool >> + >> endif # CRYPTO_DEV_FSL_CAAM_JR >> >> endif # CRYPTO_DEV_FSL_CAAM >> diff --git a/drivers/crypto/caam/Makefile b/drivers/crypto/caam/Makefile >> index 3570286eb9ce..25f7ae5a4642 100644 >> --- a/drivers/crypto/caam/Makefile >> +++ b/drivers/crypto/caam/Makefile >> @@ -21,6 +21,7 @@ caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o >> caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o >> caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o >> caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o pkc_desc.o >> +caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_BLOB_GEN) += blob_gen.o >> >> caam-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += qi.o >> ifneq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI),) >> diff --git a/drivers/crypto/caam/blob_gen.c b/drivers/crypto/caam/blob_gen.c >> new file mode 100644 >> index 000000000000..513d3f90e438 >> --- /dev/null >> +++ b/drivers/crypto/caam/blob_gen.c >> @@ -0,0 +1,230 @@ >> +// SPDX-License-Identifier: GPL-2.0-only >> +/* >> + * Copyright (C) 2015 Pengutronix, Steffen Trumtrar >> + * Copyright (C) 2021 Pengutronix, Ahmad Fatoum >> + */ >> + >> +#include >> +#include >> + >> +#include "compat.h" >> +#include "desc_constr.h" >> +#include "desc.h" >> +#include "error.h" >> +#include "intern.h" >> +#include "jr.h" >> +#include "regs.h" >> + >> +struct caam_blob_priv { >> + struct device jrdev; >> +}; >> + >> +struct caam_blob_job_result { >> + int err; >> + struct completion completion; >> +}; >> + >> +static void caam_blob_job_done(struct device *dev, u32 *desc, u32 err, void *context) >> +{ >> + struct caam_blob_job_result *res = context; >> + int ecode = 0; >> + >> + dev_dbg(dev, "%s %d: err 0x%x\n", __func__, __LINE__, err); >> + >> + if (err) >> + ecode = caam_jr_strstatus(dev, err); >> + >> + res->err = ecode; >> + >> + /* >> + * Upon completion, desc points to a buffer containing a CAAM job >> + * descriptor which encapsulates data into an externally-storable >> + * blob. >> + */ >> + complete(&res->completion); >> +} >> + >> +static u32 *caam_blob_alloc_desc(size_t keymod_len) >> +{ >> + size_t len; >> + >> + /* header + (key mod immediate) + 2x pointers + op */ >> + len = 4 + (4 + ALIGN(keymod_len, 4)) + 2*(4 + 4 + CAAM_PTR_SZ_MAX) + 4; > > Nit: the amount of magic numbers is overwhelming here. I neither understand > the statement nor how that comment should help me to understand it. header = 4 (key mod immediate) = (4 + ALIGN(keymod_len, 4)) 2x pointer = 2 * (4 + 4 + CAAM_PTR_SZ_MAX) op = 4 I haven't heard back from the CAAM maintainers yet since v1. Perhaps now is a good occasion to chime in? :-) @Jarkko, could you take a look at patch 5? That's the gist of the series and I have yet to get maintainer feedback on that one. Cheers, Ahmad > > BR, Jarkko > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |