From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 46E834A2E1C for ; Mon, 6 Jul 2026 09:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783331026; cv=none; b=QofXhR8dhbbbRGnsTusjUHl5bFp3uBVBGWha1XjpTIdiCfLsfzpODpZCELWghRIj6ltgNM0+DBHi7BfedAGav0zTEge5w0cCCXTvll3UeCsxTQ+/+RRP6zl6UHD2/YZ5mLinLgZIvho4SkAnPd+VdQtCOMlzAZgjTGWgYQBXuas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783331026; c=relaxed/simple; bh=e5OSCS1hCSbX+tH25rCEC57zuZiPV0kSnvvU+P0CKT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rkj3sWyl5NZhbh8Qk8DqlaM4GEk4815E5xJAzNtsJ1XYY1tjf+S2LlO6TtKYvQ+tzJFhlAD51KEijmfSZXIkSJ5/BMuX6McfLITP6Xjg5EtDLRiX1xVvxJliUmPAPwMT+eVvXNRe8KdFwEfYRQbCKMmRUS6hWhpaLOOBQtEHdJE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ivihnyrz; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ivihnyrz" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6669IPa03783398; Mon, 6 Jul 2026 09:43:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=F+UMGpZQYY5oCtCad l4DVVSQMMO7Tg14YadLoyTOYQE=; b=ivihnyrz/F8lgQvPQ0D/DyR844NxwS+VZ ua+38yDxOCrEg8OVynQ4MQMpK1G/MHU6bK/xg6CyNzPmVT18GUcheytrBKL+9+Rk Mg5+74/YzY0HhlGZx152cAgBHT96BJpb+c6SVnGPyErv00sFGPAqvcEk8RFzid5o OfrRTAWIlVMkVwbEuPFXfcUU2BqidbwqJt42YCUwL4JxHtgZoxeZTaWCX1VgEHxh g+8o5g8yEaDLkES9lpecUfxfgQyQiKGUxsn/sEo+sONvKwNn1iSMiLdlKEvypaeJ rlFC11eESCBq+8elI+6i4gyPL8dCzXor7iYRn98vwCg5jfTf3dp+w== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4f6sw4gqwt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Jul 2026 09:43:22 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6669YdvM030257; Mon, 6 Jul 2026 09:43:21 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4f7f6xvnqg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Jul 2026 09:43:21 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6669hIh138470016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Jul 2026 09:43:18 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 132542004B; Mon, 6 Jul 2026 09:43:18 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E13B020043; Mon, 6 Jul 2026 09:43:17 +0000 (GMT) Received: from funtu2.ibm.com (unknown [9.111.193.81]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 6 Jul 2026 09:43:17 +0000 (GMT) From: Harald Freudenberger To: richard.henderson@linaro.org, iii@linux.ibm.com, david@kernel.org, thuth@redhat.com, berrange@redhat.com Cc: qemu-s390x@nongnu.org, qemu-devel@nongnu.org, linux-s390@vger.kernel.org, dengler@linux.ibm.com, borntraeger@linux.ibm.com, fcallies@linux.ibm.com, cohuck@redhat.com Subject: [PATCH v10 10/21] target/s390x: Base support for cpacf protected keys Date: Mon, 6 Jul 2026 11:43:03 +0200 Message-ID: <20260706094317.17032-11-freude@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260706094317.17032-1-freude@linux.ibm.com> References: <20260706094317.17032-1-freude@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pTsxVVqC9Bs1EizzAavB_vsjS68Atfja X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzA2MDA5NCBTYWx0ZWRfX6q5fxfOtNokB fM4mthAwMY346pZij64DOUHo/Me1LYMNU9nZhBalOjBUwUdMn8xuKAC1R10jIuJwUKh78w9zij3 dup3fKshpK6oZJm6bFT4Wih6G9xHPjJrX66IUJndiN9OssOYgAAA/f+YUk0KBLR8OcnjiAHwTYm BkB2fYe+ZAD78iNN80TouHnBwFQFmjbZRoE1SQj8Sc4FRoEOjZruzeWbjn8vf9qcvc1uAO9Mxjs 5E0L5GWCo+y0kR4hf9xi5AWMDu69zIM3o+jJ44d8YoiFgT1xaR2uUbrZzzg8HUor+ja0acUJ12Y jAK57/qO65vfhOtWvNDetOq1WkVFqDsabPAgg9Yoa6bvRfmvp1IYVEdzikxL+K6o37p1geOJOQF 6iyfwbdU/HYzdWDNpjW7bcuGQ6vZbqkBMzXGxQNM1mAFrUbM5FP9fOZo1MYlGKggpT2zk/4/f27 Q8j2m9TluLh1RiAtmGA== X-Proofpoint-ORIG-GUID: pTsxVVqC9Bs1EizzAavB_vsjS68Atfja X-Authority-Analysis: v=2.4 cv=FqQ1OWrq c=1 sm=1 tr=0 ts=6a4b78ba cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=pDJEeJrE-AQHYYEhGn0A:9 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzA2MDA5NCBTYWx0ZWRfXzEXoPrD85wdt HBPSE8kqX1k24KQPr7MZyI+HjY+4FwISN90VpcyLWkLQBWQl6eaizTATLy/DCXvDgK0ygg96v+0 WslPovQHMz1ePKr0ziWZK4EOVNxvMk8= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-07-06_01,2026-07-03_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 spamscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607060094 Add base support for cpacf protected key handling. The qemu version provided here is only a fake intended to make protected key available for developing and testing purpose: * The protected key is 'derived' from the clear key by xoring the fixed pattern 0xAAAA... onto the key value. * The AES Wrapping Key Verification Pattern is a fixed value of 32 bytes 0xFACEFACE... Add preprocessor defines for the xor pattern and wkvp used to construct ('encrypt') a protected key from a clear key value with this implementation. Also add some static functions to 'encrypt' from clear key to protected key and 'decrypt' back to cpacf_aes.c. The preprocessor defines shall be used later in testcases to construct and decode protected keys. Signed-off-by: Harald Freudenberger --- target/s390x/tcg/cpacf.h | 25 +++++++++++++++++++++++ target/s390x/tcg/cpacf_aes.c | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/target/s390x/tcg/cpacf.h b/target/s390x/tcg/cpacf.h index e585b77766..df7f258443 100644 --- a/target/s390x/tcg/cpacf.h +++ b/target/s390x/tcg/cpacf.h @@ -254,4 +254,29 @@ int cpacf_aes_xts(CPUS390XState *env, const int mmu_idx, uintptr_t ra, uint64_t *src_ptr_reg, uint64_t *src_len_reg, uint32_t type, uint8_t fc, uint8_t mod); +/* + * Support for protected key cpacf functions. Note that this is + * a fake implementation intended for debugging and development. + * Do not use for production load ! + */ + +/* + * Hard coded pattern xored with the AES clear key + * to 'produce' the protected key. + */ +#define PROTKEY_XOR_PATTERN { \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, \ + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } + +/* + * Hard coded wkvp ("Wrapping Key Verification Pattern") + */ +#define PROTKEY_WKVP { \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E, \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E, \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E, \ + 0x0F, 0x0A, 0x0C, 0x0E, 0x0F, 0x0A, 0x0C, 0x0E } + #endif /* S390X_CPACF_H */ diff --git a/target/s390x/tcg/cpacf_aes.c b/target/s390x/tcg/cpacf_aes.c index 4a28cc3d7c..6702006b66 100644 --- a/target/s390x/tcg/cpacf_aes.c +++ b/target/s390x/tcg/cpacf_aes.c @@ -461,3 +461,42 @@ int cpacf_aes_xts(CPUS390XState *env, const int mmu_idx, uintptr_t ra, return !len ? 0 : 3; } + +/* + * Support for protected key cpacf functions. Note that this is + * a fake implementation intended for debugging and development. + * Do not use for production load ! + */ + +/* + * Hard coded pattern xored with the AES clear key + * to 'produce' the protected key. + */ +static const uint8_t protkey_xor_pattern[32] = PROTKEY_XOR_PATTERN; + +/* + * Hard coded wkvp ("Wrapping Key Verification Pattern") + */ +static const uint8_t protkey_wkvp[32] = PROTKEY_WKVP; + +/* + * 'encrypt' the clear key value into a protected key + * by xor-ing the protkey_xor_pattern onto it. + */ +static void encrypt_clrkey(uint8_t *key, int keysize) +{ + for (int i = 0; i < keysize; i++) { + key[i] ^= protkey_xor_pattern[i]; + } +} + +/* + * 'decrypt' the protected key by reverting the xor + * of the protkey_xor_pattern onto the clear key value. + */ +static void decrypt_protkey(uint8_t *key, int keysize) +{ + for (int i = 0; i < keysize; i++) { + key[i] ^= protkey_xor_pattern[i]; + } +} -- 2.43.0