RE: [EXT] [PATCH v8 3/6] KEYS: trusted: Introduce NXP DCP-backed trusted keys

2024-04-10 Thread Kshitiz Varshney
Hi Ahmad,

> -Original Message-
> From: Ahmad Fatoum 
> Sent: Tuesday, April 9, 2024 10:58 PM
> To: Kshitiz Varshney ; David Gstir
> ; Mimi Zohar ; James
> Bottomley ; Jarkko Sakkinen ;
> Herbert Xu ; David S. Miller
> 
> Cc: linux-...@vger.kernel.org; Gaurav Jain ; Catalin
> Marinas ; David Howells
> ; keyri...@vger.kernel.org; Fabio Estevam
> ; Paul Moore ; Jonathan
> Corbet ; Richard Weinberger ; Rafael J.
> Wysocki ; James Morris ;
> dl-linux-imx ; Serge E. Hallyn ;
> Paul E. McKenney ; Sascha Hauer
> ; Pankaj Gupta ; sigma
> star Kernel Team ; Steven Rostedt (Google)
> ; David Oberhollenzer  star.at>; linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org;
> Randy Dunlap ; linux-ker...@vger.kernel.org; Li
> Yang ; linux-security-mod...@vger.kernel.org; linux-
> cry...@vger.kernel.org; Pengutronix Kernel Team ;
> Tejun Heo ; linux-integr...@vger.kernel.org; Shawn Guo
> ; Varun Sethi 
> Subject: Re: [EXT] [PATCH v8 3/6] KEYS: trusted: Introduce NXP DCP-backed
> trusted keys
> 
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report
> this email' button
> 
> 
> Hello Kshitiz,
> 
> On 09.04.24 12:54, Kshitiz Varshney wrote:
> > Hi David,
> >> +   b->fmt_version = DCP_BLOB_VERSION;
> >> +   get_random_bytes(b->nonce, AES_KEYSIZE_128);
> >> +   get_random_bytes(b->blob_key, AES_KEYSIZE_128);
> >
> > We can use HWRNG instead of using kernel RNG. Please refer
> > drivers/char/hw_random/imx-rngc.c
> 
> imx-rngc can be enabled and used to seed the kernel entropy pool. Adding
> direct calls into imx-rngc here only introduces duplicated code at no extra
> benefit.
> 
> Cheers,
> Ahmad
> 
> --
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   |
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.
> pengutronix.de%2F=05%7C02%7Ckshitiz.varshney%40nxp.com%7Ce9
> 97f259d34548ad1a9808dc58ba63a8%7C686ea1d3bc2b4c6fa92cd99c5c30
> 1635%7C0%7C0%7C638482804763047266%7CUnknown%7CTWFpbGZsb3
> d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0
> %3D%7C0%7C%7C%7C=UZgE9MXqAqCwqVnWty67YLh8QnIwpuq%2
> F7%2BQeDLQhF8I%3D=0  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

Understood.

Regards,
Kshitiz


RE: [EXT] [PATCH v8 3/6] KEYS: trusted: Introduce NXP DCP-backed trusted keys

2024-04-09 Thread Kshitiz Varshney
Hi David,

