Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2580731rdb; Mon, 5 Feb 2024 10:46:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrvhorAVIVUBPg3/ELkxENnZEbgbT/b0JXFfykBDpsfJ6lokBfrOVVWSk0oqie9scT57MM X-Received: by 2002:a05:6214:1bcf:b0:68c:7fed:d1ca with SMTP id m15-20020a0562141bcf00b0068c7fedd1camr368377qvc.0.1707158768282; Mon, 05 Feb 2024 10:46:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707158768; cv=pass; d=google.com; s=arc-20160816; b=hYoqMNQfvpyJNGuuu8wywbG0Z9TMlaHkoF0fj5wfAbwr+W9Afz4WCh746pjz3ZgVP2 vTQYbY571fpR3QRUmAJAi1zrDyQuAY7t275/eSV6fFXpYQV1A4V5xyCyPXJV3/jtSnGV DXOrexSPqZbxMao0MMGnpA17dD/Iwz2qiDb8ef1t3178tx07xgdLBLM0jH+c7SuSD2t7 7ezijIJ0IVKw4lK/th8R4RsRph6B2RTFD3/cWYPo9jjHMbViX/351sqGX5j4D+xZcvyZ c/rqTY3NYaZ8Jmsy0VMAJ2fJsqhCU+OTvLMWDbHIIQYyTe+WwO6x2egV6qbBg5V5PXbn s0LA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=zYEnE8kdsoqUrl02WqEqTUud6+ujtosVwZejnyNc9bY=; fh=nFeF7biERr8zJdP0zzbp1Vzk5uPZKyFtsUwakJLQSKs=; b=FaVZTDW4pq4krtXetgkhZuA9SzZJO3ELU7yHm+qYSa1BcC7lPCEzwaJUcQz4mcM/UV kFiTNySenkBN9NF2pv43n9VQcCix+WOebTp1QmQxUB0AWR2pUoEf2rUtUUUL9c+PV56q un1/DsSq2w0ynWVFIwNrdzWhT5Q12M04zWFo/Ewb4cQalGu6v57IVcGA24ooHP6ptv++ dj1krHvFwEFNyi+wy+7cbRRaXTGI+dWkqJ22+/e1zk1hR0goFfRBpcYYLBVcu/bJ/WSy UN/RjXL0usjC9WqzBjR6RSDJBNV10EwFT6jdgzcQgEcn34YWhKyXV9BC0rR/Gg6IkTuG mPJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="HUHwEJh/"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-crypto+bounces-1863-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1863-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=1; AJvYcCUsV8gjTp1sB/8zyhTNGcucsgbDBynaGXv1sWEJ9UvEw7UmqW4E9isEHicKSGGenk6rr2ddx6kKoeha0fe8OLcsWERMLFm00RTG49YXAw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t2-20020a0562140c6200b0068c8c2b1c95si577562qvj.376.2024.02.05.10.46.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:46:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1863-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="HUHwEJh/"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-crypto+bounces-1863-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1863-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id F3B921C21B63 for ; Mon, 5 Feb 2024 18:46:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 30A7C481CD; Mon, 5 Feb 2024 18:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="HUHwEJh/" X-Original-To: linux-crypto@vger.kernel.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BBEE481AE; Mon, 5 Feb 2024 18:45:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707158758; cv=none; b=UvTFOaVTqaYWZx5fPIxjxG+ekzlekaYquE1hWq8IZf6LQzCbua/Ji7L0LLxBMAXUtGkeFU+N0laz3ktCpzUWU5izgSUxtM7fSLOgsiuuGaeopVAW9s2xdGQ3ggWDgLYNKk7RmkmQKhXAsXNfsdEpKzAt2m63MSAa9RFtyCP5tf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707158758; c=relaxed/simple; bh=heNj6/BgBMNT76DCe8GFRn6mIYSxdeYYFSNlkm4XIow=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=ovayP+iPUWNpuTBRwRNokhAETa5Rrv4RxGNpedkt1ucv2JHGDf0L7k1AAwjZTeHDeTbqotFA2DHLKL1ZSqcNup4UdIreljQc3IjepDXTLtZUbaCYLvylp64cOSyL4GH0b0ltsrjEoDO0F5D21kZW3p4ofJINv4BXv2DrcLAMjfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=HUHwEJh/; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 415Copqe024599; Mon, 5 Feb 2024 18:45:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=zYEnE8kdsoqUrl02WqEqTUud6+ujtosVwZejnyNc9bY=; b=HU HwEJh/M6bpbm4Qs7mDPE9AlAekVtDWthHYpx/Ez+EtITzpxGMRiGS9TcZ2n1znL5 X6fFT9s1Yb+JhPFdkZl8asg4keU4Avzm9jAxkbTveB0GncKdUndOhOP4CO2+baSo boHPx5TOjVWAixK6PBXZHCsMIujl/X1pmLatRKmV1CQs0rnDroxNjE6TOlleY9o2 gicjPPD/GRybFcLpHuCZHsRRAdYZ7DGRXxOnapMROjuACPFTJ5Q1cfkUtyNuvSIu G/Q3uEsIDzRHnCrsFCCCnOE4vsP48jh3GSDgBjmpUKBdxWXvoovW0VpTCK2AD6Ya WctjBlu6fOXlC3kduR6Q== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w2r929u35-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 05 Feb 2024 18:45:43 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 415Ijg7b027683 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 5 Feb 2024 18:45:42 GMT Received: from [10.216.24.76] (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 10:45:32 -0800 Message-ID: <7e0886e5-fd2b-4da1-8939-9d5c44673066@quicinc.com> Date: Tue, 6 Feb 2024 00:15:28 +0530 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 06/15] soc: qcom: ice: support for generate, import and prepare key Content-Language: en-US To: Gaurav Kashyap , , , , , , , , , CC: , , , , , , , , , , , , , References: <20240127232436.2632187-1-quic_gaurkash@quicinc.com> <20240127232436.2632187-7-quic_gaurkash@quicinc.com> From: Om Prakash Singh In-Reply-To: <20240127232436.2632187-7-quic_gaurkash@quicinc.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: azfeHzAl6Lc8k87ju2q-JCyMsmS9n4pA X-Proofpoint-ORIG-GUID: azfeHzAl6Lc8k87ju2q-JCyMsmS9n4pA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-05_12,2024-01-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 spamscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402050141 On 1/28/2024 4:44 AM, Gaurav Kashyap wrote: > Wrapped key creation and management using HWKM is currently > supported only through Qualcomm's Trustzone. > Three new SCM calls have already been added in the scm layer > for this purpose. > > This patch adds support for generate, prepare and import key > apis in ICE module and hooks it up the scm calls defined for them. > This will eventually plug into the new IOCTLS added for this > usecase in the block layer. > > Signed-off-by: Gaurav Kashyap > Tested-by: Neil Armstrong > --- > drivers/soc/qcom/ice.c | 66 ++++++++++++++++++++++++++++++++++++++++++ > include/soc/qcom/ice.h | 8 +++++ > 2 files changed, 74 insertions(+) > > diff --git a/drivers/soc/qcom/ice.c b/drivers/soc/qcom/ice.c > index c3b852269dca..93654ae704bf 100644 > --- a/drivers/soc/qcom/ice.c > +++ b/drivers/soc/qcom/ice.c > @@ -21,6 +21,13 @@ > > #define AES_256_XTS_KEY_SIZE 64 > > +/* > + * Wrapped key sizes that HWKM expects and manages is different for different > + * versions of the hardware. > + */ > +#define QCOM_ICE_HWKM_WRAPPED_KEY_SIZE(v) \ > + ((v) == 1 ? 68 : 100) > + > /* QCOM ICE registers */ > #define QCOM_ICE_REG_VERSION 0x0008 > #define QCOM_ICE_REG_FUSE_SETTING 0x0010 > @@ -420,6 +427,65 @@ int qcom_ice_derive_sw_secret(struct qcom_ice *ice, const u8 wkey[], > } > EXPORT_SYMBOL_GPL(qcom_ice_derive_sw_secret); > > +/** > + * qcom_ice_generate_key() - Generate a wrapped key for inline encryption > + * @lt_key: longterm wrapped key that is generated, which is > + * BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE in size. > + * > + * Make a scm call into trustzone to generate a wrapped key for storage > + * encryption using hwkm. > + * > + * Return: lt wrapped key size on success; err on failure. > + */ you might consider to change return value based on comment on patch 3/15. > +int qcom_ice_generate_key(struct qcom_ice *ice, > + u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE]) > +{ > + return qcom_scm_generate_ice_key(lt_key, > + QCOM_ICE_HWKM_WRAPPED_KEY_SIZE(ice->hwkm_version)); > +} > +EXPORT_SYMBOL_GPL(qcom_ice_generate_key); > + > +/** > + * qcom_ice_prepare_key() - Prepare a longterm wrapped key for inline encryption > + * @lt_key: longterm wrapped key that is generated or imported. > + * @lt_key_size: size of the longterm wrapped_key > + * @eph_key: wrapped key returned which has been wrapped with a per-boot ephemeral key, > + * size of which is BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE in size. > + * > + * Make a scm call into trustzone to prepare a wrapped key for storage > + * encryption by rewrapping the longterm wrapped key with a per boot ephemeral > + * key using hwkm. > + * > + * Return: eph wrapped key size on success; err on failure. > + */ > +int qcom_ice_prepare_key(struct qcom_ice *ice, const u8 *lt_key, size_t lt_key_size, > + u8 eph_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE]) > +{ > + return qcom_scm_prepare_ice_key(lt_key, lt_key_size, eph_key, > + QCOM_ICE_HWKM_WRAPPED_KEY_SIZE(ice->hwkm_version)); > +} > +EXPORT_SYMBOL_GPL(qcom_ice_prepare_key); > + > +/** > + * qcom_ice_import_key() - Import a raw key for inline encryption > + * @imp_key: raw key that has to be imported > + * @imp_key_size: size of the imported key > + * @lt_key: longterm wrapped key that is imported, which is > + * BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE in size. > + * > + * Make a scm call into trustzone to import a raw key for storage encryption > + * and generate a longterm wrapped key using hwkm. > + * > + * Return: lt wrapped key size on success; err on failure. > + */ > +int qcom_ice_import_key(struct qcom_ice *ice, const u8 *imp_key, size_t imp_key_size, > + u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE]) > +{ > + return qcom_scm_import_ice_key(imp_key, imp_key_size, lt_key, > + QCOM_ICE_HWKM_WRAPPED_KEY_SIZE(ice->hwkm_version)); > +} > +EXPORT_SYMBOL_GPL(qcom_ice_import_key); > + > static struct qcom_ice *qcom_ice_create(struct device *dev, > void __iomem *base) > { > diff --git a/include/soc/qcom/ice.h b/include/soc/qcom/ice.h > index dabe0d3a1fd0..dcf277d196ff 100644 > --- a/include/soc/qcom/ice.h > +++ b/include/soc/qcom/ice.h > @@ -39,5 +39,13 @@ bool qcom_ice_hwkm_supported(struct qcom_ice *ice); > int qcom_ice_derive_sw_secret(struct qcom_ice *ice, const u8 wkey[], > unsigned int wkey_size, > u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE]); > +int qcom_ice_generate_key(struct qcom_ice *ice, > + u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE]); > +int qcom_ice_prepare_key(struct qcom_ice *ice, > + const u8 *lt_key, size_t lt_key_size, > + u8 eph_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE]); > +int qcom_ice_import_key(struct qcom_ice *ice, > + const u8 *imp_key, size_t imp_key_size, > + u8 lt_key[BLK_CRYPTO_MAX_HW_WRAPPED_KEY_SIZE]); > struct qcom_ice *of_qcom_ice_get(struct device *dev); > #endif /* __QCOM_ICE_H__ */