Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A865C433F5 for ; Tue, 16 Nov 2021 10:45:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A718C61BE6 for ; Tue, 16 Nov 2021 10:45:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A718C61BE6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=walle.cc Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2AE32837E4; Tue, 16 Nov 2021 11:45:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=walle.cc Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=walle.cc header.i=@walle.cc header.b="rKBfsnZR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 73559837E9; Tue, 16 Nov 2021 11:45:48 +0100 (CET) Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DF544837B9 for ; Tue, 16 Nov 2021 11:45:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=walle.cc Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=michael@walle.cc Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810c:c240:2017:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 82D3C2223B; Tue, 16 Nov 2021 11:45:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1637059542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJWWInaQO7tvO5Ga/BpxUAx2WOEqVVfmW24sbWtBGhM=; b=rKBfsnZR1Kc6pB5HsfKGvL2wPfBGIlWLSts1C8kr21bGub3sveVyG1VYhHBho8fFUnCf9t ngGwAUWf/HABILSul6HmiFGOneAkAPAc4YHFpz2wgvv4nVuREsjnIltIESOha3EekmeYLK aXO8Ygq3hs4PhhXfebI64XU9H6XBTug= From: Michael Walle To: gaurav.jain@nxp.com Cc: Shengzhou.Liu@nxp.com, V.Sethi@nxp.com, adrian.alonso@nxp.com, alison.wang@nxp.com, andy.tang@nxp.com, festevam@gmail.com, franck.lenormand@nxp.com, horia.geanta@nxp.com, ji.luo@nxp.com, meenakshi.aggarwal@nxp.com, mingkai.hu@nxp.com, olteanv@gmail.com, pankaj.gupta@nxp.com, peng.fan@nxp.com, pramod.kumar_1@nxp.com, priyanka.jain@nxp.com, rajesh.bhagat@nxp.com, sahil.malhotra@nxp.com, sbabic@denx.de, silvano.dininno@nxp.com, sjg@chromium.org, u-boot@lists.denx.de, uboot-imx@nxp.com, wasim.khan@nxp.com, ye.li@nxp.com, Michael Walle Subject: Re: [PATCH v5 02/16] crypto/fsl: Add CAAM support for bkek, random number generation Date: Tue, 16 Nov 2021 11:45:31 +0100 Message-Id: <20211116104531.3580657-1-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211115070014.17586-3-gaurav.jain@nxp.com> References: <20211115070014.17586-3-gaurav.jain@nxp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.35 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi, > --- a/drivers/crypto/fsl/fsl_blob.c > +++ b/drivers/crypto/fsl/fsl_blob.c > @@ -1,6 +1,7 @@ > // SPDX-License-Identifier: GPL-2.0+ > /* > * Copyright 2014 Freescale Semiconductor, Inc. > + * Copyright 2021 NXP > * > */ > > @@ -152,6 +153,87 @@ int blob_encap(u8 *key_mod, u8 *src, u8 *dst, u32 len) > return ret; > } > > +int derive_blob_kek(u8 *bkek_buf, u8 *key_mod, u32 key_sz) where is this function actually used? looks like dead code to me. > +{ > + int ret, size; > + u32 *desc; > + > + if (!IS_ALIGNED((uintptr_t)bkek_buf, ARCH_DMA_MINALIGN) || > + !IS_ALIGNED((uintptr_t)key_mod, ARCH_DMA_MINALIGN)) { > + puts("Error: derive_bkek: Address arguments are not aligned!\n"); > + return -EINVAL; > + } > + > + printf("\nBlob key encryption key(bkek)\n"); > + desc = malloc_cache_aligned(sizeof(int) * MAX_CAAM_DESCSIZE); > + if (!desc) { > + printf("Not enough memory for descriptor allocation\n"); > + return -ENOMEM; > + } > + > + size = ALIGN(key_sz, ARCH_DMA_MINALIGN); > + flush_dcache_range((unsigned long)key_mod, (unsigned long)key_mod + size); > + > + /* construct blob key encryption key(bkek) derive descriptor */ > + inline_cnstr_jobdesc_derive_bkek(desc, bkek_buf, key_mod, key_sz); > + > + size = ALIGN(sizeof(int) * MAX_CAAM_DESCSIZE, ARCH_DMA_MINALIGN); > + flush_dcache_range((unsigned long)desc, (unsigned long)desc + size); > + size = ALIGN(BKEK_SIZE, ARCH_DMA_MINALIGN); > + invalidate_dcache_range((unsigned long)bkek_buf, > + (unsigned long)bkek_buf + size); > + > + /* run descriptor */ > + ret = run_descriptor_jr(desc); > + if (ret < 0) { > + printf("Error: %s failed 0x%x\n", __func__, ret); > + } else { > + invalidate_dcache_range((unsigned long)bkek_buf, > + (unsigned long)bkek_buf + size); > + puts("derive bkek successful.\n"); > + } > + > + free(desc); > + return ret; > +} > + > +int hwrng_generate(u8 *dst, u32 len) likewise. But more important what is the difference to drivers/crypto/fsl/rng.c? Why do you need a new function here? > +{ > + int ret, size; > + u32 *desc; > + > + if (!IS_ALIGNED((uintptr_t)dst, ARCH_DMA_MINALIGN)) { > + puts("Error: caam_hwrng_test: Address arguments are not aligned!\n"); > + return -EINVAL; > + } > + > + printf("\nRNG generate\n"); > + desc = malloc_cache_aligned(sizeof(int) * MAX_CAAM_DESCSIZE); > + if (!desc) { > + printf("Not enough memory for descriptor allocation\n"); > + return -ENOMEM; > + } > + > + inline_cnstr_jobdesc_rng(desc, dst, len); > + > + size = ALIGN(sizeof(int) * MAX_CAAM_DESCSIZE, ARCH_DMA_MINALIGN); > + flush_dcache_range((unsigned long)desc, (unsigned long)desc + size); > + size = ALIGN(len, ARCH_DMA_MINALIGN); > + invalidate_dcache_range((unsigned long)dst, (unsigned long)dst + size); > + > + ret = run_descriptor_jr(desc); > + if (ret < 0) { > + printf("Error: RNG generate failed 0x%x\n", ret); > + } else { > + invalidate_dcache_range((unsigned long)dst, > + (unsigned long)dst + size); > + puts("RNG generation successful.\n"); > + } > + > + free(desc); > + return ret; > +} > + > #ifdef CONFIG_CMD_DEKBLOB > int blob_dek(const u8 *src, u8 *dst, u8 len) > { -michael