> -Original Message-
> From: David Gstir 
> Sent: Wednesday, April 3, 2024 12:51 PM
> To: Mimi Zohar ; James Bottomley
> ; Jarkko Sakkinen ; Herbert Xu
> ; David S. Miller 
> Cc: David Gstir ; Shawn Guo ;
> Jonathan Corbet ; Sascha Hauer
> ; Pengutronix Kernel Team
> ; Fabio Estevam ; dl-linux-
> imx ; Ahmad Fatoum ;
> sigma star Kernel Team ; David Howells
> ; Li Yang ; Paul Moore
> ; James Morris ; Serge E.
> Hallyn ; Paul E. McKenney ;
> Randy Dunlap ; Catalin Marinas
> ; Rafael J. Wysocki
> ; Tejun Heo ; Steven Rostedt
> (Google) ; linux-...@vger.kernel.org; linux-
> ker...@vger.kernel.org; linux-integr...@vger.kernel.org;
> keyri...@vger.kernel.org; linux-cry...@vger.kernel.org; linux-arm-
> ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org; linux-security-
> mod...@vger.kernel.org; Richard Weinberger ; David
> Oberhollenzer 
> Subject: [EXT] [PATCH v8 3/6] KEYS: trusted: Introduce NXP DCP-backed
> trusted keys
> 
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report
> this email' button
> 
> 
> DCP (Data Co-Processor) is the little brother of NXP's CAAM IP.
> Beside of accelerated crypto operations, it also offers support for hardware-
> bound keys. Using this feature it is possible to implement a blob
> mechanism similar to what CAAM offers. Unlike on CAAM, constructing and
> parsing the blob has to happen in software (i.e. the kernel).
> 
> The software-based blob format used by DCP trusted keys encrypts the
> payload using AES-128-GCM with a freshly generated random key and
> nonce.
> The random key itself is AES-128-ECB encrypted using the DCP unique or
> OTP key.
> 
> The DCP trusted key blob format is:
> /*
>  * struct dcp_blob_fmt - DCP BLOB format.
>  *
>  * @fmt_version: Format version, currently being %1
>  * @blob_key: Random AES 128 key which is used to encrypt @payload,
>  *@blob_key itself is encrypted with OTP or UNIQUE device key in
>  *AES-128-ECB mode by DCP.
>  * @nonce: Random nonce used for @payload encryption.
>  * @payload_len: Length of the plain text @payload.
>  * @payload: The payload itself, encrypted using AES-128-GCM and
> @blob_key,
>  *   GCM auth tag of size AES_BLOCK_SIZE is attached at the end of it.
>  *
>  * The total size of a DCP BLOB is sizeof(struct dcp_blob_fmt) +
> @payload_len +
>  * AES_BLOCK_SIZE.
>  */
> struct dcp_blob_fmt {
> __u8 fmt_version;
> __u8 blob_key[AES_KEYSIZE_128];
> __u8 nonce[AES_KEYSIZE_128];
> __le32 payload_len;
> __u8 payload[];
> } __packed;
> 
> By default the unique key is used. It is also possible to use the OTP key.
> While the unique key should be unique it is not documented how this key is
> derived. Therefore selection the OTP key is supported as well via the
> use_otp_key module parameter.
> 
> Co-developed-by: Richard Weinberger 
> Signed-off-by: Richard Weinberger 
> Co-developed-by: David Oberhollenzer 
> Signed-off-by: David Oberhollenzer 
> Signed-off-by: David Gstir 
> Reviewed-by: Jarkko Sakkinen 
> ---
>  include/keys/trusted_dcp.h|  11 +
>  security/keys/trusted-keys/Kconfig|   8 +
>  security/keys/trusted-keys/Makefile   |   2 +
>  security/keys/trusted-keys/trusted_core.c |   6 +-
>  security/keys/trusted-keys/trusted_dcp.c  | 313
> ++
>  5 files changed, 339 insertions(+), 1 deletion(-)  create mode 100644
> include/keys/trusted_dcp.h  create mode 100644 security/keys/trusted-
> keys/trusted_dcp.c
> 
> diff --git a/include/keys/trusted_dcp.h b/include/keys/trusted_dcp.h new
> file mode 100644 index ..9aaa42075b40
> --- /dev/null
> +++ b/include/keys/trusted_dcp.h
> @@ -0,0 +1,11 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2021 sigma star gmbh
> + */
> +
> +#ifndef TRUSTED_DCP_H
> +#define TRUSTED_DCP_H
> +
> +extern struct trusted_key_ops dcp_trusted_key_ops;
> +
> +#endif
> diff --git a/security/keys/trusted-keys/Kconfig b/security/keys/trusted-
> keys/Kconfig
> index 553dc117f385..1fb8aa001995 100644
> --- a/security/keys/trusted-keys/Kconfig
> +++ b/security/keys/trusted-keys/Kconfig
> @@ -39,6 +39,14 @@ config TRUSTED_KEYS_CAAM
>   Enable use of NXP's Cryptographic Accelerator and Assurance Module
>   (CAAM) as trusted key backend.
> 
> +config TRUSTED_KEYS_DCP
> +   bool "DCP-based trusted keys"
> +   depends on CRYPTO_DEV_MXS_DCP >= TRUSTED_KEYS
> +   default y
> +   select HAVE_TRUSTED_KEYS
> +   help
> + Enable use of NXP's DCP (Data Co-Processor) as trusted key backend.
> +
>  if !HAVE_TRUSTED_KEYS
> comment "No trust source selected!"
>  endif
> diff --git a/security/keys/trusted-keys/Makefile b/security/keys/trusted-
> keys/Makefile
> index 735aa0bc08ef..f0f3b27f688b 100644
> --- a/security/keys/trusted-keys/Makefile
> +++ b/security/keys/trusted-keys/Makefile
> @@ 

Re: [EXT] [PATCH v8 3/6] KEYS: trusted: Introduce NXP DCP-backed trusted keys

2024-04-09 Thread Ahmad Fatoum
Hello Kshitiz,

On 09.04.24 12:54, Kshitiz Varshney wrote:
> Hi David,
>> +   b->fmt_version = DCP_BLOB_VERSION;
>> +   get_random_bytes(b->nonce, AES_KEYSIZE_128);
>> +   get_random_bytes(b->blob_key, AES_KEYSIZE_128);
> 
> We can use HWRNG instead of using kernel RNG. Please refer 
> drivers/char/hw_random/imx-rngc.c 

imx-rngc can be enabled and used to seed the kernel entropy pool. Adding
direct calls into imx-rngc here only introduces duplicated code at no extra
benefit.

Cheers,
Ahmad

-- 
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- |