[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YhZVmBy3/nWbqf+/@iki.fi>
Date: Wed, 23 Feb 2022 16:41:12 +0100
From: Jarkko Sakkinen <jarkko@...nel.org>
To: Ahmad Fatoum <a.fatoum@...gutronix.de>
Cc: Horia Geantă <horia.geanta@....com>,
Aymen Sghaier <aymen.sghaier@....com>,
Herbert Xu <herbert@...dor.apana.org.au>,
"David S. Miller" <davem@...emloft.net>, kernel@...gutronix.de,
David Gstir <david@...ma-star.at>,
Pankaj Gupta <pankaj.gupta@....com>,
Tim Harvey <tharvey@...eworks.com>,
Matthias Schiffer <matthias.schiffer@...tq-group.com>,
James Bottomley <jejb@...ux.ibm.com>,
Mimi Zohar <zohar@...ux.ibm.com>,
David Howells <dhowells@...hat.com>,
James Morris <jmorris@...ei.org>,
Eric Biggers <ebiggers@...nel.org>,
"Serge E. Hallyn" <serge@...lyn.com>,
Jan Luebbe <j.luebbe@...gutronix.de>,
Richard Weinberger <richard@....at>,
Franck LENORMAND <franck.lenormand@....com>,
Sumit Garg <sumit.garg@...aro.org>,
linux-integrity@...r.kernel.org, keyrings@...r.kernel.org,
linux-crypto@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-security-module@...r.kernel.org
Subject: Re: [PATCH v5 4/5] crypto: caam - add in-kernel interface for blob
generator
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 <david@...ma-star.at>
> Reviewed-by: Pankaj Gupta <pankaj.gupta@....com>
> Tested-By: Tim Harvey <tharvey@...eworks.com>
> Tested-by: Matthias Schiffer <matthias.schiffer@...tq-group.com>
> Signed-off-by: Steffen Trumtrar <s.trumtrar@...gutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@...gutronix.de>
> ---
> To: "Horia Geantă" <horia.geanta@....com>
> To: Aymen Sghaier <aymen.sghaier@....com>
> To: Herbert Xu <herbert@...dor.apana.org.au>
> To: "David S. Miller" <davem@...emloft.net>
> Cc: James Bottomley <jejb@...ux.ibm.com>
> Cc: Jarkko Sakkinen <jarkko@...nel.org>
> Cc: Mimi Zohar <zohar@...ux.ibm.com>
> Cc: David Howells <dhowells@...hat.com>
> Cc: James Morris <jmorris@...ei.org>
> Cc: Eric Biggers <ebiggers@...nel.org>
> Cc: "Serge E. Hallyn" <serge@...lyn.com>
> Cc: Jan Luebbe <j.luebbe@...gutronix.de>
> Cc: David Gstir <david@...ma-star.at>
> Cc: Richard Weinberger <richard@....at>
> Cc: Franck LENORMAND <franck.lenormand@....com>
> Cc: Sumit Garg <sumit.garg@...aro.org>
> Cc: Tim Harvey <tharvey@...eworks.com>
> Cc: Matthias Schiffer <matthias.schiffer@...tq-group.com>
> Cc: Pankaj Gupta <pankaj.gupta@....com>
> Cc: linux-integrity@...r.kernel.org
> Cc: keyrings@...r.kernel.org
> Cc: linux-crypto@...r.kernel.org
> Cc: linux-kernel@...r.kernel.org
> Cc: linux-security-module@...r.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 <kernel@...gutronix.de>
> + * Copyright (C) 2021 Pengutronix, Ahmad Fatoum <kernel@...gutronix.de>
> + */
> +
> +#include <linux/device.h>
> +#include <soc/fsl/caam-blob.h>
> +
> +#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.
BR, Jarkko
Powered by blists - more mailing lists