[PATCH v4 11/15] ufs: host: implement derive sw secret vop in ufs qcom

From: Gaurav Kashyap
Date: Sat Jan 27 2024 - 18:28:29 EST


UFS core defines a variant op to tie the corresponding
derive software secret blk crypto op to the vendor specific
implementation of wrapped keys. This patch implements
this variant op.

Signed-off-by: Gaurav Kashyap <quic_gaurkash@xxxxxxxxxxx>
Tested-by: Neil Armstrong <neil.armstrong@xxxxxxxxxx>
---
drivers/ufs/host/ufs-qcom.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c
index 5c9ba06438a9..e319176accd3 100644
--- a/drivers/ufs/host/ufs-qcom.c
+++ b/drivers/ufs/host/ufs-qcom.c
@@ -176,9 +176,23 @@ static int ufs_qcom_ice_program_key(struct ufs_hba *hba,
return qcom_ice_evict_key(host->ice, slot);
}

+/*
+ * Derive a software secret from a hardware wrapped key. The key is unwrapped in
+ * hardware from trustzone and a software key/secret is then derived from it.
+ */
+static int ufs_qcom_ice_derive_sw_secret(struct ufs_hba *hba, const u8 wkey[],
+ unsigned int wkey_size,
+ u8 sw_secret[BLK_CRYPTO_SW_SECRET_SIZE])
+{
+ struct ufs_qcom_host *host = ufshcd_get_variant(hba);
+
+ return qcom_ice_derive_sw_secret(host->ice, wkey, wkey_size, sw_secret);
+}
+
#else

#define ufs_qcom_ice_program_key NULL
+#define ufs_qcom_ice_derive_sw_secret NULL

static inline void ufs_qcom_ice_enable(struct ufs_qcom_host *host)
{
@@ -1787,6 +1801,7 @@ static const struct ufs_hba_variant_ops ufs_hba_qcom_vops = {
.device_reset = ufs_qcom_device_reset,
.config_scaling_param = ufs_qcom_config_scaling_param,
.program_key = ufs_qcom_ice_program_key,
+ .derive_sw_secret = ufs_qcom_ice_derive_sw_secret,
.reinit_notify = ufs_qcom_reinit_notify,
.mcq_config_resource = ufs_qcom_mcq_config_resource,
.get_hba_mac = ufs_qcom_get_hba_mac,
--
2.43.0